Socket
Socket
Sign inDemoInstall

objection

Package Overview
Dependencies
Maintainers
2
Versions
200
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

objection - npm Package Compare versions

Comparing version 0.4.0-rc.3 to 0.4.0-rc.4

140

lib/model/Model.js

@@ -208,3 +208,3 @@ 'use strict';

*/
var Model = (_class = (_temp = _class2 = (function (_ModelBase) {
var Model = (_class = (_temp = _class2 = function (_ModelBase) {
(0, _inherits3.default)(Model, _ModelBase);

@@ -327,45 +327,5 @@

/**
* Creates a query builder for this model instance.
* Shortcut to `this.constructor.knex()`.
*
* The returned query builder has all the methods a *knex* query builder has. See
* {@link QueryBuilder} and <a href="http://knexjs.org/#Builder">knexjs.org</a>
* for more information.
*
* All queries built using the returned builder only affect this instance.
*
* Examples:
*
* Re-fetch the instance from the database:
*
* ```js
* person.$query().then(function (person) {
* console.log(person);
* });
* ```
*
* Insert a new model to database:
*
* ```js
* Person.fromJson({firstName: 'Jennifer'}).$query().insert().then(function (jennifer) {
* console.log(jennifer.id);
* });
* ```
*
* Patch a model:
*
* ```js
* person.$query().patch({lastName: 'Cooper'}).then(function (person) {
* console.log(person.lastName); // --> 'Cooper'.
* });
* ```
*
* Delete a model.
*
* ```js
* person.$query().delete().then(function () {
* console.log('person deleted');
* });
* ```
*
* @returns {QueryBuilder}
* @returns {knex}
*/

@@ -466,2 +426,66 @@

}, {
key: '$knex',
value: function $knex() {
return this.constructor.knex();
}
/**
* Shortcut to `this.constructor.transaction()`.
*
* @returns {knex}
*/
}, {
key: '$transaction',
value: function $transaction() {
return this.constructor.transaction();
}
/**
* Creates a query builder for this model instance.
*
* The returned query builder has all the methods a *knex* query builder has. See
* {@link QueryBuilder} and <a href="http://knexjs.org/#Builder">knexjs.org</a>
* for more information.
*
* All queries built using the returned builder only affect this instance.
*
* Examples:
*
* Re-fetch the instance from the database:
*
* ```js
* person.$query().then(function (person) {
* console.log(person);
* });
* ```
*
* Insert a new model to database:
*
* ```js
* Person.fromJson({firstName: 'Jennifer'}).$query().insert().then(function (jennifer) {
* console.log(jennifer.id);
* });
* ```
*
* Patch a model:
*
* ```js
* person.$query().patch({lastName: 'Cooper'}).then(function (person) {
* console.log(person.lastName); // --> 'Cooper'.
* });
* ```
*
* Delete a model.
*
* ```js
* person.$query().delete().then(function () {
* console.log('person deleted');
* });
* ```
*
* @returns {QueryBuilder}
*/
}, {
key: '$query',

@@ -1089,3 +1113,3 @@ value: function $query() {

*
* @returns {knex|undefined}
* @returns {knex}
*/

@@ -1111,2 +1135,26 @@

/**
* Returns the transaction this model class is bound to using `bindTransaction` methods.
*
* Handy for making sure two model class are bound to the same transaction:
*
* ```js
* Person
* .bindTransaction(Animal.transaction())
* .query()
* ...
* ```
*
* The example above works even if `Animal` is not bound to any transaction. The
* `bindTransaction` call does nothing in this case.
*
* @returns {knex}
*/
}, {
key: 'transaction',
value: function transaction() {
return this.knex();
}
/**
* Shortcut for `SomeModel.knex().raw()`.

@@ -1237,3 +1285,3 @@ */

/**
* Alias for bindKnex.
* Creates a subclass of this class that is bound to the given transaction.
*

@@ -1589,3 +1637,3 @@ * ```js

return Model;
})(_ModelBase3.default), _class2.QueryBuilder = _QueryBuilder2.default, _class2.RelatedQueryBuilder = _QueryBuilder2.default, _class2.OneToOneRelation = _OneToOneRelation2.default, _class2.OneToManyRelation = _OneToManyRelation2.default, _class2.ManyToManyRelation = _ManyToManyRelation2.default, _class2.tableName = null, _class2.idColumn = 'id', _class2.uidProp = '#id', _class2.uidRefProp = '#ref', _class2.propRefRegex = /#ref{([^\.]+)\.([^}]+)}/g, _class2.jsonAttributes = null, _class2.relationMappings = null, _class2.$$knex = null, _class2.$$relations = null, _temp), (_applyDecoratedDescriptor(_class, 'getIdProperty', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class, 'getIdProperty'), _class), _applyDecoratedDescriptor(_class, 'getFullIdColumn', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class, 'getFullIdColumn'), _class)), _class);
}(_ModelBase3.default), _class2.QueryBuilder = _QueryBuilder2.default, _class2.RelatedQueryBuilder = _QueryBuilder2.default, _class2.OneToOneRelation = _OneToOneRelation2.default, _class2.OneToManyRelation = _OneToManyRelation2.default, _class2.ManyToManyRelation = _ManyToManyRelation2.default, _class2.tableName = null, _class2.idColumn = 'id', _class2.uidProp = '#id', _class2.uidRefProp = '#ref', _class2.propRefRegex = /#ref{([^\.]+)\.([^}]+)}/g, _class2.jsonAttributes = null, _class2.relationMappings = null, _class2.$$knex = null, _class2.$$relations = null, _temp), (_applyDecoratedDescriptor(_class, 'getIdProperty', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class, 'getIdProperty'), _class), _applyDecoratedDescriptor(_class, 'getFullIdColumn', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class, 'getFullIdColumn'), _class)), _class);

@@ -1592,0 +1640,0 @@ /**

@@ -163,3 +163,3 @@ 'use strict';

*/
var ModelBase = (_class = (_temp = _class2 = (function () {
var ModelBase = (_class = (_temp = _class2 = function () {
function ModelBase() {

@@ -789,3 +789,3 @@ (0, _classCallCheck3.default)(this, ModelBase);

return ModelBase;
})(), _class2.jsonSchema = null, _temp), (_applyDecoratedDescriptor(_class, 'columnNameToPropertyName', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class, 'columnNameToPropertyName'), _class), _applyDecoratedDescriptor(_class, 'propertyNameToColumnName', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class, 'propertyNameToColumnName'), _class)), _class);
}(), _class2.jsonSchema = null, _temp), (_applyDecoratedDescriptor(_class, 'columnNameToPropertyName', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class, 'columnNameToPropertyName'), _class), _applyDecoratedDescriptor(_class, 'propertyNameToColumnName', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class, 'propertyNameToColumnName'), _class)), _class);

@@ -792,0 +792,0 @@ /**

@@ -42,3 +42,3 @@ 'use strict';

var EagerFetcher = (function () {
var EagerFetcher = function () {
function EagerFetcher(_ref) {

@@ -138,4 +138,4 @@ var modelClass = _ref.modelClass;

return EagerFetcher;
})();
}();
exports.default = EagerFetcher;

@@ -52,3 +52,3 @@ 'use strict';

var InsertionOrUpdate = (function () {
var InsertionOrUpdate = function () {
function InsertionOrUpdate(_ref) {

@@ -175,4 +175,4 @@ var ModelClass = _ref.ModelClass;

return InsertionOrUpdate;
})();
}();
exports.default = InsertionOrUpdate;

@@ -59,3 +59,3 @@ 'use strict';

var InsertWithRelated = (function () {
var InsertWithRelated = function () {
function InsertWithRelated(_ref) {

@@ -358,3 +358,3 @@ var modelClass = _ref.modelClass;

return InsertWithRelated;
})();
}();

@@ -361,0 +361,0 @@ exports.default = InsertWithRelated;

"use strict";
module.exports = (function () {
module.exports = function () {
/*

@@ -783,2 +783,2 @@ * Generated by PEG.js 0.8.0.

};
})();
}();
"use strict";
module.exports = (function () {
module.exports = function () {
"use strict";

@@ -795,2 +795,2 @@

};
})();
}();

@@ -93,3 +93,3 @@ 'use strict';

var RelationExpression = (function () {
var RelationExpression = function () {
function RelationExpression(node) {

@@ -238,4 +238,4 @@ (0, _classCallCheck3.default)(this, RelationExpression);

return RelationExpression;
})();
}();
exports.default = RelationExpression;

@@ -98,3 +98,3 @@ 'use strict';

sqlite3: '_selectForModify_sqlite3'
}), _dec(_class = (_class2 = (function (_Relation) {
}), _dec(_class = (_class2 = function (_Relation) {
(0, _inherits3.default)(ManyToManyRelation, _Relation);

@@ -155,3 +155,3 @@

*
* @type {Class<Model>}
* @type {Class.<Model>}
*/

@@ -210,7 +210,22 @@ _this.joinTableModelClass = null;

if (mapping.join.through.modelClass) {
if (!(0, _classUtils.isSubclassOf)(mapping.join.through.modelClass, Model)) {
var modelClass = mapping.join.through.modelClass;
try {
if (_lodash2.default.isString(modelClass)) {
modelClass = require(modelClass);
// Compatibility with babel `export default`.
if (!(0, _classUtils.isSubclassOf)(modelClass, Model) && (0, _classUtils.isSubclassOf)(modelClass.default, Model)) {
modelClass = modelClass.default;
}
}
} catch (err) {
// Do nothing.
}
if (!(0, _classUtils.isSubclassOf)(modelClass, Model)) {
this.throwError('Join table model class is not a subclass of Model');
}
this.joinTableModelClass = mapping.join.through.modelClass;
this.joinTableModelClass = modelClass;
} else {

@@ -646,3 +661,3 @@ this.joinTableModelClass = (0, _inheritModel2.default)(Model);

return ManyToManyRelation;
})(_Relation3.default), (_applyDecoratedDescriptor(_class2.prototype, 'fullJoinTableOwnerCol', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class2.prototype, 'fullJoinTableOwnerCol'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'fullJoinTableRelatedCol', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class2.prototype, 'fullJoinTableRelatedCol'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'unrelate', [_dec2], (0, _getOwnPropertyDescriptor2.default)(_class2.prototype, 'unrelate'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, '_selectForModify', [_dec3], (0, _getOwnPropertyDescriptor2.default)(_class2.prototype, '_selectForModify'), _class2.prototype)), _class2)) || _class);
}(_Relation3.default), (_applyDecoratedDescriptor(_class2.prototype, 'fullJoinTableOwnerCol', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class2.prototype, 'fullJoinTableOwnerCol'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'fullJoinTableRelatedCol', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class2.prototype, 'fullJoinTableRelatedCol'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, 'unrelate', [_dec2], (0, _getOwnPropertyDescriptor2.default)(_class2.prototype, 'unrelate'), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, '_selectForModify', [_dec3], (0, _getOwnPropertyDescriptor2.default)(_class2.prototype, '_selectForModify'), _class2.prototype)), _class2)) || _class);
exports.default = ManyToManyRelation;

