objection
Advanced tools
Comparing version 0.8.5 to 0.8.6
@@ -7,2 +7,3 @@ 'use strict'; | ||
const $pick = require('./modelFilter').$pick; | ||
const $hasId = require('./modelId').$hasId; | ||
const $clone = require('./modelClone').$clone; | ||
@@ -72,2 +73,6 @@ const $toJson = require('./modelToJson').$toJson; | ||
$hasId() { | ||
return $hasId.apply(this, arguments); | ||
} | ||
$query(trx) { | ||
@@ -74,0 +79,0 @@ const ModelClass = this.constructor; |
@@ -11,2 +11,18 @@ 'use strict'; | ||
function $hasId() { | ||
const id = this.$id(); | ||
if (Array.isArray(id)) { | ||
for (let i = 0; i < id.length; ++i) { | ||
if (isNullOrUndefined(id[i])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} else { | ||
return !isNullOrUndefined(id); | ||
} | ||
} | ||
function setId(model, id) { | ||
@@ -56,4 +72,9 @@ const idProp = model.constructor.getIdProperty(); | ||
function isNullOrUndefined(val) { | ||
return val === null || val === undefined; | ||
} | ||
module.exports = { | ||
$id | ||
$id, | ||
$hasId | ||
}; |
@@ -56,3 +56,3 @@ 'use strict'; | ||
const node = new DependencyNode(model, modelClass); | ||
const node = new DependencyNode(parentNode, model, modelClass); | ||
@@ -126,3 +126,3 @@ this.nodesById[node.id] = node; | ||
buildForId(modelClass, item, parentNode, rel) { | ||
const node = new DependencyNode(item, modelClass); | ||
const node = new DependencyNode(parentNode, item, modelClass); | ||
node.handled = true; | ||
@@ -129,0 +129,0 @@ |
@@ -5,4 +5,5 @@ 'use strict'; | ||
constructor(model, modelClass) { | ||
constructor(parentNode, model, modelClass) { | ||
this.id = model[modelClass.uidProp]; | ||
this.parentNode = parentNode; | ||
this.model = model; | ||
@@ -9,0 +10,0 @@ this.modelClass = modelClass; |
@@ -109,3 +109,5 @@ 'use strict'; | ||
return Promise.all(promises).then(() => { | ||
if (!this.omitProps.length) { | ||
const intOpt = builder.internalOptions(); | ||
if (!this.omitProps.length || intOpt.keepImplicitJoinProps) { | ||
return result; | ||
@@ -112,0 +114,0 @@ } |
@@ -69,2 +69,6 @@ 'use strict'; | ||
onGraphInserterCreated(builder, graphInserter) { | ||
// For subclasses to implement. | ||
} | ||
// We overrode all other hooks but this one and do all the work in here. | ||
@@ -87,6 +91,8 @@ // This is a bit hacky. | ||
models: this.models, | ||
allowedRelations: builder._allowedInsertExpression || null, | ||
allowedRelations: builder._allowedUpsertExpression || null, | ||
knex: builder.knex() | ||
}); | ||
this.onGraphInserterCreated(builder, graphInserter); | ||
return graphInserter.execute(insertFunc).then(() => { | ||
@@ -93,0 +99,0 @@ return super.onAfter1(builder, this.models) |
@@ -17,2 +17,3 @@ 'use strict'; | ||
this.id = null; | ||
this.skipIdWhere = false; | ||
} | ||
@@ -31,3 +32,6 @@ | ||
super.onBuild(builder); | ||
builder.whereComposite(builder.fullIdColumnFor(builder.modelClass()), this.id); | ||
if (!this.skipIdWhere) { | ||
builder.whereComposite(builder.fullIdColumnFor(builder.modelClass()), this.id); | ||
} | ||
} | ||
@@ -34,0 +38,0 @@ |
@@ -7,2 +7,7 @@ 'use strict'; | ||
constructor(name, opt) { | ||
super(name, opt); | ||
this.prefix = opt.prefix || null; | ||
} | ||
onBuildKnex(knexBuilder) { | ||
@@ -31,3 +36,3 @@ this.build(knexBuilder, this.args[0], this.args[1]); | ||
buildCompositeValue(knexBuilder, columns, values) { | ||
knexBuilder.whereIn(columns, values); | ||
this.whereIn(knexBuilder, columns, values); | ||
} | ||
@@ -52,3 +57,3 @@ | ||
knexBuilder.whereIn(knexBuilder.client.raw(sql), subquery); | ||
this.whereIn(knexBuilder, knexBuilder.client.raw(sql), subquery); | ||
} | ||
@@ -65,4 +70,12 @@ | ||
knexBuilder.whereIn(col, values); | ||
this.whereIn(knexBuilder, col, values); | ||
} | ||
whereIn(knexBuilder, col, val) { | ||
if (this.prefix === 'not') { | ||
knexBuilder.whereNotIn(col, val); | ||
} else { | ||
knexBuilder.whereIn(col, val); | ||
} | ||
} | ||
} | ||
@@ -69,0 +82,0 @@ |
@@ -7,2 +7,7 @@ 'use strict'; | ||
constructor(name, opt) { | ||
super(name, opt); | ||
this.prefix = opt.prefix || null; | ||
} | ||
onBuildKnex(knexBuilder) { | ||
@@ -23,2 +28,4 @@ this.build(knexBuilder, this.args[0], this.args[1]); | ||
buildComposite(knexBuilder, columns, values) { | ||
const whereMethod = this.prefix === 'not' ? 'whereNot' : 'where'; | ||
if (!Array.isArray(values)) { | ||
@@ -32,3 +39,3 @@ // If the `values` is not an array of values but a function or a subquery | ||
// we can emulate it using grouped `or` clauses. | ||
knexBuilder.where(builder => { | ||
knexBuilder[whereMethod](builder => { | ||
values.forEach(val => { | ||
@@ -54,3 +61,7 @@ builder.orWhere(builder => { | ||
// For non-composite keys we can use the normal whereIn. | ||
knexBuilder.whereIn(col, values); | ||
if (this.prefix === 'not') { | ||
knexBuilder.whereNotIn(col, values); | ||
} else { | ||
knexBuilder.whereIn(col, values); | ||
} | ||
} | ||
@@ -57,0 +68,0 @@ } |
@@ -21,2 +21,3 @@ 'use strict'; | ||
const InsertGraphOperation = require('./operations/InsertGraphOperation'); | ||
const UpsertGraphOperation = require('./operations/UpsertGraphOperation'); | ||
const DeleteByIdOperation = require('./operations/DeleteByIdOperation'); | ||
@@ -52,3 +53,3 @@ const RunBeforeOperation = require('./operations/RunBeforeOperation'); | ||
this._allowedEagerExpression = null; | ||
this._allowedInsertExpression = null; | ||
this._allowedUpsertExpression = null; | ||
@@ -116,5 +117,11 @@ this._findOperationOptions = {}; | ||
childQueryOf(query) { | ||
childQueryOf(query, fork) { | ||
if (query) { | ||
this.internalContext(query.internalContext()); | ||
let ctx = query.internalContext(); | ||
if (fork) { | ||
ctx = ctx.clone(); | ||
} | ||
this.internalContext(ctx); | ||
} | ||
@@ -281,7 +288,7 @@ | ||
allowInsert(exp) { | ||
this._allowedInsertExpression = exp || null; | ||
allowUpsert(exp) { | ||
this._allowedUpsertExpression = exp || null; | ||
if (typeof this._allowedInsertExpression === 'string') { | ||
this._allowedInsertExpression = parseRelationExpression(this._modelClass, this._allowedInsertExpression); | ||
if (typeof this._allowedUpsertExpression === 'string') { | ||
this._allowedUpsertExpression = parseRelationExpression(this._modelClass, this._allowedUpsertExpression); | ||
} | ||
@@ -292,2 +299,6 @@ | ||
allowInsert(exp) { | ||
return this.allowUpsert(exp); | ||
} | ||
eagerOptions(opt) { | ||
@@ -350,3 +361,3 @@ this._eagerOperationOptions = Object.assign({}, this._eagerOperationOptions, opt); | ||
builder._allowedEagerExpression = this._allowedEagerExpression; | ||
builder._allowedInsertExpression = this._allowedInsertExpression; | ||
builder._allowedUpsertExpression = this._allowedUpsertExpression; | ||
@@ -719,2 +730,11 @@ builder._findOperationOptions = this._findOperationOptions; | ||
upsertGraph(modelsOrObjects, opt) { | ||
const upsertGraphOperation = new UpsertGraphOperation('upsertGraph', { | ||
delegate: this._insertOperationFactory(this), | ||
opt | ||
}); | ||
return this.callQueryBuilderOperation(upsertGraphOperation, [modelsOrObjects]); | ||
} | ||
patchAndFetch(modelOrObject) { | ||
@@ -731,2 +751,6 @@ const delegateOperation = this._patchOperationFactory(this); | ||
// delegateOperation is an instance update operation that already adds the | ||
// required "where id = $" clause. | ||
patchAndFetch.skipIdWhere = true; | ||
return this.callQueryBuilderOperation(patchAndFetch, [delegateOperation.instance.$id(), modelOrObject]); | ||
@@ -733,0 +757,0 @@ } |
@@ -150,2 +150,3 @@ 'use strict'; | ||
whereInComposite(columns, values) {} | ||
whereNotInComposite(columns, values) {} | ||
whereJsonEquals(fieldExpression, jsonObjectOrFieldExpression) {} | ||
@@ -306,2 +307,8 @@ orWhereJsonEquals(fieldExpression, jsonObjectOrFieldExpression) {} | ||
}, { | ||
decorator: queryBuilderOperation({ | ||
default: [WhereInCompositeOperation, {prefix: 'not'}], | ||
sqlite3: [WhereInCompositeSqliteOperation, {prefix: 'not'}] | ||
}), | ||
properties: ['whereNotInComposite'] | ||
}, { | ||
decorator: queryBuilderOperation([WhereJsonPostgresOperation, {operator: '=', bool: 'and'}]), | ||
@@ -308,0 +315,0 @@ properties: ['whereJsonEquals'] |
@@ -25,2 +25,3 @@ 'use strict'; | ||
this.skipUndefined = false; | ||
this.keepImplicitJoinProps = false; | ||
this.queryProps = null; | ||
@@ -34,2 +35,3 @@ this.debug = false; | ||
copy.skipUndefined = this.skipUndefined; | ||
copy.keepImplicitJoinProps = this.keepImplicitJoinProps; | ||
copy.queryProps = this.queryProps; | ||
@@ -36,0 +38,0 @@ copy.debug = this.debug; |
@@ -5,3 +5,3 @@ 'use strict'; | ||
const RelationFindOperation = require('../RelationFindOperation'); | ||
const OWNER_JOIN_COLUMN_ALIAS_PREFIX = 'objectiontmpjoin'; | ||
const getTempColumn = require('../../utils/tmpColumnUtils').getTempColumn; | ||
@@ -16,3 +16,3 @@ class ManyToManyFindOperation extends RelationFindOperation { | ||
for (let i = 0, l = this.relation.joinTableOwnerCol.length; i < l; ++i) { | ||
this.ownerJoinColumnAlias[i] = OWNER_JOIN_COLUMN_ALIAS_PREFIX + i; | ||
this.ownerJoinColumnAlias[i] = getTempColumn(i); | ||
} | ||
@@ -19,0 +19,0 @@ } |
@@ -82,3 +82,8 @@ 'use strict'; | ||
onAfter3(builder, related) { | ||
this.omitImplicitJoinProps(related); | ||
const intOpt = builder.internalOptions(); | ||
if (!intOpt.keepImplicitJoinProps) { | ||
this.omitImplicitJoinProps(related); | ||
} | ||
return super.onAfter3(builder, related); | ||
@@ -85,0 +90,0 @@ } |
{ | ||
"name": "objection", | ||
"version": "0.8.5", | ||
"version": "0.8.6", | ||
"description": "An SQL-friendly ORM for Node.js", | ||
@@ -9,5 +9,6 @@ "main": "lib/objection.js", | ||
"test": "mocha --slow 10 --timeout 15000 --reporter spec --recursive tests", | ||
"test-travis": "istanbul --config=.istanbul.yml cover _mocha -- --slow 100 --timeout 60000 --reporter spec --recursive tests", | ||
"test-travis": "istanbul --config=.istanbul.yml cover _mocha -- --slow 100 --timeout 60000 --reporter spec --recursive tests && npm run test-typings", | ||
"test-bail": "mocha --slow 10 --timeout 15000 --reporter spec --recursive tests --bail", | ||
"test-opt": "mocha --slow 10 --timeout 15000 --reporter spec --recursive tests --bail --trace_opt --trace_deopt --trace_inlining", | ||
"test-typings": "tsc --noEmit", | ||
"coveralls": "cat ./testCoverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", | ||
@@ -61,2 +62,3 @@ "perf": "mocha --slow 60000 --timeout 60000 --reporter spec --recursive perf", | ||
"@types/knex": "^0.0.55", | ||
"@types/node": "^8.0.17", | ||
"coveralls": "^2.13.1", | ||
@@ -72,4 +74,5 @@ "expect.js": "^0.3.1", | ||
"sqlite3": "^3.1.8", | ||
"typescript": "^2.4.1" | ||
"tslint": "^5.5.0", | ||
"typescript": "^2.4.2" | ||
} | ||
} |
@@ -16,3 +16,3 @@ [![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)](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) | ||
* **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 object graphs](http://vincit.github.io/objection.js/#graph-inserts)** | ||
* **Powerful mechanisms for [eager loading](http://vincit.github.io/objection.js/#eager-loading), [inserting](http://vincit.github.io/objection.js/#graph-inserts) and [upserting](http://vincit.github.io/objection.js/#graph-upserts) object graphs** | ||
* **A way to [store complex documents](http://vincit.github.io/objection.js/#documents) as single rows** | ||
@@ -19,0 +19,0 @@ * **Completely [Promise](https://github.com/petkaantonov/bluebird) based API** |
@@ -6,4 +6,2 @@ // Type definitions for objection v0.8.4 | ||
/// <reference types="node" /> | ||
/// <reference types="knex" /> | ||
import * as knex from "knex"; | ||
@@ -26,3 +24,3 @@ | ||
export type RelationMappings = { [relationName: string]: RelationMapping }; | ||
export interface RelationMappings { [relationName: string]: RelationMapping; } | ||
@@ -48,3 +46,3 @@ interface Relation { | ||
relation: Relation; | ||
modelClass: typeof Model | String; | ||
modelClass: typeof Model | string; | ||
join: RelationJoin; | ||
@@ -75,5 +73,7 @@ modify?: <T>(queryBuilder: QueryBuilder<T>) => QueryBuilder<T>; | ||
type FilterFunction = <T>(queryBuilder: QueryBuilder<T>) => void; | ||
interface FilterFunction<T> { | ||
(queryBuilder: QueryBuilder<T>): void; | ||
} | ||
type FilterExpression = { [namedFilter: string]: FilterFunction }; | ||
interface FilterExpression<T> { [namedFilter: string]: FilterFunction<T>; } | ||
@@ -85,3 +85,3 @@ interface RelationExpressionMethod { | ||
interface TraverserFunction { | ||
/** | ||
/** | ||
* Called if model is in a relation of some other model. | ||
@@ -101,3 +101,3 @@ * @param model the model itself | ||
type RelationOptions = { alias: boolean | string }; | ||
interface RelationOptions { alias: boolean | string; } | ||
@@ -108,3 +108,3 @@ interface JoinRelation { | ||
type JsonObjectOrFieldExpression = Object | Object[] | FieldExpression; | ||
type JsonObjectOrFieldExpression = object | object[] | FieldExpression; | ||
@@ -120,11 +120,21 @@ interface WhereJson<T> { | ||
interface WhereJsonExpression<T> { | ||
(fieldExpression: FieldExpression, keys: string | string[]): QueryBuilder<T>; | ||
( | ||
fieldExpression: FieldExpression, | ||
keys: string | string[] | ||
): QueryBuilder<T>; | ||
} | ||
interface WhereJsonField<T> { | ||
(fieldExpression: FieldExpression, operator: string, value: boolean | number | string | null): QueryBuilder<T>; | ||
( | ||
fieldExpression: FieldExpression, | ||
operator: string, | ||
value: boolean | number | string | null | ||
): QueryBuilder<T>; | ||
} | ||
interface ModifyEager<T1> { | ||
<T2>(relationExpression: string | RelationExpression, modifier: (builder: QueryBuilder<T2>) => void): QueryBuilder<T1>; | ||
<T2>( | ||
relationExpression: string | RelationExpression, | ||
modifier: (builder: QueryBuilder<T2>) => void | ||
): QueryBuilder<T1>; | ||
} | ||
@@ -137,7 +147,7 @@ | ||
interface NodeStyleCallback { | ||
(err: any, result?: any): void | ||
(err: any, result?: any): void; | ||
} | ||
type Filters<T> = { [filterName: string]: (queryBuilder: QueryBuilder<T>) => void }; | ||
type Properties = { [propertyName: string]: boolean }; | ||
interface Filters<T> { [filterName: string]: (queryBuilder: QueryBuilder<T>) => void; } | ||
interface Properties { [propertyName: string]: boolean; } | ||
@@ -174,4 +184,5 @@ /** | ||
ManyToManyRelation: Relation; | ||
HasOneThroughRelation: Relation; | ||
query(trx?: Transaction<M>): QueryBuilder<M>; | ||
query(trx?: Transaction): QueryBuilder<M>; | ||
knex(knex?: knex): knex; | ||
@@ -182,11 +193,15 @@ formatter(): any; // < the knex typings punts here too | ||
bindKnex(knex: knex): this; | ||
bindTransaction(transaction: Transaction<M>): this; | ||
bindTransaction(transaction: Transaction): this; | ||
extend<S>(subclass: { new(): S }): this & { new(...args: any[]): M & S }; | ||
fromJson(json: Object, opt?: ModelOptions): M; | ||
fromDatabaseJson(row: Object): M; | ||
fromJson(json: object, opt?: ModelOptions): M; | ||
fromDatabaseJson(row: object): M; | ||
omitImpl(f: (obj: Object, prop: string) => void): void; | ||
omitImpl(f: (obj: object, prop: string) => void): void; | ||
loadRelated(models: (Model | Object)[], expression: RelationExpression, filters?: Filters<M>): Promise<M[]>; | ||
loadRelated( | ||
models: (Model | object)[], | ||
expression: RelationExpression, | ||
filters?: Filters<M> | ||
): Promise<M[]>; | ||
@@ -222,2 +237,3 @@ traverse(filterConstructor: typeof Model, models: Model | Model[], traverser: TraverserFunction): void; | ||
static ManyToManyRelation: Relation; | ||
static HasOneThroughRelation: Relation; | ||
@@ -227,5 +243,5 @@ static JoinEagerAlgorithm: () => any; | ||
// "{ new(): T }" | ||
// "{ new(): T }" | ||
// is from https://www.typescriptlang.org/docs/handbook/generics.html#using-class-types-in-generics | ||
static query<T>(this: { new(): T }, trx?: Transaction<T>): QueryBuilder<T>; | ||
static query<T>(this: { new(): T }, trx?: Transaction): QueryBuilder<T>; | ||
static knex(knex?: knex): knex; | ||
@@ -236,5 +252,5 @@ static formatter(): any; // < the knex typings punts here too | ||
static bindKnex<T>(this: T, knex: knex): T; | ||
static bindTransaction<T>(this: T, transaction: Transaction<T>): T; | ||
static bindTransaction<T>(this: T, transaction: Transaction): T; | ||
// TODO: It'd be nicer to expose an actual T&S union class here: | ||
// TODO: It'd be nicer to expose an actual T&S union class here: | ||
static extend<M extends Model, S>( | ||
@@ -245,8 +261,13 @@ this: ModelClass<M>, | ||
static fromJson<T>(this: T, json: Object, opt?: ModelOptions): T; | ||
static fromDatabaseJson<T>(this: T, row: Object): T; | ||
static fromJson<T>(this: T, json: object, opt?: ModelOptions): T; | ||
static fromDatabaseJson<T>(this: T, row: object): T; | ||
static omitImpl(f: (obj: Object, prop: string) => void): void; | ||
static omitImpl(f: (obj: object, prop: string) => void): void; | ||
static loadRelated<T>(this: { new(): T }, models: (T | Object)[], expression: RelationExpression, filters?: Filters<T>): Promise<T[]>; | ||
static loadRelated<T>( | ||
this: { new(): T }, | ||
models: (T | object)[], | ||
expression: RelationExpression, | ||
filters?: Filters<T> | ||
): Promise<T[]>; | ||
@@ -259,17 +280,17 @@ static traverse(filterConstructor: typeof Model, models: Model | Model[], traverser: TraverserFunction): void; | ||
$beforeValidate(jsonSchema: JsonSchema, json: Object, opt: ModelOptions): JsonSchema; | ||
$validate(): void // may throw ValidationError if validation fails | ||
$afterValidate(json: Object, opt: ModelOptions): void; // may throw ValidationError if validation fails | ||
$beforeValidate(jsonSchema: JsonSchema, json: object, opt: ModelOptions): JsonSchema; | ||
$validate(): void; // may throw ValidationError if validation fails | ||
$afterValidate(json: object, opt: ModelOptions): void; // may throw ValidationError if validation fails | ||
$toDatabaseJson(): Object; | ||
$toJson(): Object; | ||
toJSON(): Object; | ||
$parseDatabaseJson(json: Object): Object; | ||
$formatDatabaseJson(json: Object): Object; | ||
$parseJson(json: Object, opt?: ModelOptions): Object; | ||
$formatJson(json: Object): Object; | ||
$setJson(json: Object, opt?: ModelOptions): this; | ||
$setDatabaseJson(json: Object): this; | ||
$toDatabaseJson(): object; | ||
$toJson(): object; | ||
toJSON(): object; | ||
$parseDatabaseJson(json: object): object; | ||
$formatDatabaseJson(json: object): object; | ||
$parseJson(json: object, opt?: ModelOptions): object; | ||
$formatJson(json: object): object; | ||
$setJson(json: object, opt?: ModelOptions): this; | ||
$setDatabaseJson(json: object): this; | ||
$set(obj: Object): this; | ||
$set(obj: object): this; | ||
$omit(keys: string | string[] | Properties): this; | ||
@@ -282,3 +303,3 @@ $pick(keys: string | string[] | Properties): this; | ||
*/ | ||
$query(trx?: Transaction<this>): QueryBuilderSingle<this>; | ||
$query(trx?: Transaction): QueryBuilderSingle<this>; | ||
@@ -290,3 +311,3 @@ /** | ||
*/ | ||
$relatedQuery<M extends Model>(relationName: string, transaction?: Transaction<M>): QueryBuilder<M>; | ||
$relatedQuery<M extends Model>(relationName: string, transaction?: Transaction): QueryBuilder<M>; | ||
@@ -301,6 +322,6 @@ $loadRelated<T>(expression: RelationExpression, filters?: Filters<T>): QueryBuilderSingle<this>; | ||
$beforeInsert(queryContext: Object): Promise<any> | void; | ||
$afterInsert(queryContext: Object): Promise<any> | void; | ||
$afterUpdate(opt: ModelOptions, queryContext: Object): Promise<any> | void; | ||
$beforeUpdate(opt: ModelOptions, queryContext: Object): Promise<any> | void; | ||
$beforeInsert(queryContext: object): Promise<any> | void; | ||
$afterInsert(queryContext: object): Promise<any> | void; | ||
$afterUpdate(opt: ModelOptions, queryContext: object): Promise<any> | void; | ||
$beforeUpdate(opt: ModelOptions, queryContext: object): Promise<any> | void; | ||
} | ||
@@ -335,2 +356,8 @@ | ||
interface Upsert<T> { | ||
(modelsOrObjects?: Array<Partial<T>>): QueryBuilder<T>; | ||
(modelOrObject?: Partial<T>): QueryBuilderSingle<T>; | ||
(): this; | ||
} | ||
interface InsertGraphAndFetch<T> { | ||
@@ -345,2 +372,3 @@ (modelsOrObjects?: Partial<T>): QueryBuilderSingle<T>; | ||
findById(idOrIds: IdOrIds): this; | ||
findOne(where: object): QueryBuilderOption<T>; | ||
@@ -352,3 +380,3 @@ insert: Insert<T>; | ||
insertGraph: Insert<T>; | ||
insertGraphAndFetch: InsertGraphAndFetch<T> | ||
insertGraphAndFetch: InsertGraphAndFetch<T>; | ||
@@ -359,3 +387,3 @@ /** | ||
insertWithRelated: Insert<T>; | ||
insertWithRelatedAndFetch: InsertGraphAndFetch<T> | ||
insertWithRelatedAndFetch: InsertGraphAndFetch<T>; | ||
@@ -376,2 +404,4 @@ /** | ||
upsertGraph: Upsert<T>; | ||
/** | ||
@@ -404,3 +434,3 @@ * @return a Promise of the number of deleted rows | ||
// TODO: the return value of this method matches the knex typescript and documentation. | ||
// The Objection documentation incorrectly states this returns a QueryBuilder. | ||
// The Objection documentation incorrectly states this returns a QueryBuilder. | ||
columnInfo(column?: string): Promise<knex.ColumnInfo>; | ||
@@ -413,4 +443,3 @@ | ||
whereComposite(columns: string[], operator: string, values: any[]): this; | ||
whereInComposite(column: string, values: any[]): this; | ||
whereInComposite(columns: string[], values: any[]): this; | ||
whereInComposite(column: string | string[], values: any[]): this; | ||
@@ -452,3 +481,3 @@ whereJsonEquals: WhereJson<T>; | ||
whereJsonField: WhereJsonField<T> | ||
whereJsonField: WhereJsonField<T>; | ||
orWhereJsonField: WhereJsonField<T>; | ||
@@ -458,3 +487,3 @@ | ||
context(queryContext: Object): this; | ||
context(queryContext: object): this; | ||
@@ -465,2 +494,3 @@ reject(reason: any): this; | ||
isExecutable(): boolean; | ||
isFindQuery(): boolean; | ||
@@ -472,4 +502,12 @@ runBefore(fn: (builder: this) => void): this; | ||
eagerAlgorithm(algo: EagerAlgorithm): this; | ||
eager(relationExpression: RelationExpression, filters?: FilterExpression): this; | ||
eager(relationExpression: RelationExpression, filters?: FilterExpression<T>): this; | ||
mergeEager(relationExpression: RelationExpression, filters?: FilterExpression<T>): this; | ||
joinEager(relationExpression: RelationExpression, filters?: FilterExpression<T>): this; | ||
mergeJoinEager(relationExpression: RelationExpression, filters?: FilterExpression<T>): this; | ||
naiveEager(relationExpression: RelationExpression, filters?: FilterExpression<T>): this; | ||
mergeNaiveEager(relationExpression: RelationExpression, filters?: FilterExpression<T>): this; | ||
allowEager: RelationExpressionMethod; | ||
@@ -480,2 +518,3 @@ modifyEager: ModifyEager<T>; | ||
allowInsert: RelationExpressionMethod; | ||
allowUpsert: RelationExpressionMethod; | ||
@@ -490,13 +529,13 @@ modelClass(): typeof Model; | ||
transacting(transation: Transaction<T>): this; | ||
transacting(transation: Transaction): this; | ||
clone(): this; | ||
execute(): Promise<any> | ||
execute(): Promise<any>; | ||
// We get `then` and `catch` by extending Promise | ||
map<T, Result>(mapper: BluebirdMapper<T, Result>): Promise<Result[]> | ||
map<V, Result>(mapper: BluebirdMapper<V, Result>): Promise<Result[]>; | ||
return<T>(returnValue: T): Promise<T> | ||
return<V>(returnValue: V): Promise<V>; | ||
@@ -526,23 +565,27 @@ bind(context: any): Promise<any>; | ||
export interface transaction<T> { | ||
start(knexOrModel: knex | ModelClass<any>): Promise<Transaction<T>>; | ||
start(knexOrModel: knex | ModelClass<any>): Promise<Transaction>; | ||
<MC extends ModelClass<any>, T>( | ||
<MC extends ModelClass<any>, V>( | ||
modelClass: MC, | ||
callback: (boundModelClass: MC) => Promise<T> | ||
): Promise<T>; | ||
callback: (boundModelClass: MC) => Promise<V> | ||
): Promise<V>; | ||
<MC1 extends ModelClass<any>, MC2 extends ModelClass<any>, T>( | ||
<MC1 extends ModelClass<any>, MC2 extends ModelClass<any>, V>( | ||
modelClass1: MC1, | ||
modelClass2: MC2, | ||
callback: (boundModel1Class: MC1, boundModel2Class: MC2) => Promise<T> | ||
): Promise<T>; | ||
callback: (boundModel1Class: MC1, boundModel2Class: MC2) => Promise<V> | ||
): Promise<V>; | ||
<MC1 extends ModelClass<any>, MC2 extends ModelClass<any>, MC3 extends ModelClass<any>, T>( | ||
<MC1 extends ModelClass<any>, MC2 extends ModelClass<any>, MC3 extends ModelClass<any>, V>( | ||
modelClass1: MC1, | ||
modelClass2: MC2, | ||
modelClass3: MC3, | ||
callback: (boundModel1Class: MC1, boundModel2Class: MC2, boundModel3Class: MC3) => Promise<T> | ||
): Promise<T>; | ||
callback: (boundModel1Class: MC1, boundModel2Class: MC2, boundModel3Class: MC3) => Promise<V> | ||
): Promise<V>; | ||
<MC1 extends ModelClass<any>, MC2 extends ModelClass<any>, MC3 extends ModelClass<any>, MC4 extends ModelClass<any>, T>( | ||
<MC1 extends ModelClass<any>, | ||
MC2 extends ModelClass<any>, | ||
MC3 extends ModelClass<any>, | ||
MC4 extends ModelClass<any>, | ||
V>( | ||
modelClass1: MC1, | ||
@@ -552,6 +595,16 @@ modelClass2: MC2, | ||
modelClass4: MC4, | ||
callback: (boundModel1Class: MC1, boundModel2Class: MC2, boundModel3Class: MC3, boundModel4Class: MC4) => Promise<T> | ||
): Promise<T>; | ||
callback: ( | ||
boundModel1Class: MC1, | ||
boundModel2Class: MC2, | ||
boundModel3Class: MC3, | ||
boundModel4Class: MC4 | ||
) => Promise<V> | ||
): Promise<V>; | ||
<MC1 extends ModelClass<any>, MC2 extends ModelClass<any>, MC3 extends ModelClass<any>, MC4 extends ModelClass<any>, MC5 extends ModelClass<any>, T>( | ||
<MC1 extends ModelClass<any>, | ||
MC2 extends ModelClass<any>, | ||
MC3 extends ModelClass<any>, | ||
MC4 extends ModelClass<any>, | ||
MC5 extends ModelClass<any>, | ||
V>( | ||
modelClass1: MC1, | ||
@@ -562,12 +615,17 @@ modelClass2: MC2, | ||
modelClass5: MC5, | ||
callback: (boundModel1Class: MC1, boundModel2Class: MC2, boundModel3Class: MC3, boundModel4Class: MC4, boundModel5Class: MC5) => Promise<T> | ||
): Promise<T>; | ||
callback: ( | ||
boundModel1Class: MC1, | ||
boundModel2Class: MC2, | ||
boundModel3Class: MC3, | ||
boundModel4Class: MC4, | ||
boundModel5Class: MC5 | ||
) => Promise<V> | ||
): Promise<V>; | ||
<T>(knex: knex, callback: (trx: Transaction<T>) => Promise<T>): Promise<T>; | ||
<V>(knex: knex, callback: (trx: Transaction) => Promise<V>): Promise<V>; | ||
} | ||
export const transaction: transaction<any> | ||
export const transaction: transaction<any>; | ||
type Raw = knex.Raw | ||
type Raw = knex.Raw; | ||
@@ -652,3 +710,3 @@ // | ||
union: Union<T>; | ||
unionAll(callback: Function): this; | ||
unionAll(callback: () => void): this; | ||
@@ -695,3 +753,3 @@ // Having | ||
transacting(trx: Transaction<T>): this; | ||
transacting(trx: Transaction): this; | ||
connection(connection: any): this; | ||
@@ -711,3 +769,3 @@ | ||
(tableName: string): QueryBuilder<T>; | ||
(callback: Function): QueryBuilder<T>; | ||
(callback: () => void): QueryBuilder<T>; | ||
(raw: Raw): QueryBuilder<T>; | ||
@@ -738,3 +796,3 @@ } | ||
(alias: string, raw: Raw): QueryBuilder<T>; | ||
(alias: string, sql: string, bindings?: Value[] | Object): QueryBuilder<T>; | ||
(alias: string, sql: string, bindings?: Value[] | object): QueryBuilder<T>; | ||
} | ||
@@ -749,3 +807,3 @@ | ||
(callback: (queryBuilder: QueryBuilder<T>) => any): QueryBuilder<T>; | ||
(object: Object): QueryBuilder<T>; | ||
(object: object): QueryBuilder<T>; | ||
(columnName: string, value: Value): QueryBuilder<T>; | ||
@@ -761,3 +819,3 @@ (columnName: string | Raw, operator: string, value: Value): QueryBuilder<T>; | ||
interface WhereWrapped<T> { | ||
(callback: Function): QueryBuilder<T>; | ||
(callback: () => void): QueryBuilder<T>; | ||
} | ||
@@ -771,4 +829,4 @@ | ||
(columnName: string, values: Value[]): QueryBuilder<T>; | ||
(columnName: string, callback: Function): QueryBuilder<T>; | ||
(columnName: string, query: QueryBuilder<T>): QueryBuilder<T>; | ||
(columnName: string, callback: () => void): QueryBuilder<T>; | ||
(columnName: string, query: QueryBuilder<any>): QueryBuilder<T>; | ||
} | ||
@@ -781,4 +839,4 @@ | ||
interface WhereExists<T> { | ||
(callback: Function): QueryBuilder<T>; | ||
(query: QueryBuilder<T>): QueryBuilder<T>; | ||
(callback: () => void): QueryBuilder<T>; | ||
(query: QueryBuilder<any>): QueryBuilder<T>; | ||
} | ||
@@ -802,6 +860,6 @@ | ||
interface Union<T> { | ||
(callback: Function, wrap?: boolean): QueryBuilder<T>; | ||
(callbacks: Function[], wrap?: boolean): QueryBuilder<T>; | ||
(...callbacks: Function[]): QueryBuilder<T>; | ||
// (...callbacks: Function[], wrap?: boolean): QueryInterface; | ||
(callback: () => void, wrap?: boolean): QueryBuilder<T>; | ||
(callbacks: (() => void)[], wrap?: boolean): QueryBuilder<T>; | ||
(...callbacks: (() => void)[]): QueryBuilder<T>; | ||
// (...callbacks: () => void[], wrap?: boolean): QueryInterface; | ||
} | ||
@@ -834,3 +892,2 @@ | ||
//TODO: Promise? | ||
columnInfo(column?: string): Promise<knex.ColumnInfo>; | ||
@@ -843,3 +900,3 @@ | ||
on(event: string, callback: Function): this; | ||
on(event: string, callback: () => void): this; | ||
} | ||
@@ -857,9 +914,9 @@ | ||
pipe(writable: any): QueryBuilder<T>; | ||
exec(callback: Function): QueryBuilder<T>; | ||
exec(callback: () => void): QueryBuilder<T>; | ||
} | ||
interface Transaction<T> extends knex { | ||
savepoint(transactionScope: (trx: Transaction<T>) => any): Promise<any>; | ||
commit(value?: any): QueryBuilder<T>; | ||
rollback(error?: any): QueryBuilder<T>; | ||
interface Transaction extends knex { | ||
savepoint(transactionScope: (trx: Transaction) => any): Promise<any>; | ||
commit<T>(value?: any): Promise<T>; | ||
rollback<T>(error?: any): Promise<T>; | ||
} | ||
@@ -894,3 +951,3 @@ | ||
export interface JsonSchema { | ||
$ref?: string | ||
$ref?: string; | ||
///////////////////////////////////////////////// | ||
@@ -903,3 +960,3 @@ // Schema Metadata | ||
*/ | ||
id?: string | ||
id?: string; | ||
/** | ||
@@ -909,11 +966,11 @@ * It is recommended that the meta-schema is | ||
*/ | ||
$schema?: JsonSchema | ||
$schema?: JsonSchema; | ||
/** | ||
* Title of the schema | ||
*/ | ||
title?: string | ||
title?: string; | ||
/** | ||
* Schema description | ||
*/ | ||
description?: string | ||
description?: string; | ||
/** | ||
@@ -923,3 +980,3 @@ * Default json for the object represented by | ||
*/ | ||
default?: any | ||
default?: any; | ||
@@ -933,13 +990,13 @@ ///////////////////////////////////////////////// | ||
*/ | ||
multipleOf?: number | ||
maximum?: number | ||
multipleOf?: number; | ||
maximum?: number; | ||
/** | ||
* If true maximum must be > value, >= otherwise | ||
*/ | ||
exclusiveMaximum?: boolean | ||
minimum?: number | ||
exclusiveMaximum?: boolean; | ||
minimum?: number; | ||
/** | ||
* If true minimum must be < value, <= otherwise | ||
*/ | ||
exclusiveMinimum?: boolean | ||
exclusiveMinimum?: boolean; | ||
@@ -949,4 +1006,4 @@ ///////////////////////////////////////////////// | ||
///////////////////////////////////////////////// | ||
maxLength?: number | ||
minLength?: number | ||
maxLength?: number; | ||
minLength?: number; | ||
/** | ||
@@ -956,3 +1013,3 @@ * This is a regex string that the value must | ||
*/ | ||
pattern?: string | ||
pattern?: string; | ||
@@ -962,7 +1019,7 @@ ///////////////////////////////////////////////// | ||
///////////////////////////////////////////////// | ||
additionalItems?: boolean | JsonSchema | ||
items?: JsonSchema | JsonSchema[] | ||
maxItems?: number | ||
minItems?: number | ||
uniqueItems?: boolean | ||
additionalItems?: boolean | JsonSchema; | ||
items?: JsonSchema | JsonSchema[]; | ||
maxItems?: number; | ||
minItems?: number; | ||
uniqueItems?: boolean; | ||
@@ -972,6 +1029,6 @@ ///////////////////////////////////////////////// | ||
///////////////////////////////////////////////// | ||
maxProperties?: number | ||
minProperties?: number | ||
required?: string[] | ||
additionalProperties?: boolean | JsonSchema | ||
maxProperties?: number; | ||
minProperties?: number; | ||
required?: string[]; | ||
additionalProperties?: boolean | JsonSchema; | ||
/** | ||
@@ -981,3 +1038,3 @@ * Holds simple JSON Schema definitions for | ||
*/ | ||
definitions?: { [key: string]: JsonSchema } | ||
definitions?: { [key: string]: JsonSchema }; | ||
/** | ||
@@ -987,3 +1044,3 @@ * The keys that can exist on the object with the | ||
*/ | ||
properties?: { [property: string]: JsonSchema } | ||
properties?: { [property: string]: JsonSchema }; | ||
/** | ||
@@ -993,3 +1050,3 @@ * The key of this object is a regex for which | ||
*/ | ||
patternProperties?: { [pattern: string]: JsonSchema } | ||
patternProperties?: { [pattern: string]: JsonSchema }; | ||
/** | ||
@@ -1002,3 +1059,3 @@ * If the key is present as a property then the | ||
*/ | ||
dependencies?: { [key: string]: JsonSchema | string[] } | ||
dependencies?: { [key: string]: JsonSchema | string[] }; | ||
@@ -1014,3 +1071,3 @@ ///////////////////////////////////////////////// | ||
*/ | ||
enum?: any[] | ||
enum?: any[]; | ||
/** | ||
@@ -1021,3 +1078,3 @@ * The basic type of this schema, can be one of | ||
*/ | ||
type?: string | string[] | ||
type?: string | string[]; | ||
@@ -1027,10 +1084,10 @@ ///////////////////////////////////////////////// | ||
///////////////////////////////////////////////// | ||
allOf?: JsonSchema[] | ||
anyOf?: JsonSchema[] | ||
oneOf?: JsonSchema[] | ||
allOf?: JsonSchema[]; | ||
anyOf?: JsonSchema[]; | ||
oneOf?: JsonSchema[]; | ||
/** | ||
* The entity being validated must not match this schema | ||
*/ | ||
not?: JsonSchema | ||
not?: JsonSchema; | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
383490
130
11163
14