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

parameters #24

Open
chase-moskal opened this issue Jun 16, 2020 · 7 comments
Open

parameters #24

chase-moskal opened this issue Jun 16, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@chase-moskal
Copy link

from the readme,

Query parameters use the format $1, $2 etc.

do the parameters have to be numbered? i'd much prefer to use names, as i'm familiar with using parameter placeholders like SELECT * FROM whatever WHERE :lol = 5 or something like that, right?

i'm just really hoping i don't have to worry about how things are ordered, i'm an options-object kind of guy

@malthe
Copy link
Owner

malthe commented Jun 16, 2020

Yes, it is probably possible to have a preprocessor that scans through the statement, replacing :<param-name> with a position-based expression and then map it correctly on query execute.

But if you look at brianc/node-postgres#268, there are plenty of reasons not to want something like that – opting instead for doing this on a higher level; for example, a query builder could provide such an interface.

@chase-moskal
Copy link
Author

oh. well that makes sense. thanks for sharing that link!

maybe we could whip up some sugar for named params?

would you rather that be in a separate repo/package, or would you be interested for some kind of sugar/ directory here for experimenting with these kinds of extras?

@chase-moskal
Copy link
Author

preprocessor that scans through the statement

i just read that, and thought about tagged template literals at the same time — and got a nerd-boner!

@malthe
Copy link
Owner

malthe commented Jun 16, 2020

It might be possible to implement this sugar using a tokenizer only and not have to actually parse the query. I wouldn't mind having a simple desugaring function in the code – the functionality is nice to have for sure.

@chase-moskal
Copy link
Author

i'm thinking something along these lines ought be possible!

const result = await query`SELECT * FROM table WHERE column = ${value}`

how do you fancy?

@malthe
Copy link
Owner

malthe commented Jun 17, 2020

That looks good. People understand the escaping of those literals because of the tagged literal syntax.

And it's far better than :param = ... which would be hard to implement correctly and is as foreign to JS/TypeScript as it is to PostgreSQL.

@chase-moskal
Copy link
Author

i'll look into putting together a pull request for you, to add a sugar directory, so we can experiment and mull it over :)

@malthe malthe added the enhancement New feature or request label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants