From 683bb23eef8a6e03e1953e477c56acfcc1530038 Mon Sep 17 00:00:00 2001 From: prodrigues Date: Mon, 16 Dec 2024 17:18:53 +0000 Subject: [PATCH] fix blob column type --- .../src/serializer/singlestoreSerializer.ts | 2 ++ drizzle-kit/src/snapshotsDiffer.ts | 13 ---------- drizzle-kit/tests/push/singlestore.test.ts | 3 +-- .../src/singlestore-core/columns/blob.ts | 26 +++++++++++++------ .../src/singlestore-core/columns/index.ts | 2 +- drizzle-orm/type-tests/singlestore/tables.ts | 2 +- 6 files changed, 23 insertions(+), 25 deletions(-) diff --git a/drizzle-kit/src/serializer/singlestoreSerializer.ts b/drizzle-kit/src/serializer/singlestoreSerializer.ts index 0f33f8696..738746120 100644 --- a/drizzle-kit/src/serializer/singlestoreSerializer.ts +++ b/drizzle-kit/src/serializer/singlestoreSerializer.ts @@ -129,6 +129,8 @@ export const generateSingleStoreSnapshot = ( } else { if (typeof column.default === 'string') { columnToSet.default = `'${column.default}'`; + } else if (typeof column.default === 'bigint') { + columnToSet.default = Number(column.default); } else { if (sqlTypeLowered === 'json') { columnToSet.default = `'${JSON.stringify(column.default)}'`; diff --git a/drizzle-kit/src/snapshotsDiffer.ts b/drizzle-kit/src/snapshotsDiffer.ts index 7eec542cf..2db4ad02c 100644 --- a/drizzle-kit/src/snapshotsDiffer.ts +++ b/drizzle-kit/src/snapshotsDiffer.ts @@ -2686,19 +2686,6 @@ export const applyMysqlSnapshotsDiff = async ( }; }; -// This is necessary to make sure that BigInt is serialized to Number -// at the diffSchemasOrTables function. Ohterwise, it will be serialized to BigInt -// and the diff will throw the following error -// "TypeError: Do not know how to serialize a BigInt" - -declare global { - interface BigInt { - toJSON(): Number; - } -} - -BigInt.prototype.toJSON = function () { return Number(this) } - export const applySingleStoreSnapshotsDiff = async ( json1: SingleStoreSchemaSquashed, json2: SingleStoreSchemaSquashed, diff --git a/drizzle-kit/tests/push/singlestore.test.ts b/drizzle-kit/tests/push/singlestore.test.ts index f60011c87..9a78866b5 100644 --- a/drizzle-kit/tests/push/singlestore.test.ts +++ b/drizzle-kit/tests/push/singlestore.test.ts @@ -257,7 +257,7 @@ const singlestoreSuite: DialectSuite = { jsonSimple: blob('json_simple', { mode: 'json' }), jsonColumnNotNull: blob('json_column_not_null', { mode: 'json' }).notNull(), jsonColumnDefault: blob('json_column_default', { mode: 'json' }).default('{"hello":"world"}'), - }) + }), }; const { statements } = await diffTestSchemasPushSingleStore( @@ -268,7 +268,6 @@ const singlestoreSuite: DialectSuite = { 'drizzle', false, ); - console.log(statements); expect(statements.length).toBe(0); expect(statements).toEqual([]); diff --git a/drizzle-orm/src/singlestore-core/columns/blob.ts b/drizzle-orm/src/singlestore-core/columns/blob.ts index a7851216f..f8125602a 100644 --- a/drizzle-orm/src/singlestore-core/columns/blob.ts +++ b/drizzle-orm/src/singlestore-core/columns/blob.ts @@ -29,7 +29,10 @@ export class SingleStoreBigIntBuilder( table: AnySingleStoreTable<{ name: TTableName }>, ): SingleStoreBigInt> { - return new SingleStoreBigInt>(table, this.config as ColumnBuilderRuntimeConfig); + return new SingleStoreBigInt>( + table, + this.config as ColumnBuilderRuntimeConfig, + ); } } @@ -48,8 +51,8 @@ export class SingleStoreBigInt> extends SingleStoreColumn { +export class SingleStoreBlobJson> + extends SingleStoreColumn +{ static override readonly [entityKind]: string = 'SingleStoreBlobJson'; getSQLType(): string { @@ -104,8 +109,8 @@ export class SingleStoreBlobJson( table: AnySingleStoreTable<{ name: TTableName }>, ): SingleStoreBlobBuffer> { - return new SingleStoreBlobBuffer>(table, this.config as ColumnBuilderRuntimeConfig); + return new SingleStoreBlobBuffer>( + table, + this.config as ColumnBuilderRuntimeConfig, + ); } } -export class SingleStoreBlobBuffer> extends SingleStoreColumn { +export class SingleStoreBlobBuffer> + extends SingleStoreColumn +{ static override readonly [entityKind]: string = 'SingleStoreBlobBuffer'; getSQLType(): string { diff --git a/drizzle-orm/src/singlestore-core/columns/index.ts b/drizzle-orm/src/singlestore-core/columns/index.ts index 709cf858d..1c3ba71f3 100644 --- a/drizzle-orm/src/singlestore-core/columns/index.ts +++ b/drizzle-orm/src/singlestore-core/columns/index.ts @@ -1,6 +1,6 @@ -export * from './blob.ts'; export * from './bigint.ts'; export * from './binary.ts'; +export * from './blob.ts'; export * from './boolean.ts'; export * from './char.ts'; export * from './common.ts'; diff --git a/drizzle-orm/type-tests/singlestore/tables.ts b/drizzle-orm/type-tests/singlestore/tables.ts index edb7f2e7a..33b2171bc 100644 --- a/drizzle-orm/type-tests/singlestore/tables.ts +++ b/drizzle-orm/type-tests/singlestore/tables.ts @@ -2,9 +2,9 @@ import { type Equal, Expect } from 'type-tests/utils.ts'; import type { BuildColumn } from '~/column-builder.ts'; import { eq } from '~/expressions.ts'; import { - blob, bigint, binary, + blob, boolean, char, customType,