mirror of
https://github.com/withastro/astro.git
synced 2025-03-17 23:11:29 -05:00
feat: move astro:db
core types to config-augment
This commit is contained in:
parent
e863632ebf
commit
7ea9be9736
3 changed files with 40 additions and 8 deletions
30
packages/db/config-augment.d.ts
vendored
30
packages/db/config-augment.d.ts
vendored
|
@ -2,3 +2,33 @@ declare namespace Config {
|
|||
type DBUserConfig = import('./dist/core/types.js').DBUserConfig;
|
||||
export interface Database extends DBUserConfig {}
|
||||
}
|
||||
|
||||
declare module 'astro:db' {
|
||||
export const db: import('./dist/runtime/index.js').SqliteDB;
|
||||
export const dbUrl: string;
|
||||
|
||||
export {
|
||||
sql,
|
||||
eq,
|
||||
gt,
|
||||
gte,
|
||||
lt,
|
||||
lte,
|
||||
ne,
|
||||
isNull,
|
||||
isNotNull,
|
||||
inArray,
|
||||
notInArray,
|
||||
exists,
|
||||
notExists,
|
||||
between,
|
||||
notBetween,
|
||||
like,
|
||||
notIlike,
|
||||
not,
|
||||
asc,
|
||||
desc,
|
||||
and,
|
||||
or,
|
||||
} from 'drizzle-orm';
|
||||
}
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
import { existsSync } from 'node:fs';
|
||||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
import type { DBCollection, DBCollections } from '../types.js';
|
||||
import { DB_TYPES_FILE, RUNTIME_DRIZZLE_IMPORT, RUNTIME_IMPORT } from '../consts.js';
|
||||
import { DB_TYPES_FILE, RUNTIME_IMPORT } from '../consts.js';
|
||||
|
||||
export async function typegen({ collections, root }: { collections: DBCollections; root: URL }) {
|
||||
const content = `// This file is generated by \`studio sync\`
|
||||
declare module 'astro:db' {
|
||||
export const db: import(${RUNTIME_IMPORT}).SqliteDB;
|
||||
export const dbUrl: string;
|
||||
export * from ${RUNTIME_DRIZZLE_IMPORT};
|
||||
const content = `/// <reference types="@astrojs/db" />
|
||||
|
||||
declare module 'astro:db' {
|
||||
${Object.entries(collections)
|
||||
.map(([name, collection]) => generateTableType(name, collection))
|
||||
.join('\n')}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import type { ColumnDataType, ColumnBaseConfig } from 'drizzle-orm';
|
||||
import type { SQLiteColumn, SQLiteTableWithColumns } from 'drizzle-orm/sqlite-core';
|
||||
import type { DBField } from '../core/types.js';
|
||||
import type {
|
||||
SQLiteColumn,
|
||||
SQLiteInsertValue,
|
||||
SQLiteTableWithColumns,
|
||||
} from 'drizzle-orm/sqlite-core';
|
||||
import type { DBField, FieldsConfig, MaybeArray, MaybePromise } from '../core/types.js';
|
||||
import type { SqliteDB } from './index.js';
|
||||
|
||||
type GeneratedConfig<T extends ColumnDataType = ColumnDataType> = Pick<
|
||||
ColumnBaseConfig<T, string>,
|
||||
|
|
Loading…
Add table
Reference in a new issue