Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid return type for db.sum() in lateral subquery #143

Open
pocin opened this issue Feb 27, 2023 · 0 comments
Open

invalid return type for db.sum() in lateral subquery #143

pocin opened this issue Feb 27, 2023 · 0 comments

Comments

@pocin
Copy link

pocin commented Feb 27, 2023

when using db.sum() shortcut in a subquery the return type should be number| null because the subquery might not match any row.

const resp = await db.select('order', db.all, {
   lateral: db.sum('order_lines', {order_id: db.parent('id')}, {columns: ['amount']})
  }).run(pool)

as is, the current code can crash at runtime with TypeError: Cannot read properties of null so i think it is a bug.

Not sure if zapatos should coalesce under the hood, or return number|null and user should coalesce on their own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant