RobinBlomberg / kysely-codegen

Generate Kysely type definitions from your database.
MIT License
819 stars 73 forks source link

MySQL generated columns #169

Open twiddler opened 5 months ago

twiddler commented 5 months ago

This MySQL table

CREATE TABLE `Foo` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `firstName` varchar(255) NOT NULL DEFAULT '',
  `lastName` varchar(255) NOT NULL DEFAULT '',
  `fullName` varchar(255) GENERATED ALWAYS AS (concat(`firstName`, ' ',`lastName`)) STORED NOT NULL
);

leads to these types

export interface Foo {
    id: Generated<number>
    firstName: Generated<string>
    lastName: Generated<string>
    fullName: string
}

This causes issues when trying

db.insertInto("Foo").values({
    firstName: "foo",
    lastName: "bar"
})

Property 'fullName' is missing in type '{ firstName: string; lastName: string; }' but required in type '{ fullName: ValueExpression<DB, "Foo", string>; }'.ts(2345)

I believe fullName should be typed Generated<string>, shouldn't it? :thinking:

Upvote & Fund

Fund with Polar