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

SafeQL error incorrect type annotation on Linux #239

Closed CornaSn closed 4 months ago

CornaSn commented 5 months ago

Describe the bug safeQL throws error: Query has incoorect type annotation.

To Reproduce Steps to reproduce the behavior:

import { Sql } from 'postgres';

export type Expert = {
  id: number;
  age: string;
  city: string;
  bio: string;
  pictureUrl: string;
  videoUrl: string | null;
  travelBlogUrl: string | null;
};

export async function up(sql: Sql) {
  await sql`
    CREATE TABLE experts (
      id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
      age varchar(3) NOT NULL,
      city varchar(20) NOT NULL,
      bio varchar(200) NOT NULL,
      picture_url varchar(100) NOT NULL,
      video_url varchar(100),
      travel_blog_url varchar(100)
    )
  `;
}

export async function down(sql: Sql) {
  await sql`DROP TABLE experts`;
}
import { cache } from 'react';
import { sql } from '../database/connect';
import { Expert } from '../migrations/00002-createExpertTable';
// Get whole database information
export const getExpertsInsecure = cache(async () => {
  const users = await sql<Expert[]>`
    SELECT
      *
    FROM
      experts
  `;
  return users;
});

// Get single user information from database
export const getExpertInsecure = cache(async (id: number) => {
  const [user] = await sql<Expert[]>`
    SELECT
      *
    FROM
      experts
    WHERE
      id = ${id}
  `;
  return user;
});
console.log(getExpertsInsecure());

Expected behavior Type annotation doesn't throw an error

Screenshots safeQL_error

Desktop (please complete the following information):