Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/guidesmiths/sql-params-format
Formatter for named sql params
https://github.com/guidesmiths/sql-params-format
Last synced: 22 days ago
JSON representation
Formatter for named sql params
- Host: GitHub
- URL: https://github.com/guidesmiths/sql-params-format
- Owner: guidesmiths
- Created: 2019-06-27T14:28:02.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-07-07T13:13:48.000Z (over 2 years ago)
- Last Synced: 2024-12-18T09:45:26.033Z (29 days ago)
- Language: JavaScript
- Size: 123 KB
- Stars: 1
- Watchers: 10
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sql-params-format
a wrapper around pg-format to allow named parameters to sql queries.
```js
// default usage, no named params. operates just like pg-format
const sql = 'insert into %I (select * from foo where %s and bar > %L)';
const formatted = format(sql, 'a_table', 'something=another', 123);
formatted => insert into a_table (select * from foo where something=another and bar > '123')// using named parameters
const sql = 'insert into %I:one (select * from foo where %s:two and bar > %L:three)';
const formatted = format(sql, {one: 'a_table', two: 'something=another', three: 123});
formatted => insert into a_table (select * from foo where something=another and bar > '123')```
It will ignore any unused named parameters.
Parameters used more than once in the query need only be passed once.Special note, this will convert moment objects to date objects if passed as parameters.