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.3.0 to 0.3.1

lib/model/inheritModel/index.js

2

lib/relations/ManyToManyRelation.js

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

if (!builder.has('select')) {
if (!builder.has(/select/)) {
// If the user hasn't specified a select clause, select the related model's columns.

@@ -87,0 +87,0 @@ // If we don't do this we also get the join table's columns.

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

, utils = require('../utils')
, QueryBuilder = require('../QueryBuilder');
, QueryBuilder = require('../queryBuilder/QueryBuilder');

@@ -189,3 +189,3 @@ /**

// Avoid require loop and import here.
var Model = require(__dirname + '/../Model');
var Model = require(__dirname + '/../model/Model');

@@ -192,0 +192,0 @@ if (!utils.isSubclassOf(this.ownerModelClass, Model)) {

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

var Promise = require('bluebird');
var Model = require('./Model');
var Model = require('./model/Model');
var utils = require('./utils');

@@ -8,0 +8,0 @@

'use strict';
var _ = require('lodash');
var util = require('util');

@@ -9,6 +8,6 @@

*
* @param {Object.<String, String>} errorMessages
* @param {Object} errors
* @constructor
*/
function ValidationError(errorMessages) {
function ValidationError(errors) {
Error.call(this);

@@ -18,7 +17,7 @@ Error.captureStackTrace(this, ValidationError);

/**
* A hash of `{'property name': 'error message'}` pairs.
* Any data that describes the errors.
*
* @type {Object.<String, String>}
* @type {Object}
*/
this.data = errorMessages;
this.data = errors;

@@ -33,3 +32,3 @@ /**

*/
this.message = _.values(errorMessages).join(', ');
this.message = JSON.stringify(errors, null, 2);
}

@@ -36,0 +35,0 @@

module.exports = {
ModelBase: require('./lib/ModelBase'),
Model: require('./lib/Model'),
QueryBuilder: require('./lib/QueryBuilder'),
RelationExpression: require('./lib/RelationExpression'),
ModelBase: require('./lib/model/ModelBase'),
Model: require('./lib/model/Model'),
QueryBuilder: require('./lib/queryBuilder/QueryBuilder'),
RelationExpression: require('./lib/queryBuilder/RelationExpression'),
ValidationError: require('./lib/ValidationError'),

@@ -7,0 +7,0 @@

{
"name": "objection",
"version": "0.3.0",
"version": "0.3.1",
"description": "An SQL-friendly ORM for Node.js",

@@ -5,0 +5,0 @@ "main": "objection.js",

@@ -219,5 +219,5 @@ [![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)

.where('age', '>', 60)
.then(function (patch) {
.then(function (numUpdated) {
console.log('all persons over 60 years old are now dinosaurs');
console.log(patch.lastName); // --> Dinosaur.
console.log(numUpdated, 'people were updated');.
})

@@ -233,2 +233,22 @@ .catch(function (err) {

The `.patch()` and `.update()` method return the number of updated rows. If you want the freshly updated
model as a result you can use the helper method `.patchAndFetchById()` and `.updateAndFetchById()`.
```js
Person
.query()
.patchAndFetchById(246, {lastName: 'Updated'})
.then(function (updated) {
console.log(updated.lastName); // --> Updated.
})
.catch(function (err) {
console.log(err.stack);
});
```
```sql
update "Person" set "lastName" = 'Updated' where "id" = 246
select * from "Person" where "id" = 246
```
While the static `.query()` method can be used to create a query to a whole table `.$relatedQuery()` method

@@ -365,3 +385,3 @@ can be used to query a single relation. `.$relatedQuery()` returns an instance of [QueryBuilder](http://vincit.github.io/objection.js/QueryBuilder.html)

console.log(persons[0].children[0].movies[0].id);
});
});
```

@@ -430,3 +450,4 @@

The query above will insert 'Sylvester', 'Sage' and 'Fluffy' into db and create relationships between them as defined
in the `relationMappings` of the models.
in the `relationMappings` of the models. Technically `insertWithRelated` builds a dependency graph from the object
tree and inserts the models that don't depend on any other models until the whole tree is inserted.

@@ -443,3 +464,3 @@ If you need to refer to the same model in multiple places you can use the special properties `#id` and `#ref` like this:

movies: [{
"#id": 'Silver Linings Playbook'
"#id": 'silverLiningsPlaybook'
name: 'Silver Linings Playbook',

@@ -453,3 +474,3 @@ duration: 122

movies: [{
"#ref": 'Silver Linings Playbook'
"#ref": 'silverLiningsPlaybook'
}]

@@ -460,3 +481,5 @@ }]);

The query above will insert only one movie (the 'Silver Linings Playbook') but both 'Jennifer' and 'Bradley' will have
the movie related to them through the many-to-many relation `movies`.
the movie related to them through the many-to-many relation `movies`. The `#id` can be any string. There are no format
or length requirements for them. It is quite easy to create circular dependencies using `#id` and `#ref`. Luckily
`insertWithRelated` detects them and rejects the query with a clear error message.

@@ -475,3 +498,3 @@ You can refer to the properties of other models anywhere in the graph using expressions of format `#ref{<id>.<property>}`

pets: [{
name: "I am the dog of #ref{jenniLaw.firstName} #ref{jenniLaw.lastName}",
name: "I am the dog of #ref{jenniLaw.firstName} whose id is #ref{jenniLaw.id}",
species: 'dog'

@@ -482,6 +505,8 @@ }]

The query above will insert a pet named `I am the dog of Jennifer Lawrence` for Jennifer.
The query above will insert a pet named `I am the dog of Jennifer whose id is 523` for Jennifer. If `#ref{}` is used
within a string, the references are replaced with the referred values inside the string. If the reference string
contains nothing but the reference, the referred value is copied to it's place preserving its type.
See the `allowInsert` method if you need to limit which relations can be inserted using this method to avoid security
issues.
See the [allowInsert](http://vincit.github.io/objection.js/QueryBuilder.html#allowInsert) method if you need to limit
which relations can be inserted using `insertWithRelated` method to avoid security issues.

@@ -584,3 +609,3 @@ By the way, if you are using Postgres the inserts are done in batches for maximum performance.

The transaction object can be created using the [objection.transaction.start](http://vincit.github.io/objection.js/global.html#transaction#start)
The transaction object can be created using the [objection.transaction.start](http://vincit.github.io/objection.js/global.html#start)
method. You need to remember to call either the `commit` or `rollback` method of the transaction object.

@@ -629,9 +654,9 @@

```js
// You need to pass some model (any model with a knex connection)
// or the knex connection itself to the start method.
var BoundPerson;
var BoundMovie;
objection.transaction.start(Person).then(function (transaction) {
BoundPerson = Person.bindTransaction(transaction);
BoundMovie = Movie.bindTransaction(transaction);
return BoundPerson

@@ -857,2 +882,9 @@ .query()

## 0.3.1
#### What's new
* `whereJson*` methods can now be used inside functions given to `where` methods.
* Added multiple missing knex methods to `QueryBuilder`.
## 0.3.0

@@ -873,4 +905,4 @@

* QueryBuilder methods `update`, `patch` and `delete` now return the number of affected rows
the new methods `updateAndFetchById` and `patchAndFetchById` may help with the migration
* QueryBuilder methods `update`, `patch` and `delete` now return the number of affected rows.
The new methods `updateAndFetchById` and `patchAndFetchById` may help with the migration
* `modelInstance.$query()` instance method now returns a single model instead of an array

@@ -877,0 +909,0 @@ * Removed `Model.generateId()` method. `$beforeInsert` can be used instead

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