node-sql-template-strings icon indicating copy to clipboard operation
node-sql-template-strings copied to clipboard

Named bindings feature request

Open elmeister opened this issue 2 years ago • 1 comments

Hello Thanks for the awesome library

Knex has a nice named bindings option, which allows to use :parametersWithColon (see docs), which in turn are supported in RDBMS editors, so we don't have to replace all ${id} with :id manually each time we're testing raw SQL The check that named parameters are present looks pretty straightforward How about adding something similar to sql-template-strings, so we would be able to build queries like this i.e.

sql`
SELECT * FROM books 
  WHERE id = :bookId
`.bind({ bookId })

elmeister avatar Feb 01 '23 16:02 elmeister

Really, if you want to use that kind of syntax, you're better off using the underlying database adapter directly, most of which already support that syntax. JS telmplate strings only naturally support the ordinal position, and your suggestion really wouldn't add much in terms of support. Also, not all the database backends currently in place support named parameters vs ordinal position.

tracker1 avatar Aug 31 '23 16:08 tracker1