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.15.8 to 0.15.9

.jshintrc

109

lib/ORM.js

@@ -1,22 +0,23 @@

!function(){
!function() {
'use strict';
var Class = require('ee-class')
, log = require('ee-log')
, type = require('ee-types')
, EventEmitter = require('ee-event-emitter')
, argv = require('ee-argv')
, async = require('ee-async')
, DBCluster = require('ee-db-cluster')
, Migration = require('./Migration')
, Database = require('./Database')
, StaticORM = require('./StaticORM')
, Set = require('./Set')
, ExtensionManager = require('./ExtensionManager')
, ModelDefinition = require('./ModelDefinition')
, debug = argv.has('debug-sql')
, Promise = Promise || require('es6-promise').Promise
, dev = argv.has('dev-orm')
, asyncMethod = require('async-method')
, staticORM
var Class = require('ee-class')
, log = require('ee-log')
, type = require('ee-types')
, EventEmitter = require('ee-event-emitter')
, argv = require('ee-argv')
, async = require('ee-async')
, DBCluster = require('ee-db-cluster')
, Migration = require('./Migration')
, Database = require('./Database')
, StaticORM = require('./StaticORM')
, Set = require('./Set')
, ExtensionManager = require('./ExtensionManager')
, ModelDefinition = require('./ModelDefinition')
, debug = argv.has('debug-sql')
, Promise = Promise || require('es6-promise').Promise
, dev = argv.has('dev-orm')
, asyncMethod = require('async-method')
, Selector = require('./Selector')
, RelatedSelector = require('related-selector')
, ORM;

@@ -26,2 +27,7 @@

// we need a single instance of the selector classs
var selector = new Selector();
ORM = new Class({

@@ -36,3 +42,7 @@ inherits: EventEmitter

// grant the orm acces to the static
// selector collection
, _selector: selector
// driver names

@@ -155,3 +165,3 @@ , _driverNames: {

* create a new database
*
*
* @param <object> database config or DBCluster instance

@@ -179,7 +189,7 @@ * @param <string> database name

/**
* drop a database
*
*
* @param <object> database config or DBCluster instance

@@ -211,3 +221,3 @@ * @param <string> database name

* drop a schema
*
*
* @param <object> database config or DBCluster instance

@@ -238,3 +248,3 @@ * @param <string> schema name

* create a new schema
*
*
* @param <object> database config or DBCluster instance

@@ -262,5 +272,5 @@ * @param <string> schema name

/**

@@ -276,3 +286,3 @@ * instantiartes a db clsuter instance

config = this._prepareConfig(config, noDatabase);
config.hosts.forEach(function(hostConfig){

@@ -310,3 +320,3 @@ db.addNode(hostConfig);

if (!excludeDatabase) hostCopy.database = config.database || config.schema;
copy.hosts.push(hostCopy);

@@ -334,6 +344,14 @@ });

, use: function(extension) {
if (!extension || !type.function(extension.isExtension) || !extension.isExtension()) throw new Error('cannot add extion to orm, it doesn\'t register itself as one!');
// register the extension
this._extensions.register(extension);
if (extension instanceof RelatedSelector) {
// got a selector extension
this._selector.registerExtension(extension);
}
else {
// old school extension
if (!extension || !type.function(extension.isExtension) || !extension.isExtension()) throw new Error('cannot add extion to orm, it doesn\'t register itself as one!');
// register the extension
this._extensions.register(extension);
}
return this;

@@ -418,5 +436,5 @@ }

/*

@@ -497,7 +515,7 @@ * initializtes the orm, reads the db definition, checks if for relations

else callback();
}.bind(this));
}.bind(this));
}
/*

@@ -521,3 +539,3 @@ * checks if there are names that are used twice, if so it

if (column.mapsTo) {
column.mapsTo.forEach(function(mapping){
column.mapsTo.forEach(function(mapping){
name = mapping.name;

@@ -579,3 +597,3 @@

}.bind(this));
// did we find a nested set on the model?

@@ -591,3 +609,3 @@ if (isNestedSet === 2) {

/*
/*
* returns the orm databse object

@@ -617,3 +635,3 @@ */

if (!type.array(config.hosts) || !config.hosts.length) throw new Error('['+config.schema+'] > Please add at least one host per db in the config!');
// check if there is anythin to load

@@ -641,3 +659,3 @@ // if the user didnt specify a schema nor a database

if (!type.array(options[databaseName].hosts) || !options[databaseName].hosts.length) throw new Error('['+databaseName+'] > Please add at least one host per db in the config!');
this._dbs.push({

@@ -680,13 +698,16 @@ databaseName : databaseName

// set static methods on the ORM constructor
Class.implement(new StaticORM(), ORM);
// export the set so extensions can make use of it
ORM.Set = Set;
// export the selector interface
selector.applyTo(ORM);
// export
module.exports = ORM;
module.exports = ORM;
}();
{
"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 and much more. No conventions. MIT Licence"
, "version" : "0.15.8"
, "version" : "0.15.9"
, "homepage" : "https://github.com/eventEmitter/ee-orm"
, "author" : "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)"
, "licence" : "mit"
, "licence" : "MIT"
, "repository": {

@@ -32,2 +32,3 @@ "url" : "https://github.com/eventEmitter/ee-orm.git"

, "async-method" : "0.1.x"
, "related-selector" : "0.1.x"
}

@@ -34,0 +35,0 @@ , "devDependencies": {

@@ -5,2 +5,9 @@ # Related ORM

[![npm](https://img.shields.io/npm/dm/ee-orm.svg?style=flat-square)](https://www.npmjs.com/package/ee-orm)
[![Travis](https://img.shields.io/travis/eventEmitter/ee-orm.svg?style=flat-square)](https://travis-ci.org/eventEmitter/ee-orm)
[![npm](https://img.shields.io/npm/l/ee-orm.svg?style=flat-square)](http://choosealicense.com/licenses/mit/)
[![node](https://img.shields.io/node/v/ee-orm.svg?style=flat-square)](https://nodejs.org/)
Got a database but not any representation of the models in Javascript? You don't want to write Javascript models for your Database? The related ORM reads the the definition fo your tables & columns from the database itself and builds an extensive API using that information. Using the related ORM you are up an running in seconds, not hours!

@@ -13,3 +20,3 @@

- Works with any relational schema, generates the API from the tables in the schema
- Automatic and manual transactions
- Automatic and manual transactions
- A simple and an advanced query builder

@@ -28,2 +35,3 @@ - Subqueries in filters, selects, inserts and updates

## Examples

@@ -39,4 +47,4 @@

// get 10 events, their images, their tags, their categories, their venues,
// the venues images, the venues types
// get 10 events, their images, their tags, their categories, their venues,
// the venues images, the venues types
orm.event({id: ORM.lt(2000)}, ['*'])

@@ -55,3 +63,3 @@ .fetchImage(['url'])

log.error('something went wrong :(');
});
});
});

@@ -68,3 +76,3 @@ ````

If the api changes the minor version number will change. So if you use the version «0.2.x» you will have always the same api.
If the api changes the minor version number will change. So if you use the version «0.2.x» you will have always the same api.

@@ -83,3 +91,3 @@ ## build status

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

@@ -113,3 +121,3 @@ eventdata: {

// load events with the ids 1-6, get also the venues for the events but select only the
// load events with the ids 1-6, get also the venues for the events but select only the
// id and the name attribute

@@ -156,6 +164,6 @@ orm.eventdata.events({id: ORM.in(1,2,3,4,5,6)}, ['*']).fetchVenues(['id', 'name']).limit(10).find(function(err, events){

For every Database used by the ORM you have to provide a complete configuration stored on the the key which must be the name of the database.
// database names «eventdata» and «shopping». the «eventdata» database
// is a single mysql server, the «shopping» database consists of a
// postgres master and a read replica. the orm tries to use the read replica
// database names «eventdata» and «shopping». the «eventdata» database
// is a single mysql server, the «shopping» database consists of a
// postgres master and a read replica. the orm tries to use the read replica
// for readonly queries

@@ -185,4 +193,4 @@ {

, mode : 'readwrite'
, maxConenctions : 20
, database : 'myDatabase' // optional, the name of the database (not the schema) to
, maxConenctions : 20
, database : 'myDatabase' // optional, the name of the database (not the schema) to
// connect to (defaults to the database name, «shopping» in this case)

@@ -197,6 +205,6 @@ }

, maxConenctions : 200
, database : 'myDatabase' // optional, the name of the database (not the schema) to
, database : 'myDatabase' // optional, the name of the database (not the schema) to
// connect to (defaults to the database name, «shopping» in this case)
}
]
]
}

@@ -222,5 +230,5 @@ }

Lets take the configuration defined above an see what tables the «eventdata» database has. The ORM scans every database for all tables and all relations between them. There are on naming conventions or requirements exept from some reserved keywords (see «reserved keywords»).
Lets take the configuration defined above an see what tables the «eventdata» database has. The ORM scans every database for all tables and all relations between them. There are on naming conventions or requirements exept from some reserved keywords (see «reserved keywords»).
log(ormInstance.eventdata);
log(ormInstance.eventdata);
// {

@@ -272,3 +280,3 @@ // event: {} // table containing events

Lets fetch some events:
// select all events in the table, returns only their id (the primary key is selected automatically)

@@ -290,3 +298,3 @@ ormInstance.eventdata.event().find(function(err, events){

Lets select & filter some events:
// fecth the event with the id 9, select the id only

@@ -303,3 +311,3 @@ ormInstance.eventdata.event({id: 9}).find(function(err, events){

Lets select all events of the venue with the id 56, select the events title and id
ormInstance.eventdata.event(['id', 'title']).fetchVenue({id:56}).find(function(err, events){

@@ -311,25 +319,25 @@

ormInstance.eventdata.event(['id', 'title']).getVenue({id:56}).find(function(err, events){
});
Lets select all events of the venue with the id 56, select the events title and id and all columns of the venue
ormInstance.eventdata.event(['id', 'title']).getVenue(['*'], {id:56}).find(function(err, events){
});
Now lets also get the images of the venue (get vs fetch)
// loads all events of the venue with the id 56 and all images attched to the venue
//the getVenue did change the scope to the venue entity, so the fetchImage points to
//the getVenue did change the scope to the venue entity, so the fetchImage points to
// the images of the ***venue***
ormInstance.eventdata.event(['id', 'title']).getVenue(['*'], {id:56}).fetchImage(['*']).find(function(err, events){
});
// fetchVenue vs getVenue: because we used fetchVenue instead of getVenue the scope
// fetchVenue vs getVenue: because we used fetchVenue instead of getVenue the scope
// stays on the previuos item which is in this case the the «event» entity. this query
// fetches all events of the venue with the id 56 and all images attched to the ***event***
ormInstance.eventdata.event(['id', 'title']).fetchVenue(['*'], {id:56}).fetchImage(['*']).find(function(err, events){
});

@@ -342,5 +350,5 @@

// filter events by the venue with the id 56, select all columns of the venue
// table, get the description locale from the locale table where the language
// is english.
// filter events by the venue with the id 56, select all columns of the venue
// table, get the description locale from the locale table where the language
// is english.
// the filter method is called on the language entity because we want all the

@@ -432,4 +440,4 @@ // events and not only those with english locales (join vs. left join) but we

);
query.find(log);

@@ -436,0 +444,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