Gathering detailed insights and metrics for mysql-query-placeholders
Gathering detailed insights and metrics for mysql-query-placeholders
Gathering detailed insights and metrics for mysql-query-placeholders
Gathering detailed insights and metrics for mysql-query-placeholders
npm install mysql-query-placeholders
Typescript
Module System
Node Version
NPM Version
TypeScript (98.82%)
JavaScript (1.18%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
1 Stars
11 Commits
1 Watchers
2 Branches
1 Contributors
Updated on Dec 04, 2020
Latest Version
0.2.2
Package Id
mysql-query-placeholders@0.2.2
Unpacked Size
8.91 kB
Size
3.20 kB
File Count
5
NPM Version
6.14.8
Node Version
12.19.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Consider the following object:
1const user = { 2 id: 123, 3 status: { 4 active: true, 5 }, 6 services: { 7 home: { 8 route: '/', 9 }, 10 dashboard: { 11 route: '/dashboard', 12 }, 13 }, 14 name: 'John', 15 email: 'email@mail.com', 16};
Then you can easily create a prepared statement for MySQL using the data from the object above.
1const mqp = require('mysql-query-placeholders'); 2const mysql = require('mysql2').createConnection... 3 4const query = 'SELECT * FROM users WHERE id = :id AND name = :name;'; 5const queryData = mqp.queryBuilder(query, user); 6console.log(queryData); 7// { 8// sql: 'SELECT * FROM users WHERE id = ? AND name = ?;', 9// values: [123, 'John'], 10// } 11 12// use named parameters 13mysql.query(queryData, (err, result) => {...});
1import {queryBuilder} from 'mysql-query-placeholders'; 2import {createConnection} from 'mysql2/promise'; 3 4const mysql = createConnection(...); 5 6const query = 'SELECT * FROM users WHERE id = :id AND name = :name;'; 7const queryData = queryBuilder(query, user); 8console.log(queryData); 9// { 10// sql: 'SELECT * FROM users WHERE id = ? AND name = ?;', 11// values: [123, 'John'], 12// } 13 14// use named parameters 15await mysql.query(queryData);
MySQL throws an error if a parameter is not given.
Passing a configuration object with useNullForMissing
set to true (which is true
by default), a null
value is used instead.
1const query = 'SELECT * FROM users WHERE id = :id AND last_name = :last_name;'; 2const queryData = mqp.queryBuilder(query, user, {useNullForMissing: true}); 3console.log(queryData); 4// { 5// sql: 'SELECT * FROM users WHERE id = ? AND last_name = ?;', 6// values: [123, null], 7// }
If you do not want to use null
by default, you can throw an error instead, setting the useNullForMissing
configuration option to false
.
1try { 2 const query = 'SELECT * FROM users WHERE id = :id AND last_name = :last_name;'; 3 const queryData = mqp.queryBuilder(query, user, {useNullForMissing: false}); 4} catch (e) { 5 errorMessage = e.message; 6 console.log(errorMessage); 7 // Missing value for statement. 8 // last_name not provided for statement: 9 // ... 10}
mqp is capable to get a object property value from a key.name.property.value syntax. This is useful when you do not want to reassign the property value to another variable or you want to use the original object instead of creating a new one.
1const query = 'SELECT * FROM services WHERE route IN (:services.dashboard.route, :services.home.route);'; 2const queryData = mqp.queryBuilder(query, user); 3console.log(queryData); 4// { 5// sql: 'SELECT * FROM services WHERE route IN (?, ?);', 6// values: [ '/dashboard', '/' ] 7// }
Missing property:
1const query = 'INSERT INTO services (name, route) VALUES (\'cpanel\', :services.cpanel.route);'; 2const queryData = mqp.queryBuilder(query, user); 3console.log(queryData); 4// { 5// sql: "INSERT INTO services (name, route) VALUES ('cpanel', ?);", 6// values: [ null ] 7// }
Or using {useNullForMissing: false}
config:
1try { 2 const query = 'SELECT * FROM services WHERE route = :services.cpanel.route;'; 3 const queryData = mqp.queryBuilder(query, user, {useNullForMissing: false}); 4} catch (e) { 5 errorMessage = e.message; 6 console.log(errorMessage); 7 // Missing value for statement. 8 // services.cpanel.route not provided for statement: 9 // ... 10}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 0/9 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
license file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
28 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More