Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix type error in seed stub on initial setup #10457

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mighty-peas-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---

Fix type error in db/seed.ts file before type generation is run.
3 changes: 0 additions & 3 deletions packages/db/src/core/integration/typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ export async function typegen(astroConfig: Pick<AstroConfig, 'root' | 'integrati
export async function typegenInternal({ tables, root }: { tables: DBTables; root: URL }) {
const content = `// This file is generated by Astro DB
declare module 'astro:db' {
export const db: import(${RUNTIME_IMPORT}).SqliteDB;
export const dbUrl: string;

${Object.entries(tables)
.map(([name, collection]) => generateTableType(name, collection))
.join('\n')}
Expand Down
8 changes: 7 additions & 1 deletion packages/db/src/runtime/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<S extends string, T extends Record<string, unknown>>(type: S, schema: T) {
return {
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 0 additions & 8 deletions packages/db/src/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';
Expand All @@ -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';
Expand Down
3 changes: 1 addition & 2 deletions packages/db/test/unit/column-queries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
3 changes: 3 additions & 0 deletions packages/db/virtual.d.ts
Original file line number Diff line number Diff line change
@@ -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'];
Expand Down
Loading