Switch from `Nullable` generic to `<type> | null`

This issue has been tracked since 2022-09-30.

Is your feature request related to a problem? Please describe.

It was confusing to me that this does not work:

type Animal = {
  id: number;
  name: string | null;
}

// error: type of name `string | null` does not match `Nullable<string>`
await sql<Animal[]>`
  SELECT * FROM animals
`

With this schema:

CREATE TABLE animals (
  id integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
  name varchar(40)
)

Describe the solution you'd like

Support the x | null union type when using a nullable database field

Describe alternatives you've considered

Apparently as shown in the examples, it shows that users can define their own Nullable generic type to achieve this:

type Nullable<T> = T | null;

type Animal = {
  id: number;
  name: Nullable<string>;
}

// no error
await sql<Animal[]>`
  SELECT * FROM animals
`

But this seems less natural and discoverable than allowing | null unions

Additional context

--

Newbie012 wrote this answer on 2022-10-17

I don't remember why I decided to go with generic rather than the traditional way (union). I will push a fix tomorrow ~

Newbie012 wrote this answer on 2022-10-17

fixed in 0.0.15

karlhorky wrote this answer on 2022-10-17

Amazing, works great, thanks! Upgraded here: upleveled/[email protected]9abffcf

More Details About Repo
Owner Name ts-safeql
Repo Name safeql
Full Name ts-safeql/safeql
Language TypeScript
Created Date 2022-09-08
Updated Date 2023-03-16
Star Count 795
Watcher Count 5
Fork Count 14
Issue Count 7

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date