drizzle-team / drizzle-team/drizzle-orm

[BUG]: transaction not commiting

Open
#1,704 18 comments 0 reactions 1 assignee Claimed by @Angelelz View on GitHub
bug db/postgres driver/pg driver/postgresjs priority qb/transactions
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### What version of `drizzle-orm` are you using?

0.29.1

### What version of `drizzle-kit` are you using?

0.20.7

### Describe the Bug

```ts
import { env } from "@locus/env"
import { drizzle } from "drizzle-orm/postgres-js"
import postgres from "postgres"
import * as schema from "./schema/schema"

export const queryClient = postgres(env.DATABASE_URL)

export const db = drizzle(queryClient, {
schema: schema,
logger: true,
})
```
this is how I have my client setup

```ts
import { sql } from "drizzle-orm"
import { db } from "../.."
import { family } from "../../schema/family"
import { member } from "../../schema/member"

export const insertFamily = async (name: string, userId: string) => {
return await db.transaction(async (tx) => {
const familyData = await tx
.insert(family)
.values({
name,
adminId: userId,
})
.returning()
await tx.insert(member).values({
userId,
isAdmin: true,
familyId: familyData[0].id,
})
db.execute(sql`commit`)
return familyData[0]
})
}
```
this is my insert query
Doesn't save the data up, `familyData[0]` is returned fine though.
the logs -> https://srcb.in/3TQV8W2v4J

### Expected behavior

Should save the data after the transaction ends.

### Environment & setup

Node version `v20.4.0`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.