ARTICLE AD BOX
I'm trying to create a simple wrapper around Drizzle to keep interacting with it DRY. Here is a minimal repro of the repository pattern I'm trying to build:
import { InferInsertModel, InferSelectModel } from 'drizzle-orm'; import { AnyPgTable } from 'drizzle-orm/pg-core'; import { drizzle } from 'drizzle-orm/node-postgres'; import { Pool } from 'pg'; const pool = new Pool({ connectionString: process.env.DATABASE_URL, }); const db = drizzle(pool); export function createRepository<TTable extends AnyPgTable>(table: TTable) { type Row = InferSelectModel<TTable>; type Data = InferInsertModel<TTable>; return { async create(data: Data): Promise<Row> { const [result] = await db.insert(table).values(data).returning(); return result; }, }; }The issue I'm having is in the return result line, with the following TS error:
Type '{ [x: string]: unknown; }' is not assignable to type '{ [K in keyof { [Key in keyof TTable["_"]["columns"] & string as Key]: TTable["_"]["columns"][Key]["_"]["notNull"] extends true ? TTable["_"]["columns"][Key]["_"]["data"] : TTable["_"]["columns"][Key]["_"]["data"] | null; }]: { [Key in keyof TTable["_"]["columns"] & string as Key]: TTable["_"]["columns"][Key]["_"]["...'.How do I fix this error, or find a better way to achieve a simple repository wrapper around Drizzle?
2,0143 gold badges17 silver badges29 bronze badges
Explore related questions
See similar questions with these tags.
