Skip to content

Commit 3a37044

Browse files
authored
BREAKING(sqlite): bump deno-sqlite to v2.2.1 and fix handling for int8/bigint/unsigned big int (#88)
1 parent 2dd2274 commit 3a37044

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

dem.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
{
4141
"protocol": "https",
4242
"path": "deno.land/x/sqlite",
43-
"version": "v2.1.0",
43+
"version": "v2.2.1",
4444
"files": [
4545
"/mod.ts"
4646
]

src/driver/sqlite-abstract/AbstractSqliteDriver.ts

+16
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ export abstract class AbstractSqliteDriver implements Driver {
263263
} else if (columnMetadata.type === "simple-enum") {
264264
return DateUtils.simpleEnumToString(value);
265265
}
266+
// Some types are treated differently from the original typeorm.
267+
else if (typeof value === "bigint") {
268+
// Unlike node-sqlite, deno-sqlite uses BigInt for large numbers.
269+
// https://github.com/dyedgreen/deno-sqlite/pull/67
270+
return value.toString();
271+
}
266272

267273
return value;
268274
}
@@ -320,6 +326,16 @@ export abstract class AbstractSqliteDriver implements Driver {
320326
value = DateUtils.stringToSimpleEnum(value, columnMetadata);
321327

322328
}
329+
// Some types are treated differently from the original typeorm.
330+
else if (
331+
columnMetadata.type === "int8" ||
332+
columnMetadata.type === "bigint" ||
333+
columnMetadata.type === "unsigned big int" ||
334+
columnMetadata.type === BigInt) {
335+
// Unlike node-sqlite, deno-sqlite uses BigInt for large numbers.
336+
// https://github.com/dyedgreen/deno-sqlite/pull/67
337+
value = BigInt(value);
338+
}
323339

324340
if (columnMetadata.transformer)
325341
value = ApplyValueTransformers.transformFrom(columnMetadata.transformer, value);

src/driver/types/ColumnTypes.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,5 @@ export type ColumnType = WithPrecisionColumnType
207207
|DateConstructor
208208
|NumberConstructor
209209
|StringConstructor
210-
|Uint8ArrayConstructor; // TODO(uki001) This type is not fully tested yet.
210+
|Uint8ArrayConstructor
211+
|BigIntConstructor;

test/functional/database-schema/column-types/sqlite/column-types-sqlite.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,19 @@ describe("database schema > column types > sqlite", () => {
3232
post.integer = 2147483647;
3333
post.int = 2147483647;
3434
post.int2 = 32767;
35-
post.int8 = 8223372036854775807;
35+
post.int8 = 8223372036854775807n; // Unlike node-sqlite, deno-sqlite uses BigInt for large numbers.
3636
post.tinyint = 127;
3737
post.smallint = 32767;
3838
post.mediumint = 8388607;
39-
post.bigint = 8223372036854775807;
40-
post.unsignedBigInt = 8223372036854775807;
39+
post.bigint = 8223372036854775807n; // Unlike node-sqlite, deno-sqlite uses BigInt for large numbers.
40+
post.unsignedBigInt = 8223372036854775807n; // Unlike node-sqlite, deno-sqlite uses BigInt for large numbers.
4141
post.character = "A";
4242
post.varchar = "This is varchar";
4343
post.varyingCharacter = "This is varying character";
4444
post.nchar = "This is nchar";
4545
post.nativeCharacter = "This is native character";
4646
post.nvarchar = "This is nvarchar";
47-
// TODO(uki00a) not fully tested yet.
48-
post.blob = encoder.encode("This is blob");/* new Buffer("This is blob"); */
47+
post.blob = encoder.encode("This is blob");
4948
post.clob = "This is clob";
5049
post.text = "This is text";
5150
post.real = 10.5;

test/functional/database-schema/column-types/sqlite/entity/Post.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class Post {
2626
int2!: number;
2727

2828
@Column("int8")
29-
int8!: number;
29+
int8!: BigInt;
3030

3131
@Column("tinyint")
3232
tinyint!: number;
@@ -38,10 +38,10 @@ export class Post {
3838
mediumint!: number;
3939

4040
@Column("bigint")
41-
bigint!: number;
41+
bigint!: BigInt;
4242

4343
@Column("unsigned big int")
44-
unsignedBigInt!: number;
44+
unsignedBigInt!: BigInt;
4545

4646
// -------------------------------------------------------------------------
4747
// Character Types
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "https://deno.land/x/sqlite@v2.1.0/mod.ts";
1+
export * from "https://deno.land/x/sqlite@v2.2.1/mod.ts";

0 commit comments

Comments
 (0)