@@ -43,3 +43,3 @@ 'use strict';

var OneToManyRelation = (function (_Relation) {
var OneToManyRelation = function (_Relation) {
(0, _inherits3.default)(OneToManyRelation, _Relation);

@@ -157,4 +157,4 @@

return OneToManyRelation;
})(_Relation3.default);
}(_Relation3.default);
exports.default = OneToManyRelation;

@@ -43,3 +43,3 @@ 'use strict';

var OneToOneRelation = (function (_Relation) {
var OneToOneRelation = function (_Relation) {
(0, _inherits3.default)(OneToOneRelation, _Relation);

@@ -169,4 +169,4 @@

return OneToOneRelation;
})(_Relation3.default);
}(_Relation3.default);
exports.default = OneToOneRelation;

@@ -110,3 +110,3 @@ 'use strict';

*
* @property {Model} through.modelClass
* @property {Class.<Model>} through.modelClass
* If the there is model class available for the join table, it can be provided

@@ -129,3 +129,3 @@ * using this property.

*
* @property {Model|string} modelClass
* @property {Class.<Model>|string} modelClass
* A {@link Model} subclass constructor or an absolute path to a module that exports one.

@@ -159,3 +159,3 @@ *

*/
var Relation = (_class = (function () {
var Relation = (_class = function () {
function Relation(relationName, OwnerClass) {

@@ -176,3 +176,3 @@ (0, _classCallCheck3.default)(this, Relation);

*
* @type {Class<Model>}
* @type {Class.<Model>}
*/

@@ -186,3 +186,3 @@ this.ownerModelClass = OwnerClass;

*
* @type {Class<Model>}
* @type {Class.<Model>}
*/

@@ -231,3 +231,3 @@ this.relatedModelClass = null;

* @param {function=} subclassConstructor
* @return {function}
* @return {Class.<Model>}
*/

@@ -757,3 +757,3 @@

return Relation;
})(), (_applyDecoratedDescriptor(_class.prototype, 'fullOwnerCol', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'fullOwnerCol'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'fullRelatedCol', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'fullRelatedCol'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'relatedTableAlias', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'relatedTableAlias'), _class.prototype)), _class);
}(), (_applyDecoratedDescriptor(_class.prototype, 'fullOwnerCol', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'fullOwnerCol'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'fullRelatedCol', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'fullRelatedCol'), _class.prototype), _applyDecoratedDescriptor(_class.prototype, 'relatedTableAlias', [_decorators.memoize], (0, _getOwnPropertyDescriptor2.default)(_class.prototype, 'relatedTableAlias'), _class.prototype)), _class);
exports.default = Relation;

