diff --git a/packages/db/src/core/queries.ts b/packages/db/src/core/queries.ts index cf4436e0ab..bae6de518b 100644 --- a/packages/db/src/core/queries.ts +++ b/packages/db/src/core/queries.ts @@ -219,11 +219,11 @@ export function hasDefault(field: DBField): field is DBFieldWithDefault { function toStringDefault(def: T | SQL): string { const type = typeof def; - if(def instanceof SQL) { + if (def instanceof SQL) { return sqlite.sqlToQuery(def).sql; - } else if(type === 'string') { + } else if (type === 'string') { return sqlite.escapeString(def as string); - } else if(type === 'boolean') { + } else if (type === 'boolean') { return def ? 'TRUE' : 'FALSE'; } else { return def + ''; @@ -233,11 +233,8 @@ function toStringDefault(def: T | SQL): string { function getDefaultValueSql(columnName: string, column: DBFieldWithDefault): string { switch (column.type) { case 'boolean': - return toStringDefault(column.default); case 'number': - return `${column.default ? toStringDefault(column.default) : 'AUTOINCREMENT'}`; case 'text': - return toStringDefault(column.default); case 'date': return toStringDefault(column.default); case 'json': { diff --git a/packages/db/src/runtime/index.ts b/packages/db/src/runtime/index.ts index 00bac04249..67331573d2 100644 --- a/packages/db/src/runtime/index.ts +++ b/packages/db/src/runtime/index.ts @@ -24,7 +24,7 @@ export function hasPrimaryKey(field: DBField) { // Exports a few common expressions export const NOW = sql`CURRENT_TIMESTAMP`; export const TRUE = sql`TRUE`; -export const FALSE = sql`FALSE` +export const FALSE = sql`FALSE`; const dateType = customType<{ data: Date; driverData: string }>({ dataType() { @@ -105,8 +105,7 @@ function columnMapper(fieldName: string, field: DBField, isJsonSerializable: boo case 'number': { c = integer(fieldName); if (field.default !== undefined) c = c.default(field.default); - // TODO: remove autoincrement per https://www.sqlite.org/autoinc.html - if (field.primaryKey === true) c = c.primaryKey({ autoIncrement: true }); + if (field.primaryKey === true) c = c.primaryKey(); break; } case 'boolean': { @@ -132,9 +131,9 @@ function columnMapper(fieldName: string, field: DBField, isJsonSerializable: boo c = c.default( def instanceof SQL ? def - // default comes pre-transformed to an ISO string for D1 storage. + : // default comes pre-transformed to an ISO string for D1 storage. // parse back to a Date for Drizzle. - : z.coerce.date().parse(field.default) + z.coerce.date().parse(field.default) ); } } @@ -152,8 +151,8 @@ function isSerializedSQL(obj: unknown): boolean { } function convertSerializedSQL(obj: T): SQL | T { - if(isSerializedSQL(obj)) { - return new SQL((obj as any).queryChunks) + if (isSerializedSQL(obj)) { + return new SQL((obj as any).queryChunks); } else { return obj; }