Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
like-sql
Advanced tools
Readme
Simple SQL query builder
const SQL = require('like-sql')
const builder = new SQL()
// CREATE DATABASE IF NOT EXISTS `myapp`
const [sql] = builder.createDatabase('myapp')
// DROP DATABASE IF EXISTS `myapp`
const [sql] = builder.dropDatabase('myapp')
// INSERT INTO `ips` (`addr`, `hits`) VALUES (?, ?)
const [sql, values] = builder.insert('ips', { addr: req.ip, hits: 0 })
// SELECT `addr`, `hits` FROM `ips` WHERE addr = ?
const [sql, values] = builder.select('ips', ['addr', 'hits'], 'addr = ?', req.ip)
// SELECT `addr`, `hits` FROM `ips` WHERE addr = ? LIMIT 1
const [sql, values] = builder.selectOne('ips', ['addr', 'hits'], 'addr = ?', req.ip)
// SELECT EXISTS(SELECT 1 FROM `ips` WHERE addr = ? LIMIT 1)
const [sql, values] = builder.exists('ips', 'addr = ?', req.ip)
// SELECT COUNT(1) FROM `ips` WHERE addr = ?
const [sql, values] = builder.count('ips', 'addr = ?', req.ip)
// UPDATE `ips` SET `hits` = ? WHERE addr = ? LIMIT 1
const [sql, values] = builder.update('ips', { hits: 1 }, 'addr = ? LIMIT 1', req.ip)
// UPDATE `ips` SET `hits` = hits + ? WHERE addr = ?
const [sql, values] = builder.update('ips', [{ hits: 'hits + ?' }, 1], 'addr = ?', req.ip)
// DELETE FROM `ips` WHERE addr = ? LIMIT 1
const [sql, values] = builder.delete('ips', 'addr = ? LIMIT 1', req.ip)
Extends:
const SQL = require('like-sql')
class MySQL extends SQL {
constructor (opts = {}) {
super(opts)
this.pool = mysql2.createPool(...)
}
async _insert (sql, values) {
const [res] = await this.pool.execute(sql, values)
return res.insertId
}
async _select (sql, values) {
...
}
async _selectOne (sql, values) {
...
}
// ...
}
const db = new MySQL()
const id = await db.insert('ips', { addr: req.ip, hits: 0 })
npm i like-sql
npm run test
Code released under the MIT License.
FAQs
Simple SQL query builder
The npm package like-sql receives a total of 7 weekly downloads. As such, like-sql popularity was classified as not popular.
We found that like-sql demonstrated a healthy version release cadence and project activity because the last version was released less than 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 four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.