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

ee-orm

Package Overview
Dependencies
Maintainers
2
Versions
156
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ee-orm - npm Package Compare versions

Comparing version 0.8.2 to 0.8.3

96

lib/ORM.js

@@ -17,2 +17,3 @@ !function(){

, debug = argv.has('debug-sql')
, Promise = Promise || require('es6-promise').Promise
, dev = argv.has('dev-orm')

@@ -24,3 +25,2 @@ , staticORM

ORM = new Class({

@@ -38,3 +38,24 @@ inherits: EventEmitter

*/
, init: function(options) {
, init: function(options, pass, host, db, dbName, rdbmsType) {
var opts;
// the constructor accepts also simple conneciton paramters
if (type.string(options) && type.string(pass) && type.string(db)) {
// build options object
opts = {};
opts[db] = {};
opts[db].type = rdbmsType || 'postgres';
opts[db].hosts = [];
opts[db].hosts.push({
host : host || '127.0.0.1'
, username : options
, password : pass
, database : dbName
, port : 5432
, mode : 'readwrite'
});
options = opts;
}
// store my options

@@ -58,14 +79,2 @@ Class.define(this, '_options', Class(options));

this._initializeDatabases(options);
// load the orm, but wait for the next cycle doing
// this, preventing a reload when the user adds his
// extensions in time
process.nextTick(function() {
this._initializeOrm(function(err){
this._loaded = true;
this._loading = false;
this.emit('load', err);
}.bind(this));
}.bind(this));
}

@@ -103,17 +112,62 @@

/*
* the load method is mainly used when working with promises
*/
, load: function(callback) {
if (callback) {
if (this._loaded && !this._loading) callback();
else if (this._loading) this.once('load', callback);
else this.reload(callback);
}
else {
return new Promise(function(resolve, reject) {
var cb = function(err) {
if (err) reject(err);
else resolve(this);
}.bind(this);
if (this._loaded && !this._loading) cb();
else if (this._loading) this.once('load', cb);
else this.reload(cb);
}.bind(this));
}
}
/*
* rebuilds the orm from scratch, basically used
* for integrating extensions very late
*/
, reload: function(callback) {
if (callback) this._reload(callback);
else {
return new Promise(function(resolve, reject) {
this._reload(function(err) {
if (err) reject(err);
else resolve(this);
}.bind(this));
}.bind(this));
}
}
/*
* rebuilds the orm from scratch
*/
, reload: function(callback) {
, _reload: function(callback) {
if (!this._loading) {
this._loaded = false;
this._initializeOrm(function(err) {
this._loaded = true;
this._loading = false;
this.emit('reload', err);
if (callback) callback(err);
process.nextTick(function() {
this._initializeOrm(function(err) {
this._loaded = true;
this._loading = false;
this.emit('load', err);
if (callback) callback(err, this);
}.bind(this));
}.bind(this));
}
else {
this.once('reload', function() {
this.once('load', function() {
this.relaod(callback);

@@ -120,0 +174,0 @@ }.bind(this));

{
"name" : "ee-orm"
, "description" : "ORM for postgres and mysql. Loads and saves referenced entites, executes complex queries, supports joins, transactions, complex database clusters & connection pooling. No conventions."
, "version" : "0.8.2"
, "version" : "0.8.3"
, "homepage" : "https://github.com/eventEmitter/ee-orm"

@@ -6,0 +6,0 @@ , "author" : "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)"

@@ -16,3 +16,3 @@ # ee-orm

- plugins
- promises
- ES6 Promises

@@ -38,3 +38,3 @@ Does not require:

// generate the models from the db
new ORM(connectionConfig).on('load', function(err, orm) {
new ORM(user, pass, host, db, [schema], ['mysql']).load(function(err, orm) {

@@ -81,3 +81,4 @@ // get 10 events, their images, their tags, their categories, their venues,

// load models from the «eventdata» db
// load models from the «eventdata» db, using adb config object instead of a
// simple string for conencting to the db
var orm = new ORM({

@@ -100,3 +101,3 @@ eventdata: {

// you may not interact with the orm before it was laoded
orm.on('load', function(err){
orm.load(function(err){
if (err) console.log('failed to load ORM!', err);

@@ -103,0 +104,0 @@ else {

@@ -69,4 +69,10 @@

this.timeout(5000);
orm = new ORM(config);
orm.on('load', done);
new ORM(config).load(function(err, ormObject) {
if (err) done(err);
else {
orm = ormObject;
done();
}
});
//orm.on('load', done);
});

@@ -754,2 +760,11 @@

describe('[Promises]', function() {
it('should work for loading the ORM', function(done) {
new ORM(config.ee_orm_test.hosts[0].username, config.ee_orm_test.hosts[0].password, config.ee_orm_test.hosts[0].host, 'ee_orm_test', 'test').load().then(function(orm2) {
assert.equal(JSON.stringify(orm2), '{"ee_orm_test":{}}');
done();
}).catch(function(err) {
done(err);
});
});
it ('should work on queries', function(done) {

@@ -756,0 +771,0 @@ db.event(['*']).joinVenue(true).joinImages().count().then(function(data){

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