Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
downstairs
Advanced tools
Documentation currently a work in progress.
A Node.js ORM Framework with
Downstairs is in production use for three Moneytribe codebases.
Currently in development:
Downstairs has 'Collections' and 'Records'. A Collection is a group of documents. A Record is a single document.
Configure Downstairs with as many database connections and adapters as needed:
var pgConnection = new Downstairs.Connection.PostgreSQL(env.connectionString);
var sqlAdapter = new SQLAdapter();
Downstairs.add(pgConnection, sqlAdapter, "primarydb");
Assign a Collection to a configuration:
var sql = require('sql')
, Validator = require('validator').Validator;
var userConfig = sql.Table.define({
name: 'users'
, quote: true
, schema: 'public'
, columns: ['id'
, 'username'
, 'created_at'
, 'updated_at'
, 'email'
, 'password'
, 'role_id'
]
});
var validations = {
passwordPresent: function(cb){
var validator = new Validator();
try{
validator.check(this.password).notNull();
cb(null, null);
}
catch(e){
cb(null, "Password: " + e.message);
}
}
};
var User = Collection.model('User', userConfig, validations, 'primarydb');
Once you have configured a Collection you can manipulate it at a Collection level to produce a record:
User.create({username: 'fred2', password: 'nottelling', email: 'test2@test.com'}, function(err, user) {
...
});
Collection level behaviours mandated by every adapter are:
mandatedCalls = ['find', 'findAll', 'update', 'create', 'delete', 'count'];
Some additional query parameters are:
User.findAll({ like: {name: 'fre%', surname: 'jon%'} });
# This finds all users with a name that starts with 'fre' and a surname that starts with 'jon'
User.findAll({ queryParameters: {limit: 6, orderBy: 'name ASC' } } });
# This orders the query ascending by name and limits the number of results to 6
User.findAll({ name: [ 'Fred', 'Mary'] });
# This finds all users named Fred and Mary.
For migrations use VisionMedia's node-migrate: https://github.com/visionmedia/node-migrate .
This means you will have to hand craft your SQL to create tables but this is a good thing.
For example, we have a migrations directory and a migrations helper to expedite things. We also export the migration so it can be called upon in tests (when we want to rapidly construct tables after tearing down the database).
# Copyright (c) 2012 MoneyTribe
migrator = require './helper'
upStatement = "CREATE TABLE users
(
id bigserial NOT NULL,
username character varying(100) UNIQUE NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT now(),
updated_at timestamp with time zone NOT NULL DEFAULT now(),
is_active boolean DEFAULT true,
email character varying(512) UNIQUE,
password character varying(64),
CONSTRAINT pk_users PRIMARY KEY (id)
WITH (FILLFACTOR=90)
)
WITH (
OIDS=FALSE
);"
downStatement = "DROP TABLE users;";
exports.up = (next) ->
migrator.run upStatement, (err, result) ->
next() if result
throw err if err
exports.down = (next)->
migrator.run downStatement, (err, result) ->
next() if result
throw err if err
exports.upStatement = upStatement
Install the module with: npm install downstairs
var downstairs = require('downstairs');
Copyright (c) 2012 Moneytribe Pty Ltd. Licensed under the MIT license.
FAQs
A light ORM wrapped about brianc's node-sql and node-pg
The npm package downstairs receives a total of 30 weekly downloads. As such, downstairs popularity was classified as not popular.
We found that downstairs 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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.