RobinBlomberg / kysely-codegen

Generate Kysely type definitions from your database.
MIT License
769 stars 69 forks source link

Deduplicated `ColumnType` type arguments are incorrect #203

Open glacius-mitchell opened 1 week ago

glacius-mitchell commented 1 week ago

I believe the ColumnType type argument deduplication logic in https://github.com/RobinBlomberg/kysely-codegen/commit/ad03d2ef67f40c7d22df27e30a16bcf6083da463 was incorrect.

In particular, it assumed an omitted update type would default to the insert type, when in fact Kysely's update type defaults to the select type (see https://github.com/kysely-org/kysely/blob/0.27.4/src/util/column-type.ts#L41).

This led to some regressions in the types generated by kysely-codegen.

For instance, where we previously had these generated types

export type Int8 = ColumnType<string, bigint | number | string, bigint | number | string>;

export type Timestamp = ColumnType<Date, Date | string, Date | string>;

which expanded to

type Int8 = {
    readonly __select__: string;
    readonly __insert__: string | number | bigint;
    readonly __update__: string | number | bigint;
}

type Timestamp = {
    readonly __select__: Date;
    readonly __insert__: string | Date;
    readonly __update__: string | Date;
}

we now have these generated types

export type Int8 = ColumnType<string, bigint | number | string>;

export type Timestamp = ColumnType<Date, Date | string>;

which expand to

type Int8 = {
    readonly __select__: string;
    readonly __insert__: string | number | bigint;
    readonly __update__: string;
}

type Timestamp = {
    readonly __select__: Date;
    readonly __insert__: string | Date;
    readonly __update__: Date;
}

The new column types are overly strict on what types of values can be specified for an update.

Upvote & Fund

Fund with Polar

glacius-mitchell commented 1 week ago

Hi @RobinBlomberg, I see you've already addressed this in https://github.com/RobinBlomberg/kysely-codegen/commit/e4f54f4b41a8d4a7833ae9409ce97c12512c701b. Is there any chance that commit will make its way into a release soon? We're unable to upgrade at the moment due to the type regressions above. Thanks!