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

Use SQL comment line for parameter hint to retain .sql usability #43

Open
bkmdev opened this issue Sep 12, 2020 · 5 comments
Open

Use SQL comment line for parameter hint to retain .sql usability #43

bkmdev opened this issue Sep 12, 2020 · 5 comments

Comments

@bkmdev
Copy link

bkmdev commented Sep 12, 2020

Enhancement Request: Currently, to make existing .sql files usable by pugSQL, one needs to "corrupt" them by injecting :myVar references into the SQL queries, thus invalidating them as usable .sql files.

I feel like this is a missed opportunity, as it would have been nicer / more elegant, if one simply could have just annotated them via the comment line (--) providing hints as to the variable to use (ie: parse for in the subsequent line(s)) to maintain the usability of the original .sql file.

@Yeganloo
Copy link

Yeganloo commented Sep 12, 2020

Can you give an example of what you propose?
What the query will be look like?
If : is all your problem, using a database tool like "DBeaver" will solve your problems and all of your queries are still usable!

@bkmdev
Copy link
Author

bkmdev commented Sep 12, 2020

I was thinking something like:

-- :name find_user :var "42" :one
select * from users where user_id = "42"

(basically some kind of space delimited token in the comment line keyed by the :var reserved word to indicate what in the next line is the variable to parse for & replace)

Re. DBeaver: Are you referring to https://dbeaver.io/ ? If so, I tried searching the site for PugSQL but didn't get any hits... Can you clarify? (I'm not familiar with it and normally just use MySQL Workbench)

@Yeganloo
Copy link

Yeganloo commented Sep 12, 2020

Yes. That is DBeaver.
It is a SQL tool, there is no pugsql in it.
Did you use PG-Admin4 or SQL-MyAdmin? it is something like them, but it can almost connect all kind of SQL-Engines.
Your problem is that queries you write for Pugsql are not usable in your db too (pgAdmin for example). Right?
If you run those kind of query in DBeaver, it prompts before running query and ask for : marked parameters.
Like this:
Screenshot from 2020-09-12 22-57-35

So i think it's not Pugsql problem and it's about the query tool you use!

About your proposal, what is fantastic in Pugsql is that queries inside app are exactly what you use outside of code!
The main problem with this proposal is, it cause Pugsql to regenerate a new query, before execution!
So all the benefits of debugging are gone from Pugsql!
Query in sql file is not exectly the query that run in your DBMS!

@doekman
Copy link

doekman commented Dec 22, 2020

I've tackled this issue by giving SQL files with parameters the extension .psql instead of .sql.

I've used this with other project, and it can also be used with PugSQL, since globbing is done via *sql (without a dot before sql).

@bkmdev
Copy link
Author

bkmdev commented Jan 15, 2021 via email

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

3 participants