Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kanel-kysely: Differentiate null and undefined for insert types #488

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/kanel-kysely/example/models/public/Actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export type ActorId = number;

/** Represents the table public.actor */
export default interface ActorTable {
actor_id: ColumnType<ActorId, ActorId | null, ActorId>;
actor_id: ColumnType<ActorId, ActorId | undefined, ActorId>;

first_name: ColumnType<string, string, string>;

last_name: ColumnType<string, string, string>;

last_update: ColumnType<Date, Date | string | null, Date | string>;
last_update: ColumnType<Date, Date | string | undefined, Date | string>;
}

export type Actor = Selectable<ActorTable>;
Expand Down
4 changes: 2 additions & 2 deletions packages/kanel-kysely/example/models/public/Address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type AddressId = number;

/** Represents the table public.address */
export default interface AddressTable {
address_id: ColumnType<AddressId, AddressId | null, AddressId>;
address_id: ColumnType<AddressId, AddressId | undefined, AddressId>;

address: ColumnType<string, string, string>;

Expand All @@ -22,7 +22,7 @@ export default interface AddressTable {

phone: ColumnType<string, string, string>;

last_update: ColumnType<Date, Date | string | null, Date | string>;
last_update: ColumnType<Date, Date | string | undefined, Date | string>;
}

export type Address = Selectable<AddressTable>;
Expand Down
4 changes: 2 additions & 2 deletions packages/kanel-kysely/example/models/public/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export type CategoryId = number;

/** Represents the table public.category */
export default interface CategoryTable {
category_id: ColumnType<CategoryId, CategoryId | null, CategoryId>;
category_id: ColumnType<CategoryId, CategoryId | undefined, CategoryId>;

name: ColumnType<string, string, string>;

last_update: ColumnType<Date, Date | string | null, Date | string>;
last_update: ColumnType<Date, Date | string | undefined, Date | string>;
}

export type Category = Selectable<CategoryTable>;
Expand Down
4 changes: 2 additions & 2 deletions packages/kanel-kysely/example/models/public/City.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export type CityId = number;

/** Represents the table public.city */
export default interface CityTable {
city_id: ColumnType<CityId, CityId | null, CityId>;
city_id: ColumnType<CityId, CityId | undefined, CityId>;

city: ColumnType<string, string, string>;

country_id: ColumnType<CountryId, CountryId, CountryId>;

last_update: ColumnType<Date, Date | string | null, Date | string>;
last_update: ColumnType<Date, Date | string | undefined, Date | string>;
}

export type City = Selectable<CityTable>;
Expand Down
4 changes: 2 additions & 2 deletions packages/kanel-kysely/example/models/public/Country.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export type CountryId = number;

/** Represents the table public.country */
export default interface CountryTable {
country_id: ColumnType<CountryId, CountryId | null, CountryId>;
country_id: ColumnType<CountryId, CountryId | undefined, CountryId>;

country: ColumnType<string, string, string>;

last_update: ColumnType<Date, Date | string | null, Date | string>;
last_update: ColumnType<Date, Date | string | undefined, Date | string>;
}

export type Country = Selectable<CountryTable>;
Expand Down
6 changes: 3 additions & 3 deletions packages/kanel-kysely/example/models/public/Customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type CustomerId = number;

/** Represents the table public.customer */
export default interface CustomerTable {
customer_id: ColumnType<CustomerId, CustomerId | null, CustomerId>;
customer_id: ColumnType<CustomerId, CustomerId | undefined, CustomerId>;

store_id: ColumnType<number, number, number>;

Expand All @@ -20,9 +20,9 @@ export default interface CustomerTable {

address_id: ColumnType<AddressId, AddressId, AddressId>;

activebool: ColumnType<boolean, boolean | null, boolean>;
activebool: ColumnType<boolean, boolean | undefined, boolean>;

create_date: ColumnType<Date, Date | string | null, Date | string>;
create_date: ColumnType<Date, Date | string | undefined, Date | string>;

last_update: ColumnType<Date | null, Date | string | null, Date | string | null>;

Expand Down
10 changes: 5 additions & 5 deletions packages/kanel-kysely/example/models/public/Film.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type FilmId = number;

/** Represents the table public.film */
export default interface FilmTable {
film_id: ColumnType<FilmId, FilmId | null, FilmId>;
film_id: ColumnType<FilmId, FilmId | undefined, FilmId>;

title: ColumnType<string, string, string>;

Expand All @@ -20,17 +20,17 @@ export default interface FilmTable {

language_id: ColumnType<LanguageId, LanguageId, LanguageId>;

rental_duration: ColumnType<number, number | null, number>;
rental_duration: ColumnType<number, number | undefined, number>;

rental_rate: ColumnType<string, string | null, string>;
rental_rate: ColumnType<string, string | undefined, string>;

length: ColumnType<number | null, number | null, number | null>;

replacement_cost: ColumnType<string, string | null, string>;
replacement_cost: ColumnType<string, string | undefined, string>;

rating: ColumnType<MpaaRating | null, MpaaRating | null, MpaaRating | null>;

last_update: ColumnType<Date, Date | string | null, Date | string>;
last_update: ColumnType<Date, Date | string | undefined, Date | string>;

special_features: ColumnType<string[] | null, string[] | null, string[] | null>;

Expand Down
2 changes: 1 addition & 1 deletion packages/kanel-kysely/example/models/public/FilmActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default interface FilmActorTable {

film_id: ColumnType<FilmId, FilmId, FilmId>;

last_update: ColumnType<Date, Date | string | null, Date | string>;
last_update: ColumnType<Date, Date | string | undefined, Date | string>;
}

export type FilmActor = Selectable<FilmActorTable>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default interface FilmCategoryTable {

category_id: ColumnType<CategoryId, CategoryId, CategoryId>;

last_update: ColumnType<Date, Date | string | null, Date | string>;
last_update: ColumnType<Date, Date | string | undefined, Date | string>;
}

export type FilmCategory = Selectable<FilmCategoryTable>;
Expand Down
4 changes: 2 additions & 2 deletions packages/kanel-kysely/example/models/public/Inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export type InventoryId = number;

/** Represents the table public.inventory */
export default interface InventoryTable {
inventory_id: ColumnType<InventoryId, InventoryId | null, InventoryId>;
inventory_id: ColumnType<InventoryId, InventoryId | undefined, InventoryId>;

film_id: ColumnType<FilmId, FilmId, FilmId>;

store_id: ColumnType<number, number, number>;

last_update: ColumnType<Date, Date | string | null, Date | string>;
last_update: ColumnType<Date, Date | string | undefined, Date | string>;
}

export type Inventory = Selectable<InventoryTable>;
Expand Down
4 changes: 2 additions & 2 deletions packages/kanel-kysely/example/models/public/Language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export type LanguageId = number;

/** Represents the table public.language */
export default interface LanguageTable {
language_id: ColumnType<LanguageId, LanguageId | null, LanguageId>;
language_id: ColumnType<LanguageId, LanguageId | undefined, LanguageId>;

name: ColumnType<string, string, string>;

last_update: ColumnType<Date, Date | string | null, Date | string>;
last_update: ColumnType<Date, Date | string | undefined, Date | string>;
}

export type Language = Selectable<LanguageTable>;
Expand Down
2 changes: 1 addition & 1 deletion packages/kanel-kysely/example/models/public/Payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type PaymentId = number;

/** Represents the table public.payment */
export default interface PaymentTable {
payment_id: ColumnType<PaymentId, PaymentId | null, PaymentId>;
payment_id: ColumnType<PaymentId, PaymentId | undefined, PaymentId>;

customer_id: ColumnType<CustomerId, CustomerId, CustomerId>;

Expand Down
4 changes: 2 additions & 2 deletions packages/kanel-kysely/example/models/public/Rental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type RentalId = number;

/** Represents the table public.rental */
export default interface RentalTable {
rental_id: ColumnType<RentalId, RentalId | null, RentalId>;
rental_id: ColumnType<RentalId, RentalId | undefined, RentalId>;

rental_date: ColumnType<Date, Date | string, Date | string>;

Expand All @@ -22,7 +22,7 @@ export default interface RentalTable {

staff_id: ColumnType<StaffId, StaffId, StaffId>;

last_update: ColumnType<Date, Date | string | null, Date | string>;
last_update: ColumnType<Date, Date | string | undefined, Date | string>;
}

export type Rental = Selectable<RentalTable>;
Expand Down
6 changes: 3 additions & 3 deletions packages/kanel-kysely/example/models/public/Staff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type StaffId = number;

/** Represents the table public.staff */
export default interface StaffTable {
staff_id: ColumnType<StaffId, StaffId | null, StaffId>;
staff_id: ColumnType<StaffId, StaffId | undefined, StaffId>;

first_name: ColumnType<string, string, string>;

Expand All @@ -21,13 +21,13 @@ export default interface StaffTable {

store_id: ColumnType<number, number, number>;

active: ColumnType<boolean, boolean | null, boolean>;
active: ColumnType<boolean, boolean | undefined, boolean>;

username: ColumnType<string, string, string>;

password: ColumnType<string | null, string | null, string | null>;

last_update: ColumnType<Date, Date | string | null, Date | string>;
last_update: ColumnType<Date, Date | string | undefined, Date | string>;

picture: ColumnType<bytea | null, bytea | null, bytea | null>;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/kanel-kysely/example/models/public/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export type StoreId = number;

/** Represents the table public.store */
export default interface StoreTable {
store_id: ColumnType<StoreId, StoreId | null, StoreId>;
store_id: ColumnType<StoreId, StoreId | undefined, StoreId>;

manager_staff_id: ColumnType<StaffId, StaffId, StaffId>;

address_id: ColumnType<AddressId, AddressId, AddressId>;

last_update: ColumnType<Date, Date | string | null, Date | string>;
last_update: ColumnType<Date, Date | string | undefined, Date | string>;
}

export type Store = Selectable<StoreTable>;
Expand Down
12 changes: 8 additions & 4 deletions packages/kanel-kysely/src/processFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,17 @@ const processFile = (
if (baseType === "Date") {
baseType += " | string";
}
initializerType =
column.isNullable ||

initializerType = baseType;
if (column.isNullable) {
initializerType += " | null";
} else if (
column.defaultValue ||
column.isIdentity ||
column.generated === "BY DEFAULT"
? `${baseType} | null`
: baseType;
) {
initializerType += " | undefined";
}
}

let mutatorType = "never";
Expand Down