objection 3.9.1 → 4.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dbErrors/LICENSE +21 -0
- package/lib/dbErrors/errorCodes/mssql.js +19 -0
- package/lib/dbErrors/errorCodes/mysql.js +805 -0
- package/lib/dbErrors/errorCodes/postgres.js +241 -0
- package/lib/dbErrors/errors/CheckViolationError.js +10 -0
- package/lib/dbErrors/errors/ConstraintViolationError.js +3 -0
- package/lib/dbErrors/errors/DBError.js +9 -0
- package/lib/dbErrors/errors/DataError.js +3 -0
- package/lib/dbErrors/errors/ForeignKeyViolationError.js +11 -0
- package/lib/dbErrors/errors/NotNullViolationError.js +12 -0
- package/lib/dbErrors/errors/UniqueViolationError.js +12 -0
- package/lib/dbErrors/index.js +59 -0
- package/lib/dbErrors/parsers/mssql/DBError/CheckViolationError/parser.js +28 -0
- package/lib/dbErrors/parsers/mssql/DBError/DataError/parser.js +25 -0
- package/lib/dbErrors/parsers/mssql/DBError/ForeignKeyViolationError/parser.js +39 -0
- package/lib/dbErrors/parsers/mssql/DBError/NotNullViolationError/parser.js +30 -0
- package/lib/dbErrors/parsers/mssql/DBError/UniqueViolationError/parser.js +53 -0
- package/lib/dbErrors/parsers/mssql/DBError/parser.js +51 -0
- package/lib/dbErrors/parsers/mssql/DBError/util.js +16 -0
- package/lib/dbErrors/parsers/mysql/DBError/ConstraintViolationError/ForeignKeyViolationError/parser.js +43 -0
- package/lib/dbErrors/parsers/mysql/DBError/ConstraintViolationError/NotNullViolationError/parser.js +29 -0
- package/lib/dbErrors/parsers/mysql/DBError/ConstraintViolationError/UniqueViolationError/parser.js +27 -0
- package/lib/dbErrors/parsers/mysql/DBError/ConstraintViolationError/parser.js +23 -0
- package/lib/dbErrors/parsers/mysql/DBError/DataError/parser.js +24 -0
- package/lib/dbErrors/parsers/mysql/DBError/parser.js +28 -0
- package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/CheckViolationError/parser.js +18 -0
- package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/ForeignKeyViolationError/parser.js +18 -0
- package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/NotNullViolationError/parser.js +18 -0
- package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/UniqueViolationError/parser.js +40 -0
- package/lib/dbErrors/parsers/postgres/DBError/ConstraintViolationError/parser.js +25 -0
- package/lib/dbErrors/parsers/postgres/DBError/DataError/parser.js +16 -0
- package/lib/dbErrors/parsers/postgres/DBError/parser.js +27 -0
- package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/CheckViolationError/parser.js +20 -0
- package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/ForeignKeyViolationError/parser.js +20 -0
- package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/NotNullViolationError/parser.js +27 -0
- package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/UniqueViolationError/parser.js +28 -0
- package/lib/dbErrors/parsers/sqlite/DBError/ConstraintViolationError/parser.js +24 -0
- package/lib/dbErrors/parsers/sqlite/DBError/parser.js +23 -0
- package/lib/dbErrors/utils/sqlState.js +3 -0
- package/lib/initialize.js +1 -7
- package/lib/model/AjvValidator.js +51 -117
- package/lib/model/Model.js +84 -59
- package/lib/model/ModifierNotFoundError.js +1 -7
- package/lib/model/NotFoundError.js +1 -7
- package/lib/model/RelationDoesNotExistError.js +1 -7
- package/lib/model/ValidationError.js +3 -10
- package/lib/model/Validator.js +1 -7
- package/lib/model/getModel.js +7 -6
- package/lib/model/inheritModel.js +1 -7
- package/lib/model/modelBindKnex.js +4 -10
- package/lib/model/modelClone.js +5 -11
- package/lib/model/modelColPropMap.js +3 -10
- package/lib/model/modelId.js +3 -10
- package/lib/model/modelJsonAttributes.js +35 -16
- package/lib/model/modelParseRelations.js +2 -8
- package/lib/model/modelQueryProps.js +11 -23
- package/lib/model/modelSet.js +89 -41
- package/lib/model/modelTableMetadata.js +4 -11
- package/lib/model/modelToJson.js +6 -13
- package/lib/model/modelUtils.js +14 -13
- package/lib/model/modelValidate.js +3 -9
- package/lib/model/modelValues.js +5 -14
- package/lib/model/modelVisitor.js +1 -7
- package/lib/objection.js +33 -71
- package/lib/queryBuilder/FunctionBuilder.js +4 -11
- package/lib/queryBuilder/InternalOptions.js +4 -9
- package/lib/queryBuilder/JoinBuilder.js +5 -8
- package/lib/queryBuilder/QueryBuilder.js +126 -95
- package/lib/queryBuilder/QueryBuilderBase.js +41 -123
- package/lib/queryBuilder/QueryBuilderContext.js +2 -8
- package/lib/queryBuilder/QueryBuilderContextBase.js +2 -8
- package/lib/queryBuilder/QueryBuilderOperationSupport.js +7 -21
- package/lib/queryBuilder/QueryBuilderUserContext.js +1 -7
- package/lib/queryBuilder/RawBuilder.js +5 -13
- package/lib/queryBuilder/ReferenceBuilder.js +20 -48
- package/lib/queryBuilder/RelationExpression.js +18 -16
- package/lib/queryBuilder/StaticHookArguments.js +74 -16
- package/lib/queryBuilder/ValueBuilder.js +11 -13
- package/lib/queryBuilder/getJoinBuilder.js +10 -0
- package/lib/queryBuilder/graph/GraphLoader.js +304 -0
- package/lib/queryBuilder/graph/GraphNode.js +235 -0
- package/lib/queryBuilder/graph/GraphOptions.js +55 -248
- package/lib/queryBuilder/graph/GraphPlan.js +395 -0
- package/lib/queryBuilder/graph/GraphUpsert.js +466 -414
- package/lib/queryBuilder/graph/GraphWriter.js +1263 -0
- package/lib/queryBuilder/join/JoinResultColumn.js +1 -7
- package/lib/queryBuilder/join/JoinResultParser.js +6 -11
- package/lib/queryBuilder/join/RelationJoiner.js +66 -84
- package/lib/queryBuilder/join/TableNode.js +2 -8
- package/lib/queryBuilder/join/TableTree.js +3 -9
- package/lib/queryBuilder/join/utils.js +5 -15
- package/lib/queryBuilder/jsonDialects/JsonDialect.js +51 -0
- package/lib/queryBuilder/jsonDialects/MySqlJsonDialect.js +81 -0
- package/lib/queryBuilder/jsonDialects/PostgresJsonDialect.js +45 -0
- package/lib/queryBuilder/jsonDialects/SqliteJsonDialect.js +67 -0
- package/lib/queryBuilder/jsonDialects/index.js +44 -0
- package/lib/queryBuilder/operations/DelegateOperation.js +2 -8
- package/lib/queryBuilder/operations/DeleteOperation.js +10 -39
- package/lib/queryBuilder/operations/FindByIdOperation.js +7 -12
- package/lib/queryBuilder/operations/FindByIdsOperation.js +4 -8
- package/lib/queryBuilder/operations/FindOperation.js +14 -34
- package/lib/queryBuilder/operations/FirstOperation.js +6 -10
- package/lib/queryBuilder/operations/FromOperation.js +3 -9
- package/lib/queryBuilder/operations/InsertAndFetchOperation.js +13 -12
- package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +4 -10
- package/lib/queryBuilder/operations/InsertGraphOperation.js +7 -18
- package/lib/queryBuilder/operations/InsertOperation.js +118 -45
- package/lib/queryBuilder/operations/InstanceDeleteOperation.js +5 -12
- package/lib/queryBuilder/operations/InstanceFindOperation.js +4 -11
- package/lib/queryBuilder/operations/InstanceInsertOperation.js +2 -8
- package/lib/queryBuilder/operations/InstanceUpdateOperation.js +7 -14
- package/lib/queryBuilder/operations/JoinRelatedOperation.js +5 -11
- package/lib/queryBuilder/operations/KnexOperation.js +2 -8
- package/lib/queryBuilder/operations/LimitPerParentOperation.js +7 -69
- package/lib/queryBuilder/operations/MergeOperation.js +5 -11
- package/lib/queryBuilder/operations/NoneOperation.js +2 -8
- package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +20 -49
- package/lib/queryBuilder/operations/OnBuildKnexOperation.js +2 -8
- package/lib/queryBuilder/operations/OnBuildOperation.js +2 -8
- package/lib/queryBuilder/operations/OnErrorOperation.js +2 -8
- package/lib/queryBuilder/operations/QueryBuilderOperation.js +1 -7
- package/lib/queryBuilder/operations/RangeOperation.js +11 -26
- package/lib/queryBuilder/operations/RelateOperation.js +2 -8
- package/lib/queryBuilder/operations/ReturningOperation.js +3 -9
- package/lib/queryBuilder/operations/RunAfterOperation.js +2 -12
- package/lib/queryBuilder/operations/RunBeforeOperation.js +2 -8
- package/lib/queryBuilder/operations/UnrelateOperation.js +2 -8
- package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +14 -17
- package/lib/queryBuilder/operations/UpdateOperation.js +32 -132
- package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +8 -11
- package/lib/queryBuilder/operations/UpsertGraphOperation.js +6 -12
- package/lib/queryBuilder/operations/WhereCompositeOperation.js +3 -9
- package/lib/queryBuilder/operations/WhereGroupOperation.js +2 -8
- package/lib/queryBuilder/operations/eager/EagerOperation.js +3 -9
- package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +72 -10
- package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +2 -8
- package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +23 -44
- package/lib/queryBuilder/operations/fieldExpressions.js +122 -0
- package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +20 -0
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +44 -0
- package/lib/queryBuilder/operations/jsonApi/WhereJsonTypeOperation.js +14 -0
- package/lib/queryBuilder/operations/select/SelectOperation.js +11 -21
- package/lib/queryBuilder/operations/select/Selection.js +19 -17
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +4 -10
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +4 -10
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +4 -10
- package/lib/queryBuilder/operations/windowOrder.js +56 -0
- package/lib/queryBuilder/parsers/jsonFieldExpressionParser.js +3 -7
- package/lib/queryBuilder/parsers/relationExpressionParser.js +42 -43
- package/lib/queryBuilder/parsers/relationExpressionParser.pegjs +39 -36
- package/lib/queryBuilder/transformations/CompositeQueryTransformation.js +2 -8
- package/lib/queryBuilder/transformations/QueryTransformation.js +1 -7
- package/lib/queryBuilder/transformations/WrapMysqlModifySubqueryTransformation.js +3 -9
- package/lib/queryBuilder/transformations/index.js +3 -11
- package/lib/queryBuilder/whereGroups.js +9 -24
- package/lib/queryBuilder/withoutOrder.js +4 -11
- package/lib/relations/Relation.js +47 -28
- package/lib/relations/RelationDeleteOperation.js +4 -14
- package/lib/relations/RelationFindOperation.js +119 -90
- package/lib/relations/RelationInsertOperation.js +2 -8
- package/lib/relations/RelationOwner.js +5 -11
- package/lib/relations/RelationProperty.js +4 -10
- package/lib/relations/RelationUpdateOperation.js +4 -14
- package/lib/relations/RelationWriteResultOperation.js +15 -0
- package/lib/relations/belongsToMany/BelongsToManyDeleteOperation.js +23 -0
- package/lib/relations/belongsToMany/BelongsToManyFindOperation.js +35 -0
- package/lib/relations/belongsToMany/BelongsToManyInsertOperation.js +28 -0
- package/lib/relations/belongsToMany/BelongsToManyRelateOperation.js +16 -0
- package/lib/relations/belongsToMany/BelongsToManyRelation.js +276 -0
- package/lib/relations/belongsToMany/BelongsToManyUnrelateOperation.js +11 -0
- package/lib/relations/belongsToOne/BelongsToOneDeleteOperation.js +2 -8
- package/lib/relations/belongsToOne/BelongsToOneInsertOperation.js +6 -11
- package/lib/relations/belongsToOne/BelongsToOneRelateOperation.js +3 -9
- package/lib/relations/belongsToOne/BelongsToOneRelation.js +8 -19
- package/lib/relations/belongsToOne/BelongsToOneUnrelateOperation.js +53 -27
- package/lib/relations/hasMany/HasManyInsertOperation.js +5 -10
- package/lib/relations/hasMany/HasManyRelateOperation.js +5 -11
- package/lib/relations/hasMany/HasManyRelation.js +9 -11
- package/lib/relations/hasMany/HasManyUnrelateOperation.js +3 -9
- package/lib/relations/hasOne/HasOneRelation.js +2 -8
- package/lib/relations/hasOneThrough/HasOneThroughRelation.js +2 -8
- package/lib/relations/manyToMany/ManyToManyModifyMixin.js +10 -15
- package/lib/relations/manyToMany/ManyToManyMySqlModifyMixin.js +2 -8
- package/lib/relations/manyToMany/ManyToManyRelation.js +82 -50
- package/lib/relations/manyToMany/ManyToManySqliteModifyMixin.js +2 -8
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperation.js +5 -9
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +2 -8
- package/lib/relations/manyToMany/delete/ManyToManyDeleteSqliteOperation.js +3 -9
- package/lib/relations/manyToMany/find/ManyToManyFindOperation.js +20 -59
- package/lib/relations/manyToMany/insert/ManyToManyInsertOperation.js +6 -11
- package/lib/relations/manyToMany/relate/ManyToManyRelateOperation.js +4 -10
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateMySqlOperation.js +3 -9
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperation.js +5 -9
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateOperationBase.js +3 -9
- package/lib/relations/manyToMany/unrelate/ManyToManyUnrelateSqliteOperation.js +3 -9
- package/lib/relations/manyToMany/update/ManyToManyUpdateMySqlOperation.js +3 -9
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperation.js +5 -9
- package/lib/relations/manyToMany/update/ManyToManyUpdateOperationBase.js +64 -72
- package/lib/relations/manyToMany/update/ManyToManyUpdateSqliteOperation.js +3 -9
- package/lib/transaction.js +3 -9
- package/lib/utils/assert.js +3 -11
- package/lib/utils/buildUtils.js +2 -8
- package/lib/utils/classUtils.js +1 -7
- package/lib/utils/createModifier.js +2 -8
- package/lib/utils/identifierMapping.js +23 -27
- package/lib/utils/internalPropUtils.js +1 -7
- package/lib/utils/knexUtils.js +84 -40
- package/lib/utils/mixin.js +3 -10
- package/lib/utils/normalizeIds.js +2 -8
- package/lib/utils/objectUtils.js +41 -60
- package/lib/utils/parseFieldExpression.js +16 -16
- package/lib/utils/promiseUtils/after.js +2 -8
- package/lib/utils/promiseUtils/afterReturn.js +2 -8
- package/lib/utils/promiseUtils/index.js +7 -16
- package/lib/utils/promiseUtils/isPromise.js +2 -8
- package/lib/utils/promiseUtils/map.js +2 -8
- package/lib/utils/promiseUtils/mapAfterAllReturn.js +2 -8
- package/lib/utils/promiseUtils/try.js +2 -8
- package/lib/utils/resolveModel.js +10 -17
- package/lib/utils/tmpColumnUtils.js +2 -9
- package/lib/utils/warnings.js +2 -14
- package/package.json +25 -17
- package/typings/objection/index.d.ts +3217 -2179
- package/lib/.eslintrc.json +0 -8
- package/lib/model/graph/ModelGraph.js +0 -80
- package/lib/model/graph/ModelGraphBuilder.js +0 -241
- package/lib/model/graph/ModelGraphEdge.js +0 -52
- package/lib/model/graph/ModelGraphNode.js +0 -238
- package/lib/queryBuilder/graph/GraphAction.js +0 -69
- package/lib/queryBuilder/graph/GraphData.js +0 -53
- package/lib/queryBuilder/graph/GraphFetcher.js +0 -197
- package/lib/queryBuilder/graph/GraphNodeDbExistence.js +0 -184
- package/lib/queryBuilder/graph/GraphOperation.js +0 -27
- package/lib/queryBuilder/graph/delete/GraphDelete.js +0 -73
- package/lib/queryBuilder/graph/delete/GraphDeleteAction.js +0 -88
- package/lib/queryBuilder/graph/insert/DeferredRelationGraphInsertAction.js +0 -58
- package/lib/queryBuilder/graph/insert/GraphInsert.js +0 -296
- package/lib/queryBuilder/graph/insert/GraphInsertAction.js +0 -233
- package/lib/queryBuilder/graph/insert/JoinRowGraphInsertAction.js +0 -92
- package/lib/queryBuilder/graph/patch/GraphPatch.js +0 -20
- package/lib/queryBuilder/graph/patch/GraphPatchAction.js +0 -289
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsert.js +0 -31
- package/lib/queryBuilder/graph/recursiveUpsert/GraphRecursiveUpsertAction.js +0 -126
- package/lib/queryBuilder/operations/jsonApi/WhereJsonHasPostgresOperation.js +0 -30
- package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectPostgresOperation.js +0 -37
- package/lib/queryBuilder/operations/jsonApi/WhereJsonPostgresOperation.js +0 -62
- package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +0 -192
- package/lib/utils/wrapDbError.js +0 -64
package/lib/objection.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { Model as NativeModel } from './model/Model.js';
|
|
2
|
+
import { QueryBuilder as NativeQueryBuilder } from './queryBuilder/QueryBuilder.js';
|
|
3
|
+
import { AjvValidator as NativeAjvValidator } from './model/AjvValidator.js';
|
|
4
|
+
import { Validator as NativeValidator } from './model/Validator.js';
|
|
5
|
+
import { inherit } from './utils/classUtils.js';
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
export {
|
|
4
8
|
DBError,
|
|
5
9
|
UniqueViolationError,
|
|
6
10
|
NotNullViolationError,
|
|
@@ -8,55 +12,51 @@ const {
|
|
|
8
12
|
ConstraintViolationError,
|
|
9
13
|
CheckViolationError,
|
|
10
14
|
DataError,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const { transaction } = require('./transaction');
|
|
28
|
-
const { initialize } = require('./initialize');
|
|
29
|
-
|
|
30
|
-
const {
|
|
15
|
+
} from './dbErrors/index.js';
|
|
16
|
+
export { QueryBuilderBase } from './queryBuilder/QueryBuilderBase.js';
|
|
17
|
+
export { QueryBuilderOperation } from './queryBuilder/operations/QueryBuilderOperation.js';
|
|
18
|
+
export { RelationExpression } from './queryBuilder/RelationExpression.js';
|
|
19
|
+
export { ValidationError } from './model/ValidationError.js';
|
|
20
|
+
export { NotFoundError } from './model/NotFoundError.js';
|
|
21
|
+
export { Relation } from './relations/Relation.js';
|
|
22
|
+
export { HasOneRelation } from './relations/hasOne/HasOneRelation.js';
|
|
23
|
+
export { HasManyRelation } from './relations/hasMany/HasManyRelation.js';
|
|
24
|
+
export { BelongsToOneRelation } from './relations/belongsToOne/BelongsToOneRelation.js';
|
|
25
|
+
export { HasOneThroughRelation } from './relations/hasOneThrough/HasOneThroughRelation.js';
|
|
26
|
+
export { ManyToManyRelation } from './relations/manyToMany/ManyToManyRelation.js';
|
|
27
|
+
export { BelongsToManyRelation } from './relations/belongsToMany/BelongsToManyRelation.js';
|
|
28
|
+
export { transaction } from './transaction.js';
|
|
29
|
+
export { initialize } from './initialize.js';
|
|
30
|
+
export {
|
|
31
31
|
snakeCaseMappers,
|
|
32
32
|
knexSnakeCaseMappers,
|
|
33
33
|
knexIdentifierMapping,
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
} from './utils/identifierMapping.js';
|
|
35
|
+
export { compose, mixin } from './utils/mixin.js';
|
|
36
|
+
export { asArray } from './utils/objectUtils.js';
|
|
37
|
+
export { ref } from './queryBuilder/ReferenceBuilder.js';
|
|
38
|
+
export { val } from './queryBuilder/ValueBuilder.js';
|
|
39
|
+
export { raw } from './queryBuilder/RawBuilder.js';
|
|
40
|
+
export { fn } from './queryBuilder/FunctionBuilder.js';
|
|
41
41
|
|
|
42
42
|
// We need to wrap the classes, that people can inherit, with ES5 classes
|
|
43
43
|
// so that babel is able to use ES5 inheritance. sigh... Maybe people
|
|
44
44
|
// should stop transpiling node apps to ES5 in the year 2019? Node 6
|
|
45
45
|
// with full class support was released three years ago.
|
|
46
46
|
|
|
47
|
-
function Model() {
|
|
47
|
+
export function Model() {
|
|
48
48
|
// Nothing to do here.
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
function QueryBuilder(...args) {
|
|
51
|
+
export function QueryBuilder(...args) {
|
|
52
52
|
NativeQueryBuilder.init(this, ...args);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
function Validator(...args) {
|
|
55
|
+
export function Validator(...args) {
|
|
56
56
|
NativeValidator.init(this, ...args);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
function AjvValidator(...args) {
|
|
59
|
+
export function AjvValidator(...args) {
|
|
60
60
|
NativeAjvValidator.init(this, ...args);
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -66,41 +66,3 @@ inherit(Validator, NativeValidator);
|
|
|
66
66
|
inherit(AjvValidator, NativeAjvValidator);
|
|
67
67
|
|
|
68
68
|
Model.QueryBuilder = QueryBuilder;
|
|
69
|
-
|
|
70
|
-
module.exports = {
|
|
71
|
-
Model,
|
|
72
|
-
QueryBuilder,
|
|
73
|
-
QueryBuilderBase,
|
|
74
|
-
QueryBuilderOperation,
|
|
75
|
-
RelationExpression,
|
|
76
|
-
ValidationError,
|
|
77
|
-
NotFoundError,
|
|
78
|
-
AjvValidator,
|
|
79
|
-
Validator,
|
|
80
|
-
Relation,
|
|
81
|
-
HasOneRelation,
|
|
82
|
-
HasManyRelation,
|
|
83
|
-
BelongsToOneRelation,
|
|
84
|
-
HasOneThroughRelation,
|
|
85
|
-
ManyToManyRelation,
|
|
86
|
-
|
|
87
|
-
transaction,
|
|
88
|
-
initialize,
|
|
89
|
-
compose,
|
|
90
|
-
mixin,
|
|
91
|
-
ref,
|
|
92
|
-
val,
|
|
93
|
-
raw,
|
|
94
|
-
fn,
|
|
95
|
-
snakeCaseMappers,
|
|
96
|
-
knexSnakeCaseMappers,
|
|
97
|
-
knexIdentifierMapping,
|
|
98
|
-
|
|
99
|
-
DBError,
|
|
100
|
-
UniqueViolationError,
|
|
101
|
-
NotNullViolationError,
|
|
102
|
-
ForeignKeyViolationError,
|
|
103
|
-
ConstraintViolationError,
|
|
104
|
-
CheckViolationError,
|
|
105
|
-
DataError,
|
|
106
|
-
};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { RawBuilder, normalizeRawArgs } from './RawBuilder.js';
|
|
2
|
+
import { asSingle, isNumber } from '../utils/objectUtils.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
const { asSingle, isNumber } = require('../utils/objectUtils');
|
|
4
|
+
export class FunctionBuilder extends RawBuilder {}
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function fn(...argsIn) {
|
|
6
|
+
export function fn(...argsIn) {
|
|
9
7
|
const { sql, args } = normalizeRawArgs(argsIn);
|
|
10
8
|
return new FunctionBuilder(`${sql}(${args.map(() => '?').join(', ')})`, args);
|
|
11
9
|
}
|
|
@@ -27,8 +25,3 @@ fn.now = (precision) => {
|
|
|
27
25
|
// injection here.
|
|
28
26
|
return new FunctionBuilder(`CURRENT_TIMESTAMP(${precision})`, []);
|
|
29
27
|
};
|
|
30
|
-
|
|
31
|
-
module.exports = {
|
|
32
|
-
FunctionBuilder,
|
|
33
|
-
fn,
|
|
34
|
-
};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
class InternalOptions {
|
|
1
|
+
export class InternalOptions {
|
|
4
2
|
constructor() {
|
|
5
|
-
this.skipUndefined = false;
|
|
6
3
|
this.keepImplicitJoinProps = false;
|
|
7
4
|
this.returnImmediatelyValue = undefined;
|
|
8
5
|
this.isInternalQuery = false;
|
|
9
6
|
this.skipRelationFilter = false;
|
|
7
|
+
// The join table extras that related updates write, all of them if null:
|
|
8
|
+
this.joinTableExtras = null;
|
|
10
9
|
this.debug = false;
|
|
11
10
|
this.schema = undefined;
|
|
12
11
|
}
|
|
@@ -14,18 +13,14 @@ class InternalOptions {
|
|
|
14
13
|
clone() {
|
|
15
14
|
const copy = new this.constructor();
|
|
16
15
|
|
|
17
|
-
copy.skipUndefined = this.skipUndefined;
|
|
18
16
|
copy.keepImplicitJoinProps = this.keepImplicitJoinProps;
|
|
19
17
|
copy.returnImmediatelyValue = this.returnImmediatelyValue;
|
|
20
18
|
copy.isInternalQuery = this.isInternalQuery;
|
|
21
19
|
copy.skipRelationFilter = this.skipRelationFilter;
|
|
20
|
+
copy.joinTableExtras = this.joinTableExtras;
|
|
22
21
|
copy.debug = this.debug;
|
|
23
22
|
copy.schema = this.schema;
|
|
24
23
|
|
|
25
24
|
return copy;
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
module.exports = {
|
|
30
|
-
InternalOptions,
|
|
31
|
-
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { QueryBuilderOperationSupport } from './QueryBuilderOperationSupport.js';
|
|
2
|
+
import { KnexOperation } from './operations/KnexOperation.js';
|
|
3
|
+
import { setJoinBuilder } from './getJoinBuilder.js';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
const { KnexOperation } = require('./operations/KnexOperation');
|
|
5
|
-
|
|
6
|
-
class JoinBuilder extends QueryBuilderOperationSupport {
|
|
5
|
+
export class JoinBuilder extends QueryBuilderOperationSupport {
|
|
7
6
|
using(...args) {
|
|
8
7
|
return this.addOperation(new KnexOperation('using'), args);
|
|
9
8
|
}
|
|
@@ -137,6 +136,4 @@ class JoinBuilder extends QueryBuilderOperationSupport {
|
|
|
137
136
|
}
|
|
138
137
|
}
|
|
139
138
|
|
|
140
|
-
|
|
141
|
-
JoinBuilder,
|
|
142
|
-
};
|
|
139
|
+
setJoinBuilder(JoinBuilder);
|
|
@@ -1,58 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
1
|
+
import { wrapError } from '../dbErrors/index.js';
|
|
2
|
+
|
|
3
|
+
import { raw } from './RawBuilder.js';
|
|
4
|
+
import { createModifier } from '../utils/createModifier.js';
|
|
5
|
+
import { ValidationErrorType } from '../model/ValidationError.js';
|
|
6
|
+
import { isObject, isString, isFunction, last, flatten } from '../utils/objectUtils.js';
|
|
7
|
+
import {
|
|
8
|
+
RelationExpression,
|
|
9
|
+
DuplicateRelationError,
|
|
10
|
+
MisplacedTokenError,
|
|
11
|
+
} from './RelationExpression.js';
|
|
12
|
+
import { assertIdNotUndefined, assertHasIdColumn } from '../utils/assert.js';
|
|
13
|
+
import { warnOnce } from '../utils/warnings.js';
|
|
14
|
+
import { isMsSql } from '../utils/knexUtils.js';
|
|
15
|
+
|
|
16
|
+
import { Selection, isSameIdentifier } from './operations/select/Selection.js';
|
|
17
|
+
|
|
18
|
+
import { QueryBuilderContext } from './QueryBuilderContext.js';
|
|
19
|
+
import { QueryBuilderBase } from './QueryBuilderBase.js';
|
|
20
|
+
import { StaticHookArguments, isGraphQuery } from './StaticHookArguments.js';
|
|
21
|
+
|
|
22
|
+
import { FindOperation } from './operations/FindOperation.js';
|
|
23
|
+
import { DeleteOperation } from './operations/DeleteOperation.js';
|
|
24
|
+
import { UpdateOperation } from './operations/UpdateOperation.js';
|
|
25
|
+
import { InsertOperation } from './operations/InsertOperation.js';
|
|
26
|
+
import { RelateOperation } from './operations/RelateOperation.js';
|
|
27
|
+
import { UnrelateOperation } from './operations/UnrelateOperation.js';
|
|
28
|
+
|
|
29
|
+
import { JoinEagerOperation } from './operations/eager/JoinEagerOperation.js';
|
|
30
|
+
import { NaiveEagerOperation } from './operations/eager/NaiveEagerOperation.js';
|
|
31
|
+
import { WhereInEagerOperation } from './operations/eager/WhereInEagerOperation.js';
|
|
32
|
+
|
|
33
|
+
import { InsertGraphAndFetchOperation } from './operations/InsertGraphAndFetchOperation.js';
|
|
34
|
+
import { UpsertGraphAndFetchOperation } from './operations/UpsertGraphAndFetchOperation.js';
|
|
35
|
+
import { InsertAndFetchOperation } from './operations/InsertAndFetchOperation.js';
|
|
36
|
+
import { UpdateAndFetchOperation } from './operations/UpdateAndFetchOperation.js';
|
|
37
|
+
import { JoinRelatedOperation } from './operations/JoinRelatedOperation.js';
|
|
38
|
+
import { OnBuildKnexOperation } from './operations/OnBuildKnexOperation.js';
|
|
39
|
+
import { InsertGraphOperation } from './operations/InsertGraphOperation.js';
|
|
40
|
+
import { UpsertGraphOperation } from './operations/UpsertGraphOperation.js';
|
|
41
|
+
import { RunBeforeOperation } from './operations/RunBeforeOperation.js';
|
|
42
|
+
import { RunAfterOperation } from './operations/RunAfterOperation.js';
|
|
43
|
+
import { FindByIdOperation } from './operations/FindByIdOperation.js';
|
|
44
|
+
import { FindByIdsOperation } from './operations/FindByIdsOperation.js';
|
|
45
|
+
import { OnBuildOperation } from './operations/OnBuildOperation.js';
|
|
46
|
+
import { OnErrorOperation } from './operations/OnErrorOperation.js';
|
|
47
|
+
import { SelectOperation } from './operations/select/SelectOperation.js';
|
|
48
|
+
import { EagerOperation } from './operations/eager/EagerOperation.js';
|
|
49
|
+
import { RangeOperation } from './operations/RangeOperation.js';
|
|
50
|
+
import { FirstOperation } from './operations/FirstOperation.js';
|
|
51
|
+
import { NoneOperation } from './operations/NoneOperation.js';
|
|
52
|
+
import { LimitPerParentOperation } from './operations/LimitPerParentOperation.js';
|
|
53
|
+
import { FromOperation } from './operations/FromOperation.js';
|
|
54
|
+
import { KnexOperation } from './operations/KnexOperation.js';
|
|
55
|
+
import { clearUnsupportedOrder } from './withoutOrder.js';
|
|
56
|
+
// Loaded for its side effect: it registers itself for `getJoinBuilder()`, which
|
|
57
|
+
// the operations use to convert join callbacks.
|
|
58
|
+
import './JoinBuilder.js';
|
|
59
|
+
|
|
60
|
+
export class QueryBuilder extends QueryBuilderBase {
|
|
56
61
|
static init(self, modelClass) {
|
|
57
62
|
super.init(self, modelClass);
|
|
58
63
|
|
|
@@ -64,6 +69,7 @@ class QueryBuilder extends QueryBuilderBase {
|
|
|
64
69
|
|
|
65
70
|
self._allowedGraphExpression = null;
|
|
66
71
|
self._graphModifiersAtPath = [];
|
|
72
|
+
self._joinModifiersAtPath = [];
|
|
67
73
|
// The eager algorithm that was most recently used explicitly, see `withGraph()`.
|
|
68
74
|
self._graphAlgorithm = null;
|
|
69
75
|
self._isJoinChildQuery = false;
|
|
@@ -332,6 +338,15 @@ class QueryBuilder extends QueryBuilderBase {
|
|
|
332
338
|
return this;
|
|
333
339
|
}
|
|
334
340
|
|
|
341
|
+
joinModifiersAtPath() {
|
|
342
|
+
return this._joinModifiersAtPath;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
modifyJoin(path, modifier) {
|
|
346
|
+
this._joinModifiersAtPath.push({ path: RelationExpression.create(path), modifier });
|
|
347
|
+
return this;
|
|
348
|
+
}
|
|
349
|
+
|
|
335
350
|
findOptions(opt) {
|
|
336
351
|
if (arguments.length !== 0) {
|
|
337
352
|
this._findOperationOptions = Object.assign({}, this._findOperationOptions, opt);
|
|
@@ -434,6 +449,7 @@ class QueryBuilder extends QueryBuilderBase {
|
|
|
434
449
|
|
|
435
450
|
builder._allowedGraphExpression = this._allowedGraphExpression;
|
|
436
451
|
builder._graphModifiersAtPath = this._graphModifiersAtPath.slice();
|
|
452
|
+
builder._joinModifiersAtPath = this._joinModifiersAtPath.slice();
|
|
437
453
|
builder._graphAlgorithm = this._graphAlgorithm;
|
|
438
454
|
builder._isJoinChildQuery = this._isJoinChildQuery;
|
|
439
455
|
builder._findOperationOptions = this._findOperationOptions;
|
|
@@ -1023,35 +1039,21 @@ class QueryBuilder extends QueryBuilderBase {
|
|
|
1023
1039
|
}
|
|
1024
1040
|
|
|
1025
1041
|
updateById(id, modelOrObject) {
|
|
1026
|
-
|
|
1027
|
-
// can't get around it. See `whereGroups.js`.
|
|
1028
|
-
return addWhereGroup(this, () => this.findById(id))
|
|
1042
|
+
return this.findById(id)
|
|
1029
1043
|
.update(modelOrObject)
|
|
1030
|
-
.runBefore((
|
|
1031
|
-
if (!builder.internalOptions().skipUndefined) {
|
|
1032
|
-
assertIdNotUndefined(id, `undefined was passed to updateById`);
|
|
1033
|
-
}
|
|
1034
|
-
});
|
|
1044
|
+
.runBefore(() => assertIdNotUndefined(id, `undefined was passed to updateById`));
|
|
1035
1045
|
}
|
|
1036
1046
|
|
|
1037
1047
|
patchById(id, modelOrObject) {
|
|
1038
|
-
return
|
|
1048
|
+
return this.findById(id)
|
|
1039
1049
|
.patch(modelOrObject)
|
|
1040
|
-
.runBefore((
|
|
1041
|
-
if (!builder.internalOptions().skipUndefined) {
|
|
1042
|
-
assertIdNotUndefined(id, `undefined was passed to patchById`);
|
|
1043
|
-
}
|
|
1044
|
-
});
|
|
1050
|
+
.runBefore(() => assertIdNotUndefined(id, `undefined was passed to patchById`));
|
|
1045
1051
|
}
|
|
1046
1052
|
|
|
1047
1053
|
deleteById(id) {
|
|
1048
|
-
return
|
|
1054
|
+
return this.findById(id)
|
|
1049
1055
|
.delete()
|
|
1050
|
-
.runBefore((
|
|
1051
|
-
if (!builder.internalOptions().skipUndefined) {
|
|
1052
|
-
assertIdNotUndefined(id, `undefined was passed to deleteById`);
|
|
1053
|
-
}
|
|
1054
|
-
});
|
|
1056
|
+
.runBefore(() => assertIdNotUndefined(id, `undefined was passed to deleteById`));
|
|
1055
1057
|
}
|
|
1056
1058
|
|
|
1057
1059
|
findById(...args) {
|
|
@@ -1318,17 +1320,13 @@ function parseRelationExpression(modelClass, exp) {
|
|
|
1318
1320
|
try {
|
|
1319
1321
|
return RelationExpression.create(exp);
|
|
1320
1322
|
} catch (err) {
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
type: ValidationErrorType.RelationExpression,
|
|
1329
|
-
message: `Invalid relation expression "${exp}"`,
|
|
1330
|
-
});
|
|
1331
|
-
}
|
|
1323
|
+
throw modelClass.createValidationError({
|
|
1324
|
+
type: ValidationErrorType.RelationExpression,
|
|
1325
|
+
message:
|
|
1326
|
+
err instanceof DuplicateRelationError || err instanceof MisplacedTokenError
|
|
1327
|
+
? `Invalid relation expression "${exp}": ${err.message}`
|
|
1328
|
+
: `Invalid relation expression "${exp}"`,
|
|
1329
|
+
});
|
|
1332
1330
|
}
|
|
1333
1331
|
}
|
|
1334
1332
|
|
|
@@ -1465,15 +1463,51 @@ function afterExecute(builder, result) {
|
|
|
1465
1463
|
promise = chainOperationHooks(promise, builder, 'onAfter1');
|
|
1466
1464
|
promise = chainOperationHooks(promise, builder, 'onAfter2');
|
|
1467
1465
|
promise = promise.then((result) => omitInternalSelections(builder, result));
|
|
1466
|
+
promise = chainOperationHooks(promise, builder, 'onAfter3');
|
|
1467
|
+
promise = promise.then((result) => callStaticAfterHook(builder, result));
|
|
1468
1468
|
|
|
1469
1469
|
promise = chainHooks(promise, builder, builder.context().runAfter);
|
|
1470
1470
|
promise = chainHooks(promise, builder, builder.internalContext().runAfter);
|
|
1471
|
-
|
|
1472
|
-
promise = chainOperationHooks(promise, builder, 'onAfter3');
|
|
1471
|
+
promise = chainHooks(promise, builder, getRunAfterFuncs(builder));
|
|
1473
1472
|
|
|
1474
1473
|
return promise;
|
|
1475
1474
|
}
|
|
1476
1475
|
|
|
1476
|
+
// Call the static after hook of the model class with the value that the query
|
|
1477
|
+
// returns, once its shape is final.
|
|
1478
|
+
async function callStaticAfterHook(builder, result) {
|
|
1479
|
+
const modelClass = builder.modelClass();
|
|
1480
|
+
let afterHook = null;
|
|
1481
|
+
|
|
1482
|
+
if (isGraphQuery(builder)) {
|
|
1483
|
+
// Leave the hooks to the queries that the graph runs.
|
|
1484
|
+
} else if (builder.isInsert()) {
|
|
1485
|
+
afterHook = modelClass.afterInsert;
|
|
1486
|
+
} else if (builder.isUpdate()) {
|
|
1487
|
+
afterHook = modelClass.afterUpdate;
|
|
1488
|
+
} else if (builder.isDelete()) {
|
|
1489
|
+
afterHook = modelClass.afterDelete;
|
|
1490
|
+
} else if (builder.isFind() && !builder.findOptions().dontCallFindHooks) {
|
|
1491
|
+
afterHook = modelClass.afterFind;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
if (afterHook) {
|
|
1495
|
+
const args = StaticHookArguments.create({ builder, result });
|
|
1496
|
+
const maybeResult = await afterHook.call(modelClass, args);
|
|
1497
|
+
return maybeResult === undefined ? result : maybeResult;
|
|
1498
|
+
} else {
|
|
1499
|
+
return result;
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
// The callbacks of `runAfter()`, and the ones that `range()`, `throwIfNotFound()`
|
|
1504
|
+
// and `traverse()` add, in the order they were added to the query:
|
|
1505
|
+
function getRunAfterFuncs(builder) {
|
|
1506
|
+
const funcs = [];
|
|
1507
|
+
builder.forEachOperation(RunAfterOperation, (op) => funcs.push(op.func));
|
|
1508
|
+
return funcs;
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1477
1511
|
function omitInternalSelections(builder, result) {
|
|
1478
1512
|
const props = builder._internalSelections;
|
|
1479
1513
|
|
|
@@ -1508,7 +1542,7 @@ function handleExecuteError(builder, err) {
|
|
|
1508
1542
|
return Promise.resolve(err.value);
|
|
1509
1543
|
}
|
|
1510
1544
|
|
|
1511
|
-
let promise = Promise.reject(
|
|
1545
|
+
let promise = Promise.reject(wrapError(err));
|
|
1512
1546
|
|
|
1513
1547
|
builder.forEachOperation(true, (op) => {
|
|
1514
1548
|
if (op.hasOnError()) {
|
|
@@ -1714,15 +1748,16 @@ function createModels(result, builder) {
|
|
|
1714
1748
|
}
|
|
1715
1749
|
|
|
1716
1750
|
const modelClass = builder.resultModelClass();
|
|
1751
|
+
const options = { knex: builder.knex() };
|
|
1717
1752
|
|
|
1718
1753
|
if (Array.isArray(result)) {
|
|
1719
1754
|
if (result.length && shouldBeConvertedToModel(result[0], modelClass)) {
|
|
1720
1755
|
for (let i = 0, l = result.length; i < l; ++i) {
|
|
1721
|
-
result[i] = modelClass.fromDatabaseJson(result[i]);
|
|
1756
|
+
result[i] = modelClass.fromDatabaseJson(result[i], options);
|
|
1722
1757
|
}
|
|
1723
1758
|
}
|
|
1724
1759
|
} else if (shouldBeConvertedToModel(result, modelClass)) {
|
|
1725
|
-
result = modelClass.fromDatabaseJson(result);
|
|
1760
|
+
result = modelClass.fromDatabaseJson(result, options);
|
|
1726
1761
|
}
|
|
1727
1762
|
|
|
1728
1763
|
return result;
|
|
@@ -1781,7 +1816,3 @@ function unrelateOperationFactory() {
|
|
|
1781
1816
|
function deleteOperationFactory() {
|
|
1782
1817
|
return new DeleteOperation('delete');
|
|
1783
1818
|
}
|
|
1784
|
-
|
|
1785
|
-
module.exports = {
|
|
1786
|
-
QueryBuilder,
|
|
1787
|
-
};
|