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

Does not accept placeholder names that begin with underscore ('_') #6

Open
rmullenix opened this issue Apr 7, 2017 · 4 comments
Open

Comments

@rmullenix
Copy link

rmullenix commented Apr 7, 2017

When the parameter names lead with an underscore, they are ignored by the system.

'use strict';
const nph = require('named-placeholders')();

let query = 'SELECT 1 + :_foo + :bar;';
let params = {'_foo': 2, 'bar': 3 };

let q = nph(query, params);

console.log(q[0]);  // SELECT 1 + :_foo + ?;
console.log(q[1]); // [ 3 ]

MySQL allows for column names to lead with an underscore and Javascript allows for Object properties to lead with an underscore, so this should be supported behavior.

@sidorares
Copy link
Member

should be an easy fix to

var RE_PARAM = /(?:\?)|(?::(\d+|(?:[a-zA-Z][a-zA-Z0-9_]*)))/g,
regex

@rmullenix
Copy link
Author

Yup.. I made a local edit to add the _ to the initial regex and it worked great

@sidorares
Copy link
Member

feel free to add a test and submit pr!

@rmullenix
Copy link
Author

Submitted PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants