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

[question] How to get the query string before execution? #818

Open
IAkumaI opened this issue Feb 27, 2024 · 3 comments
Open

[question] How to get the query string before execution? #818

IAkumaI opened this issue Feb 27, 2024 · 3 comments

Comments

@IAkumaI
Copy link

IAkumaI commented Feb 27, 2024

let where = sql`col = 1`;
let query = sql`SELECT * FROM WHERE ${where}`;

let sql_as_string = query.(what?);

Hello. Is there any way to get the actual sql query string before/without the exucution?
I know we have sql.statement but it is not available before the query exucution and if the query has errors (while building it dynamically) I don't know how to debug it properly.

I found query.strings but it's...well not what i need.

@masfahru
Copy link

masfahru commented Mar 1, 2024

@IAkumaI
Copy link
Author

IAkumaI commented Mar 1, 2024

Describe executes the query. Without correct query and correct connection it will not give me the query string:

let where = sql`WHERE a = 1`;
console.log(await sql`SELECT ERROR ${where}`.describe()); // column "error" does not exist

This shows only error, but not the actual query string. What do I do wrong?

@IAkumaI
Copy link
Author

IAkumaI commented Mar 1, 2024

Found a "tricky" way: #760
But maybe there is another more "right" way?
There is nothing about this in the docs, btw.

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

2 participants