Kysely types - ID

We've created tables directly with sql script as we need inheritance and don't want xata_* columns in our data. Everything works nice, but when I try to query with id column I get this error:
Argument of type '1' is not assignable to parameter of type 'OperandValueExpressionOrList<Model<DatabaseSchema>, "buildings", "id">'
Argument of type '1' is not assignable to parameter of type 'OperandValueExpressionOrList<Model<DatabaseSchema>, "buildings", "id">'
Everything works when I try to get any other column. My guess is it's got something to do with the xata types for ID (every record type has & XataRecord) id_test works and id doesn't, even though they are the same
xata.ts

{
name: "id",
type: "int",
notNull: true,
unique: true,
defaultValue:
"nextval('id_seq'::regclass)",
comment: "",
},
{
name: "id_test",
type: "int",
notNull: true,
unique: true,
defaultValue:
"nextval('id_test_seq'::regclass)",
comment: "",
},
xata.ts

{
name: "id",
type: "int",
notNull: true,
unique: true,
defaultValue:
"nextval('id_seq'::regclass)",
comment: "",
},
{
name: "id_test",
type: "int",
notNull: true,
unique: true,
defaultValue:
"nextval('id_test_seq'::regclass)",
comment: "",
},
No description
4 Replies
cmck
cmck2mo ago
Hi there! Your suspicion is correct. The name "id" for a column is still reserved in xata and several functions assume you mean xata_id when you use this name. If you're creating tables with their own columns named "id" via a script, you won't receive an error, but you will run into issues further down the line. If you don't want xata columns in your data I would recommend using "id_x" for your id columns. This is something we need to clarify and clean up on our end.
brownfox.dev
brownfox.devOP2mo ago
I see. Is there any benefit to keeping the internal xata_* columns? Will everything work without them?
cmck
cmck2mo ago
Yes there's a benefit. Certain functions, bulk update of records, require the xata_id column (and accept "id" as the argument. For example https://discordapp.com/channels/996791218879086662/1306637331146608660/1306665470598058066
brownfox.dev
brownfox.devOP2mo ago
Would it be possible to change this by some flag/argument for xata codegen? It's not much of an issue, just DX.
Want results from more Discord servers?
Add your server