ts-safeql / safeql

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

Internal error: Cannot read properties of undefined (reading 'tableName') #291

Closed gajus closed 21 hours ago

gajus commented 23 hours ago

Seeing quite a few of these errors:

/Users/x/Developer/contra/gaia/apps/contra-api/src/temporal-workflows/routines/invoice/sendInvoiceOverdueFiveDaysReminderEmail.ts
  20:43  error  Internal error: Cannot read properties of undefined (reading 'tableName')  @ts-safeql/check-sql

/Users/x/Developer/contra/gaia/apps/contra-api/src/temporal-workflows/routines/invoice/sendInvoiceOverdueTwoDaysReminderEmail.ts
  23:43  error  Internal error: Cannot read properties of undefined (reading 'tableName')  @ts-safeql/check-sql

Looking at the underlying queries, nothing really stands out as unusual, e.g.

const result = await pool.one(sql.type(InvoiceDetailsShape)`
  SELECT
    pp.client_user_account_id,
    contractor.id contractor_user_account_id,
    contractor.given_name contractor_first_name,
    client.id client_user_account_id,
    client.given_name client_first_name,
    i.total_amount invoice_total_amount
  FROM invoice i
  INNER JOIN paid_project pp ON
    pp.id = i.paid_project_id
  INNER JOIN user_account client ON
    client.id = pp.client_user_account_id
  INNER JOIN user_account contractor ON
    contractor.id = pp.contractor_user_account_id
  LEFT JOIN workspace_team wt ON wt.id = pp.client_workspace_team_id
  WHERE
    i.id = ${invoiceId}
`);
gajus commented 23 hours ago

Will debug further and share findings.

Newbie012 commented 22 hours ago

The issue here is that you're trying to select two columns with the same name (client_user_account_id).

I'm pushing a fix for the internal error. There was an incorrect lookup when dealing with duplicate columns and aliases.

gajus commented 21 hours ago

The issue here is that you're trying to select two columns with the same name (client_user_account_id).

I'm pushing a fix for the internal error. There was an incorrect lookup when dealing with duplicate columns and aliases.

oh wow, didn't even notice it!

ts-safeql delivers value yet again.

I cannot tell you enough just how many small things it already caught!