UNPKG

drizzle-zero

Version:

Generate Zero schemas from Drizzle ORM schemas

18 lines (15 loc) 1.05 kB
import { DBConnection, Row, DBTransaction } from '@rocicorp/zero/pg'; import { PgTransaction } from 'drizzle-orm/pg-core'; import { PostgresJsQueryResultHKT, PostgresJsDatabase } from 'drizzle-orm/postgres-js'; import { ExtractTablesWithRelations } from 'drizzle-orm/relations'; import postgres from 'postgres'; type PostgresJsZeroTransaction<TSchema extends Record<string, unknown>> = PgTransaction<PostgresJsQueryResultHKT, TSchema, ExtractTablesWithRelations<TSchema>>; declare class PostgresJsConnection<TDrizzle extends PostgresJsDatabase<Record<string, unknown>> & { $client: postgres.Sql<{}>; }, TSchema extends TDrizzle extends PostgresJsDatabase<infer TSchema> ? TSchema : never, TTransaction extends PostgresJsZeroTransaction<TSchema>> implements DBConnection<TTransaction> { #private; constructor(drizzle: TDrizzle); query(sql: string, params: unknown[]): Promise<Row[]>; transaction<T>(fn: (tx: DBTransaction<TTransaction>) => Promise<T>): Promise<T>; } export { PostgresJsConnection, type PostgresJsZeroTransaction };