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: Named bindings #1654

Closed
theoephraim opened this issue Apr 6, 2021 · 1 comment
Closed

Question: Named bindings #1654

theoephraim opened this issue Apr 6, 2021 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@theoephraim
Copy link

I have a situation where I have some pretty complex raw queries that are being constructed. To avoid dealing with escaping values myself, I'd like to let the query builder handle this. Additionally, because the queries are complex and constructed in many steps, I'd rather not have the ordering of the replacements be significant. In many other tools, I would use "named bindings" to do this, but I can't find any example of this in the docs.

For example, something like runQuery('SELECT * FROM mytable WHERE foo = :fooval', { fooval: 'value to use in the query' })

Knex mentions this here as "named bindings", but I can't seem to find the right way to get access to this method, as the TS type for queryBuilder.raw() only accepts a single string.

@theoephraim theoephraim added the enhancement New feature or request label Apr 6, 2021
@B4nan
Copy link
Member

B4nan commented Apr 6, 2021

qb.raw() is just a shortcut for qb.getKnex().raw(), so you could use that to work with the real knex method (where the binding parameter exists).

sure we can add it here too (PR welcome)

@B4nan B4nan added good first issue Good for newcomers help wanted Extra attention is needed labels Apr 6, 2021
@B4nan B4nan closed this as completed in aa423a5 Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants