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

cormo

Package Overview
Dependencies
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cormo - npm Package Compare versions

Comparing version 0.6.5 to 0.6.6

lib/console_future.js

29

guides/CLIGuide.md

@@ -35,2 +35,4 @@ # CORMO console

If you give '$' in place of callback, console waits to finish the execution ant returns its result.
```bash

@@ -46,1 +48,28 @@ $ cormo console -l model.coffee

```
For CORMO methods, you can omit '$'.
And for Query objects, you can also omit calling 'exec'.
```bash
cormo> user = User.create name: 'croquis.com', age: 2
{ name: 'croquis.com',
age: 2,
id: '5180f6850c8f82829d000003' }
cormo> User.find(user.id).select('name')
{ name: 'croquis.com',
id: '5180f6850c8f82829d000003' }
```
If you want omit '$' when calling your methods, wrap it with 'cormo.console_future.execute'.
```coffeescript
User.createUser = (name, age, callback) ->
cormo.console_future.execute callback, (callback) =>
User.create name: name, age: age, callback
```
```bash
cormo> user = User.createUser 'croquis.com', 2
```
'cormo.console_future.execute' does not do anything special when you use methods not on the console.

@@ -177,2 +177,12 @@ To query, create a query object using [[#ModelQuery.query]] first.

## Request only one record
If you know that there will be only one result (e.x. query on unique column), [[#Query::one]] will be helpful.
It makes a query return a single instance (or null) instead of array of instances.
```
User.where(age: 27).one().exec (error, user) ->
console.log user
```
# Count records

@@ -179,0 +189,0 @@

12

lib/adapters/mongodb.js
// Generated by CoffeeScript 1.6.2
(function() {
var AdapterBase, MongoDBAdapter, ObjectID, async, error, mongodb, tableize, types, _, _buildGroupFields, _buildWhere, _buildWhereSingle, _convertValueToObjectID, _objectIdToString,
var AdapterBase, MongoDBAdapter, ObjectID, async, error, mongodb, types, _, _buildGroupFields, _buildWhere, _buildWhereSingle, _convertValueToObjectID, _objectIdToString,
__hasProp = {}.hasOwnProperty,

@@ -21,4 +21,2 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

tableize = require('../inflector').tableize;
async = require('async');

@@ -368,4 +366,6 @@

MongoDBAdapter.prototype._collection = function(name) {
name = tableize(name);
MongoDBAdapter.prototype._collection = function(model) {
var name;
name = this._connection.models[model].tableName;
if (!this._collections[name]) {

@@ -439,3 +439,3 @@ return this._collections[name] = new mongodb.Collection(this._client, _getMongoDBColName(name));

name = tableize(model);
name = this._connection.models[model].tableName;
delete this._collections[name];

@@ -442,0 +442,0 @@ return this._client.dropCollection(_getMongoDBColName(name), function(error) {

// Generated by CoffeeScript 1.6.2
(function() {
var MySQLAdapter, SQLAdapterBase, async, e, mysql, tableize, types, _, _propertyToSQL, _typeToSQL,
var MySQLAdapter, SQLAdapterBase, async, e, mysql, types, _, _propertyToSQL, _typeToSQL,
__hasProp = {}.hasOwnProperty,

@@ -19,4 +19,2 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

tableize = require('../inflector').tableize;
async = require('async');

@@ -85,6 +83,6 @@

MySQLAdapter.prototype._createTable = function(model, callback) {
var column, column_sql, columns, index, integrity, model_class, order, property, sql, table, unique, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3;
var column, column_sql, columns, index, integrity, model_class, order, property, sql, tableName, unique, _i, _j, _len, _len1, _ref, _ref1, _ref2, _ref3;
table = tableize(model);
model_class = this._connection.models[model];
tableName = model_class.tableName;
sql = [];

@@ -117,10 +115,10 @@ sql.push('id INT NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY');

if (integrity.type === 'child_nullify') {
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + (tableize(integrity.parent._name)) + "(id) ON DELETE SET NULL");
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + integrity.parent.tableName + "(id) ON DELETE SET NULL");
} else if (integrity.type === 'child_restrict') {
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + (tableize(integrity.parent._name)) + "(id) ON DELETE RESTRICT");
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + integrity.parent.tableName + "(id) ON DELETE RESTRICT");
} else if (integrity.type === 'child_delete') {
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + (tableize(integrity.parent._name)) + "(id) ON DELETE CASCADE");
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + integrity.parent.tableName + "(id) ON DELETE CASCADE");
}
}
sql = "CREATE TABLE " + table + " ( " + (sql.join(',')) + " )";
sql = "CREATE TABLE " + tableName + " ( " + (sql.join(',')) + " )";
return this._query(sql, function(error, result) {

@@ -139,5 +137,7 @@ if (error) {

MySQLAdapter.prototype.applySchema = function(model, callback) {
var _this = this;
var tableName,
_this = this;
return this._query("SHOW COLUMNS FROM " + (tableize(model)), function(error, columns) {
tableName = this._connection.models[model].tableName;
return this._query("SHOW COLUMNS FROM " + tableName, function(error, columns) {
if ((error != null ? error.code : void 0) === 'ER_NO_SUCH_TABLE') {

@@ -152,6 +152,6 @@ return _this._createTable(model, callback);

MySQLAdapter.prototype.drop = function(model, callback) {
var table;
var tableName;
table = tableize(model);
return this._query("DROP TABLE IF EXISTS " + table, function(error) {
tableName = this._connection.models[model].tableName;
return this._query("DROP TABLE IF EXISTS " + tableName, function(error) {
if (error) {

@@ -251,7 +251,8 @@ return callback(MySQLAdapter.wrapError('unknown error', error));

MySQLAdapter.prototype.create = function(model, data, callback) {
var fields, places, sql, values, _ref;
var fields, places, sql, tableName, values, _ref;
tableName = this._connection.models[model].tableName;
values = [];
_ref = this._buildUpdateSet(model, data, values, true), fields = _ref[0], places = _ref[1];
sql = "INSERT INTO " + (tableize(model)) + " (" + fields + ") VALUES (" + places + ")";
sql = "INSERT INTO " + tableName + " (" + fields + ") VALUES (" + places + ")";
return this._query(sql, values, function(error, result) {

@@ -272,5 +273,6 @@ var id;

MySQLAdapter.prototype.createBulk = function(model, data, callback) {
var fields, places, sql, values,
var fields, places, sql, tableName, values,
_this = this;
tableName = this._connection.models[model].tableName;
values = [];

@@ -285,3 +287,3 @@ fields = void 0;

});
sql = "INSERT INTO " + (tableize(model)) + " (" + fields + ") VALUES " + (places.join(','));
sql = "INSERT INTO " + tableName + " (" + fields + ") VALUES " + (places.join(','));
return this._query(sql, values, function(error, result) {

@@ -304,8 +306,9 @@ var id;

MySQLAdapter.prototype.update = function(model, data, callback) {
var fields, sql, values;
var fields, sql, tableName, values;
tableName = this._connection.models[model].tableName;
values = [];
fields = this._buildUpdateSet(model, data, values)[0];
values.push(data.id);
sql = "UPDATE " + (tableize(model)) + " SET " + fields + " WHERE id=?";
sql = "UPDATE " + tableName + " SET " + fields + " WHERE id=?";
return this._query(sql, values, function(error) {

@@ -320,7 +323,8 @@ if (error) {

MySQLAdapter.prototype.updatePartial = function(model, data, conditions, options, callback) {
var fields, sql, values;
var fields, sql, tableName, values;
tableName = this._connection.models[model].tableName;
values = [];
fields = this._buildPartialUpdateSet(model, data, values)[0];
sql = "UPDATE " + (tableize(model)) + " SET " + fields;
sql = "UPDATE " + tableName + " SET " + fields;
if (conditions.length > 0) {

@@ -346,7 +350,8 @@ try {

MySQLAdapter.prototype.findById = function(model, id, options, callback) {
var select, sql,
var select, sql, tableName,
_this = this;
select = this._buildSelect(this._connection.models[model], options.select);
sql = "SELECT " + select + " FROM " + (tableize(model)) + " WHERE id=? LIMIT 1";
tableName = this._connection.models[model].tableName;
sql = "SELECT " + select + " FROM " + tableName + " WHERE id=? LIMIT 1";
return this._query(sql, id, function(error, result) {

@@ -371,3 +376,3 @@ if (error) {

MySQLAdapter.prototype.find = function(model, conditions, options, callback) {
var field, location, order_by, orders, params, select, sql,
var field, location, order_by, orders, params, select, sql, tableName,
_this = this;

@@ -386,3 +391,4 @@

params = [];
sql = "SELECT " + select + " FROM " + (tableize(model));
tableName = this._connection.models[model].tableName;
sql = "SELECT " + select + " FROM " + tableName;
if (conditions.length > 0) {

@@ -451,7 +457,8 @@ try {

MySQLAdapter.prototype.count = function(model, conditions, callback) {
var params, sql,
var params, sql, tableName,
_this = this;
params = [];
sql = "SELECT COUNT(*) AS count FROM " + (tableize(model));
tableName = this._connection.models[model].tableName;
sql = "SELECT COUNT(*) AS count FROM " + tableName;
if (conditions.length > 0) {

@@ -477,6 +484,7 @@ try {

MySQLAdapter.prototype["delete"] = function(model, conditions, callback) {
var params, sql;
var params, sql, tableName;
params = [];
sql = "DELETE FROM " + (tableize(model));
tableName = this._connection.models[model].tableName;
sql = "DELETE FROM " + tableName;
if (conditions.length > 0) {

@@ -483,0 +491,0 @@ try {

// Generated by CoffeeScript 1.6.2
(function() {
var PostgreSQLAdapter, SQLAdapterBase, async, e, pg, tableize, types, _, _propertyToSQL, _typeToSQL,
var PostgreSQLAdapter, SQLAdapterBase, async, e, pg, types, _, _propertyToSQL, _typeToSQL,
__hasProp = {}.hasOwnProperty,

@@ -19,4 +19,2 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

tableize = require('../inflector').tableize;
async = require('async');

@@ -89,7 +87,7 @@

PostgreSQLAdapter.prototype._createTable = function(model, callback) {
var column, column_sql, integrity, model_class, property, sql, table, _i, _len, _ref, _ref1,
var column, column_sql, integrity, model_class, property, sql, tableName, _i, _len, _ref, _ref1,
_this = this;
table = tableize(model);
model_class = this._connection.models[model];
tableName = model_class.tableName;
sql = [];

@@ -109,10 +107,10 @@ sql.push('id SERIAL PRIMARY KEY');

if (integrity.type === 'child_nullify') {
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + (tableize(integrity.parent._name)) + "(id) ON DELETE SET NULL");
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + integrity.parent.tableName + "(id) ON DELETE SET NULL");
} else if (integrity.type === 'child_restrict') {
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + (tableize(integrity.parent._name)) + "(id) ON DELETE RESTRICT");
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + integrity.parent.tableName + "(id) ON DELETE RESTRICT");
} else if (integrity.type === 'child_delete') {
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + (tableize(integrity.parent._name)) + "(id) ON DELETE CASCADE");
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + integrity.parent.tableName + "(id) ON DELETE CASCADE");
}
}
sql = "CREATE TABLE " + table + " ( " + (sql.join(',')) + " )";
sql = "CREATE TABLE " + tableName + " ( " + (sql.join(',')) + " )";
return this._query(sql, function(error) {

@@ -133,3 +131,3 @@ if (error) {

unique = index.options.unique ? 'UNIQUE ' : '';
sql = "CREATE " + unique + "INDEX " + index.options.name + " ON " + table + " (" + (columns.join(',')) + ")";
sql = "CREATE " + unique + "INDEX " + index.options.name + " ON " + tableName + " (" + (columns.join(',')) + ")";
return _this._query(sql, callback);

@@ -150,7 +148,7 @@ }, function(error) {

PostgreSQLAdapter.prototype.applySchema = function(model, callback) {
var table,
var tableName,
_this = this;
table = tableize(model);
return this._query("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name=$1", [table], function(error, result) {
tableName = this._connection.models[model].tableName;
return this._query("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name=$1", [tableName], function(error, result) {
var columns;

@@ -168,6 +166,6 @@

PostgreSQLAdapter.prototype.drop = function(model, callback) {
var table;
var tableName;
table = tableize(model);
return this._query("DROP TABLE IF EXISTS " + table, function(error) {
tableName = this._connection.models[model].tableName;
return this._query("DROP TABLE IF EXISTS " + tableName, function(error) {
if (error) {

@@ -184,3 +182,3 @@ return callback(PostgreSQLAdapter.wrapError('unknown error', error));

_processSaveError = function(model, error, callback) {
_processSaveError = function(tableName, error, callback) {
var column, key;

@@ -195,3 +193,3 @@

column = key[1];
key = column.match(new RegExp("" + (tableize(model)) + "_([^']*)_key"));
key = column.match(new RegExp("" + tableName + "_([^']*)_key"));
if (key != null) {

@@ -252,7 +250,8 @@ column = key[1];

PostgreSQLAdapter.prototype.create = function(model, data, callback) {
var fields, places, sql, values, _ref;
var fields, places, sql, tableName, values, _ref;
tableName = this._connection.models[model].tableName;
values = [];
_ref = this._buildUpdateSet(model, data, values, true), fields = _ref[0], places = _ref[1];
sql = "INSERT INTO " + (tableize(model)) + " (" + fields + ") VALUES (" + places + ") RETURNING id";
sql = "INSERT INTO " + tableName + " (" + fields + ") VALUES (" + places + ") RETURNING id";
return this._query(sql, values, function(error, result) {

@@ -263,3 +262,3 @@ var rows;

if (error) {
return _processSaveError(model, error, callback);
return _processSaveError(tableName, error, callback);
}

@@ -275,5 +274,6 @@ if ((rows != null ? rows.length : void 0) === 1 && (rows[0].id != null)) {

PostgreSQLAdapter.prototype.createBulk = function(model, data, callback) {
var fields, places, sql, values,
var fields, places, sql, tableName, values,
_this = this;
tableName = this._connection.models[model].tableName;
values = [];

@@ -288,3 +288,3 @@ fields = void 0;

});
sql = "INSERT INTO " + (tableize(model)) + " (" + fields + ") VALUES " + (places.join(',')) + " RETURNING id";
sql = "INSERT INTO " + tableName + " (" + fields + ") VALUES " + (places.join(',')) + " RETURNING id";
return this._query(sql, values, function(error, result) {

@@ -294,3 +294,3 @@ var ids;

if (error) {
return _processSaveError(model, error, callback);
return _processSaveError(tableName, error, callback);
}

@@ -309,11 +309,12 @@ ids = result != null ? result.rows.map(function(row) {

PostgreSQLAdapter.prototype.update = function(model, data, callback) {
var fields, sql, values;
var fields, sql, tableName, values;
tableName = this._connection.models[model].tableName;
values = [];
fields = this._buildUpdateSet(model, data, values)[0];
values.push(data.id);
sql = "UPDATE " + (tableize(model)) + " SET " + fields + " WHERE id=$" + values.length;
sql = "UPDATE " + tableName + " SET " + fields + " WHERE id=$" + values.length;
return this._query(sql, values, function(error) {
if (error) {
return _processSaveError(model, error, callback);
return _processSaveError(tableName, error, callback);
}

@@ -325,7 +326,8 @@ return callback(null);

PostgreSQLAdapter.prototype.updatePartial = function(model, data, conditions, options, callback) {
var fields, sql, values;
var fields, sql, tableName, values;
tableName = this._connection.models[model].tableName;
values = [];
fields = this._buildPartialUpdateSet(model, data, values)[0];
sql = "UPDATE " + (tableize(model)) + " SET " + fields;
sql = "UPDATE " + tableName + " SET " + fields;
if (conditions.length > 0) {

@@ -341,3 +343,3 @@ try {

if (error) {
return _processSaveError(model, error, callback);
return _processSaveError(tableName, error, callback);
}

@@ -349,8 +351,8 @@ return callback(null, result.rowCount);

PostgreSQLAdapter.prototype.findById = function(model, id, options, callback) {
var select, table,
var select, tableName,
_this = this;
select = this._buildSelect(this._connection.models[model], options.select);
table = tableize(model);
return this._query("SELECT " + select + " FROM " + table + " WHERE id=$1 LIMIT 1", [id], function(error, result) {
tableName = this._connection.models[model].tableName;
return this._query("SELECT " + select + " FROM " + tableName + " WHERE id=$1 LIMIT 1", [id], function(error, result) {
var rows;

@@ -377,3 +379,3 @@

PostgreSQLAdapter.prototype.find = function(model, conditions, options, callback) {
var orders, params, select, sql,
var orders, params, select, sql, tableName,
_this = this;

@@ -387,3 +389,4 @@

params = [];
sql = "SELECT " + select + " FROM " + (tableize(model));
tableName = this._connection.models[model].tableName;
sql = "SELECT " + select + " FROM " + tableName;
if (conditions.length > 0) {

@@ -452,7 +455,8 @@ try {

PostgreSQLAdapter.prototype.count = function(model, conditions, callback) {
var params, sql,
var params, sql, tableName,
_this = this;
params = [];
sql = "SELECT COUNT(*) AS count FROM " + (tableize(model));
tableName = this._connection.models[model].tableName;
sql = "SELECT COUNT(*) AS count FROM " + tableName;
if (conditions.length > 0) {

@@ -481,6 +485,7 @@ try {

PostgreSQLAdapter.prototype["delete"] = function(model, conditions, callback) {
var params, sql;
var params, sql, tableName;
params = [];
sql = "DELETE FROM " + (tableize(model));
tableName = this._connection.models[model].tableName;
sql = "DELETE FROM " + tableName;
if (conditions.length > 0) {

@@ -487,0 +492,0 @@ try {

// Generated by CoffeeScript 1.6.2
(function() {
var SQLAdapterBase, SQLite3Adapter, async, e, sqlite3, tableize, types, _, _propertyToSQL, _typeToSQL,
var SQLAdapterBase, SQLite3Adapter, async, e, sqlite3, types, _, _propertyToSQL, _typeToSQL,
__hasProp = {}.hasOwnProperty,

@@ -19,4 +19,2 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

tableize = require('../inflector').tableize;
async = require('async');

@@ -81,7 +79,7 @@

SQLite3Adapter.prototype._createTable = function(model, callback) {
var column, column_sql, integrity, model_class, property, sql, table, _i, _len, _ref, _ref1,
var column, column_sql, integrity, model_class, property, sql, tableName, _i, _len, _ref, _ref1,
_this = this;
table = tableize(model);
model_class = this._connection.models[model];
tableName = model_class.tableName;
sql = [];

@@ -101,10 +99,10 @@ sql.push('id INTEGER PRIMARY KEY AUTOINCREMENT');

if (integrity.type === 'child_nullify') {
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + (tableize(integrity.parent._name)) + "(id) ON DELETE SET NULL");
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + integrity.parent.tableName + "(id) ON DELETE SET NULL");
} else if (integrity.type === 'child_restrict') {
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + (tableize(integrity.parent._name)) + "(id) ON DELETE RESTRICT");
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + integrity.parent.tableName + "(id) ON DELETE RESTRICT");
} else if (integrity.type === 'child_delete') {
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + (tableize(integrity.parent._name)) + "(id) ON DELETE CASCADE");
sql.push("FOREIGN KEY (" + integrity.column + ") REFERENCES " + integrity.parent.tableName + "(id) ON DELETE CASCADE");
}
}
sql = "CREATE TABLE " + table + " ( " + (sql.join(',')) + " )";
sql = "CREATE TABLE " + tableName + " ( " + (sql.join(',')) + " )";
return this._query('run', sql, function(error, result) {

@@ -125,3 +123,3 @@ if (error) {

unique = index.options.unique ? 'UNIQUE ' : '';
sql = "CREATE " + unique + "INDEX " + index.options.name + " ON " + table + " (" + (columns.join(',')) + ")";
sql = "CREATE " + unique + "INDEX " + index.options.name + " ON " + tableName + " (" + (columns.join(',')) + ")";
return _this._query('run', sql, callback);

@@ -142,6 +140,6 @@ }, function(error) {

SQLite3Adapter.prototype.drop = function(model, callback) {
var table;
var tableName;
table = tableize(model);
return this._query('run', "DROP TABLE IF EXISTS " + table, function(error) {
tableName = this._connection.models[model].tableName;
return this._query('run', "DROP TABLE IF EXISTS " + tableName, function(error) {
if (error) {

@@ -228,7 +226,8 @@ return callback(SQLite3Adapter.wrapError('unknown error', error));

SQLite3Adapter.prototype.create = function(model, data, callback) {
var fields, places, sql, values, _ref;
var fields, places, sql, tableName, values, _ref;
tableName = this._connection.models[model].tableName;
values = [];
_ref = this._buildUpdateSet(model, data, values, true), fields = _ref[0], places = _ref[1];
sql = "INSERT INTO " + (tableize(model)) + " (" + fields + ") VALUES (" + places + ")";
sql = "INSERT INTO " + tableName + " (" + fields + ") VALUES (" + places + ")";
return this._query('run', sql, values, function(error) {

@@ -247,8 +246,9 @@ if (error) {

SQLite3Adapter.prototype.update = function(model, data, callback) {
var fields, sql, values;
var fields, sql, tableName, values;
tableName = this._connection.models[model].tableName;
values = [];
fields = this._buildUpdateSet(model, data, values)[0];
values.push(data.id);
sql = "UPDATE " + (tableize(model)) + " SET " + fields + " WHERE id=?";
sql = "UPDATE " + tableName + " SET " + fields + " WHERE id=?";
return this._query('run', sql, values, function(error) {

@@ -263,7 +263,8 @@ if (error) {

SQLite3Adapter.prototype.updatePartial = function(model, data, conditions, options, callback) {
var fields, sql, values;
var fields, sql, tableName, values;
tableName = this._connection.models[model].tableName;
values = [];
fields = this._buildPartialUpdateSet(model, data, values)[0];
sql = "UPDATE " + (tableize(model)) + " SET " + fields;
sql = "UPDATE " + tableName + " SET " + fields;
if (conditions.length > 0) {

@@ -286,8 +287,8 @@ try {

SQLite3Adapter.prototype.findById = function(model, id, options, callback) {
var select, table,
var select, tableName,
_this = this;
select = this._buildSelect(this._connection.models[model], options.select);
table = tableize(model);
return this._query('all', "SELECT " + select + " FROM " + table + " WHERE id=? LIMIT 1", id, function(error, result) {
tableName = this._connection.models[model].tableName;
return this._query('all', "SELECT " + select + " FROM " + tableName + " WHERE id=? LIMIT 1", id, function(error, result) {
if (error) {

@@ -311,3 +312,3 @@ return callback(SQLite3Adapter.wrapError('unknown error', error));

SQLite3Adapter.prototype.find = function(model, conditions, options, callback) {
var orders, params, select, sql,
var orders, params, select, sql, tableName,
_this = this;

@@ -320,4 +321,5 @@

}
tableName = this._connection.models[model].tableName;
params = [];
sql = "SELECT " + select + " FROM " + (tableize(model));
sql = "SELECT " + select + " FROM " + tableName;
if (conditions.length > 0) {

@@ -383,7 +385,8 @@ try {

SQLite3Adapter.prototype.count = function(model, conditions, callback) {
var params, sql,
var params, sql, tableName,
_this = this;
params = [];
sql = "SELECT COUNT(*) AS count FROM " + (tableize(model));
tableName = this._connection.models[model].tableName;
sql = "SELECT COUNT(*) AS count FROM " + tableName;
if (conditions.length > 0) {

@@ -409,6 +412,7 @@ try {

SQLite3Adapter.prototype["delete"] = function(model, conditions, callback) {
var params, sql;
var params, sql, tableName;
params = [];
sql = "DELETE FROM " + (tableize(model));
tableName = this._connection.models[model].tableName;
sql = "DELETE FROM " + tableName;
if (conditions.length > 0) {

@@ -415,0 +419,0 @@ try {

// Generated by CoffeeScript 1.6.2
(function() {
var CommandConsole, Connection, Fiber, Future, Model, addHistory, addMultilineHandler, coffee, commander, fs, path, prettyErrorMessage, repl, vm;
var CommandConsole, Connection, Fiber, Future, Model, Query, addHistory, addMultilineHandler, coffee, commander, console_future, fs, path, prettyErrorMessage, repl, vm;

@@ -25,2 +25,19 @@ coffee = require('coffee-script');

Query = require('../query');
console_future = require('../console_future');
console_future.execute = function(callback, func) {
var future;
if (typeof callback !== 'function') {
future = new Future();
callback = future.resolver();
}
func(callback);
if (future) {
return future.wait();
}
};
prettyErrorMessage = coffee.helpers.prettyErrorMessage || function(e) {

@@ -185,2 +202,9 @@ return e;

delete context.$;
} else if (result instanceof Query) {
future = new Future();
result.exec(future.resolver());
result = future.wait();
if (assign_to) {
context[assign_to] = result;
}
}

@@ -209,3 +233,3 @@ } catch (_error) {

CommandConsole.prototype._setupContext = function(context) {
var connection, model, modelClass, _ref, _results;
var connection, model, modelClass, _ref;

@@ -217,9 +241,8 @@ context.Connection = Connection;

_ref = connection.models;
_results = [];
for (model in _ref) {
modelClass = _ref[model];
_results.push(context[model] = modelClass);
context[model] = modelClass;
}
return _results;
}
return connection.applySchemas();
};

@@ -226,0 +249,0 @@

// Generated by CoffeeScript 1.6.2
(function() {
var Connection, EventEmitter, Model, async, redis, _, _bindDomain, _use,
var Connection, EventEmitter, Model, async, inspect, redis, _, _bindDomain, _use,
__hasProp = {}.hasOwnProperty,

@@ -19,2 +19,4 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

inspect = require('util').inspect;
_bindDomain = function(fn) {

@@ -184,2 +186,6 @@ var d;

Connection.prototype.inspect = function(depth) {
return inspect(this.models);
};
return Connection;

@@ -186,0 +192,0 @@

// Generated by CoffeeScript 1.6.2
(function() {
var ConnectionManipulate, async, inflector, types;
var ConnectionManipulate, async, console_future, inflector, types;
async = require('async');
console_future = require('../console_future');
inflector = require('../inflector');

@@ -114,70 +116,73 @@

ConnectionManipulate.prototype.manipulate = function(commands, callback) {
var id_to_record_map,
_this = this;
var _this = this;
this.log('<conn>', 'manipulate', commands);
id_to_record_map = {};
if (!Array.isArray(commands)) {
commands = [commands];
}
return async.forEachSeries(commands, function(command, callback) {
var data, id, key, model;
return console_future.execute(callback, function(callback) {
var id_to_record_map;
if (typeof command === 'object') {
key = Object.keys(command);
if (key.length === 1) {
key = key[0];
data = command[key];
} else {
key = void 0;
}
} else if (typeof command === 'string') {
key = command;
id_to_record_map = {};
if (!Array.isArray(commands)) {
commands = [commands];
}
if (!key) {
return callback(new Error('invalid command: ' + JSON.stringify(command)));
}
if (key.substr(0, 7) === 'create_') {
model = key.substr(7);
id = data.id;
delete data.id;
_this._manipulateConvertIds(id_to_record_map, model, data);
return _this._manipulateCreate(model, data, function(error, record) {
if (error) {
return callback(error);
return async.forEachSeries(commands, function(command, callback) {
var data, id, key, model;
if (typeof command === 'object') {
key = Object.keys(command);
if (key.length === 1) {
key = key[0];
data = command[key];
} else {
key = void 0;
}
if (id) {
id_to_record_map[id] = record;
} else if (typeof command === 'string') {
key = command;
}
if (!key) {
return callback(new Error('invalid command: ' + JSON.stringify(command)));
}
if (key.substr(0, 7) === 'create_') {
model = key.substr(7);
id = data.id;
delete data.id;
_this._manipulateConvertIds(id_to_record_map, model, data);
return _this._manipulateCreate(model, data, function(error, record) {
if (error) {
return callback(error);
}
if (id) {
id_to_record_map[id] = record;
}
return callback(null);
});
} else if (key.substr(0, 7) === 'delete_') {
model = key.substr(7);
return _this._manipulateDelete(model, data, callback);
} else if (key === 'deleteAll') {
return _this._manipulateDeleteAllModels(callback);
} else if (key.substr(0, 5) === 'drop_') {
model = key.substr(5);
return _this._manipulateDropModel(model, callback);
} else if (key === 'dropAll') {
return _this._manipulateDropAllModels(callback);
} else if (key.substr(0, 5) === 'find_') {
model = key.substr(5);
id = data.id;
delete data.id;
if (!id) {
return callback(null);
}
return callback(null);
});
} else if (key.substr(0, 7) === 'delete_') {
model = key.substr(7);
return _this._manipulateDelete(model, data, callback);
} else if (key === 'deleteAll') {
return _this._manipulateDeleteAllModels(callback);
} else if (key.substr(0, 5) === 'drop_') {
model = key.substr(5);
return _this._manipulateDropModel(model, callback);
} else if (key === 'dropAll') {
return _this._manipulateDropAllModels(callback);
} else if (key.substr(0, 5) === 'find_') {
model = key.substr(5);
id = data.id;
delete data.id;
if (!id) {
return callback(null);
return _this._manipulateFind(model, data, function(error, records) {
if (error) {
return callback(error);
}
id_to_record_map[id] = records;
return callback(null);
});
} else {
return callback(new Error('unknown command: ' + key));
}
return _this._manipulateFind(model, data, function(error, records) {
if (error) {
return callback(error);
}
id_to_record_map[id] = records;
return callback(null);
});
} else {
return callback(new Error('unknown command: ' + key));
}
}, function(error) {
return callback(error, id_to_record_map);
}, function(error) {
return callback(error, id_to_record_map);
});
});

@@ -184,0 +189,0 @@ };

@@ -11,2 +11,4 @@ // Generated by CoffeeScript 1.6.2

exports.console_future = require('./console_future');
}).call(this);
// Generated by CoffeeScript 1.6.2
(function() {
var ColumnProperty, Model, types, util, _, _bindDomain, _use,
var ColumnProperty, Model, console_future, tableize, types, util, _, _bindDomain, _use,
__hasProp = {}.hasOwnProperty,

@@ -9,2 +9,6 @@ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

console_future = require('./console_future');
tableize = require('./inflector').tableize;
types = require('./types');

@@ -97,5 +101,8 @@

});
return Object.defineProperty(this, '_integrities', {
Object.defineProperty(this, '_integrities', {
value: []
});
if (!this.tableName) {
return this.tableName = tableize(name);
}
};

@@ -195,7 +202,9 @@

}
return this._adapter.drop(this._name, _bindDomain(function(error) {
_this._schema_changed = true;
_this._connection._schema_changed = true;
return callback(error);
}));
return console_future.execute(callback, function(callback) {
return _this._adapter.drop(_this._name, _bindDomain(function(error) {
_this._schema_changed = true;
_this._connection._schema_changed = true;
return callback(error);
}));
});
};

@@ -446,24 +455,30 @@

if (typeof callback !== 'function') {
callback = (function() {});
}
this._runCallbacks('destroy', 'before');
if (this.id) {
this.constructor["delete"]({
id: this.id
}, function(error, count) {
return console_future.execute(callback, function(callback) {
if (typeof callback !== 'function') {
callback = (function() {});
}
_this._runCallbacks('destroy', 'before');
if (_this.id) {
return _this.constructor["delete"]({
id: _this.id
}, function(error, count) {
_this._runCallbacks('destroy', 'after');
return callback(error);
});
} else {
_this._runCallbacks('destroy', 'after');
return callback(error);
});
} else {
this._runCallbacks('destroy', 'after');
callback(null);
}
return callback(null);
}
});
};
Model.deleteAll = function(callback) {
if (typeof callback !== 'function') {
callback = (function() {});
}
this["delete"](callback);
var _this = this;
return console_future.execute(callback, function(callback) {
if (typeof callback !== 'function') {
callback = (function() {});
}
return _this["delete"](callback);
});
};

@@ -501,2 +516,12 @@

Model.inspect = function(depth) {
var schema,
_this = this;
schema = Object.keys(this._schema).sort().map(function(column) {
return "" + column + ": " + _this._schema[column].type;
}).join(', ');
return '\u001b[36m' + ("[Model: " + this.name + "(") + '\u001b[90m' + schema + '\u001b[36m' + ")]" + '\u001b[39m';
};
return Model;

@@ -503,0 +528,0 @@

// Generated by CoffeeScript 1.6.2
(function() {
var ModelPersistence, async, inflector, util, _, _bindDomain;
var ModelPersistence, async, console_future, inflector, util, _, _bindDomain;
_ = require('underscore');
async = require('async');
console_future = require('../console_future');
inflector = require('../inflector');

@@ -11,4 +15,2 @@

_ = require('underscore');
_bindDomain = function(fn) {

@@ -28,2 +30,4 @@ var d;

ModelPersistence.create = function(data, options, callback) {
var _this = this;
if (typeof data === 'function') {

@@ -37,3 +41,5 @@ callback = data;

}
return this.build(data).save(options, callback);
return console_future.execute(callback, function(callback) {
return _this.build(data).save(options, callback);
});
};

@@ -40,0 +46,0 @@

// Generated by CoffeeScript 1.6.2
(function() {
var ModelQuery, Query;
var ModelQuery, Query, console_future;
console_future = require('../console_future');
Query = require('../query');

@@ -10,3 +12,3 @@

ModelQuery._createQueryAndRun = function(criteria, data, operation, callback) {
ModelQuery._createQueryAndRun = function(criteria, data, callback) {
var query;

@@ -17,3 +19,3 @@

if (typeof callback === 'function') {
query[operation](callback);
query.exec(callback);
}

@@ -23,7 +25,7 @@ return query;

ModelQuery._createOptionalQueryAndRun = function(criteria, data, operation, callback) {
ModelQuery._createOptionalQueryAndRun = function(criteria, data, callback) {
if (typeof data === 'function') {
return this._createQueryAndRun(criteria, null, operation, data);
return this._createQueryAndRun(criteria, null, data);
} else {
return this._createQueryAndRun(criteria, data, operation, callback);
return this._createQueryAndRun(criteria, data, callback);
}

@@ -37,19 +39,19 @@ };

ModelQuery.find = function(id, callback) {
return this._createQueryAndRun('find', id, 'exec', callback);
return this._createQueryAndRun('find', id, callback);
};
ModelQuery.findPreserve = function(ids, callback) {
return this._createQueryAndRun('findPreserve', ids, 'exec', callback);
return this._createQueryAndRun('findPreserve', ids, callback);
};
ModelQuery.where = function(condition, callback) {
return this._createOptionalQueryAndRun('where', condition, 'exec', callback);
return this._createOptionalQueryAndRun('where', condition, callback);
};
ModelQuery.select = function(columns, callback) {
return this._createOptionalQueryAndRun('select', columns, 'exec', callback);
return this._createOptionalQueryAndRun('select', columns, callback);
};
ModelQuery.order = function(orders, callback) {
return this._createOptionalQueryAndRun('order', orders, 'exec', callback);
return this._createOptionalQueryAndRun('order', orders, callback);
};

@@ -69,7 +71,22 @@

ModelQuery.count = function(condition, callback) {
return this._createOptionalQueryAndRun('where', condition, 'count', callback);
var _this = this;
if (typeof condition === 'function') {
callback = condition;
condition = null;
}
return console_future.execute(callback, function(callback) {
var query;
if (typeof callback !== 'function') {
callback = (function() {});
}
query = new Query(_this);
query.where(condition);
return query.count(callback);
});
};
ModelQuery.update = function(updates, condition, callback) {
var query;
var _this = this;

@@ -80,12 +97,31 @@ if (typeof condition === 'function') {

}
query = new Query(this);
query.where(condition);
if (typeof callback === 'function') {
query.update(updates, callback);
}
return query;
return console_future.execute(callback, function(callback) {
var query;
if (typeof callback !== 'function') {
callback = (function() {});
}
query = new Query(_this);
query.where(condition);
return query.update(updates, callback);
});
};
ModelQuery["delete"] = function(condition, callback) {
return this._createOptionalQueryAndRun('where', condition, 'delete', callback);
var _this = this;
if (typeof condition === 'function') {
callback = condition;
condition = null;
}
return console_future.execute(callback, function(callback) {
var query;
if (typeof callback !== 'function') {
callback = (function() {});
}
query = new Query(_this);
query.where(condition);
return query["delete"](callback);
});
};

@@ -92,0 +128,0 @@

// Generated by CoffeeScript 1.6.2
(function() {
var Query, async, _, _bindDomain;
var Query, async, console_future, _, _bindDomain;

@@ -9,2 +9,4 @@ _ = require('underscore');

console_future = require('./console_future');
_bindDomain = function(fn) {

@@ -149,2 +151,8 @@ var d;

Query.prototype.one = function() {
this._options.limit = 1;
this._options.one = true;
return this;
};
Query.prototype.limit = function(limit) {

@@ -232,3 +240,3 @@ this._options.limit = limit;

if (_this._preserve_order_ids) {
return callback(null, _this._preserve_order_ids.map(function(id) {
records = _this._preserve_order_ids.map(function(id) {
var record, _i, _len;

@@ -242,3 +250,9 @@

}
}));
});
}
if (_this._options.one) {
if (records.length > 1) {
return callback(new Error('unknown error'));
}
return callback(null, records.length === 1 ? records[0] : null);
} else {

@@ -266,4 +280,3 @@ return callback(null, records);

Query.prototype.exec = function(options, callback) {
var cache_key, cache_options,
_this = this;
var _this = this;

@@ -277,35 +290,43 @@ if (this._model._waitingForReady(this, this.exec, arguments)) {

}
if ((cache_options = this._options.cache) && (cache_key = cache_options.key)) {
return this._model._loadFromCache(cache_key, cache_options.refresh, function(error, records) {
if (!error) {
return callback(null, records);
}
return _this._execAndInclude(options, function(error, records) {
if (error) {
return callback(error);
return console_future.execute(callback, function(callback) {
var cache_key, cache_options;
if ((cache_options = _this._options.cache) && (cache_key = cache_options.key)) {
return _this._model._loadFromCache(cache_key, cache_options.refresh, function(error, records) {
if (!error) {
return callback(null, records);
}
return _this._model._saveToCache(cache_key, cache_options.ttl, records, function(error) {
return callback(error, records);
return _this._execAndInclude(options, function(error, records) {
if (error) {
return callback(error);
}
return _this._model._saveToCache(cache_key, cache_options.ttl, records, function(error) {
return callback(error, records);
});
});
});
});
} else {
return this._execAndInclude(options, callback);
}
} else {
return _this._execAndInclude(options, callback);
}
});
};
Query.prototype.count = function(callback) {
var _this = this;
if (this._model._waitingForReady(this, this.count, arguments)) {
return;
}
if (this._id) {
this._conditions.push({
id: this._id
return console_future.execute(callback, function(callback) {
if (_this._id) {
_this._conditions.push({
id: _this._id
});
delete _this._id;
}
_this._connection.log(_this._name, 'count', {
conditions: _this._conditions
});
delete this._id;
}
this._connection.log(this._name, 'count', {
conditions: this._conditions
return _this._adapter.count(_this._name, _this._conditions, _bindDomain(callback));
});
return this._adapter.count(this._name, this._conditions, _bindDomain(callback));
};

@@ -348,3 +369,3 @@

Query.prototype.update = function(updates, callback) {
var data, errors;
var _this = this;

@@ -354,20 +375,24 @@ if (this._model._waitingForReady(this, this.update, arguments)) {

}
errors = [];
data = {};
this._validateAndBuildSaveData(errors, data, updates, '', updates);
if (errors.length > 0) {
return callback(new Error(errors.join(',')));
}
if (this._id) {
this._conditions.push({
id: this._id
return console_future.execute(callback, function(callback) {
var data, errors;
errors = [];
data = {};
_this._validateAndBuildSaveData(errors, data, updates, '', updates);
if (errors.length > 0) {
return callback(new Error(errors.join(',')));
}
if (_this._id) {
_this._conditions.push({
id: _this._id
});
delete _this._id;
}
_this._connection.log(_this._name, 'update', {
data: data,
conditions: _this._conditions,
options: _this._options
});
delete this._id;
}
this._connection.log(this._name, 'update', {
data: data,
conditions: this._conditions,
options: this._options
return _this._adapter.updatePartial(_this._name, data, _this._conditions, _this._options, _bindDomain(callback));
});
return this._adapter.updatePartial(this._name, data, this._conditions, this._options, _bindDomain(callback));
};

@@ -487,18 +512,20 @@

}
if (this._id) {
this._conditions.push({
id: this._id
return console_future.execute(callback, function(callback) {
if (_this._id) {
_this._conditions.push({
id: _this._id
});
delete _this._id;
}
if (!(options != null ? options.skip_log : void 0)) {
_this._connection.log(_this._name, 'delete', {
conditions: _this._conditions
});
}
return _this._doArchiveAndIntegrity(options, function(error) {
if (error) {
return callback(error);
}
return _this._adapter["delete"](_this._name, _this._conditions, _bindDomain(callback));
});
delete this._id;
}
if (!(options != null ? options.skip_log : void 0)) {
this._connection.log(this._name, 'delete', {
conditions: this._conditions
});
}
return this._doArchiveAndIntegrity(options, function(error) {
if (error) {
return callback(error);
}
return _this._adapter["delete"](_this._name, _this._conditions, _bindDomain(callback));
});

@@ -505,0 +532,0 @@ };

{
"name": "cormo",
"description": "ORM framework for Node.js",
"version": "0.6.5",
"version": "0.6.6",
"keywords": [

@@ -6,0 +6,0 @@ "orm",

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