drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

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

Open MarByteBeep opened this issue 1 year ago • 0 comments

Describe what you want

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

{ 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:

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

A workaround would be:

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.

MarByteBeep avatar Sep 28 '24 16:09 MarByteBeep