DT
Join ServerDrizzle Team
help
sqliteTable wrapper which modifies fields, with proper types
More of a TypeScript question, but I'm trying to create a wrapper for sqliteTable to add a set of standard fields (and keys) to the fields provided:
This results in a type error on
import { sqliteTable, SQLiteTableFn } from "drizzle-orm/sqlite-core"
const extraFields = { ... }
const wrapper: SQLiteTableFn = (name, fields, keys) => {
return sqliteTable(
name,
{ ...extraFields, ...fields },
(Table) => ({ ...keys })
);
};
This results in a type error on
wrapper
as the generics applied to SQLiteTableFn
and the return value of wrapper
return value sqliteTable
on modified fields) no longer correspond. How can I create a type for wrapper
which returns object properly typed?Message Not Public
Sign In & Join Server To View
I was doing something like that previously, but my goal is to create a function which returns two tables: one with the fields as is, and a second table with extra fields added. The part I am struggling with is the return type of table2, which is intended to be the modified version of the second table.
const [table1, table2] = wrapper("name", { {/* fields */} })