Socket
Socket
Sign inDemoInstall

objection

Package Overview
Dependencies
Maintainers
2
Versions
201
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 2.0.0-alpha.10 to 2.0.0-rc.1

lib/queryBuilder/operations/JoinRelatedOperation.js

18

lib/model/Model.js

@@ -28,2 +28,3 @@ 'use strict';

const { ref } = require('../queryBuilder/ReferenceBuilder');
const { fn } = require('../queryBuilder/FunctionBuilder');

@@ -622,4 +623,4 @@ const { AjvValidator } = require('./AjvValidator');

static raw(...args) {
return raw(...args).toKnexRaw(this.query());
static get raw() {
return raw;
}

@@ -633,15 +634,4 @@

/**
* NB. for v2.0, this can simply return `this.knex().fn`.
* However, in order to maintain backwards comparability of a bug that didn't
* have this method as a getter, the returned value needs to be callable and
* return the "same" `knex#FunctionHelper` instance.
* The effect is that `Model.fn.now()` and `Model.fn().now()` produce the same result.
*/
static get fn() {
const fnHelper = this.knex().fn;
const wrapper = () => fnHelper;
Object.assign(wrapper, fnHelper);
Object.setPrototypeOf(wrapper, Object.getPrototypeOf(fnHelper));
return wrapper;
return fn;
}

@@ -648,0 +638,0 @@

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

const { UpdateAndFetchOperation } = require('./operations/UpdateAndFetchOperation');
const { JoinRelationOperation } = require('./operations/JoinRelationOperation');
const { JoinRelatedOperation } = require('./operations/JoinRelatedOperation');
const { OnBuildKnexOperation } = require('./operations/OnBuildKnexOperation');

@@ -1122,4 +1122,4 @@ const { InsertGraphOperation } = require('./operations/InsertGraphOperation');

joinRelation(expression, options) {
ensureJoinRelationOperation(this, 'innerJoin').addCall({
joinRelated(expression, options) {
ensureJoinRelatedOperation(this, 'innerJoin').addCall({
expression,

@@ -1132,4 +1132,12 @@ options

innerJoinRelation(expression, options) {
ensureJoinRelationOperation(this, 'innerJoin').addCall({
joinRelation(...args) {
deprecate(
`joinRelation is deprecated. Use joinRelated instead. This method will be removed in version 3.0`
);
return this.joinRelated(...args);
}
innerJoinRelated(expression, options) {
ensureJoinRelatedOperation(this, 'innerJoin').addCall({
expression,

@@ -1142,4 +1150,12 @@ options

outerJoinRelation(expression, options) {
ensureJoinRelationOperation(this, 'outerJoin').addCall({
innerJoinRelation(...args) {
deprecate(
`innerJoinRelation is deprecated. Use innerJoinRelated instead. This method will be removed in version 3.0`
);
return this.innerJoinRelated(...args);
}
outerJoinRelated(expression, options) {
ensureJoinRelatedOperation(this, 'outerJoin').addCall({
expression,

@@ -1152,4 +1168,12 @@ options

fullOuterJoinRelation(expression, options) {
ensureJoinRelationOperation(this, 'fullOuterJoin').addCall({
outerJoinRelation(...args) {
deprecate(
`outerJoinRelation is deprecated. Use outerJoinRelated instead. This method will be removed in version 3.0`
);
return this.outerJoinRelated(...args);
}
fullOuterJoinRelated(expression, options) {
ensureJoinRelatedOperation(this, 'fullOuterJoin').addCall({
expression,

@@ -1162,4 +1186,12 @@ options

leftJoinRelation(expression, options) {
ensureJoinRelationOperation(this, 'leftJoin').addCall({
fullOuterJoinRelation(...args) {
deprecate(
`fullOuterJoinRelation is deprecated. Use fullOuterJoinRelated instead. This method will be removed in version 3.0`
);
return this.fullOuterJoinRelated(...args);
}
leftJoinRelated(expression, options) {
ensureJoinRelatedOperation(this, 'leftJoin').addCall({
expression,

@@ -1172,4 +1204,12 @@ options

leftOuterJoinRelation(expression, options) {
ensureJoinRelationOperation(this, 'leftOuterJoin').addCall({
leftJoinRelation(...args) {
deprecate(
`leftJoinRelation is deprecated. Use leftJoinRelated instead. This method will be removed in version 3.0`
);
return this.leftJoinRelated(...args);
}
leftOuterJoinRelated(expression, options) {
ensureJoinRelatedOperation(this, 'leftOuterJoin').addCall({
expression,

@@ -1182,4 +1222,12 @@ options

rightJoinRelation(expression, options) {
ensureJoinRelationOperation(this, 'rightJoin').addCall({
leftOuterJoinRelation(...args) {
deprecate(
`leftOuterJoinRelation is deprecated. Use leftOuterJoinRelated instead. This method will be removed in version 3.0`
);
return this.leftOuterJoinRelated(...args);
}
rightJoinRelated(expression, options) {
ensureJoinRelatedOperation(this, 'rightJoin').addCall({
expression,

@@ -1192,4 +1240,12 @@ options

rightOuterJoinRelation(expression, options) {
ensureJoinRelationOperation(this, 'rightOuterJoin').addCall({
rightJoinRelation(...args) {
deprecate(
`rightJoinRelation is deprecated. Use rightJoinRelated instead. This method will be removed in version 3.0`
);
return this.rightJoinRelated(...args);
}
rightOuterJoinRelated(expression, options) {
ensureJoinRelatedOperation(this, 'rightOuterJoin').addCall({
expression,

@@ -1202,2 +1258,10 @@ options

rightOuterJoinRelation(...args) {
deprecate(
`rightOuterJoinRelation is deprecated. Use rightOuterJoinRelated instead. This method will be removed in version 3.0`
);
return this.rightOuterJoinRelated(...args);
}
deleteById(...args) {

@@ -1478,3 +1542,3 @@ return this.findById(...args).delete();

function ensureJoinRelationOperation(builder, joinOperation) {
function ensureJoinRelatedOperation(builder, joinOperation) {
const opName = joinOperation + 'Relation';

@@ -1484,3 +1548,3 @@ let op = builder.findOperation(opName);

if (!op) {
op = new JoinRelationOperation(opName, { joinOperation });
op = new JoinRelatedOperation(opName, { joinOperation });
builder.addOperation(op);

@@ -1487,0 +1551,0 @@ }

@@ -6,4 +6,4 @@ 'use strict';

class QueryBuilderContext extends QueryBuilderContextBase {
constructor(userContext) {
super(userContext);
constructor(builder) {
super(builder);

@@ -10,0 +10,0 @@ this.runBefore = [];

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

const { deprecate } = require('../utils/deprecate');
const { isString, isFunction, isRegExp, last } = require('../utils/objectUtils');

@@ -15,3 +16,3 @@ const { QueryBuilderContextBase } = require('./QueryBuilderContextBase');

const OrderBySelector = /orderBy/;
const JoinSelector = /(join|joinRaw|joinRelation)$/i;
const JoinSelector = /(join|joinRaw|joinRelated)$/i;
const FromSelector = /^(from|into|table)$/;

@@ -83,3 +84,3 @@

} else {
ctx.userContext = ctx.userContext.newFromObject(this, obj);
ctx.userContext = ctx.userContext.newMerge(this, obj);
return this;

@@ -90,4 +91,12 @@ }

mergeContext(obj) {
deprecate(
'`QueryBuilder#mergeContext` method is deprecated. The `context` method now behaves just like `mergeContext`. `mergeContext` method will be removed in 3.0'
);
return this.context(obj || {});
}
clearContext() {
const ctx = this._context;
ctx.userContext = ctx.userContext.newMerge(this, obj);
ctx.userContext = new this.constructor.QueryBuilderUserContext(this);
return this;

@@ -94,0 +103,0 @@ }

{
"name": "objection",
"version": "2.0.0-alpha.10",
"version": "2.0.0-rc.1",
"description": "An SQL-friendly ORM for Node.js",

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

"husky": "^3.0.8",
"knex": "0.20.1",
"knex": "0.20.2",
"lint-staged": "^9.4.1",

@@ -87,0 +87,0 @@ "mocha": "^6.2.0",

@@ -13,23 +13,23 @@ [![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/github/Vincit/objection.js/badge.svg?branch=master&service=github)](https://coveralls.io/github/Vincit/objection.js?branch=master) [![Join the chat at https://gitter.im/Vincit/objection.js](https://badges.gitter.im/Vincit/objection.js.svg)](https://gitter.im/Vincit/objection.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

* **An easy declarative way of [defining models](https://vincit.github.io/objection.js/guide/models.html) and relationships between them**
* **Simple and fun way to [fetch, insert, update and delete](https://vincit.github.io/objection.js/guide/query-examples.html#basic-queries) objects using the full power of SQL**
* **Powerful mechanisms for [eager loading](https://vincit.github.io/objection.js/guide/query-examples.html#eager-loading), [inserting](https://vincit.github.io/objection.js/guide/query-examples.html#graph-inserts) and [upserting](https://vincit.github.io/objection.js/guide/query-examples.html#graph-upserts) object graphs**
* **Easy to use [transactions](https://vincit.github.io/objection.js/guide/transactions.html)**
* **Official [TypeScript](https://github.com/Vincit/objection.js/blob/master/typings/objection/index.d.ts) support**
* **Optional [JSON schema](https://vincit.github.io/objection.js/guide/validation.html) validation**
* **A way to [store complex documents](https://vincit.github.io/objection.js/guide/documents.html) as single rows**
- **An easy declarative way of [defining models](/guide/models.html) and relationships between them**
- **Simple and fun way to [fetch, insert, update and delete](/guide/query-examples.html#basic-queries) objects using the full power of SQL**
- **Powerful mechanisms for [eager loading](/guide/query-examples.html#eager-loading), [inserting](/guide/query-examples.html#graph-inserts) and [upserting](/guide/query-examples.html#graph-upserts) object graphs**
- **Easy to use [transactions](/guide/transactions.html)**
- **Official [TypeScript](https://github.com/Vincit/objection.js/blob/master/typings/objection/index.d.ts) support**
- **Optional [JSON schema](/guide/validation.html) validation**
- **A way to [store complex documents](/guide/documents.html) as single rows**
What objection.js **doesn't** give you:
* **A custom query DSL. SQL is used as a query language.**
- **A custom query DSL. SQL is used as a query language.**
This doesn't mean you have to write SQL strings though. A query builder based on [knex](http://knexjs.org) is
used to build the SQL. However, if the query builder fails you for some reason, raw SQL strings can be easily
written using the [raw](https://vincit.github.io/objection.js/api/objection/#raw) helper function.
* **Automatic database schema creation and migration from model definitions.**
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-es6).
used to build the SQL. However, if the query builder fails you for some reason, raw SQL strings can be easily
written using the [raw](https://vincit.github.io/objection.js/api/objection/#raw) helper function.
- **Automatic database schema creation and migration from model definitions.**
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/koa-ts).
The best way to get started is to clone our [ES2015](https://github.com/Vincit/objection.js/tree/master/examples/express-es6), [ESNext](https://github.com/Vincit/objection.js/tree/master/examples/express-es7) or [typescript](https://github.com/Vincit/objection.js/tree/master/examples/express-ts) example project.
The best way to get started is to clone our [example project](https://github.com/Vincit/objection.js/tree/master/examples/koa) and start playing with it. There's also a [typescript version](https://github.com/Vincit/objection.js/tree/master/examples/koa-ts) available.

@@ -39,7 +39,9 @@ Check out [this issue](https://github.com/Vincit/objection.js/issues/1069) to see who is using objection and what they think about it.

Shortcuts:
* [Who uses objection.js](https://github.com/Vincit/objection.js/issues/1069)
* [API reference](https://vincit.github.io/objection.js/api/query-builder/)
* [Example projects](https://github.com/Vincit/objection.js/tree/master/examples)
* [Changelog](https://vincit.github.io/objection.js/changelog/)
* [Contribution guide](https://vincit.github.io/objection.js/guide/contributing.html)
* [Plugins](https://vincit.github.io/objection.js/guide/plugins.html)
- [Who uses objection.js](https://github.com/Vincit/objection.js/issues/1069)
- [API reference](https://vincit.github.io/objection.js/api/query-builder/)
- [Example projects](https://github.com/Vincit/objection.js/tree/master/examples)
- [Changelog](https://vincit.github.io/objection.js/changelog/)
- [v1 -> v2 migration guide](https://vincit.github.io/objection.js/1.x/migration.html)
- [Contribution guide](https://vincit.github.io/objection.js/guide/contributing.html)
- [Plugins](https://vincit.github.io/objection.js/guide/plugins.html)

@@ -486,3 +486,3 @@ /// <reference types="node" />

interface JoinRelationOptions {
interface JoinRelatedOptions {
alias?: string | boolean;

@@ -492,4 +492,4 @@ aliases?: Record<string, string>;

interface JoinRelationMethod<QB extends AnyQueryBuilder> {
(expr: RelationExpression<ModelType<QB>>, opt?: JoinRelationOptions): QB;
interface JoinRelatedMethod<QB extends AnyQueryBuilder> {
(expr: RelationExpression<ModelType<QB>>, opt?: JoinRelatedOptions): QB;
}

@@ -841,2 +841,6 @@

interface ClearContextMethod<QB extends AnyQueryBuilder> {
(): QB;
}
interface ModifyMethod<QB extends AnyQueryBuilder> {

@@ -969,11 +973,28 @@ (modifier: Modifier<QB> | Modifier<QB>[], ...args: any[]): QB;

joinRelation: JoinRelationMethod<this>;
innerJoinRelation: JoinRelationMethod<this>;
outerJoinRelation: JoinRelationMethod<this>;
leftJoinRelation: JoinRelationMethod<this>;
leftOuterJoinRelation: JoinRelationMethod<this>;
rightJoinRelation: JoinRelationMethod<this>;
rightOuterJoinRelation: JoinRelationMethod<this>;
fullOuterJoinRelation: JoinRelationMethod<this>;
// Deprecated
joinRelation: JoinRelatedMethod<this>;
// Deprecated
innerJoinRelation: JoinRelatedMethod<this>;
// Deprecated
outerJoinRelation: JoinRelatedMethod<this>;
// Deprecated
leftJoinRelation: JoinRelatedMethod<this>;
// Deprecated
leftOuterJoinRelation: JoinRelatedMethod<this>;
// Deprecated
rightJoinRelation: JoinRelatedMethod<this>;
// Deprecated
rightOuterJoinRelation: JoinRelatedMethod<this>;
// Deprecated
fullOuterJoinRelation: JoinRelatedMethod<this>;
joinRelated: JoinRelatedMethod<this>;
innerJoinRelated: JoinRelatedMethod<this>;
outerJoinRelated: JoinRelatedMethod<this>;
leftJoinRelated: JoinRelatedMethod<this>;
leftOuterJoinRelated: JoinRelatedMethod<this>;
rightJoinRelated: JoinRelatedMethod<this>;
rightOuterJoinRelated: JoinRelatedMethod<this>;
fullOuterJoinRelated: JoinRelatedMethod<this>;
join: JoinMethod<this>;

@@ -1131,2 +1152,4 @@ joinRaw: JoinRawMethod<this>;

context: ContextMethod<this>;
clearContext: ClearContextMethod<this>;
// Deprecated
mergeContext: ContextMethod<this>;

@@ -1523,3 +1546,3 @@

static ref: ReferenceFunction;
static fn: knex.FunctionHelper;
static fn: FunctionFunction;

@@ -1526,0 +1549,0 @@ static BelongsToOneRelation: RelationType;

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