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

fix: handle AExpr and NullTest nodes in SQL parsing #354

Merged
merged 2 commits into from
Jan 1, 2025

Conversation

Newbie012
Copy link
Collaborator

fixes #352 #353

This fix addresses an issue where AExpr and NullTest nodes were not being correctly handled in SQL parsing. This ensures that expressions like  and  are properly interpreted and typed.

Example queries:
-
-
Copy link

changeset-bot bot commented Dec 30, 2024

🦋 Changeset detected

Latest commit: e79da23

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@ts-safeql/eslint-plugin Patch
@ts-safeql/generate Patch
@ts-safeql-demos/basic-flat-config Patch
@ts-safeql-demos/basic-migrations-raw Patch
@ts-safeql-demos/basic-transform-type Patch
@ts-safeql-demos/basic Patch
@ts-safeql-demos/big-project Patch
@ts-safeql-demos/config-file-flat-config Patch
@ts-safeql-demos/from-config-file Patch
@ts-safeql-demos/multi-connections Patch
@ts-safeql-demos/playground Patch
@ts-safeql-demos/postgresjs-custom-types Patch
@ts-safeql-demos/postgresjs-demo Patch
@ts-safeql-demos/vercel-postgres Patch
@ts-safeql/shared Patch
@ts-safeql/sql-ast Patch
@ts-safeql/test-utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Dec 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
safeql ⬜️ Ignored (Inspect) Visit Preview Dec 30, 2024 1:47pm

@Newbie012 Newbie012 linked an issue Dec 30, 2024 that may be closed by this pull request
@Newbie012 Newbie012 merged commit e583c77 into main Jan 1, 2025
3 checks passed
@Newbie012 Newbie012 deleted the fix-aexpr-nulltest-handling branch January 1, 2025 20:03
@karlhorky
Copy link
Collaborator

karlhorky commented Jan 3, 2025

Great, can confirm that this fixed #352:

// ✅
await sql<{ has_url: boolean }[]>`
  SELECT
    CASE
      WHEN TRUE THEN personal_intro_url_private IS NOT NULL
      ELSE tech_achievements_url_private IS NOT NULL
    END AS has_url
  FROM
    users
`;

And also fixed #353:

type User = {
  lecturer: {
    is_guest: boolean;
  } | null;
};

// ✅
await sql<User[]>`
  SELECT
    CASE
      WHEN lecturers.id IS NOT NULL THEN (
        jsonb_build_object(
          'is_guest',
          lecturer_users.email NOT LIKE '%@upleveled.io'
        )
      )
      ELSE NULL
    END AS lecturer
  FROM
    lecturers
    INNER JOIN users lecturer_users ON lecturers.user_id = lecturer_users.id
`;

Thanks so much, amazing! 🎉

@karlhorky
Copy link
Collaborator

However, this PR introduced a new problem with inference of summed count(*) subqueries:

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

Successfully merging this pull request may close these issues.

Regression: Some JsonbAgg types returning unknown Missing type on boolean inside CASE
2 participants