client-ts
client-ts copied to clipboard
Type error on transaction delete with const table name
Describe the bug
The transaction API requires the table name as const, but in a situation like this you get an error:
const records = await xata.db.test.getAll();
const toDelete = records.map(rec => {
return {
delete: {
table: 'test',
id: rec.id
}
}
})
const page = await xata.transactions.run(toDelete);
console.log(page);
The workaround is to do 'test' as const like this:
const records = await xata.db.test.getAll();
const toDelete = records.map(rec => {
return {
delete: {
table: 'test' as const,
id: rec.id
}
}
})
const page = await xata.transactions.run(toDelete);
console.log(page);
To avoid this issue, @SferaDev suggested that we could accept string & {} so that auto-complete still works.