Bryan3
Bryan3
Explore posts from servers
DTDrizzle Team
Created by Bryan3 on 9/29/2023 in #help
Delete operation in transaction sometimes not deleting row in database
I've found that I'm occasional getting this error in the Supabase postgres logs password authentication failed for user "postgres" Could this be causing the issue?
6 replies
DTDrizzle Team
Created by Bryan3 on 9/29/2023 in #help
Delete operation in transaction sometimes not deleting row in database
Currently patched the issue by checking if object exists after the deleting and deleting it again if it still exists
await db.transaction(async (tx) => {
// Update the organizationId of all related contacts to new id
await tx
.update(contact)
.set({ organizationId: input.newId })
.where(eq(contact.organizationId, input.id));
// Delete the organization with old id
data = await tx
.delete(organization)
.where(eq(organization.id, input.id))
.returning();
});

// check if organization still exists
const deletedOrg = await db
.select({ id: organization.id })
.from(organization)
.where(eq(organization.id, input.id));

// call delete again if can still find organization
if (deletedOrg[0] && deletedOrg[0].id === input.id) {
console.log("contact not deleted yet, deleting again");
await db
.delete(organization)
.where(eq(organization.id, input.id))
.returning();
}
await db.transaction(async (tx) => {
// Update the organizationId of all related contacts to new id
await tx
.update(contact)
.set({ organizationId: input.newId })
.where(eq(contact.organizationId, input.id));
// Delete the organization with old id
data = await tx
.delete(organization)
.where(eq(organization.id, input.id))
.returning();
});

// check if organization still exists
const deletedOrg = await db
.select({ id: organization.id })
.from(organization)
.where(eq(organization.id, input.id));

// call delete again if can still find organization
if (deletedOrg[0] && deletedOrg[0].id === input.id) {
console.log("contact not deleted yet, deleting again");
await db
.delete(organization)
.where(eq(organization.id, input.id))
.returning();
}
6 replies
DTDrizzle Team
Created by Bryan3 on 9/28/2023 in #help
How to include all fields in partial select syntax
Thanks, found it searching the earlier questions on the server
10 replies
DTDrizzle Team
Created by Bryan3 on 9/28/2023 in #help
How to include all fields in partial select syntax
10 replies
DTDrizzle Team
Created by Bryan3 on 9/28/2023 in #help
How to include all fields in partial select syntax
I used getTableColumns() to solve the issue
const { ...rest } = getTableColumns(contact);

const response = (await db
.select({
...rest,
organization: {
name: organization.name,
},
})
.from(contact)
.leftJoin(
organization,
eq(contact.organizationId, organization.id),
))
const { ...rest } = getTableColumns(contact);

const response = (await db
.select({
...rest,
organization: {
name: organization.name,
},
})
.from(contact)
.leftJoin(
organization,
eq(contact.organizationId, organization.id),
))
10 replies