drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Return `changes/lastInsertRowid` as opposed to `void` when using Bun Sqlite driver

Open
#3,023 0 comments 6 reactions 0 assignees View on GitHub
db/sqlite driver/bun-sqlite enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe what you want

As of Bun 1.1.14 `db.insert` returns a result in the form:

```ts
{ changes: number, lastInsertRowid: number }
```

(see https://bun.sh/blog/bun-v1.1.14#track-changes-with-query-run-sql )

However Drizzle `db.insert()` returns void, causing the following TS error:
`Property 'lastInsertRowid' does not exist on type 'void'.` in the following example:

```ts
const result = db.insert(users).values(user).run();
console.log(result.lastInsertRowid);
```

A workaround would be:
```ts
const result = db.insert(users).values(user).run() as unknown as { changes: number; lastInsertRowid: number };
console.log(result.lastInsertRowid);
```

It would be great if the return value from the sqlite driver could be passed on so TypeScript understands it.

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.