https://github.com/mysqljs/named-placeholders
PDO-style named to unnamed placeholders compiler
https://github.com/mysqljs/named-placeholders
Last synced: 2 months ago
JSON representation
PDO-style named to unnamed placeholders compiler
- Host: GitHub
- URL: https://github.com/mysqljs/named-placeholders
- Owner: mysqljs
- License: mit
- Created: 2014-08-30T07:56:49.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2024-09-20T21:35:37.000Z (9 months ago)
- Last Synced: 2025-04-01T16:06:46.214Z (3 months ago)
- Language: JavaScript
- Size: 43 KB
- Stars: 22
- Watchers: 3
- Forks: 13
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://nodei.co/npm/named-placeholders/)
[](https://github.com/mysqljs/named-placeholders/actions/workflows/ci.yml)
# named-placeholders
compiles "select foo where foo.id = :bar and foo.baz < :baz" into "select foo where foo.id = ? and foo.baz < ?" + ["bar", "baz"]
## usage
```sh
npm install named-placeholders
```see [this mysql2 discussion](https://github.com/sidorares/node-mysql2/issues/117)
```js
var mysql = require('mysql');
var toUnnamed = require('named-placeholders')();var q = toUnnamed('select 1+:test', { test: 123});
mysql.createConnection().query(q[0], q[1]);
```## credits
parser is based on @mscdex code of his excellent [node-mariasql](https://github.com/mscdex/node-mariasql) library