diff --git a/.changeset/mighty-peas-reply.md b/.changeset/mighty-peas-reply.md new file mode 100644 index 0000000000..408b43580d --- /dev/null +++ b/.changeset/mighty-peas-reply.md @@ -0,0 +1,5 @@ +--- +"@astrojs/db": patch +--- + +Fix type error in db/seed.ts file before type generation is run. diff --git a/packages/db/src/core/integration/typegen.ts b/packages/db/src/core/integration/typegen.ts index cc3664a6e9..ad0cc915fa 100644 --- a/packages/db/src/core/integration/typegen.ts +++ b/packages/db/src/core/integration/typegen.ts @@ -15,9 +15,6 @@ export async function typegen(astroConfig: Pick generateTableType(name, collection)) .join('\n')} diff --git a/packages/db/src/runtime/config.ts b/packages/db/src/runtime/config.ts index 04229eb219..a93aaa43df 100644 --- a/packages/db/src/runtime/config.ts +++ b/packages/db/src/runtime/config.ts @@ -8,6 +8,9 @@ import type { TableConfig, TextColumnOpts, } from '../core/types.js'; +import { sql as _sql } from 'drizzle-orm'; + +export type { LibSQLDatabase } from 'drizzle-orm/libsql'; function createColumn>(type: S, schema: T) { return { @@ -45,7 +48,10 @@ export function defineDb(userConfig: DBConfigInput) { return userConfig; } -export { NOW, TRUE, FALSE } from './index.js'; +// Exports a few common expressions +export const NOW = _sql`CURRENT_TIMESTAMP`; +export const TRUE = _sql`TRUE`; +export const FALSE = _sql`FALSE`; export { sql, diff --git a/packages/db/src/runtime/index.ts b/packages/db/src/runtime/index.ts index 6463f5f0e0..4688f250e3 100644 --- a/packages/db/src/runtime/index.ts +++ b/packages/db/src/runtime/index.ts @@ -1,5 +1,4 @@ import { type ColumnBuilderBaseConfig, type ColumnDataType, sql } from 'drizzle-orm'; -import type { LibSQLDatabase } from 'drizzle-orm/libsql'; import { type IndexBuilder, type SQLiteColumnBuilderBase, @@ -12,8 +11,6 @@ import { import { type DBColumn, type DBTable } from '../core/types.js'; import { type SerializedSQL, isSerializedSQL } from './types.js'; -export { sql }; -export type SqliteDB = LibSQLDatabase; export type { Table } from './types.js'; export { createRemoteDatabaseClient, createLocalDatabaseClient } from './db-client.js'; export { seedLocal } from './seed-local.js'; @@ -22,11 +19,6 @@ export function hasPrimaryKey(column: DBColumn) { return 'primaryKey' in column.schema && !!column.schema.primaryKey; } -// Exports a few common expressions -export const NOW = sql`CURRENT_TIMESTAMP`; -export const TRUE = sql`TRUE`; -export const FALSE = sql`FALSE`; - const dateType = customType<{ data: Date; driverData: string }>({ dataType() { return 'text'; diff --git a/packages/db/test/unit/column-queries.test.js b/packages/db/test/unit/column-queries.test.js index d7f65dff27..bc2ab0ee01 100644 --- a/packages/db/test/unit/column-queries.test.js +++ b/packages/db/test/unit/column-queries.test.js @@ -6,8 +6,7 @@ import { } from '../../dist/core/cli/migration-queries.js'; import { MIGRATION_VERSION } from '../../dist/core/consts.js'; import { tableSchema } from '../../dist/core/schemas.js'; -import { column, defineTable } from '../../dist/runtime/config.js'; -import { NOW } from '../../dist/runtime/index.js'; +import { column, defineTable, NOW } from '../../dist/runtime/config.js'; const TABLE_NAME = 'Users'; diff --git a/packages/db/virtual.d.ts b/packages/db/virtual.d.ts index b97d2a19f2..e6825bd466 100644 --- a/packages/db/virtual.d.ts +++ b/packages/db/virtual.d.ts @@ -1,6 +1,9 @@ declare module 'astro:db' { type RuntimeConfig = typeof import('./dist/_internal/runtime/config.js'); + export const db: import('./dist/_internal/runtime/config.js').LibSQLDatabase; + export const dbUrl: string; + export const sql: RuntimeConfig['sql']; export const NOW: RuntimeConfig['NOW']; export const TRUE: RuntimeConfig['TRUE'];