diff --git a/drizzle-orm/src/sqlite-core/columns/integer.ts b/drizzle-orm/src/sqlite-core/columns/integer.ts index 13d52c0eaf..87010a4dff 100644 --- a/drizzle-orm/src/sqlite-core/columns/integer.ts +++ b/drizzle-orm/src/sqlite-core/columns/integer.ts @@ -201,12 +201,52 @@ export class SQLiteBoolean = SQLiteIntegerBigIntBuilder<{ + name: TName; + dataType: 'bigint'; + columnType: 'SQLiteIntegerBigInt'; + data: bigint; + driverParam: string; + enumValues: undefined; +}>; + +export class SQLiteIntegerBigIntBuilder> + extends SQLiteBaseIntegerBuilder +{ + static override readonly [entityKind]: string = 'SQLiteIntegerBigIntBuilder'; + + constructor(name: T['name']) { + super(name, 'bigint', 'SQLiteIntegerBigInt'); + } + + /** @internal */ + override build( + table: AnySQLiteTable<{ name: TTableName }>, + ): SQLiteIntegerBigInt> { + return new SQLiteIntegerBigInt>( + table, + this.config as ColumnBuilderRuntimeConfig, + ); + } +} + +export class SQLiteIntegerBigInt> + extends SQLiteBaseInteger +{ + static override readonly [entityKind]: string = 'SQLiteIntegerBigInt'; + + override mapFromDriverValue = BigInt; + + override mapToDriverValue = String; +} + export interface IntegerConfig< - TMode extends 'number' | 'timestamp' | 'timestamp_ms' | 'boolean' = + TMode extends 'number' | 'timestamp' | 'timestamp_ms' | 'boolean' | 'bigint' = | 'number' | 'timestamp' | 'timestamp_ms' - | 'boolean', + | 'boolean' + | 'bigint', > { mode: TMode; } @@ -216,12 +256,14 @@ export function integer( config?: IntegerConfig, ): Or, Equal> extends true ? SQLiteTimestampBuilderInitial<''> : Equal extends true ? SQLiteBooleanBuilderInitial<''> + : Equal extends true ? SQLiteIntegerBigIntBuilderInitial<''> : SQLiteIntegerBuilderInitial<''>; export function integer( name: TName, config?: IntegerConfig, ): Or, Equal> extends true ? SQLiteTimestampBuilderInitial : Equal extends true ? SQLiteBooleanBuilderInitial + : Equal extends true ? SQLiteIntegerBigIntBuilderInitial : SQLiteIntegerBuilderInitial; export function integer(a?: string | IntegerConfig, b?: IntegerConfig) { const { name, config } = getColumnNameAndConfig(a, b); @@ -231,6 +273,9 @@ export function integer(a?: string | IntegerConfig, b?: IntegerConfig) { if (config?.mode === 'boolean') { return new SQLiteBooleanBuilder(name, config.mode); } + if (config?.mode === 'bigint') { + return new SQLiteIntegerBigIntBuilder(name); + } return new SQLiteIntegerBuilder(name); } diff --git a/drizzle-orm/src/sqlite-core/dialect.ts b/drizzle-orm/src/sqlite-core/dialect.ts index 2f4a0c366d..e80c0306d1 100644 --- a/drizzle-orm/src/sqlite-core/dialect.ts +++ b/drizzle-orm/src/sqlite-core/dialect.ts @@ -185,7 +185,7 @@ export abstract class SQLiteDialect { } } else if (is(field, Column)) { const tableName = field.table[Table.Symbol.Name]; - if (field.columnType === 'SQLiteNumericBigInt') { + if (field.columnType === 'SQLiteNumericBigInt' || field.columnType === 'SQLiteIntegerBigInt') { if (isSingleTable) { chunk.push(sql`cast(${sql.identifier(this.casing.getColumnCasing(field))} as text)`); } else { diff --git a/integration-tests/tests/sqlite/sqlite-common.ts b/integration-tests/tests/sqlite/sqlite-common.ts index 3af9c64b4d..6211219edd 100644 --- a/integration-tests/tests/sqlite/sqlite-common.ts +++ b/integration-tests/tests/sqlite/sqlite-common.ts @@ -70,6 +70,9 @@ const allTypesTable = sqliteTable('all_types', { timeMs: integer('time_ms', { mode: 'timestamp_ms', }), + integerBig: integer('integer_big', { + mode: 'bigint', + }), bigint: blob('bigint', { mode: 'bigint', }), @@ -3283,6 +3286,7 @@ export function tests() { \`bool\` integer, \`time\` integer, \`time_ms\` integer, + \`integer_big\` integer, \`bigint\` blob, \`buffer\` blob, \`json\` blob, @@ -3336,6 +3340,7 @@ export function tests() { text: 'TEXT STRING', time: new Date(1741743161623), timeMs: new Date(1741743161623), + integerBig: 5044565289845416380n, }); const rawRes = await db.select().from(allTypesTable); @@ -3347,6 +3352,7 @@ export function tests() { bool: boolean | null; time: Date | null; timeMs: Date | null; + integerBig: bigint | null; bigint: bigint | null; buffer: Buffer | null; json: unknown; @@ -3364,6 +3370,7 @@ export function tests() { bool: true, time: new Date('2025-03-12T01:32:41.000Z'), timeMs: new Date('2025-03-12T01:32:41.623Z'), + integerBig: 5044565289845416380n, bigint: 5044565289845416380n, buffer: Buffer.from([ 0x44,