diff --git a/packages/db/src/core/queries.ts b/packages/db/src/core/queries.ts index ec2d80f7e6..7b94975111 100644 --- a/packages/db/src/core/queries.ts +++ b/packages/db/src/core/queries.ts @@ -11,7 +11,7 @@ import { type TextField, } from '../core/types.js'; import { bold } from 'kleur/colors'; -import { SQL, sql } from 'drizzle-orm'; +import { type SQL, sql } from 'drizzle-orm'; import { SQLiteAsyncDialect } from 'drizzle-orm/sqlite-core'; import type { AstroIntegrationLogger } from 'astro'; import type { DBUserConfig } from '../core/types.js'; @@ -222,7 +222,7 @@ function toDefault(def: T | SQL): string { function getDefaultValueSql(columnName: string, column: DBFieldWithDefault): string { if (isSerializedSQL(column.default)) { - return sqlite.sqlToQuery(new SQL(column.default.queryChunks)).sql; + return column.default.sql; } switch (column.type) { diff --git a/packages/db/src/core/types.ts b/packages/db/src/core/types.ts index c8aea5fe69..c1d76ff39e 100644 --- a/packages/db/src/core/types.ts +++ b/packages/db/src/core/types.ts @@ -1,4 +1,4 @@ -import { type SQLiteInsertValue } from 'drizzle-orm/sqlite-core'; +import { SQLiteAsyncDialect, type SQLiteInsertValue } from 'drizzle-orm/sqlite-core'; import type { InferSelectModel } from 'drizzle-orm'; import { collectionToTable, type SqliteDB, type Table } from '../runtime/index.js'; import { z, type ZodTypeDef } from 'zod'; @@ -10,10 +10,12 @@ export type MaybePromise = T | Promise; export type MaybeArray = T | T[]; // Transform to serializable object for migration files +const sqlite = new SQLiteAsyncDialect(); + const sqlSchema = z.instanceof(SQL).transform( (sqlObj): SerializedSQL => ({ [SERIALIZED_SQL_KEY]: true, - queryChunks: sqlObj.queryChunks, + sql: sqlite.sqlToQuery(sqlObj).sql, }) ); diff --git a/packages/db/src/runtime/index.ts b/packages/db/src/runtime/index.ts index 2160477232..c763cb7727 100644 --- a/packages/db/src/runtime/index.ts +++ b/packages/db/src/runtime/index.ts @@ -149,7 +149,7 @@ function columnMapper(fieldName: string, field: DBField, isJsonSerializable: boo function handleSerializedSQL(def: T | SerializedSQL) { if (isSerializedSQL(def)) { - return new SQL(def.queryChunks); + return sql.raw(def.sql); } return def; } diff --git a/packages/db/src/runtime/types.ts b/packages/db/src/runtime/types.ts index 17136e37bc..e0d20fd1cc 100644 --- a/packages/db/src/runtime/types.ts +++ b/packages/db/src/runtime/types.ts @@ -101,7 +101,7 @@ export type Table< export const SERIALIZED_SQL_KEY = '__serializedSQL'; export type SerializedSQL = { [SERIALIZED_SQL_KEY]: true; - queryChunks: SQLChunk[]; + sql: string; }; export function isSerializedSQL(value: any): value is SerializedSQL {