Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Heads up! - v0.4.0 changed transaction event names. If you had listeners for
'committed' or 'rolled back' events before, they are now called 'commit:complete'
and 'rollback:complete' respectively. They are emitted after the corresponding
SQL query has completed, if you want the old behaviour (events emitted when the
commit
/rollback
methods are called) use 'commit:start' and 'rollback:start'.
(There's also detailed API documentation available)
var anyDB = require('any-db')
var dbURL = 'driver://user:pass@hostname/database'
Establish a connection:
var conn = anyDB.createConnection(dbURL) // Takes an optional callback
Make queries:
var sql = 'SELECT * FROM my_table'
conn.query(sql).on('row', function (row) {}) // evented
conn.query(sql, function (error, result) {}) // or callback
Use bound parameters:
sql += ' WHERE my_column = ?'
conn.query(sql, [42]).on('row', ...) // again, evented
conn.query(sql, [42], function (err, res) {}) // or callback
Close a connection:
conn.end()
Start a transaction:
var tx = conn.begin() // Can also take a callback
tx.on('error', function (err) {}) // Emitted for unhandled query errors
tx.query(...) // same interface as connections, plus...
tx.commit() // takes an optional callback for errors
tx.rollback() // this too
Create a connection pool that maintains 2-20 connections
var pool = anyDB.createPool(dbURL, {min: 2, max: 20})
pool.query(...) // perform a single query, same API as connection
var tx = pool.begin() // start a transaction, again, same API as connection
pool.close() // close the pool (call when your app should exit)
The purpose of this library is to provide a consistent API for the commonly used functionality of SQL database drivers, while avoiding altering driver behaviour as much as possible.
The long-term goal of this project is to serve as the testing ground for finding a suitable common interface, then (hopefully) convincing driver implementors to support it natively. In short, any-db hopes to prove it's usefulness well enough that most of it can be obviated by the drivers themselves.
driver://user:pass@host/database
pool.query("SELECT 1", function (err, results) { ... })
.first
or .fetchAll
npm install --save any-db
npm install --save {pg,mysql,sqlite3}
For ideas that would change an existing API or behaviour please open an issue to propose the change before spending time on implementing it. I know it's hard (I code-first-ask-questions-later way too frequently :smile:) but I'd really hate for anybody to put their time into something that won't be merged.
I'm not terribly picky about code-formatting, but please try and keep lines under 80 characters long if you can help it.
MIT
FAQs
Database-agnostic connection pooling, querying, and result sets
The npm package any-db receives a total of 1,675 weekly downloads. As such, any-db popularity was classified as popular.
We found that any-db 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.