Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

downstairs

Package Overview
Dependencies
Maintainers
3
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

downstairs - npm Package Compare versions

Comparing version 0.3.5 to 0.3.6

test/blueprints.js

6

config/defaults_sample.json

@@ -5,3 +5,3 @@ {

"host": "localhost",
"port": "3306",
"port": "5432",
"user": "nicholas",

@@ -15,3 +15,3 @@ "password": null,

"host": "localhost",
"port": "3306",
"port": "5432",
"user": "nicholas",

@@ -25,3 +25,3 @@ "password": null,

"host": "localhost",
"port": "3306",
"port": "5432",
"user": "nicholas",

@@ -28,0 +28,0 @@ "password": null,

@@ -19,3 +19,12 @@ {

}
},
"production": {
"database": {
"host": "localhost",
"port": "5432",
"user": "nicholas",
"password": null,
"name": "downstairs_production"
}
}
}

@@ -5,3 +5,4 @@ var Collection = {}

, Record = require('./record')
, lingo = require('lingo');
, lingo = require('lingo')
, fleck = require('fleck');

@@ -317,3 +318,3 @@ Collection.use = function(Downstairs){

Collection.belongsTo = function(model){
var belongsToAssociationName = model._name.toLowerCase();
var belongsToAssociationName = fleck.underscore(model._name);
var foreignKeyName = belongsToAssociationName + "_id"; //oneday this will be configurable

@@ -334,5 +335,4 @@

Collection.hasOne = function(model){
var keyName = this._name.toLowerCase();
var hasOneAssociationName = model._name;
hasOneAssociationName = hasOneAssociationName.toLowerCase();
var keyName = fleck.underscore(this._name);
var hasOneAssociationName = fleck.underscore(model._name);
var foreignKeyName = keyName + "_id"; //oneday this will be configurable

@@ -355,5 +355,5 @@

Collection.hasMany = function(model){
var keyName = this._name.toLowerCase();
var hasManyAssociationName = lingo.en.pluralize(model._name);
hasManyAssociationName = hasManyAssociationName.toLowerCase();
var keyName = fleck.underscore(this._name);
keyName = keyName.toLowerCase();
var hasManyAssociationName = lingo.en.pluralize(fleck.underscore(model._name));
var foreignKeyName = keyName + "_id"; //oneday this will be configurable

@@ -360,0 +360,0 @@

{
"name": "downstairs",
"description": "A light ORM wrapped about brianc's node-sql and node-pg",
"version": "0.3.5",
"version": "0.3.6",
"homepage": "https://github.com/moneytribeaustralia/downstairs.js",

@@ -33,7 +33,8 @@ "author": {

"should": "~1.2.0",
"ectypes": "~1.0.0",
"ectypes-postgres": "~0.1.2",
"ectypes": "~1.1.0",
"ectypes-downstairs": "~0.1.1",
"mocha": "~1.5.0",
"sql": "~0.1.0",
"faker2": "~0.5.0"
"faker2": "~0.5.0",
"ectypes-postgres": "~0.1.2"
},

@@ -47,4 +48,5 @@ "keywords": [],

"validator": "~0.4.13",
"underscore": "~1.4.1"
"underscore": "~1.4.1",
"fleck": "~0.5.1"
}
}

@@ -1,2 +0,2 @@

[![build status](https://secure.travis-ci.org/moneytribeaustralia/downstairs.js.png)](http://travis-ci.org/moneytribeaustralia/downstairs.js)
The README below is out of date. Read through the tests to get a sense of how Downstairs works.

@@ -3,0 +3,0 @@ # downstairs

@@ -125,3 +125,77 @@ var Downstairs = require('../lib/downstairs')

});
it('returns the right associated objects for the right objects', function(done){
var User = Collection.model('User', helper.userConfig);
var Role = Collection.model('Role', helper.roleConfig);
Role.hasMany(User);
User.belongsTo(Role);
var roleData = {name: 'someRole'};
ectypes.Role.create(roleData, function(err, results){
Role.find({name: 'someRole'}, function(err, role){
var userData = {
password: '5f4dcc3b5aa765d61d8327deb882cf99'
, username: 'fred'
, email: 'fred@moneytribe.com.au'
, role_id: role.id
};
ectypes.User.create(userData, function(err, results) {
ectypes.Role.create({name: 'role2'}, function(err, result) {
Role.find({name: 'role2'}, function(err, role2){
role2.get('users', function(err, users){
// console.log(users, role2, "aha!");
users.length.should.equal(0);
role.get('users', function(err, users){
users.length.should.equal(1);
done();
});
});
});
});
});
});
});
});
});
describe("associations using longer table names", function(done){
beforeEach(function(done){
helper.resetDb(helper.userSQL + helper.longerTableNameSQL, done);
});
it('can create a hasMany for a complex table name', function(done){
var User = Collection.model('User', helper.userConfig);
var LongerTableName = Collection.model('LongerTableName', helper.longerTableNameConfig);
User.hasMany(LongerTableName);
LongerTableName.belongsTo(User);
var userData = {
password: '5f4dcc3b5aa765d61d8327deb882cf99'
, username: 'fred'
, email: 'fred@moneytribe.com.au'
};
ectypes.User.create(userData, function(err, results){
User.find({username: 'fred'}, function(err, fred){
ectypes.LongerTableName.create({user_id: fred.id}, function(err, result){
userData.username = 'mary';
userData.email = 'mary@moneytribe.com.au';
ectypes.User.create(userData, function(err, results){
User.find({username: 'mary'}, function(err, mary){
fred.get('longer_table_names', function(err, longerTableNames){
fred.longer_table_names.length.should.equal(1);
mary.get('longer_table_names', function(err, longerTableNames){
mary.longer_table_names.length.should.equal(0);
done();
})
})
});
});
});
});
});
});
});

@@ -45,4 +45,6 @@ var Downstairs = require('../lib/downstairs')

var User = Collection.model('User', helper.userConfig);
console.log(1);
var data = {password: '5f4dcc3b5aa765d61d8327deb882cf99', username: 'fred', email: 'fred@moneytribe.com.au'};
ectypes.User.create(data, function(err, results) {
console.log(2, arguments);
User.find({ username: 'fred', email: 'fred@moneytribe.com.au' } , function(err, user){

@@ -56,2 +58,18 @@ should.exist(user);

it('finds the *right* record with a where JSON condition', function(done) {
var User = Collection.model('User', helper.userConfig);
var data = {password: '5f4dcc3b5aa765d61d8327deb882cf99', username: 'fred', email: 'fred@moneytribe.com.au'};
ectypes.User.create(data, function(err, results) {
data.username = 'mary';
data.email = 'mary@moneytribe.com.au'
ectypes.User.create(data, function(err, results) {
User.find({ username: 'mary'} , function(err, user){
should.exist(user);
user.username.should.equal('mary');
done();
});
});
});
});
it('finds a record with a where JSON condition including a null field', function(done) {

@@ -58,0 +76,0 @@ var User = Collection.model('User', helper.userConfig);

@@ -11,32 +11,6 @@ var pg = require('pg')

var strategy = new PGStrategy(env.connectionString);
ctx.load(strategy);
pg.defaults.poolSize = 50;
var userBlueprint =
{User: {
email: function(){ return faker2.Internet.email()}
, password: function(){ return "5f4dcc3b5aa765d61d8327deb882cf99"}
, username: function(){ return faker2.Internet.userName()}
,
}
}
exports.ectypes = require('./blueprints');
var accountBlueprint = {
Account: {
name: function(){ return faker2.Lorem.words(1).join(''); }
}
}
var roleBlueprint = {
Role: {
name: function(){ return faker2.Lorem.words(1).join(''); }
}
}
ctx.add(userBlueprint);
ctx.add(accountBlueprint);
ctx.add(roleBlueprint);
exports.ectypes = ctx;
exports.resetDb = function(tableSql, done){

@@ -90,2 +64,12 @@ pg.connect(env.connectionString, function(err, client) {

exports.longerTableNameConfig = sql.Table.define({
name: 'longer_table_names'
, quote: true
, schema: 'public'
, columns: ['id'
, 'name'
, 'user_id']
});
exports.userSQL = "CREATE TABLE users\

@@ -122,2 +106,9 @@ (\

exports.longerTableNameSQL = "create table longer_table_names\
(\
id serial NOT NULL,\
name character varying(100),\
user_id integer \
);"
var defaultConnection = new Connection.PostgreSQL(env.connectionString);

@@ -124,0 +115,0 @@ exports.defaultConnection = defaultConnection;

@@ -7,3 +7,4 @@ var Downstairs = require('../lib/downstairs')

, Connection = Downstairs.Connection
, helper = require('./helper');
, helper = require('./helper')
, ectypes = helper.ectypes;

@@ -26,2 +27,18 @@ Collection.use(Downstairs);

it('finds a record with a where JSON condition', function(done) {
var pgConnection = new Connection.PostgreSQL(env.connectionString);
Downstairs.add(pgConnection);
var User = Collection.model('User', helper.userConfig);
console.log(1);
var data = {password: '5f4dcc3b5aa765d61d8327deb882cf99', username: 'fred', email: 'fred@moneytribe.com.au'};
ectypes.User.create(data, function(err, results) {
console.log(2, arguments);
User.find({ username: 'fred', email: 'fred@moneytribe.com.au' } , function(err, user){
should.exist(user);
user.username.should.equal('fred');
done();
});
});
});
it('creates a new Model and returns an instance', function(done) {

@@ -28,0 +45,0 @@ var pgConnection = new Connection.PostgreSQL(env.connectionString);

@@ -180,2 +180,30 @@ var Downstairs = require('../lib/downstairs')

});
it('with arguments to use with associations', function(done){
var User = Collection.model('User', helper.userConfig);
var Role = Collection.model('Role', helper.roleConfig);
Role.hasMany(User);
User.belongsTo(Role);
var loadUsers = function(role, cb){
role.get('users', cb);
}
Role.when('loadUsers', loadUsers);
Role.create({name: 'admin'}, function(err, role){
Role.create({name: 'empty'}, function(err, emptyRole){
User.create({role_id: role.id, username: 'donald'}, function(err, user) {
Role.find({name: 'empty', callbacks: ['loadUsers']}, function(err, role){
role.users.length.should.equal(0);
Role.find({name: 'admin', callbacks: ['loadUsers']}, function(err, role){
role.users.length.should.equal(1);
done();
});
});
});
});
});
});
});

@@ -182,0 +210,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc