Skip to content

Commit

Permalink
fix: use tx instead of db when inside a tx
Browse files Browse the repository at this point in the history
  • Loading branch information
karrui committed Oct 3, 2024
1 parent dc3c981 commit f69ee9e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions apps/studio/src/server/modules/resource/resource.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const updatePageById = (
}

export const updateBlobById = async (
db: Transaction<DB>,
tx: Transaction<DB>,
{
pageId,
content,
Expand All @@ -174,7 +174,7 @@ export const updateBlobById = async (
siteId: number
},
) => {
const page = await db
const page = await tx
.selectFrom("Resource")
.where("Resource.id", "=", String(pageId))
.where("siteId", "=", siteId)
Expand All @@ -192,20 +192,20 @@ export const updateBlobById = async (

if (!page.draftBlobId) {
// NOTE: no draft for this yet, need to create a new one
const newBlob = await db
const newBlob = await tx
.insertInto("Blob")
.values({ content: jsonb(content) })
.returning("id")
.executeTakeFirstOrThrow()
await db
await tx
.updateTable("Resource")
.where("id", "=", String(pageId))
.set({ draftBlobId: newBlob.id })
.execute()
}

return (
db
tx
.updateTable("Blob")
// NOTE: This works because a page has a 1-1 relation with a blob
.set({ content: jsonb(content) })
Expand Down Expand Up @@ -387,7 +387,7 @@ export const getResourcePermalinkTree = async (
return []
}

const resourcePermalinks = await db
const resourcePermalinks = await tx
.withRecursive("Ancestors", (eb) =>
eb
// Base case: Get the actual resource
Expand Down

0 comments on commit f69ee9e

Please sign in to comment.