@@ -172,3 +172,3 @@ 'use strict';

*
* @param {Model|knex} modelClassOrKnex
* @param {Class.<Model>|knex} modelClassOrKnex
* A knex instance or any model that has a knex connection set. Note that you can bind any model

@@ -191,7 +191,7 @@ * to the created transaction regardless of the model given to this method. This argument is used

return new _bluebird2.default(function (resolve) {
return new _bluebird2.default(function (resolve, reject) {
knex.transaction(function (trx) {
resolve(trx);
}).catch(function () {
// Nothing to do here.
}).catch(function (err) {
reject(err);
});

@@ -198,0 +198,0 @@ });

@@ -8,2 +8,4 @@ 'use strict';

exports.isPostgres = isPostgres;
exports.isMySql = isMySql;
exports.isSqlite = isSqlite;
exports.isKnexQueryBuilder = isKnexQueryBuilder;

@@ -35,2 +37,16 @@ exports.overwriteForDatabase = overwriteForDatabase;

*/
function isMySql(knex) {
return getDialect(knex) === 'mysql';
}
/**
* @ignore
*/
function isSqlite(knex) {
return getDialect(knex) === 'sqlite3';
}
/**
* @ignore
*/
function isKnexQueryBuilder(knexQueryBuilder) {

@@ -45,3 +61,3 @@ return knexQueryBuilder && knexQueryBuilder.client && _lodash2.default.isString(knexQueryBuilder.client.dialect);

if (!input) {
input = function (inst) {
input = function input(inst) {
return inst.knex();

@@ -48,0 +64,0 @@ };

{
"name": "objection",
"version": "0.4.0-rc.3",
"version": "0.4.0-rc.4",
"description": "An SQL-friendly ORM for Node.js",

@@ -57,2 +57,3 @@ "main": "lib/objection.js",

"expect.js": "^0.3.1",
"fs-extra": "^0.26.4",
"glob": "^6.0.1",

@@ -63,3 +64,2 @@ "grunt": "^0.4.5",

"knex": "^0.9.0",
"mkdirp": "^0.5.1",
"mocha": "^2.3.4",

@@ -66,0 +66,0 @@ "mysql": "^2.7.0",

[![Build Status](https://travis-ci.org/Vincit/objection.js.svg?branch=master)](https://travis-ci.org/Vincit/objection.js) [![Coverage Status](https://coveralls.io/repos/Vincit/objection.js/badge.svg?branch=master&service=github)](https://coveralls.io/github/Vincit/objection.js?branch=master)
# [Objection.js](http://vincit.github.io/objection.js)
# [Objection.js](http://vincit.github.io/objection.js) is an [ORM](https://en.wikipedia.org/wiki/Object-relational_mapping)
for [Node.js](https://nodejs.org/) that aims to stay out of your way and make it as easy as possible to use the full
power of SQL and the underlying database engine.
Objection.js is built on the wonderful SQL query builder [knex](http://knexjs.org). All databases supported by knex
are supported by objection.js. **SQLite3**, **Postgres** and **MySQL** are [thoroughly tested](https://travis-ci.org/Vincit/objection.js).
What objection.js gives you:
* **An easy declarative way of [defining models](http://vincit.github.io/objection.js/#models) and relations between them**
* **Simple and fun way to [fetch, insert, update and delete](http://vincit.github.io/objection.js/#query-examples) objects using the full power of SQL**
* **Powerful mechanisms for [eager loading](http://vincit.github.io/objection.js/#eager-loading) and [inserting](http://vincit.github.io/objection.js/#graph-inserts) object graphs**
* **A way to [store complex documents](http://vincit.github.io/objection.js/#documents) as single rows**
* **Completely [Promise](https://github.com/petkaantonov/bluebird) based API**
* **Easy to use [transactions](http://vincit.github.io/objection.js/#transactions)**
* **Optional [JSON schema](http://vincit.github.io/objection.js/#validation) validation**
What objection.js **doesn't** give you:
* **A custom query DSL. SQL is used as a query language.**
* **Automatic database schema creation and migration.**
For simple things it is useful that the database schema is automatically generated from the model definitions,
but usually just gets in your way when doing anything non-trivial. Objection.js leaves the schema related things
to you. knex has a great [migration tool](http://knexjs.org/#Migrations) that we recommend for this job. Check
out the [example project](https://github.com/Vincit/objection.js/tree/master/examples/express).
Objection.js uses Promises and coding practices that make it ready for the future. We use Well known
[OOP](https://en.wikipedia.org/wiki/Object-oriented_programming) techniques and ES6 compatible classes and inheritance
in the codebase. You can even use things like ES7 [async/await](http://jakearchibald.com/2014/es7-async-functions/)
using a transpiler such as [Babel](https://babeljs.io/). Check out our [ES6](https://github.com/Vincit/objection.js/tree/master/examples/express-es6)
and [ES7](https://github.com/Vincit/objection.js/tree/master/examples/express-es7) example projects.
Tutorials and blogs:
* [Introduction](https://www.vincit.fi/en/blog/introducing-moron-js-a-new-orm-for-node-js/)
* [Eager loading](https://www.vincit.fi/en/blog/nested-eager-loading-and-inserts-with-objection-js/)
* [JSON queries](https://www.vincit.fi/en/blog/by-the-power-of-json-queries/)

@@ -315,2 +315,20 @@ import _ from 'lodash';

/**
* Shortcut to `this.constructor.knex()`.
*
* @returns {knex}
*/
$knex() {
return this.constructor.knex();
}
/**
* Shortcut to `this.constructor.transaction()`.
*
* @returns {knex}
*/
$transaction() {
return this.constructor.transaction();
}
/**
* Creates a query builder for this model instance.

@@ -965,3 +983,3 @@ *

*
* @returns {knex|undefined}
* @returns {knex}
*/

@@ -984,2 +1002,23 @@ static knex(knex) {

/**
* Returns the transaction this model class is bound to using `bindTransaction` methods.
*
* Handy for making sure two model class are bound to the same transaction:
*
* ```js
* Person
* .bindTransaction(Animal.transaction())
* .query()
* ...
* ```
*
* The example above works even if `Animal` is not bound to any transaction. The
* `bindTransaction` call does nothing in this case.
*
* @returns {knex}
*/
static transaction() {
return this.knex();
}
/**
* Shortcut for `SomeModel.knex().raw()`.

@@ -1095,3 +1134,3 @@ */

/**
* Alias for bindKnex.
* Creates a subclass of this class that is bound to the given transaction.
*

@@ -1098,0 +1137,0 @@ * ```js

@@ -29,3 +29,3 @@ import _ from 'lodash';

* @param {function=} subclassConstructor
* @return {function}
* @return {Class.<QueryBuilderBase>}
*/

@@ -50,11 +50,2 @@ static extend(subclassConstructor) {

/**
* Returns the knex connection passed to the constructor.
*
* @ignore
*/
knex() {
return this._knex;
}
/**
* Sets/gets the query full internal context.

@@ -76,2 +67,11 @@ *

/**
* Returns the knex connection passed to the constructor.
*
* @ignore
*/
knex() {
return this._knex;
}
/**
* Calls the given function immediately and passes `this` as an argument.

@@ -885,12 +885,40 @@ *

/**
* @typedef {string} FieldExpression
*
* Json field expression to refer to jsonb columns or keys / objects inside columns.
*
* e.g. `Person.jsonColumnName:details.names[1]` would refer to column
* `Person.jsonColumnName` which has `{ details: { names: ['First', 'Second', 'Last'] } }`
* object stored in it.
*
*/
/**
* @typedef {String} FieldExpression
*
* Field expressions allow one to refer to separate JSONB fields inside columns.
*
* Syntax: <column reference>[:<json field reference>]
*
* e.g. `Person.jsonColumnName:details.names[1]` would refer to value `'Second'`
* in column `Person.jsonColumnName` which has
* `{ details: { names: ['First', 'Second', 'Last'] } }` object stored in it.
*
* First part `<column reference>` is compatible with column references used in
* knex e.g. `MyFancyTable.tributeToThBestColumnNameEver`.
*
* Second part describes a path to an attribute inside the referred column.
* It is optional and it always starts with colon which follows directly with
* first path element. e.g. `Table.jsonObjectColumnName:jsonFieldName` or
* `Table.jsonArrayColumn:[321]`.
*
* Syntax supports `[<key or index>]` and `.<key or index>` flavors of reference
* to json keys / array indexes:
*
* e.g. both `Table.myColumn:[1][3]` and `Table.myColumn:1.3` would access correctly
* both of the following objects `[null, [null,null,null, "I was accessed"]]` and
* `{ "1": { "3" : "I was accessed" } }`
*
* Caveats when using special characters in keys:
*
* 1. `objectColumn.key` This is the most common syntax, good if you are
* not using dots or square brackets `[]` in your json object key name.
* 2. Keys containing dots `objectColumn:[keywith.dots]` Column `{ "keywith.dots" : "I was referred" }`
* 3. Keys containing square brackets `column['[]']` `{ "[]" : "This is getting ridiculous..." }`
* 4. Keys containing square brackets and quotes
* `objectColumn:['Double."Quote".[]']` and `objectColumn:["Sinlge.'Quote'.[]"]`
* Column `{ "Double.\"Quote\".[]" : "I was referred", "Sinlge.'Quote'.[]" : "Mee too!" }`
* 99. Keys containing dots, square brackets, single quotes and double quotes in one json key is
* not currently supported
*/

@@ -961,3 +989,3 @@ /**

* // These people have all or some of their dogs at home. Person might have some
* // additional dogs in their custody since myDogs is supreset of dogsAtHome.
* // additional dogs in their custody since myDogs is superset of dogsAtHome.
* });

@@ -964,0 +992,0 @@ *

@@ -62,3 +62,3 @@ import _ from 'lodash';

*
* @type {Class<Model>}
* @type {Class.<Model>}
*/

@@ -113,7 +113,22 @@ this.joinTableModelClass = null;

if (mapping.join.through.modelClass) {
if (!isSubclassOf(mapping.join.through.modelClass, Model)) {
let modelClass = mapping.join.through.modelClass;
try {
if (_.isString(modelClass)) {
modelClass = require(modelClass);
// Compatibility with babel `export default`.
if (!isSubclassOf(modelClass, Model) && isSubclassOf(modelClass.default, Model)) {
modelClass = modelClass.default;
}
}
} catch (err) {
// Do nothing.
}
if (!isSubclassOf(modelClass, Model)) {
this.throwError('Join table model class is not a subclass of Model');
}
this.joinTableModelClass = mapping.join.through.modelClass;
this.joinTableModelClass = modelClass;
} else {

@@ -120,0 +135,0 @@ this.joinTableModelClass = inheritModel(Model);

@@ -47,3 +47,3 @@ import _ from 'lodash';

*
* @property {Model} through.modelClass
* @property {Class.<Model>} through.modelClass
* If the there is model class available for the join table, it can be provided

@@ -66,3 +66,3 @@ * using this property.

*
* @property {Model|string} modelClass
* @property {Class.<Model>|string} modelClass
* A {@link Model} subclass constructor or an absolute path to a module that exports one.

@@ -111,3 +111,3 @@ *

*
* @type {Class<Model>}
* @type {Class.<Model>}
*/

@@ -121,3 +121,3 @@ this.ownerModelClass = OwnerClass;

*
* @type {Class<Model>}
* @type {Class.<Model>}
*/

@@ -166,3 +166,3 @@ this.relatedModelClass = null;

* @param {function=} subclassConstructor
* @return {function}
* @return {Class.<Model>}
*/

@@ -169,0 +169,0 @@ static extend(subclassConstructor) {

@@ -154,3 +154,3 @@ import _ from 'lodash';

*
* @param {Model|knex} modelClassOrKnex
* @param {Class.<Model>|knex} modelClassOrKnex
* A knex instance or any model that has a knex connection set. Note that you can bind any model

@@ -173,7 +173,7 @@ * to the created transaction regardless of the model given to this method. This argument is used

return new Promise(resolve => {
return new Promise((resolve, reject) => {
knex.transaction(trx => {
resolve(trx);
}).catch(() => {
// Nothing to do here.
}).catch(err => {
reject(err);
});

@@ -180,0 +180,0 @@ });

@@ -20,2 +20,16 @@ import _ from 'lodash';

*/
export function isMySql(knex) {
return getDialect(knex) === 'mysql';
}
/**
* @ignore
*/
export function isSqlite(knex) {
return getDialect(knex) === 'sqlite3';
}
/**
* @ignore
*/
export function isKnexQueryBuilder(knexQueryBuilder) {

@@ -81,2 +95,2 @@ return knexQueryBuilder

};
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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