ts-safeql / safeql

Validate and auto-generate TypeScript types from raw SQL queries in PostgreSQL.
https://safeql.dev
MIT License
1.35k stars 22 forks source link

nullable timestamptz support (`Date | null`) #279

Open timvandam opened 1 month ago

timvandam commented 1 month ago

Describe the bug A clear and concise description of what the bug is.

Currently inserting/updating nullable timestamptz values in postgres don't work. Using variables of type Date | null causes error ESLint: Invalid Query: Unsupported union type(@ts-safeql/ check-sql)

To Reproduce Steps to reproduce the behavior:

Make a table with a nullable timestamptz column and try to insert a Date | null value

Expected behavior A clear and concise description of what you expected to happen.

It should work

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

I may have some time to try to fix this over the weekend

karlhorky commented 1 month ago

@timvandam If you can provide a reproduction in this format with the table schema, sql tag and ESLint error, that would be helpful to understand the problem:

CREATE TABLE users (
  -- ...
)
// 💥 Query has incorrect type annotation.
//  Expected: { has_private_url: boolean; }
//  Actual: { has_private_url: boolean | null; }[]
await sql<{ has_private_url: boolean }[]>`
  SELECT
    ${true} AS has_private_url
  FROM
    users
`;