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

error: internal compiler error: prepared statement had 2 statements, expected 1 #79

Closed
simplenotezy opened this issue Oct 21, 2023 · 7 comments
Labels
question Further information is requested

Comments

@simplenotezy
Copy link

Trying to set it up for a Nest.js project, it fails with the following error:

❯ npx sqlx-ts src/ --db-host=127.0.0.1 --db-port=26257 --db-type=postgres --db-user=root
[INFO] Scanning "src/" for SQLs with extension Ts
error: internal compiler error: prepared statement had 2 statements, expected 1
    --> <src/database/cli/seed.command.ts>:1728:3
     |
1728 | /   return dataSource.query(`
1729 | |   insert into public.interest_category (name)
1730 | |   values  ('Creativity'),
1731 | |           ('Food & Drinks'),
...    |
1813 | |         ('Yoga', 'Sports');
1814 | |   `);
     | |_____^
@JasonShin
Copy link
Owner

JasonShin commented Oct 22, 2023

Hello, could you revise the SQL that you have in this example?

I see that this is an INSERT query against interest_category table with the target column name name, however, the values that you are trying to insert do not match
('Yoga', 'Sports') are two values but the SQL is looking for just a single value.

Also, could you provide an example of this code (if possible?) because sqlx-ts wouldn't be able to pick up code that is not contained inside sql tag (for example sql'SELECT id FROM items')

However, 2 statements, expected 1 I will double check how can I reproduce it. I can see that the stack trace isn't quite accurate and pointing to the right location of the code.

But again, an example would be very helpful.


In the meantime, please check if you have any raw SQLs sql'...' with multiple queries inside a single sql tag. sqlx-ts does not support multiple queries inside a single sql tag.

@JasonShin
Copy link
Owner

JasonShin commented Oct 22, 2023

Also, I will add testing against nest.js source code in https://github.com/JasonShin/sqlx-ts-demo

@JasonShin JasonShin added the question Further information is requested label Oct 22, 2023
@simplenotezy
Copy link
Author

Hey @JasonShin sure thing! This is the code that it picked up:

Line 1727:

const createInterests = (dataSource: DataSource) => {
  return dataSource.query(`
  insert into public.interest_category (name)
  values  ('Creativity'),
          ('Food & Drinks'),
          ('Going out'),
          ('Movies & TV'),
          ('Music'),
          ('Pets'),
          ('Sports'),
          ('Trips');

  insert into public.interest (name, category)
values  ('A sweet tooth', 'Food & Drinks'),
        ('Acting', 'Creativity'),
        ('Action', 'Movies & TV'),
        ('Animated', 'Movies & TV'),
        ('Anime', 'Movies & TV'),
        ('Art', 'Creativity'),
        ('Athletics', 'Sports'),
        ('Backpacking', 'Trips'),
        ('Badminton', 'Sports'),
        ('Bar', 'Going out'),
        ('Beach holiday', 'Trips'),
        ('Beer', 'Food & Drinks'),
        ('Big city holiday', 'Trips'),
        ('Birds', 'Pets'),
        ('Cats', 'Pets'),
        ('Caviar', 'Food & Drinks'),
        ('Champagne', 'Food & Drinks'),
        ('Classic', 'Music'),
        ('Coffee', 'Food & Drinks'),
        ('Comedy', 'Movies & TV'),
        ('Cycling', 'Sports'),
        ('Design', 'Creativity'),
        ('Dogs', 'Pets'),
        ('Doubbledate', 'Going out'),
        ('Drama', 'Movies & TV'),
        ('Drinks', 'Going out'),
        ('Fest', 'Going out'),
        ('Festival', 'Going out'),
        ('Fish', 'Pets'),
        ('Fitness', 'Sports'),
        ('Foodie', 'Food & Drinks'),
        ('Football', 'Sports'),
        ('Golf', 'Sports'),
        ('Gymnastics', 'Sports'),
        ('Handball', 'Sports'),
        ('Handiwork', 'Creativity'),
        ('Hiking', 'Trips'),
        ('Hip hop', 'Music'),
        ('Horror', 'Movies & TV'),
        ('House', 'Music'),
        ('In', 'Creativity'),
        ('Jazz', 'Music'),
        ('Meditation', 'Sports'),
        ('Netflix', 'Movies & TV'),
        ('Nightclub', 'Going out'),
        ('Photography', 'Creativity'),
        ('Pop', 'Music'),
        ('R&B', 'Music'),
        ('Rabbit', 'Pets'),
        ('Rap', 'Music'),
        ('Road trip', 'Trips'),
        ('Rock', 'Music'),
        ('Punk', 'Music'),
        ('Punk rock', 'Music'),
        ('Hardcore punk', 'Music'),
        ('Skate punk', 'Music'),
        ('Romantic', 'Movies & TV'),
        ('Rowing', 'Sports'),
        ('Run', 'Sports'),
        ('Sci-fi', 'Movies & TV'),
        ('Singing', 'Creativity'),
        ('Skateboard', 'Sports'),
        ('Ski', 'Sports'),
        ('Ski holiday', 'Trips'),
        ('Snowboard', 'Sports'),
        ('Swimming', 'Sports'),
        ('Table tennis', 'Sports'),
        ('Tennis', 'Sports'),
        ('Theater', 'Creativity'),
        ('Vegan', 'Food & Drinks'),
        ('Vin', 'Food & Drinks'),
        ('Volleyball', 'Sports'),
        ('Write', 'Creativity'),
        ('Yoga', 'Sports');
  `);
};

@JasonShin
Copy link
Owner

JasonShin commented Oct 27, 2023

Hello @simplenotezy, I've released more fix to enhance support for nest.js project source code and it was released in 0.7.0. I figured out some TS syntax wasn't picked up via sqlx-ts in nest.js codebase #80.

In regards to the query above in your last example, I will try to reproduce it on my end. However, that query is not even contained inside sql tag, so I highly doubt that's the problematic query 🤔

@simplenotezy
Copy link
Author

Hello @simplenotezy, I've released more fix to enhance support for nest.js project source code and it was released in 0.7.0. I figured out some TS syntax wasn't picked up via sqlx-ts in nest.js codebase #80.

In regards to the query above in your last example, I will try to reproduce it on my end. However, that query is not even contained inside sql tag, so I highly doubt that's the problematic query 🤔

Amazing!

And regarding the last part; sure it's strange, but I just copy pasted the error output, and that's indeed the line 🤔

@JasonShin
Copy link
Owner

JasonShin commented Dec 2, 2023

Could you please try v0.9.0? apologies for this - how did I completely miss this (?). Check the PR #85 from @andersthuesen 🚀

@JasonShin
Copy link
Owner

I will close this for now hoping that it is fixed with the latest updates

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

No branches or pull requests

2 participants