Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
anydb-sql combines node-anydb and node-sql into a single package full of awesomeness.
Initializing an instance also creates a connection pool. The url argument is the same as in node-anydb
var anydbsql = require('anydb-sql');
var db = anydbsql({
url: 'postgres://user:pass@host:port/database',
connections: { min: 2, max: 20 }
});
Defining a table for that database is the same as in node-sql:
var user = db.define({
name: 'Users',
columns: ['id', 'email', 'password']
});
Queries have all the methods as in node-sql, plus the additional methods:
If you omit the callback from the additional methods, an eventemitter will be returned instead (like in anydb).
Use regular node-sql queries then chain one of the additional methods at the end:
user.where({email: user.email}).get(function(err, user) {
// user.name,
});
Join queries can be constructed using node-sql. The format of the results is the same as with anydb
user.select(user.name, post.content)
.from(user.join(post).on(user.id.equals(post.userId)))
.where(post.date.gt(yesterday))
.all(function(err, userposts) {
// res[0].name and res[0].content
});
When creating join queries, you can generate sub-objects in the result by specifying aliases that contain dots in the name:
user.select(user.name.as('user.name'), post.content.as('post.content'))
.from(user.join(post).on(user.id.equals(post.userId)))
.where(post.date.gt(yesterday))
.all(function(err, res) {
// res[0].user.name and res[0].post.content
});
or you can use db.allOf to do the above for all the table's columns :
user.select(db.allOf(user, post))
.from(user.join(post).on(user.id.equals(post.userId)))
.where(post.date.gt(yesterday))
.all(function(err, res) {
// contains res[0].user.name, res[0].post.content and all
// other columns from both tables in two subobjects per row.
});
Create a transactions and execute queries within it
var tx = db.begin()
user.insert({name: 'blah'}).returning(user.id).execWithin(tx);
user.insert({name: 'bleh'}).returning(user.id).execWithin(tx);
tx.commit();
Transactions have the same API as anydb tranactions
You can close the connection pool
db.close();
Or execute custom queries
db.query(...anydb arguments...)
MIT
FAQs
Minimal ORM for mysql, postgresql and sqlite with complete arbitrary SQL query support (based on brianc's query builder sql)
The npm package anydb-sql receives a total of 81 weekly downloads. As such, anydb-sql popularity was classified as not popular.
We found that anydb-sql demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.