0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Improve asDrizzleTable() types (#10882)

This commit is contained in:
Chris Swithinbank 2024-04-26 16:07:55 +02:00 committed by GitHub
parent 22d00865cf
commit cf58d1ed56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 2 deletions

View file

@ -0,0 +1,7 @@
---
"@astrojs/db": patch
---
Improves the typing of the `asDrizzleTable()` utility
Fixes a type error when passing the output of `defineTable()` to the utility and returns a more detailed type inferred from the columns of the passed table config.

View file

@ -8,7 +8,7 @@ import {
sqliteTable,
text,
} from 'drizzle-orm/sqlite-core';
import { type DBColumn, type DBTable } from '../core/types.js';
import type { DBColumn, DBTable } from '../core/types.js';
import { type SerializedSQL, isSerializedSQL } from './types.js';
import { pathToFileURL } from './utils.js';

View file

@ -1,2 +1,11 @@
export { defineDbIntegration } from './core/utils.js';
export { asDrizzleTable } from './runtime/index.js';
import { tableSchema } from './core/schemas.js';
import type { ColumnsConfig, TableConfig } from './core/types.js';
import { type Table, asDrizzleTable as internal_asDrizzleTable } from './runtime/index.js';
export function asDrizzleTable<
TableName extends string = string,
TColumns extends ColumnsConfig = ColumnsConfig,
>(name: TableName, tableConfig: TableConfig<TColumns>) {
return internal_asDrizzleTable(name, tableSchema.parse(tableConfig)) as Table<TableName, TColumns>;
}