Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Unable to Use BigInt Types with Bun and Drizzle #2603

Closed
saeta-eth opened this issue Jul 8, 2024 · 2 comments
Closed

[BUG]: Unable to Use BigInt Types with Bun and Drizzle #2603

saeta-eth opened this issue Jul 8, 2024 · 2 comments
Assignees
Labels
bug Something isn't working db/sqlite driver/bun-sqlite priority Will be worked on next qb/crud

Comments

@saeta-eth
Copy link

saeta-eth commented Jul 8, 2024

What version of drizzle-orm are you using?

^0.31.2

What version of drizzle-kit are you using?

No response

Describe the Bug

I have been experimenting with Bun and Drizzle for the past few days, and I have encountered an issue when trying to use BigInt types. To illustrate the problem, I have simplified my code example below.

Schema Definition (schema.ts):

import { sqliteTable, text, integer, blob } from "drizzle-orm/sqlite-core";

const table = sqliteTable("table", {
  id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
  bigInt: blob("big_int", { mode: "bigint" }).notNull(),
});

Store Data (store.ts):

const myBigInt = {
   bigInt: BigInt(100)
}

await db.insert(table).values(myBigInt);

Retrieve Data (retrieve.ts):

const results = await db.select().from(table).all()

When attempting to retrieve the stored data, I encounter the following error:

23 |             node[pathChunk] = {};
24 |           }
25 |           node = node[pathChunk];
26 |         } else {
27 |           const rawValue = row[columnIndex];
28 |           const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
                                                                                  ^
SyntaxError: Failed to parse String to BigInt
      at /Users/saeta/Projects/example/node_modules/drizzle-orm/utils.js:28:78
      at reduce (:1:11)
      at mapResultRow (/Users/saeta/Projects/example/node_modules/drizzle-orm/utils.js:9:26)
      at map (:1:11)

It appears the error occurs at this line in the Drizzle ORM utility:

const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);

Am I doing something wrong? Thank you!

Expected behavior

A SyntaxError is thrown when trying to parse the stored BigInt value.

Environment & setup

MacOS M3 Max
MacOS Sonoma 14.5

@saeta-eth saeta-eth added the bug Something isn't working label Jul 8, 2024
@saeta-eth
Copy link
Author

Please let me know if I can add any more information that may be helpful in resolving this issue, ty!

@AndriiSherman
Copy link
Member

was fixed in drizzle-orm@0.36.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working db/sqlite driver/bun-sqlite priority Will be worked on next qb/crud
Projects
None yet
Development

No branches or pull requests

3 participants