client-ts
client-ts copied to clipboard
Typescript errors for inserting with Kysely
Describe the bug
db.insertInto('my_table').values(<some values>) throws errors in Typescript since it expects the presence of fields and methods from XataRecord.
To Reproduce
- Create a simple schema
- Use
xata pullto codegen thexata.tsfile Example code snippet from generated file:export type MyTable = InferredTypes["my_table"]; export type MyTableRecord = MyTable & XataRecord; export type DatabaseSchema = { my_table: MyTableRecord; }; - Build an
insertIntostatement with Kyselydb.insertInto('my_table').values({...myValues}) - Will throw TypeScript errors for
type ... is missing the following properties from type ... id, xata, getMetadata, toSerializable, and 4 more- Those missing properties come from
XataRecord
- Those missing properties come from
Expected behavior
- Accept object without
XataRecordproperties to insert into a table
Software version
"dependencies": {
"@xata.io/client": "^0.30.1",
"@xata.io/kysely": "^0.2.1",
"kysely": "^0.27.4",
"zod": "^3.23.8",
"zod-validation-error": "^3.4.0"
},
Additional context
The docs only show an example for selecting a table entry. An insertInto example would be a great addition.
I just run into this issue too, setting up Kysely with Xata and NextJS.
My desired partial type from form data is missing the following properties from type: replace xata_id xata_createdat xata_updatedat and 5 more...