0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

fix type error in seed stub on initial setup (#10457)

* fix: move db type to base types for seed stub

* chore: changeset

* fix(test): bad NOW import
This commit is contained in:
Ben Holmes 2024-03-18 07:55:39 -04:00 committed by GitHub
parent 4dcfa2bd90
commit 219c49473f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 16 additions and 14 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/db": patch
---
Fix type error in db/seed.ts file before type generation is run.

View file

@ -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')}

View file

@ -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 {
@ -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,

View file

@ -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';

View file

@ -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';

View file

@ -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'];