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
--
Amazing, works great, thanks! Upgraded here: upleveled/[email protected]9abffcf
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 |
Issue Title | Created Date | Updated Date |
---|