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

backbone-sql

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backbone-sql - npm Package Compare versions

Comparing version 0.6.4 to 0.6.5

2

lib/core.js

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

// Generated by CoffeeScript 1.7.1
// Generated by CoffeeScript 1.9.2
(function() {

@@ -3,0 +3,0 @@ module.exports = {};

@@ -1,5 +0,5 @@

// Generated by CoffeeScript 1.7.1
// Generated by CoffeeScript 1.9.2
/*
backbone-sql.js 0.6.4
backbone-sql.js 0.6.5
Copyright (c) 2013 Vidigami - https://github.com/vidigami/backbone-sql

@@ -10,11 +10,11 @@ License: MIT (http://www.opensource.org/licenses/mit-license.php)

(function() {
var COMPARATORS, COMPARATOR_KEYS, Knex, SqlCursor, sync, _, _appendCondition, _appendConditionalWhere, _appendWhere, _columnName, _extractCount, _ref,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__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; },
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
var COMPARATORS, COMPARATOR_KEYS, Knex, SqlCursor, _, _appendCondition, _appendConditionalWhere, _appendWhere, _columnName, _extractCount, ref, sync,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
extend = 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; },
hasProp = {}.hasOwnProperty,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
Knex = require('knex');
_ref = require('backbone-orm'), _ = _ref._, sync = _ref.sync;
ref = require('backbone-orm'), _ = ref._, sync = ref.sync;

@@ -32,5 +32,5 @@ COMPARATORS = {

_appendCondition = function(conditions, key, value) {
var mongo_op, mongo_ops, operations, ops_length, parameter, _ref1, _ref2;
var mongo_op, mongo_ops, operations, ops_length, parameter, ref1, ref2;
if (value != null ? value.$in : void 0) {
if ((_ref1 = value.$in) != null ? _ref1.length : void 0) {
if ((ref1 = value.$in) != null ? ref1.length : void 0) {
conditions.wheres.push({

@@ -46,3 +46,3 @@ method: 'whereIn',

} else if (value != null ? value.$nin : void 0) {
if ((_ref2 = value.$nin) != null ? _ref2.length : void 0) {
if ((ref2 = value.$nin) != null ? ref2.length : void 0) {
conditions.wheres.push({

@@ -54,2 +54,7 @@ method: 'whereNotIn',

}
} else if ((value != null ? value.$exists : void 0) != null) {
conditions.wheres.push({
method: ((value != null ? value.$exists : void 0) ? 'whereNotNull' : 'whereNull'),
key: key
});
} else if (_.isObject(value) && (ops_length = _.size(mongo_ops = _.pick(value, COMPARATOR_KEYS)))) {

@@ -88,3 +93,3 @@ operations = [];

if (table) {
return "" + table + "." + col;
return table + "." + col;
} else {

@@ -112,6 +117,6 @@ return col;

_appendWhere = function(query, conditions, table) {
var condition, _i, _j, _len, _len1, _ref1, _ref2;
_ref1 = conditions.wheres;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
condition = _ref1[_i];
var condition, i, j, len, len1, ref1, ref2;
ref1 = conditions.wheres;
for (i = 0, len = ref1.length; i < len; i++) {
condition = ref1[i];
if (condition.method) {

@@ -125,18 +130,18 @@ query[condition.method](_columnName(condition.key, table), condition.value);

}
_ref2 = conditions.where_conditionals;
for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
condition = _ref2[_j];
ref2 = conditions.where_conditionals;
for (j = 0, len1 = ref2.length; j < len1; j++) {
condition = ref2[j];
if (condition.operations) {
query.where(function() {
var nested_query, operation, _k, _len2, _ref3, _results;
var k, len2, nested_query, operation, ref3, results;
operation = condition.operations.pop();
nested_query = this;
_appendConditionalWhere(nested_query, condition.key, operation, table, false);
_ref3 = condition.operations;
_results = [];
for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
operation = _ref3[_k];
_results.push(_appendConditionalWhere(nested_query, condition.key, operation, table, true));
ref3 = condition.operations;
results = [];
for (k = 0, len2 = ref3.length; k < len2; k++) {
operation = ref3[k];
results.push(_appendConditionalWhere(nested_query, condition.key, operation, table, true));
}
return _results;
return results;
});

@@ -161,7 +166,7 @@ } else if (_.isNull(condition.value)) {

module.exports = SqlCursor = (function(_super) {
__extends(SqlCursor, _super);
module.exports = SqlCursor = (function(superClass) {
extend(SqlCursor, superClass);
function SqlCursor() {
this._exec = __bind(this._exec, this);
this._exec = bind(this._exec, this);
return SqlCursor.__super__.constructor.apply(this, arguments);

@@ -173,3 +178,3 @@ }

SqlCursor.prototype._parseConditions = function(find, cursor) {
var conditions, key, related_conditions, related_wheres, relation, reverse_relation, value, _base, _name, _ref1;
var base, conditions, key, name, ref1, related_conditions, related_wheres, relation, reverse_relation, value;
conditions = {

@@ -188,3 +193,3 @@ wheres: [],

if (key.indexOf('.') > 0) {
_ref1 = key.split('.'), relation = _ref1[0], key = _ref1[1];
ref1 = key.split('.'), relation = ref1[0], key = ref1[1];
related_wheres[relation] || (related_wheres[relation] = {});

@@ -194,3 +199,3 @@ related_wheres[relation][key] = value;

relation = reverse_relation.reverse_relation;
(_base = conditions.joined_wheres)[_name = relation.key] || (_base[_name] = {
(base = conditions.joined_wheres)[name = relation.key] || (base[name] = {
wheres: [],

@@ -223,3 +228,3 @@ where_conditionals: []

SqlCursor.prototype.queryToJSON = function(callback) {
var $columns, $fields, err, from_columns, key, query, rank_field, related_model_type, related_wheres, relation, sort_dir, sort_field, subquery, to_columns, _base, _i, _len, _ref1, _ref2, _ref3;
var $columns, $fields, base, err, from_columns, i, key, len, query, rank_field, ref1, ref2, ref3, related_model_type, related_wheres, relation, sort_dir, sort_field, subquery, to_columns;
if (this.hasCursorQuery('$zero')) {

@@ -262,6 +267,6 @@ return callback(null, this.hasCursorQuery('$one') ? null : []);

} else {
(_base = this._cursor).$sort || (_base.$sort = []);
(base = this._cursor).$sort || (base.$sort = []);
rank_field = this._cursor.$unique[0];
_ref2 = this._parseSortField(((_ref1 = this._cursor.$sort) != null ? _ref1[0] : void 0) || 'id'), sort_field = _ref2[0], sort_dir = _ref2[1];
subquery = this.connection.select(this.connection.raw("" + ($fields.join(', ')) + ", rank() over (partition by " + rank_field + " order by " + sort_field + " " + sort_dir + ")"));
ref2 = this._parseSortField(((ref1 = this._cursor.$sort) != null ? ref1[0] : void 0) || 'id'), sort_field = ref2[0], sort_dir = ref2[1];
subquery = this.connection.select(this.connection.raw(($fields.join(', ')) + ", rank() over (partition by " + rank_field + " order by " + sort_field + " " + sort_dir + ")"));
subquery.from(this.model_type.tableName()).as('subquery');

@@ -298,5 +303,5 @@ query.select($fields).from(subquery).where('rank', 1);

to_columns = [];
_ref3 = this.include_keys;
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
key = _ref3[_i];
ref3 = this.include_keys;
for (i = 0, len = ref3.length; i < len; i++) {
key = ref3[i];
relation = this._getRelation(key);

@@ -348,6 +353,6 @@ related_model_type = relation.reverse_relation.model_type;

SqlCursor.prototype._processResponse = function(json, callback) {
var model_json, number, query, schema, _i, _len;
var i, len, model_json, number, query, schema, subquery;
schema = this.model_type.schema();
for (_i = 0, _len = json.length; _i < _len; _i++) {
model_json = json[_i];
for (i = 0, len = json.length; i < len; i++) {
model_json = json[i];
this.backbone_adapter.nativeToAttributes(model_json, schema);

@@ -369,7 +374,20 @@ }

if (this.hasCursorQuery('$page')) {
query = this.connection(this.model_type.tableName());
query = this.connection();
_appendWhere(query, this._conditions, this.model_type.tableName());
this._appendRelatedWheres(query);
this._appendJoinedWheres(query);
return query.count('*').exec((function(_this) {
if (this._cursor.$unique) {
subquery = this.connection.distinct(this._cursor.$unique);
subquery.from(this.model_type.tableName()).as('subquery');
query.from(subquery);
} else {
query.from(this.model_type.tableName());
}
query.count('*');
if (this.verbose) {
console.log('\n---------- counting rows for $page');
console.log(query.toString());
console.log('----------');
}
return query.exec((function(_this) {
return function(err, count_json) {

@@ -417,10 +435,10 @@ if (err) {

SqlCursor.prototype._appendSort = function(query) {
var col, dir, sort, _i, _len, _ref1, _ref2;
var col, dir, i, len, ref1, ref2, sort;
if (!this._cursor.$sort) {
return query;
}
_ref1 = this._cursor.$sort;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
sort = _ref1[_i];
_ref2 = this._parseSortField(sort), col = _ref2[0], dir = _ref2[1];
ref1 = this._cursor.$sort;
for (i = 0, len = ref1.length; i < len; i++) {
sort = ref1[i];
ref2 = this._parseSortField(sort), col = ref2[0], dir = ref2[1];
query.orderBy(col, dir);

@@ -432,9 +450,9 @@ }

SqlCursor.prototype._appendCompleteRelations = function(json, callback) {
var key, new_query, related_model_type, relation, to_columns, _i, _len, _ref1;
var i, key, len, new_query, ref1, related_model_type, relation, to_columns;
new_query = this.connection(this.model_type.tableName());
new_query.whereIn(_columnName('id', this.model_type.tableName()), _.pluck(json, 'id'));
to_columns = [];
_ref1 = this.queued_queries;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
key = _ref1[_i];
ref1 = this.queued_queries;
for (i = 0, len = ref1.length; i < len; i++) {
key = ref1[i];
relation = this._getRelation(key);

@@ -448,6 +466,9 @@ related_model_type = relation.reverse_relation.model_type;

return function(err, new_json) {
var model, placeholder, relation_json, _j, _len1;
var j, len1, model, placeholder, relation_json;
if (err) {
return callback(err);
}
relation_json = _this._joinedResultsToJSON(new_json);
for (_j = 0, _len1 = relation_json.length; _j < _len1; _j++) {
placeholder = relation_json[_j];
for (j = 0, len1 = relation_json.length; j < len1; j++) {
placeholder = relation_json[j];
model = _.find(json, function(test) {

@@ -464,3 +485,3 @@ return test.id === placeholder.id;

SqlCursor.prototype._appendRelatedWheres = function(query) {
var key, related_wheres, relation, _ref1, _results;
var key, ref1, related_wheres, relation, results;
if (_.isEmpty(this._conditions.related_wheres)) {

@@ -473,15 +494,15 @@ return;

}
_ref1 = this._conditions.related_wheres;
_results = [];
for (key in _ref1) {
related_wheres = _ref1[key];
ref1 = this._conditions.related_wheres;
results = [];
for (key in ref1) {
related_wheres = ref1[key];
relation = this._getRelation(key);
this._joinTo(query, relation);
_results.push(_appendWhere(query, related_wheres, relation.reverse_relation.model_type.tableName()));
results.push(_appendWhere(query, related_wheres, relation.reverse_relation.model_type.tableName()));
}
return _results;
return results;
};
SqlCursor.prototype._appendJoinedWheres = function(query) {
var from_key, joined_wheres, key, relation, to_key, _ref1, _results;
var from_key, joined_wheres, key, ref1, relation, results, to_key;
if (_.isEmpty(this._conditions.joined_wheres)) {

@@ -491,15 +512,15 @@ return;

this.joined = true;
_ref1 = this._conditions.joined_wheres;
_results = [];
for (key in _ref1) {
joined_wheres = _ref1[key];
ref1 = this._conditions.joined_wheres;
results = [];
for (key in ref1) {
joined_wheres = ref1[key];
relation = this._getRelation(key);
if (!(__indexOf.call(_.keys(this._conditions.related_wheres), key) >= 0 || (this.include_keys && __indexOf.call(this.include_keys, key) >= 0))) {
from_key = "" + (this.model_type.tableName()) + ".id";
to_key = "" + (relation.join_table.tableName()) + "." + relation.foreign_key;
if (!(indexOf.call(_.keys(this._conditions.related_wheres), key) >= 0 || (this.include_keys && indexOf.call(this.include_keys, key) >= 0))) {
from_key = (this.model_type.tableName()) + ".id";
to_key = (relation.join_table.tableName()) + "." + relation.foreign_key;
query.join(relation.join_table.tableName(), from_key, '=', to_key, 'left outer');
}
_results.push(_appendWhere(query, joined_wheres, relation.join_table.tableName()));
results.push(_appendWhere(query, joined_wheres, relation.join_table.tableName()));
}
return _results;
return results;
};

@@ -512,15 +533,15 @@

pivot_table = relation.join_table.tableName();
from_key = "" + (this.model_type.tableName()) + ".id";
pivot_to_key = "" + pivot_table + "." + relation.foreign_key;
from_key = (this.model_type.tableName()) + ".id";
pivot_to_key = pivot_table + "." + relation.foreign_key;
query.join(pivot_table, from_key, '=', pivot_to_key, 'left outer');
pivot_from_key = "" + pivot_table + "." + relation.reverse_relation.foreign_key;
to_key = "" + (related_model_type.tableName()) + ".id";
pivot_from_key = pivot_table + "." + relation.reverse_relation.foreign_key;
to_key = (related_model_type.tableName()) + ".id";
return query.join(related_model_type.tableName(), pivot_from_key, '=', to_key, 'left outer');
} else {
if (relation.type === 'belongsTo') {
from_key = "" + (this.model_type.tableName()) + "." + relation.foreign_key;
to_key = "" + (related_model_type.tableName()) + ".id";
from_key = (this.model_type.tableName()) + "." + relation.foreign_key;
to_key = (related_model_type.tableName()) + ".id";
} else {
from_key = "" + (this.model_type.tableName()) + ".id";
to_key = "" + (related_model_type.tableName()) + "." + relation.foreign_key;
from_key = (this.model_type.tableName()) + ".id";
to_key = (related_model_type.tableName()) + "." + relation.foreign_key;
}

@@ -532,3 +553,3 @@ return query.join(related_model_type.tableName(), from_key, '=', to_key, 'left outer');

SqlCursor.prototype._joinedResultsToJSON = function(raw_json) {
var found, include_key, json, key, match, model_json, related_json, related_model_type, reverse_relation_schema, row, row_relation_json, value, _i, _j, _len, _len1, _ref1;
var found, i, include_key, j, json, key, len, len1, match, model_json, ref1, related_json, related_model_type, reverse_relation_schema, row, row_relation_json, value;
if (!(raw_json && raw_json.length)) {

@@ -538,4 +559,4 @@ return raw_json;

json = [];
for (_i = 0, _len = raw_json.length; _i < _len; _i++) {
row = raw_json[_i];
for (i = 0, len = raw_json.length; i < len; i++) {
row = raw_json[i];
model_json = {};

@@ -548,5 +569,5 @@ row_relation_json = {};

} else if (this.include_keys) {
_ref1 = this.include_keys;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
include_key = _ref1[_j];
ref1 = this.include_keys;
for (j = 0, len1 = ref1.length; j < len1; j++) {
include_key = ref1[j];
related_json = (row_relation_json[include_key] || (row_relation_json[include_key] = {}));

@@ -597,3 +618,3 @@ related_model_type = this.model_type.relation(include_key).reverse_relation.model_type;

columns = fields ? _.clone(fields) : model_type.schema().columns();
if (__indexOf.call(columns, 'id') < 0) {
if (indexOf.call(columns, 'id') < 0) {
columns.push('id');

@@ -607,13 +628,13 @@ }

columns = fields ? _.clone(fields) : model_type.schema().columns();
if (__indexOf.call(columns, 'id') < 0) {
if (indexOf.call(columns, 'id') < 0) {
columns.push('id');
}
return (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = columns.length; _i < _len; _i++) {
col = columns[_i];
_results.push("" + (model_type.tableName()) + "." + col + " as " + (this._tablePrefix(model_type)) + col);
var i, len, results;
results = [];
for (i = 0, len = columns.length; i < len; i++) {
col = columns[i];
results.push((model_type.tableName()) + "." + col + " as " + (this._tablePrefix(model_type)) + col);
}
return _results;
return results;
}).call(this);

@@ -623,3 +644,3 @@ };

SqlCursor.prototype._tablePrefix = function(model_type) {
return "" + (model_type.tableName()) + "_";
return (model_type.tableName()) + "_";
};

@@ -634,3 +655,3 @@

if (!(relation = this.model_type.relation(key))) {
throw new Error("" + key + " is not a relation of " + this.model_type.model_name);
throw new Error(key + " is not a relation of " + this.model_type.model_name);
}

@@ -637,0 +658,0 @@ return relation;

@@ -1,5 +0,5 @@

// Generated by CoffeeScript 1.7.1
// Generated by CoffeeScript 1.9.2
/*
backbone-sql.js 0.6.4
backbone-sql.js 0.6.5
Copyright (c) 2013 Vidigami - https://github.com/vidigami/backbone-sql

@@ -10,8 +10,8 @@ License: MIT (http://www.opensource.org/licenses/mit-license.php)

(function() {
var DatabaseTools, KNEX_COLUMN_OPTIONS, KNEX_SKIP, KNEX_TYPES, Knex, Queue, knex_helpers, _, _deprecate, _ref,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
var DatabaseTools, KNEX_COLUMN_OPTIONS, KNEX_SKIP, KNEX_TYPES, Knex, Queue, _, _deprecate, knex_helpers, ref,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Knex = require('knex');
_ref = require('backbone-orm'), _ = _ref._, Queue = _ref.Queue;
ref = require('backbone-orm'), _ = ref._, Queue = ref.Queue;

@@ -45,18 +45,18 @@ KNEX_COLUMN_OPTIONS = ['textType', 'length', 'precision', 'scale', 'value', 'values'];

}
this.renameTable = __bind(this.renameTable, this);
this.dropTableIfExists = __bind(this.dropTableIfExists, this);
this.dropTable = __bind(this.dropTable, this);
this.hasTable = __bind(this.hasTable, this);
this.hasColumn = __bind(this.hasColumn, this);
this.updateColumn = __bind(this.updateColumn, this);
this.addColumn = __bind(this.addColumn, this);
this.createOrUpdateTable = __bind(this.createOrUpdateTable, this);
this.ensureSchema = __bind(this.ensureSchema, this);
this.resetSchema = __bind(this.resetSchema, this);
this.renameTable = bind(this.renameTable, this);
this.dropTableIfExists = bind(this.dropTableIfExists, this);
this.dropTable = bind(this.dropTable, this);
this.hasTable = bind(this.hasTable, this);
this.hasColumn = bind(this.hasColumn, this);
this.updateColumn = bind(this.updateColumn, this);
this.addColumn = bind(this.addColumn, this);
this.createOrUpdateTable = bind(this.createOrUpdateTable, this);
this.ensureSchema = bind(this.ensureSchema, this);
this.resetSchema = bind(this.resetSchema, this);
}
DatabaseTools.prototype.resetSchema = function(options, callback) {
var queue, _ref1;
var queue, ref1;
if (arguments.length === 1) {
_ref1 = [options, {}], callback = _ref1[0], options = _ref1[1];
ref1 = [options, {}], callback = ref1[0], options = ref1[1];
}

@@ -75,6 +75,6 @@ if (this.resetting) {

return function(callback) {
var join_queue, join_table, _fn, _i, _len, _ref2;
var fn, i, join_queue, join_table, len, ref2;
join_queue = new Queue(1);
_ref2 = _this.schema.joinTables();
_fn = function(join_table) {
ref2 = _this.schema.joinTables();
fn = function(join_table) {
return join_queue.defer(function(callback) {

@@ -84,5 +84,5 @@ return join_table.db().resetSchema(callback);

};
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
join_table = _ref2[_i];
_fn(join_table);
for (i = 0, len = ref2.length; i < len; i++) {
join_table = ref2[i];
fn(join_table);
}

@@ -104,5 +104,5 @@ return join_queue.await(callback);

DatabaseTools.prototype.ensureSchema = function(options, callback) {
var queue, _ref1;
var queue, ref1;
if (arguments.length === 1) {
_ref1 = [options, {}], callback = _ref1[0], options = _ref1[1];
ref1 = [options, {}], callback = ref1[0], options = ref1[1];
}

@@ -121,6 +121,6 @@ if (this.ensuring) {

return function(callback) {
var join_queue, join_table, _fn, _i, _len, _ref2;
var fn, i, join_queue, join_table, len, ref2;
join_queue = new Queue(1);
_ref2 = _this.schema.joinTables();
_fn = function(join_table) {
ref2 = _this.schema.joinTables();
fn = function(join_table) {
return join_queue.defer(function(callback) {

@@ -130,5 +130,5 @@ return join_table.db().ensureSchema(callback);

};
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
join_table = _ref2[_i];
_fn(join_table);
for (i = 0, len = ref2.length; i < len; i++) {
join_table = ref2[i];
fn(join_table);
}

@@ -149,3 +149,3 @@ return join_queue.await(callback);

return function(err, table_exists) {
var columns, field, group, key, override, relation, type, _i, _len, _ref1, _ref2;
var columns, field, group, i, key, len, override, ref1, ref2, relation, type;
if (err) {

@@ -158,5 +158,5 @@ return callback(err);

columns = [];
_ref1 = _this.schema.columns();
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
key = _ref1[_i];
ref1 = _this.schema.columns();
for (i = 0, len = ref1.length; i < len; i++) {
key = ref1[i];
if (field = _this.schema.fields[key]) {

@@ -182,5 +182,5 @@ if (override = KNEX_TYPES[type = field.type.toLowerCase()]) {

}
_ref2 = _this.schema.relations;
for (key in _ref2) {
relation = _ref2[key];
ref2 = _this.schema.relations;
for (key in ref2) {
relation = ref2[key];
if ((relation.type === 'belongsTo') && !relation.isVirtual() && !relation.isEmbedded()) {

@@ -200,3 +200,3 @@ (function(key, relation) {

group = function(columns, callback) {
var column_info, queue, result, _fn, _j, _len1;
var column_info, fn, j, len1, queue, result;
if (!table_exists) {

@@ -213,3 +213,3 @@ return callback(null, {

queue = new Queue();
_fn = function(column_info) {
fn = function(column_info) {
return queue.defer(function(callback) {

@@ -225,5 +225,5 @@ return _this.hasColumn(column_info.key, function(err, exists) {

};
for (_j = 0, _len1 = columns.length; _j < _len1; _j++) {
column_info = columns[_j];
_fn(column_info);
for (j = 0, len1 = columns.length; j < len1; j++) {
column_info = columns[j];
fn(column_info);
}

@@ -239,15 +239,15 @@ return queue.await(function(err) {

return _this.connection.knex().schema[table_exists ? 'table' : 'createTable'](_this.table_name, function(table) {
var column_info, _j, _k, _len1, _len2, _ref3, _ref4, _results;
_ref3 = result.add;
for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) {
column_info = _ref3[_j];
var column_info, j, k, len1, len2, ref3, ref4, results;
ref3 = result.add;
for (j = 0, len1 = ref3.length; j < len1; j++) {
column_info = ref3[j];
_this.addColumn(table, column_info);
}
_ref4 = result.update;
_results = [];
for (_k = 0, _len2 = _ref4.length; _k < _len2; _k++) {
column_info = _ref4[_k];
_results.push(_this.updateColumn(table, column_info));
ref4 = result.update;
results = [];
for (k = 0, len2 = ref4.length; k < len2; k++) {
column_info = ref4[k];
results.push(_this.updateColumn(table, column_info));
}
return _results;
return results;
}).exec(callback);

@@ -260,7 +260,7 @@ });

DatabaseTools.prototype.addColumn = function(table, column_info) {
var column, column_args, constructor_options, _ref1;
var column, column_args, constructor_options, ref1;
column_args = [column_info.key];
constructor_options = _.pick(column_info.options, KNEX_COLUMN_OPTIONS);
if (!_.isEmpty(constructor_options)) {
if ((_ref1 = column_info.type) === 'float' || _ref1 === 'decimal') {
if ((ref1 = column_info.type) === 'float' || ref1 === 'decimal') {
column_args[1] = constructor_options['precision'];

@@ -267,0 +267,0 @@ column_args[2] = constructor_options['scale'];

@@ -1,5 +0,5 @@

// Generated by CoffeeScript 1.7.1
// Generated by CoffeeScript 1.9.2
/*
backbone-sql.js 0.6.4
backbone-sql.js 0.6.5
Copyright (c) 2013 Vidigami - https://github.com/vidigami/backbone-sql

@@ -10,5 +10,5 @@ License: MIT (http://www.opensource.org/licenses/mit-license.php)

(function() {
var Backbone, BackboneORM, BackboneSQL, key, publish, value, _, _ref, _ref1;
var Backbone, BackboneORM, BackboneSQL, _, key, publish, ref, ref1, value;
_ref = BackboneORM = require('backbone-orm'), _ = _ref._, Backbone = _ref.Backbone;
ref = BackboneORM = require('backbone-orm'), _ = ref._, Backbone = ref.Backbone;

@@ -30,5 +30,5 @@ module.exports = BackboneSQL = require('./core');

_ref1 = BackboneORM.modules;
for (key in _ref1) {
value = _ref1[key];
ref1 = BackboneORM.modules;
for (key in ref1) {
value = ref1[key];
BackboneSQL.modules[key] = value;

@@ -35,0 +35,0 @@ }

@@ -1,5 +0,5 @@

// Generated by CoffeeScript 1.7.1
// Generated by CoffeeScript 1.9.2
/*
backbone-sql.js 0.6.4
backbone-sql.js 0.6.5
Copyright (c) 2013 Vidigami - https://github.com/vidigami/backbone-sql

@@ -6,0 +6,0 @@ License: MIT (http://www.opensource.org/licenses/mit-license.php)

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

// Generated by CoffeeScript 1.7.1
// Generated by CoffeeScript 1.9.2
(function() {

@@ -3,0 +3,0 @@ module.exports = require('backbone-orm').configure;

@@ -1,5 +0,5 @@

// Generated by CoffeeScript 1.7.1
// Generated by CoffeeScript 1.9.2
/*
backbone-sql.js 0.6.4
backbone-sql.js 0.6.5
Copyright (c) 2013 Vidigami - https://github.com/vidigami/backbone-sql

@@ -10,7 +10,7 @@ License: MIT (http://www.opensource.org/licenses/mit-license.php)

(function() {
var Connection, ConnectionPool, DatabaseURL, Knex, KnexConnection, Queue, Utils, _, _ref;
var Connection, ConnectionPool, DatabaseURL, Knex, KnexConnection, Queue, Utils, _, ref;
Knex = require('knex');
_ref = require('backbone-orm'), _ = _ref._, Queue = _ref.Queue, DatabaseURL = _ref.DatabaseURL, ConnectionPool = _ref.ConnectionPool;
ref = require('backbone-orm'), _ = ref._, Queue = ref.Queue, DatabaseURL = ref.DatabaseURL, ConnectionPool = ref.ConnectionPool;

@@ -20,4 +20,4 @@ Utils = require('./utils');

KnexConnection = (function() {
function KnexConnection(knex) {
this.knex = knex;
function KnexConnection(knex1) {
this.knex = knex1;
}

@@ -64,4 +64,4 @@

Connection.prototype.knex = function() {
var _ref1;
return (_ref1 = this.knex_connection) != null ? _ref1.knex : void 0;
var ref1;
return (ref1 = this.knex_connection) != null ? ref1.knex : void 0;
};

@@ -68,0 +68,0 @@

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

// Generated by CoffeeScript 1.7.1
// Generated by CoffeeScript 1.9.2
(function() {

@@ -3,0 +3,0 @@ var DatabaseURL, PROTOCOLS, Utils;

@@ -1,5 +0,5 @@

// Generated by CoffeeScript 1.7.1
// Generated by CoffeeScript 1.9.2
/*
backbone-sql.js 0.6.4
backbone-sql.js 0.6.5
Copyright (c) 2013 Vidigami - https://github.com/vidigami/backbone-sql

@@ -10,6 +10,6 @@ License: MIT (http://www.opensource.org/licenses/mit-license.php)

(function() {
var Backbone, BackboneORM, CAPABILITIES, Connection, DESTROY_BATCH_LIMIT, DatabaseTools, DatabaseURL, JSONUtils, Queue, SQLUtils, Schema, SqlCursor, SqlSync, Utils, _, _ref,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
var Backbone, BackboneORM, CAPABILITIES, Connection, DESTROY_BATCH_LIMIT, DatabaseTools, DatabaseURL, JSONUtils, Queue, SQLUtils, Schema, SqlCursor, SqlSync, Utils, _, ref,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
_ref = BackboneORM = require('backbone-orm'), _ = _ref._, Backbone = _ref.Backbone, Queue = _ref.Queue, Schema = _ref.Schema, Utils = _ref.Utils, JSONUtils = _ref.JSONUtils, DatabaseURL = _ref.DatabaseURL;
ref = BackboneORM = require('backbone-orm'), _ = ref._, Backbone = ref.Backbone, Queue = ref.Queue, Schema = ref.Schema, Utils = ref.Utils, JSONUtils = ref.JSONUtils, DatabaseURL = ref.DatabaseURL;

@@ -54,14 +54,14 @@ SqlCursor = require('./cursor');

SqlSync = (function() {
function SqlSync(model_type, options) {
function SqlSync(model_type1, options) {
var key, value;
this.model_type = model_type;
this.model_type = model_type1;
if (options == null) {
options = {};
}
this.db = __bind(this.db, this);
this.getConnection = __bind(this.getConnection, this);
this.getTable = __bind(this.getTable, this);
this.deleteCB = __bind(this.deleteCB, this);
this.update = __bind(this.update, this);
this.create = __bind(this.create, this);
this.db = bind(this.db, this);
this.getConnection = bind(this.getConnection, this);
this.getTable = bind(this.getTable, this);
this.deleteCB = bind(this.deleteCB, this);
this.update = bind(this.update, this);
this.create = bind(this.create, this);
for (key in options) {

@@ -189,5 +189,5 @@ value = options[key];

SqlSync.prototype.destroy = function(query, callback) {
var _ref1;
var ref1;
if (arguments.length === 1) {
_ref1 = [{}, query], query = _ref1[0], callback = _ref1[1];
ref1 = [{}, query], query = ref1[0], callback = ref1[1];
}

@@ -203,3 +203,3 @@ return this.model_type.each(_.extend({

SqlSync.prototype.connect = function(url) {
var slave_url, _i, _len, _ref1, _ref2;
var i, len, ref1, ref2, slave_url;
this.table = (new DatabaseURL(url)).table;

@@ -211,7 +211,7 @@ this.connections || (this.connections = {

});
if ((_ref1 = this.slaves) != null ? _ref1.length : void 0) {
_ref2 = this.slaves;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
slave_url = _ref2[_i];
this.connections.slaves.push(new Connection("" + slave_url + "/" + this.table));
if ((ref1 = this.slaves) != null ? ref1.length : void 0) {
ref2 = this.slaves;
for (i = 0, len = ref2.length; i < len; i++) {
slave_url = ref2[i];
this.connections.slaves.push(new Connection(slave_url + "/" + this.table));
}

@@ -218,0 +218,0 @@ }

{
"name": "backbone-sql",
"version": "0.6.4",
"version": "0.6.5",
"description": "PostgreSQL, MySQL, and SQLite3 storage for BackboneORM",

@@ -31,3 +31,3 @@ "main": "./lib/index.js",

"test": "gulp test-postgres",
"prepublish": "npm run build"
"prepublish": "gulp build"
},

@@ -50,7 +50,7 @@ "devDependencies": {

"sqlite3": "2.x",
"supertest": "*"
"supertest": "0.13.x"
},
"dependencies": {
"underscore": "1.6.x",
"backbone": "1.1.x",
"underscore": "1.x",
"backbone": "1.x",
"backbone-orm": "0.7.x",

@@ -57,0 +57,0 @@ "knex": "0.6.x"

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

[![Build Status](https://travis-ci.org/vidigami/backbone-sql.svg?branch=develop)](https://travis-ci.org/vidigami/backbone-sql)
[![Build Status](https://travis-ci.org/vidigami/backbone-sql.svg?branch=master)](https://travis-ci.org/vidigami/backbone-sql)

@@ -59,3 +59,3 @@ ![logo](https://github.com/vidigami/backbone-sql/raw/master/media/logo.png)

var Project = Backbon.Model.extend({
var Project = Backbone.Model.extend({

@@ -62,0 +62,0 @@ // Database connection and table name are specified with the urlRoot

Please refer to the following release notes when upgrading your version of BackboneSQL.
### 0.6.5
* Bug fix for missing callback
* Bug fix $exists checks for nulls
* improve row counts for $unique
### 0.6.4

@@ -4,0 +9,0 @@ * Bug fix for join tables

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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