Skip to content

Commit

Permalink
Improve asDrizzleTable() types (#10882)
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis authored Apr 26, 2024
1 parent 22d0086 commit cf58d1e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/angry-lemons-tie.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion packages/db/src/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
11 changes: 10 additions & 1 deletion packages/db/src/utils.ts
Original file line number Diff line number Diff line change
@@ -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>;
}

0 comments on commit cf58d1e

Please sign in to comment.