
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
node-sql-gen
Advanced tools
Simple sql query generator. No orm, raw sql forever!! 🎉
# yarn
$ yarn add node-sql-gen
# npm
$ npm install node-sql-gen
for more details, check src/ dir
Support = > < >= <= LIKE IN Operators
const whereExample01 = {
id: 1, // same with id: { "=": 1 }
nick: { LIKE: "%ben%" },
age: { ">": 10, "<=": 15, [OR]: { "IN": [1, 2, 3] } }, // means (10, 15] + 1 2 3
}
Support JSON type
const setDataExample01 = {
id: 1,
nick: 'newNick',
favorite: ['games', 'food']
}
AvailableOperator = ["LIKE", "IN", ">", "<", ">=", "<=", "=", OR]
ErrorWhereNull = "where cannot be null or empty"
ErrorSetNull = "set data cannot be null or empty"
ErrorWhereInEmptyArray = "where condition [in] value must be array (len>0)"
ErrorUnknownOperator = "unknown operator, only " + JSON.stringify(AvailableOperator) + " is available"
const sqlGen = require('sql-gen')
const mysql = require('mysql2')
const dbClient = mysql.createPool({ ... })
async function query (gen) {
return dbClient.query(gen.sql, gen.args)
}
query(sqlGen.select("user")).then(console.log).catch(console.error)
const OR = sqlGen.OR
function log (obj) {
console.dir(obj, { depth: null })
console.log('mysql:', mysql.format(obj.sql, obj.args))
}
let s0 = sqlGen.select("user")
log(s0)
// { sql: 'SELECT * FROM ??', args: [ 'user' ] }
// mysql: SELECT * FROM `user`
let s1 = sqlGen.select("user", "id,order", {
id: 1,
[OR]: {
nick: { LIKE: "ben%" },
age: { ">=": 10 },
}
}, "id DESC", { offset: 0, size: 20 })
log(s1)
// {
// sql: 'SELECT `id`, `order` FROM ?? WHERE `id` = ? OR (`nick` LIKE ? AND `age` >= ?) ORDER BY id DESC LIMIT 0, 20',
// args: [ 'user', 1, 'ben%', 10 ]
// }
// mysql: SELECT `id`, `order` FROM `user` WHERE `id` = 1 OR (`nick` LIKE 'ben%' AND `age` >= 10) ORDER BY id DESC LIMIT 0, 20
const s2 = sqlGen.insert("user", {
id: 1,
nick: "ben",
null_: null,
int_: 10,
datetime_: "1901-01-01 01:01:01",
json: {
t1: false,
},
json2: ["basketball", "football"],
})
log(s2)
// {
// sql: 'INSERT INTO ?? SET ?',
// args: [
// 'user',
// { id: 1, nick: 'ben', null_: null, int_: 10, datetime_: '1901-01-01 01:01:01', json: '{"t1":false}', json2: '["basketball","football"]'}
// ]
// }
// mysql: INSERT INTO `user` SET `id` = 1, `nick` = 'ben', `null_` = NULL, `int_` = 10, `datetime_` = '1901-01-01 01:01:01', `json` = '{\"t1\":false}', `json2` = '[\"basketball\",\"football\"]'
const where = { id: null }
const setData = { id: 1 }
const s3 = sqlGen.update("user", where, setData)
log(s3)
// {
// sql: 'UPDATE ?? SET ? WHERE `id` IS NULL',
// args: [ 'user', { id: 1 } ]
// }
// mysql: UPDATE `user` SET `id` = 1 WHERE `id` IS NULL
FAQs
simple sql query generator
The npm package node-sql-gen receives a total of 8 weekly downloads. As such, node-sql-gen popularity was classified as not popular.
We found that node-sql-gen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.