-
-
Notifications
You must be signed in to change notification settings - Fork 688
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
[FEATURE]: bigint mode in SQLite integer column #1980
Comments
One complication with this will be supporting all the different sqlite drivers. For example, better-sqlite3 has some documentation on how to set up BigInt, but it seems to be sort of an all-or-nothing thing, not column specific. So turning on BigInt for everything would mean that all the other int types would need to convert bigints to normal javascript numbers in order for the types to work. |
Will try and create a PR for this this weekend, but not sure what to do about the complication @ksmithut mentioned. |
Did some digging into this and it looks likes most drivers have a configuration option on how SQLite integers are converted to JavaScript values for the entire database. Since we do not have the ability to configure this per column and not all drivers support conversion to big ints, I suggest we add a new So for example, with the libsql driver you would do this: import { drizzle } from 'drizzle-orm/libsql';
import { createClient } from '@libsql/client';
const client = createClient({
url: "DATABASE_URL",
authToken: "DATABASE_AUTH_TOKEN",
intMode: "bigint"
});
const db = drizzle(client);
// all integer columns would use the bigint column
const table = sqliteTable('table', {
id: bigint('id')
});
// you can customize integer mode to be number, boolean, timestamp, timestamp_ms
bigint('id', { mode: 'number' })
bigint('id', { mode: 'boolean' })
bigint('id', { mode: 'timestamp_ms' })
bigint('id', { mode: 'timestamp' }) // Date @dankochetov I can create a PR if you are okay with this aproach |
@MrRahulRamkumar If the int mode is set to BigInt, are What would happen to the (existing) const client = createClient({ intMode: 'bigint' });
const db = drizzle(client);
const db = drizzle(client, { schema }); // Check for the schema here? If BigInt → Number conversion has minimal performance impacts, this could be possible: // Always returns a Number
// If the driver returns Number, keep
// In the driver returns BigInt, covnert
integer('id', { mode: 'number' });
// Always returns a BigInt
// If the driver returns Number, convert
// In the driver returns BigInt, keep
integer('id', { mode: 'bigint' }); Values larger than the |
@hyunbinseo if the int mode is set to Your suggestion would work but we would need to make sure that all integer modes (number, boolean, timestamp, timestamp_ms) are also updated to handle big ints being returned by the driver. There might also be some cases where the developer would have to manually handle big ints being returned by drizzle. I will create a PR that implements what you suggested. Let's see what the maintainers think. |
+1 |
Any news on the PR? |
Honestly, I would almost consider this a BUG, not just an enhancement (as this issue has been labeled). Could lead to a security vulnerability or critical system failure later down the line. |
This is the main reason I can't use something like Snowflake Id in SQLite with turso. If a table holds the primary key as blob, it would be unqueriable (see #2902 ), but Drizzle won't let us set it as a integer, despite SQLite supporting up to 8 bytes integers |
Describe what you want
9223372036854775807
9007199254740991
Allow SQLite integer columns to be inferred as JavaScript BigInt.
PostgreSQL and MySQL support this feature in the bigint column.
This will be useful for Autoincrement columns that can become large.
Related issues:
bigint
and addtimestamp_ms
#739The text was updated successfully, but these errors were encountered: