@abedmurrar/objection 4.0.0-beta.1 → 4.0.0-beta.2
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/queryBuilder/operations/DelegateOperation.js +6 -6
- package/lib/queryBuilder/operations/DeleteOperation.js +11 -11
- package/lib/queryBuilder/operations/FindByIdOperation.js +8 -8
- package/lib/queryBuilder/operations/FindByIdsOperation.js +6 -6
- package/lib/queryBuilder/operations/FindOperation.js +23 -23
- package/lib/queryBuilder/operations/FirstOperation.js +6 -6
- package/lib/queryBuilder/operations/FromOperation.js +13 -13
- package/lib/queryBuilder/operations/InsertAndFetchOperation.js +12 -12
- package/lib/queryBuilder/operations/InsertGraphAndFetchOperation.js +10 -10
- package/lib/queryBuilder/operations/InsertGraphOperation.js +11 -11
- package/lib/queryBuilder/operations/InsertOperation.js +23 -22
- package/lib/queryBuilder/operations/InstanceDeleteOperation.js +12 -12
- package/lib/queryBuilder/operations/InstanceFindOperation.js +10 -10
- package/lib/queryBuilder/operations/InstanceInsertOperation.js +6 -6
- package/lib/queryBuilder/operations/InstanceUpdateOperation.js +14 -14
- package/lib/queryBuilder/operations/JoinRelatedOperation.js +13 -13
- package/lib/queryBuilder/operations/KnexOperation.js +6 -6
- package/lib/queryBuilder/operations/MergeOperation.js +11 -11
- package/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js +26 -22
- package/lib/queryBuilder/operations/OnBuildKnexOperation.js +6 -6
- package/lib/queryBuilder/operations/OnBuildOperation.js +6 -6
- package/lib/queryBuilder/operations/OnErrorOperation.js +6 -6
- package/lib/queryBuilder/operations/QueryBuilderOperation.js +6 -4
- package/lib/queryBuilder/operations/RangeOperation.js +7 -6
- package/lib/queryBuilder/operations/RelateOperation.js +6 -6
- package/lib/queryBuilder/operations/ReturningOperation.js +8 -8
- package/lib/queryBuilder/operations/RunAfterOperation.js +6 -6
- package/lib/queryBuilder/operations/RunBeforeOperation.js +6 -6
- package/lib/queryBuilder/operations/UnrelateOperation.js +6 -6
- package/lib/queryBuilder/operations/UpdateAndFetchOperation.js +12 -12
- package/lib/queryBuilder/operations/UpdateOperation.js +24 -24
- package/lib/queryBuilder/operations/UpsertGraphAndFetchOperation.js +10 -10
- package/lib/queryBuilder/operations/UpsertGraphOperation.js +10 -10
- package/lib/queryBuilder/operations/WhereCompositeOperation.js +8 -8
- package/lib/queryBuilder/operations/WhereInOperation.js +11 -9
- package/lib/queryBuilder/operations/eager/EagerOperation.js +11 -9
- package/lib/queryBuilder/operations/eager/JoinEagerOperation.js +10 -12
- package/lib/queryBuilder/operations/eager/NaiveEagerOperation.js +6 -6
- package/lib/queryBuilder/operations/eager/WhereInEagerOperation.js +64 -28
- package/lib/queryBuilder/operations/jsonApi/WhereJsonHasOperation.js +45 -12
- package/lib/queryBuilder/operations/jsonApi/WhereJsonNotObjectOperation.js +45 -12
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOperation.js +45 -12
- package/lib/queryBuilder/operations/jsonApi/WhereJsonOverlapsOperation.js +46 -13
- package/lib/queryBuilder/operations/jsonApi/mysqlJsonApi.js +22 -27
- package/lib/queryBuilder/operations/jsonApi/postgresJsonApi.js +51 -17
- package/lib/queryBuilder/operations/select/SelectOperation.js +12 -12
- package/lib/queryBuilder/operations/select/Selection.js +23 -19
- package/lib/queryBuilder/operations/types.js +8 -0
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeMsSqlOperation.js +13 -12
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeOperation.js +11 -11
- package/lib/queryBuilder/operations/whereInComposite/WhereInCompositeSqliteOperation.js +10 -10
- package/lib/relations/RelationDeleteOperation.js +0 -2
- package/lib/relations/RelationFindOperation.js +0 -1
- package/lib/relations/RelationUpdateOperation.js +0 -1
- package/lib/relations/manyToMany/delete/ManyToManyDeleteOperationBase.js +0 -1
- package/package.json +1 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DelegateOperation = void 0;
|
|
4
|
+
const QueryBuilderOperation_1 = require("./QueryBuilderOperation");
|
|
3
5
|
// Operation that simply delegates all calls to the operation passed
|
|
4
6
|
// to to the constructor in `opt.delegate`.
|
|
5
|
-
class DelegateOperation extends QueryBuilderOperation {
|
|
7
|
+
class DelegateOperation extends QueryBuilderOperation_1.QueryBuilderOperation {
|
|
6
8
|
constructor(name, opt) {
|
|
7
9
|
super(name, opt);
|
|
8
10
|
this.delegate = opt.delegate;
|
|
@@ -96,6 +98,4 @@ class DelegateOperation extends QueryBuilderOperation {
|
|
|
96
98
|
return clone;
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
|
-
|
|
100
|
-
DelegateOperation,
|
|
101
|
-
};
|
|
101
|
+
exports.DelegateOperation = DelegateOperation;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeleteOperation = void 0;
|
|
4
|
+
const QueryBuilderOperation_1 = require("./QueryBuilderOperation");
|
|
5
|
+
const StaticHookArguments_1 = require("../StaticHookArguments");
|
|
6
|
+
class DeleteOperation extends QueryBuilderOperation_1.QueryBuilderOperation {
|
|
5
7
|
async onBefore2(builder, result) {
|
|
6
8
|
await callBeforeDelete(builder);
|
|
7
9
|
return result;
|
|
@@ -16,24 +18,25 @@ class DeleteOperation extends QueryBuilderOperation {
|
|
|
16
18
|
return null;
|
|
17
19
|
}
|
|
18
20
|
}
|
|
21
|
+
exports.DeleteOperation = DeleteOperation;
|
|
19
22
|
function callBeforeDelete(builder) {
|
|
20
23
|
return callStaticBeforeDelete(builder);
|
|
21
24
|
}
|
|
22
25
|
function callStaticBeforeDelete(builder) {
|
|
23
|
-
if (!hasStaticHook(builder.modelClass(), 'beforeDelete')) {
|
|
26
|
+
if (!(0, StaticHookArguments_1.hasStaticHook)(builder.modelClass(), 'beforeDelete')) {
|
|
24
27
|
return undefined;
|
|
25
28
|
}
|
|
26
|
-
const args = StaticHookArguments.create({ builder });
|
|
29
|
+
const args = StaticHookArguments_1.StaticHookArguments.create({ builder });
|
|
27
30
|
return builder.modelClass().beforeDelete(args);
|
|
28
31
|
}
|
|
29
32
|
function callAfterDelete(builder, result) {
|
|
30
33
|
return callStaticAfterDelete(builder, result);
|
|
31
34
|
}
|
|
32
35
|
async function callStaticAfterDelete(builder, result) {
|
|
33
|
-
if (!hasStaticHook(builder.modelClass(), 'afterDelete')) {
|
|
36
|
+
if (!(0, StaticHookArguments_1.hasStaticHook)(builder.modelClass(), 'afterDelete')) {
|
|
34
37
|
return result;
|
|
35
38
|
}
|
|
36
|
-
const args = StaticHookArguments.create({ builder, result });
|
|
39
|
+
const args = StaticHookArguments_1.StaticHookArguments.create({ builder, result });
|
|
37
40
|
const maybeResult = await builder.modelClass().afterDelete(args);
|
|
38
41
|
if (maybeResult === undefined) {
|
|
39
42
|
return result;
|
|
@@ -42,6 +45,3 @@ async function callStaticAfterDelete(builder, result) {
|
|
|
42
45
|
return maybeResult;
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
|
-
module.exports = {
|
|
46
|
-
DeleteOperation,
|
|
47
|
-
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FindByIdOperation = void 0;
|
|
4
|
+
const QueryBuilderOperation_1 = require("./QueryBuilderOperation");
|
|
5
|
+
const assert_1 = require("../../utils/assert");
|
|
6
|
+
class FindByIdOperation extends QueryBuilderOperation_1.QueryBuilderOperation {
|
|
5
7
|
constructor(name, opt) {
|
|
6
8
|
super(name, opt);
|
|
7
9
|
this.id = this.opt.id;
|
|
@@ -14,7 +16,7 @@ class FindByIdOperation extends QueryBuilderOperation {
|
|
|
14
16
|
}
|
|
15
17
|
onBuild(builder) {
|
|
16
18
|
if (!builder.internalOptions().skipUndefined) {
|
|
17
|
-
assertIdNotUndefined(this.id, `undefined was passed to ${this.name}`);
|
|
19
|
+
(0, assert_1.assertIdNotUndefined)(this.id, `undefined was passed to ${this.name}`);
|
|
18
20
|
}
|
|
19
21
|
builder.whereComposite(builder.fullIdColumn(), this.id);
|
|
20
22
|
}
|
|
@@ -24,6 +26,4 @@ class FindByIdOperation extends QueryBuilderOperation {
|
|
|
24
26
|
return clone;
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
|
-
|
|
28
|
-
FindByIdOperation,
|
|
29
|
-
};
|
|
29
|
+
exports.FindByIdOperation = FindByIdOperation;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FindByIdsOperation = void 0;
|
|
4
|
+
const QueryBuilderOperation_1 = require("./QueryBuilderOperation");
|
|
5
|
+
class FindByIdsOperation extends QueryBuilderOperation_1.QueryBuilderOperation {
|
|
4
6
|
constructor(name, opt) {
|
|
5
7
|
super(name, opt);
|
|
6
8
|
this.ids = null;
|
|
@@ -18,6 +20,4 @@ class FindByIdsOperation extends QueryBuilderOperation {
|
|
|
18
20
|
return clone;
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
FindByIdsOperation,
|
|
23
|
-
};
|
|
23
|
+
exports.FindByIdsOperation = FindByIdsOperation;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FindOperation = void 0;
|
|
4
|
+
const QueryBuilderOperation_1 = require("./QueryBuilderOperation");
|
|
5
|
+
const StaticHookArguments_1 = require("../StaticHookArguments");
|
|
6
|
+
const promiseUtils_1 = require("../../utils/promiseUtils");
|
|
7
|
+
const objectUtils_1 = require("../../utils/objectUtils");
|
|
8
|
+
class FindOperation extends QueryBuilderOperation_1.QueryBuilderOperation {
|
|
7
9
|
onBefore2(builder, result) {
|
|
8
|
-
return afterReturn(callStaticBeforeFind(builder), result);
|
|
10
|
+
return (0, promiseUtils_1.afterReturn)(callStaticBeforeFind(builder), result);
|
|
9
11
|
}
|
|
10
12
|
onAfter3(builder, results) {
|
|
11
13
|
const opt = builder.findOptions();
|
|
@@ -17,25 +19,26 @@ class FindOperation extends QueryBuilderOperation {
|
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
}
|
|
22
|
+
exports.FindOperation = FindOperation;
|
|
20
23
|
function callStaticBeforeFind(builder) {
|
|
21
|
-
if (!hasStaticHook(builder.modelClass(), 'beforeFind')) {
|
|
24
|
+
if (!(0, StaticHookArguments_1.hasStaticHook)(builder.modelClass(), 'beforeFind')) {
|
|
22
25
|
return undefined;
|
|
23
26
|
}
|
|
24
|
-
const args = StaticHookArguments.create({ builder });
|
|
27
|
+
const args = StaticHookArguments_1.StaticHookArguments.create({ builder });
|
|
25
28
|
return builder.modelClass().beforeFind(args);
|
|
26
29
|
}
|
|
27
30
|
function callAfterFind(builder, result) {
|
|
28
31
|
const opt = builder.findOptions();
|
|
29
32
|
const maybePromise = callInstanceAfterFind(builder.context(), result, opt.callAfterFindDeeply);
|
|
30
|
-
return after(maybePromise, () => callStaticAfterFind(builder, result));
|
|
33
|
+
return (0, promiseUtils_1.after)(maybePromise, () => callStaticAfterFind(builder, result));
|
|
31
34
|
}
|
|
32
35
|
function callStaticAfterFind(builder, result) {
|
|
33
|
-
if (!hasStaticHook(builder.modelClass(), 'afterFind')) {
|
|
36
|
+
if (!(0, StaticHookArguments_1.hasStaticHook)(builder.modelClass(), 'afterFind')) {
|
|
34
37
|
return result;
|
|
35
38
|
}
|
|
36
|
-
const args = StaticHookArguments.create({ builder, result });
|
|
39
|
+
const args = StaticHookArguments_1.StaticHookArguments.create({ builder, result });
|
|
37
40
|
const maybePromise = builder.modelClass().afterFind(args);
|
|
38
|
-
return after(maybePromise, (maybeResult) => {
|
|
41
|
+
return (0, promiseUtils_1.after)(maybePromise, (maybeResult) => {
|
|
39
42
|
if (maybeResult === undefined) {
|
|
40
43
|
return result;
|
|
41
44
|
}
|
|
@@ -58,14 +61,14 @@ function callInstanceAfterFind(ctx, results, deep) {
|
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
function callAfterFindArray(ctx, results, deep) {
|
|
61
|
-
if (results.length === 0 || !isObject(results[0])) {
|
|
64
|
+
if (results.length === 0 || !(0, objectUtils_1.isObject)(results[0])) {
|
|
62
65
|
return results;
|
|
63
66
|
}
|
|
64
67
|
const mapped = new Array(results.length);
|
|
65
68
|
let containsPromise = false;
|
|
66
69
|
for (let i = 0, l = results.length; i < l; ++i) {
|
|
67
70
|
mapped[i] = callAfterFindForOne(ctx, results[i], results[i], deep);
|
|
68
|
-
if (isPromise(mapped[i])) {
|
|
71
|
+
if ((0, promiseUtils_1.isPromise)(mapped[i])) {
|
|
69
72
|
containsPromise = true;
|
|
70
73
|
}
|
|
71
74
|
}
|
|
@@ -77,7 +80,7 @@ function callAfterFindArray(ctx, results, deep) {
|
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
82
|
function callAfterFindForOne(ctx, model, result, deep) {
|
|
80
|
-
if (!isObject(model) || !model.$isObjectionModel) {
|
|
83
|
+
if (!(0, objectUtils_1.isObject)(model) || !model.$isObjectionModel) {
|
|
81
84
|
return result;
|
|
82
85
|
}
|
|
83
86
|
if (deep) {
|
|
@@ -104,7 +107,7 @@ function callAfterFindForRelations(ctx, model, results) {
|
|
|
104
107
|
const value = model[key];
|
|
105
108
|
if (isRelation(value)) {
|
|
106
109
|
const maybePromise = callInstanceAfterFind(ctx, value, true);
|
|
107
|
-
if (isPromise(maybePromise)) {
|
|
110
|
+
if ((0, promiseUtils_1.isPromise)(maybePromise)) {
|
|
108
111
|
containsPromise = true;
|
|
109
112
|
}
|
|
110
113
|
results.push(maybePromise);
|
|
@@ -113,17 +116,17 @@ function callAfterFindForRelations(ctx, model, results) {
|
|
|
113
116
|
return containsPromise;
|
|
114
117
|
}
|
|
115
118
|
function isRelation(value) {
|
|
116
|
-
return ((isObject(value) && value.$isObjectionModel) ||
|
|
119
|
+
return (((0, objectUtils_1.isObject)(value) && value.$isObjectionModel) ||
|
|
117
120
|
(isNonEmptyObjectArray(value) && value[0].$isObjectionModel));
|
|
118
121
|
}
|
|
119
122
|
function isNonEmptyObjectArray(value) {
|
|
120
|
-
return Array.isArray(value) && value.length > 0 && isObject(value[0]);
|
|
123
|
+
return Array.isArray(value) && value.length > 0 && (0, objectUtils_1.isObject)(value[0]);
|
|
121
124
|
}
|
|
122
125
|
function doCallAfterFind(ctx, model, result) {
|
|
123
126
|
const afterFind = getAfterFindHook(model);
|
|
124
127
|
if (afterFind !== null) {
|
|
125
128
|
const maybePromise = afterFind.call(model, ctx);
|
|
126
|
-
if (isPromise(maybePromise)) {
|
|
129
|
+
if ((0, promiseUtils_1.isPromise)(maybePromise)) {
|
|
127
130
|
return maybePromise.then(() => result);
|
|
128
131
|
}
|
|
129
132
|
else {
|
|
@@ -142,6 +145,3 @@ function getAfterFindHook(model) {
|
|
|
142
145
|
return null;
|
|
143
146
|
}
|
|
144
147
|
}
|
|
145
|
-
module.exports = {
|
|
146
|
-
FindOperation,
|
|
147
|
-
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FirstOperation = void 0;
|
|
4
|
+
const QueryBuilderOperation_1 = require("./QueryBuilderOperation");
|
|
5
|
+
class FirstOperation extends QueryBuilderOperation_1.QueryBuilderOperation {
|
|
4
6
|
onBuildKnex(knexBuilder, builder) {
|
|
5
7
|
const modelClass = builder.modelClass();
|
|
6
8
|
if (builder.isFind() && modelClass.useLimitInFirst) {
|
|
@@ -17,6 +19,4 @@ class FirstOperation extends QueryBuilderOperation {
|
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
|
-
|
|
21
|
-
FirstOperation,
|
|
22
|
-
};
|
|
22
|
+
exports.FirstOperation = FirstOperation;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FromOperation = void 0;
|
|
4
|
+
const ObjectionToKnexConvertingOperation_1 = require("./ObjectionToKnexConvertingOperation");
|
|
5
|
+
const objectUtils_1 = require("../../utils/objectUtils");
|
|
6
|
+
const resolveModel_1 = require("../../utils/resolveModel");
|
|
5
7
|
const ALIAS_REGEX = /\s+as\s+/i;
|
|
6
8
|
// FromOperation corresponds to a `.from(args)` call. The call is delegated to
|
|
7
9
|
// knex, but we first try to parse the arguments so that we can determine which
|
|
8
10
|
// tables have been mentioned in a query's from clause. We only parse string
|
|
9
11
|
// references and not `raw` or `ref` etc. references at this point thouhg.
|
|
10
|
-
class FromOperation extends ObjectionToKnexConvertingOperation {
|
|
12
|
+
class FromOperation extends ObjectionToKnexConvertingOperation_1.ObjectionToKnexConvertingOperation {
|
|
11
13
|
constructor(name, opt) {
|
|
12
14
|
super(name, opt);
|
|
13
15
|
this.table = null;
|
|
@@ -37,14 +39,15 @@ class FromOperation extends ObjectionToKnexConvertingOperation {
|
|
|
37
39
|
return clone;
|
|
38
40
|
}
|
|
39
41
|
}
|
|
42
|
+
exports.FromOperation = FromOperation;
|
|
40
43
|
function parseTableAndAlias(arg, builder) {
|
|
41
|
-
if (isModelClass(arg)) {
|
|
44
|
+
if ((0, resolveModel_1.isModelClass)(arg)) {
|
|
42
45
|
return parseTableAndAliasFromString(arg.getTableName());
|
|
43
46
|
}
|
|
44
|
-
else if (isString(arg)) {
|
|
47
|
+
else if ((0, objectUtils_1.isString)(arg)) {
|
|
45
48
|
return parseTableAndAliasFromString(arg);
|
|
46
49
|
}
|
|
47
|
-
else if (isPlainObject(arg)) {
|
|
50
|
+
else if ((0, objectUtils_1.isPlainObject)(arg)) {
|
|
48
51
|
return parseTableAndAliasFromObject(arg, builder);
|
|
49
52
|
}
|
|
50
53
|
else {
|
|
@@ -72,8 +75,8 @@ function parseTableAndAliasFromString(arg) {
|
|
|
72
75
|
}
|
|
73
76
|
function parseTableAndAliasFromObject(arg, builder) {
|
|
74
77
|
for (const alias of Object.keys(arg)) {
|
|
75
|
-
const value = isModelClass(arg[alias]) ? arg[alias].getTableName() : arg[alias];
|
|
76
|
-
if (!isString(value)) {
|
|
78
|
+
const value = (0, resolveModel_1.isModelClass)(arg[alias]) ? arg[alias].getTableName() : arg[alias];
|
|
79
|
+
if (!(0, objectUtils_1.isString)(value)) {
|
|
77
80
|
continue;
|
|
78
81
|
}
|
|
79
82
|
const table = value.trim();
|
|
@@ -86,6 +89,3 @@ function parseTableAndAliasFromObject(arg, builder) {
|
|
|
86
89
|
}
|
|
87
90
|
throw new Error(`one of the tables in ${JSON.stringify(arg)} must be the query's model class's table.`);
|
|
88
91
|
}
|
|
89
|
-
module.exports = {
|
|
90
|
-
FromOperation,
|
|
91
|
-
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InsertAndFetchOperation = void 0;
|
|
4
|
+
const InsertOperation_1 = require("./InsertOperation");
|
|
5
|
+
const DelegateOperation_1 = require("./DelegateOperation");
|
|
6
|
+
const modelUtils_1 = require("../../model/modelUtils");
|
|
7
|
+
const objectUtils_1 = require("../../utils/objectUtils");
|
|
8
|
+
class InsertAndFetchOperation extends DelegateOperation_1.DelegateOperation {
|
|
7
9
|
constructor(name, opt) {
|
|
8
10
|
super(name, opt);
|
|
9
|
-
if (!this.delegate.is(InsertOperation)) {
|
|
11
|
+
if (!this.delegate.is(InsertOperation_1.InsertOperation)) {
|
|
10
12
|
throw new Error('Invalid delegate');
|
|
11
13
|
}
|
|
12
14
|
}
|
|
@@ -16,7 +18,7 @@ class InsertAndFetchOperation extends DelegateOperation {
|
|
|
16
18
|
async onAfter2(builder, inserted) {
|
|
17
19
|
const modelClass = builder.modelClass();
|
|
18
20
|
const insertedModels = await super.onAfter2(builder, inserted);
|
|
19
|
-
const insertedModelArray = asArray(insertedModels);
|
|
21
|
+
const insertedModelArray = (0, objectUtils_1.asArray)(insertedModels);
|
|
20
22
|
const idProps = modelClass.getIdPropertyArray();
|
|
21
23
|
const ids = insertedModelArray.map((model) => model.$id());
|
|
22
24
|
const fetchedModels = await modelClass
|
|
@@ -24,7 +26,7 @@ class InsertAndFetchOperation extends DelegateOperation {
|
|
|
24
26
|
.childQueryOf(builder)
|
|
25
27
|
.findByIds(ids)
|
|
26
28
|
.castTo(builder.resultModelClass());
|
|
27
|
-
const modelsById = keyByProps(fetchedModels, idProps);
|
|
29
|
+
const modelsById = (0, modelUtils_1.keyByProps)(fetchedModels, idProps);
|
|
28
30
|
// Instead of returning the freshly fetched models, update the input
|
|
29
31
|
// models with the fresh values.
|
|
30
32
|
insertedModelArray.forEach((insertedModel) => {
|
|
@@ -33,6 +35,4 @@ class InsertAndFetchOperation extends DelegateOperation {
|
|
|
33
35
|
return insertedModels;
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
|
-
|
|
37
|
-
InsertAndFetchOperation,
|
|
38
|
-
};
|
|
38
|
+
exports.InsertAndFetchOperation = InsertAndFetchOperation;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InsertGraphAndFetchOperation = void 0;
|
|
4
|
+
const DelegateOperation_1 = require("./DelegateOperation");
|
|
5
|
+
const InsertGraphOperation_1 = require("./InsertGraphOperation");
|
|
6
|
+
const RelationExpression_1 = require("../RelationExpression");
|
|
7
|
+
class InsertGraphAndFetchOperation extends DelegateOperation_1.DelegateOperation {
|
|
6
8
|
constructor(name, opt) {
|
|
7
9
|
super(name, opt);
|
|
8
|
-
if (!this.delegate.is(InsertGraphOperation)) {
|
|
10
|
+
if (!this.delegate.is(InsertGraphOperation_1.InsertGraphOperation)) {
|
|
9
11
|
throw new Error('Invalid delegate');
|
|
10
12
|
}
|
|
11
13
|
}
|
|
@@ -19,7 +21,7 @@ class InsertGraphAndFetchOperation extends DelegateOperation {
|
|
|
19
21
|
if (this.models.length === 0) {
|
|
20
22
|
return this.isArray ? [] : null;
|
|
21
23
|
}
|
|
22
|
-
const eager = RelationExpression.fromModelGraph(this.models);
|
|
24
|
+
const eager = RelationExpression_1.RelationExpression.fromModelGraph(this.models);
|
|
23
25
|
const modelClass = this.models[0].constructor;
|
|
24
26
|
const ids = this.models.map((model) => model.$id());
|
|
25
27
|
const models = await modelClass
|
|
@@ -30,6 +32,4 @@ class InsertGraphAndFetchOperation extends DelegateOperation {
|
|
|
30
32
|
return this.isArray ? models : models[0] || null;
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
|
-
|
|
34
|
-
InsertGraphAndFetchOperation,
|
|
35
|
-
};
|
|
35
|
+
exports.InsertGraphAndFetchOperation = InsertGraphAndFetchOperation;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InsertGraphOperation = void 0;
|
|
4
|
+
const DelegateOperation_1 = require("./DelegateOperation");
|
|
5
|
+
const InsertOperation_1 = require("./InsertOperation");
|
|
6
|
+
const GraphUpsert_1 = require("../graph/GraphUpsert");
|
|
7
|
+
class InsertGraphOperation extends DelegateOperation_1.DelegateOperation {
|
|
6
8
|
constructor(name, opt = null) {
|
|
7
9
|
super(name, opt);
|
|
8
|
-
if (!this.delegate.is(InsertOperation)) {
|
|
10
|
+
if (!this.delegate.is(InsertOperation_1.InsertOperation)) {
|
|
9
11
|
throw new Error('Invalid delegate');
|
|
10
12
|
}
|
|
11
|
-
Object.assign(this.delegate.modelOptions, GraphUpsert.modelOptions);
|
|
13
|
+
Object.assign(this.delegate.modelOptions, GraphUpsert_1.GraphUpsert.modelOptions);
|
|
12
14
|
this.upsertOptions = opt.opt || {};
|
|
13
15
|
this.upsert = null;
|
|
14
16
|
}
|
|
@@ -23,7 +25,7 @@ class InsertGraphOperation extends DelegateOperation {
|
|
|
23
25
|
}
|
|
24
26
|
onAdd(builder, args) {
|
|
25
27
|
const retVal = super.onAdd(builder, args);
|
|
26
|
-
this.upsert = new GraphUpsert({
|
|
28
|
+
this.upsert = new GraphUpsert_1.GraphUpsert({
|
|
27
29
|
objects: this.models,
|
|
28
30
|
rootModelClass: builder.modelClass(),
|
|
29
31
|
upsertOptions: Object.assign({}, this.upsertOptions, {
|
|
@@ -82,6 +84,4 @@ class InsertGraphOperation extends DelegateOperation {
|
|
|
82
84
|
return clone;
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
|
-
|
|
86
|
-
InsertGraphOperation,
|
|
87
|
-
};
|
|
87
|
+
exports.InsertGraphOperation = InsertGraphOperation;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
/* global BigInt */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.InsertOperation = void 0;
|
|
5
|
+
const QueryBuilderOperation_1 = require("./QueryBuilderOperation");
|
|
6
|
+
const StaticHookArguments_1 = require("../StaticHookArguments");
|
|
7
|
+
const promiseUtils_1 = require("../../utils/promiseUtils");
|
|
8
|
+
const knexUtils_1 = require("../../utils/knexUtils");
|
|
9
|
+
const objectUtils_1 = require("../../utils/objectUtils");
|
|
8
10
|
// `@@auto_increment_increment` for each MySQL knex instance, keyed by the knex config,
|
|
9
11
|
// which transactions share with the knex they were started from.
|
|
10
12
|
const autoIncrementIncrements = new WeakMap();
|
|
11
13
|
// Base class for all insert operations.
|
|
12
|
-
class InsertOperation extends QueryBuilderOperation {
|
|
14
|
+
class InsertOperation extends QueryBuilderOperation_1.QueryBuilderOperation {
|
|
13
15
|
constructor(name, opt) {
|
|
14
16
|
super(name, opt);
|
|
15
17
|
this.models = null;
|
|
@@ -26,7 +28,7 @@ class InsertOperation extends QueryBuilderOperation {
|
|
|
26
28
|
}
|
|
27
29
|
async onBefore2(builder, result) {
|
|
28
30
|
await callBeforeInsert(builder, this.models);
|
|
29
|
-
if (this.models.length > 1 && isMySql(builder.knex())) {
|
|
31
|
+
if (this.models.length > 1 && (0, knexUtils_1.isMySql)(builder.knex())) {
|
|
30
32
|
await this.prepareMySqlBatchInsert(builder);
|
|
31
33
|
}
|
|
32
34
|
return result;
|
|
@@ -57,7 +59,7 @@ class InsertOperation extends QueryBuilderOperation {
|
|
|
57
59
|
}
|
|
58
60
|
onBuildKnex(knexBuilder, builder) {
|
|
59
61
|
const knex = builder.knex();
|
|
60
|
-
const returnsIds = !isMySql(knex) && (!isSqlite(knex) || this.models.length > 1);
|
|
62
|
+
const returnsIds = !(0, knexUtils_1.isMySql)(knex) && (!(0, knexUtils_1.isSqlite)(knex) || this.models.length > 1);
|
|
61
63
|
if (returnsIds && !builder.has(/returning/)) {
|
|
62
64
|
// If the user hasn't specified a `returning` clause, we make sure
|
|
63
65
|
// that at least the identifier is returned. SQLite only returns the
|
|
@@ -66,6 +68,7 @@ class InsertOperation extends QueryBuilderOperation {
|
|
|
66
68
|
}
|
|
67
69
|
return knexBuilder.insert(this.models.map((model) => model.$toDatabaseJson(builder)));
|
|
68
70
|
}
|
|
71
|
+
// The subclasses may be async.
|
|
69
72
|
onAfter1(builder, ret) {
|
|
70
73
|
if (!Array.isArray(ret) || !ret.length || ret === this.models) {
|
|
71
74
|
// Early exit if there is nothing to do.
|
|
@@ -74,7 +77,7 @@ class InsertOperation extends QueryBuilderOperation {
|
|
|
74
77
|
if (ret.length === 1 && this.models.length > 1) {
|
|
75
78
|
this.setMySqlBatchInsertIds(builder, ret[0]);
|
|
76
79
|
}
|
|
77
|
-
else if (isObject(ret[0])) {
|
|
80
|
+
else if ((0, objectUtils_1.isObject)(ret[0])) {
|
|
78
81
|
// If the user specified a `returning` clause the result may be an array of objects.
|
|
79
82
|
// Merge all values of the objects to our models.
|
|
80
83
|
for (let i = 0, l = this.models.length; i < l; ++i) {
|
|
@@ -119,6 +122,7 @@ class InsertOperation extends QueryBuilderOperation {
|
|
|
119
122
|
return clone;
|
|
120
123
|
}
|
|
121
124
|
}
|
|
125
|
+
exports.InsertOperation = InsertOperation;
|
|
122
126
|
// The id can be a string or a BigInt when the driver is configured to
|
|
123
127
|
// return big numbers that way.
|
|
124
128
|
function addToId(id, amount) {
|
|
@@ -134,32 +138,32 @@ function addToId(id, amount) {
|
|
|
134
138
|
}
|
|
135
139
|
function callBeforeInsert(builder, models) {
|
|
136
140
|
const maybePromise = callInstanceBeforeInsert(builder, models);
|
|
137
|
-
return after(maybePromise, () => callStaticBeforeInsert(builder));
|
|
141
|
+
return (0, promiseUtils_1.after)(maybePromise, () => callStaticBeforeInsert(builder));
|
|
138
142
|
}
|
|
139
143
|
function callInstanceBeforeInsert(builder, models) {
|
|
140
|
-
return mapAfterAllReturn(models, (model) => model.$beforeInsert(builder.context()), models);
|
|
144
|
+
return (0, promiseUtils_1.mapAfterAllReturn)(models, (model) => model.$beforeInsert(builder.context()), models);
|
|
141
145
|
}
|
|
142
146
|
function callStaticBeforeInsert(builder) {
|
|
143
|
-
if (!hasStaticHook(builder.modelClass(), 'beforeInsert')) {
|
|
147
|
+
if (!(0, StaticHookArguments_1.hasStaticHook)(builder.modelClass(), 'beforeInsert')) {
|
|
144
148
|
return undefined;
|
|
145
149
|
}
|
|
146
|
-
const args = StaticHookArguments.create({ builder });
|
|
150
|
+
const args = StaticHookArguments_1.StaticHookArguments.create({ builder });
|
|
147
151
|
return builder.modelClass().beforeInsert(args);
|
|
148
152
|
}
|
|
149
153
|
function callAfterInsert(builder, models, result) {
|
|
150
154
|
const maybePromise = callInstanceAfterInsert(builder, models);
|
|
151
|
-
return after(maybePromise, () => callStaticAfterInsert(builder, result));
|
|
155
|
+
return (0, promiseUtils_1.after)(maybePromise, () => callStaticAfterInsert(builder, result));
|
|
152
156
|
}
|
|
153
157
|
function callInstanceAfterInsert(builder, models) {
|
|
154
|
-
return mapAfterAllReturn(models, (model) => model.$afterInsert(builder.context()), models);
|
|
158
|
+
return (0, promiseUtils_1.mapAfterAllReturn)(models, (model) => model.$afterInsert(builder.context()), models);
|
|
155
159
|
}
|
|
156
160
|
function callStaticAfterInsert(builder, result) {
|
|
157
|
-
if (!hasStaticHook(builder.modelClass(), 'afterInsert')) {
|
|
161
|
+
if (!(0, StaticHookArguments_1.hasStaticHook)(builder.modelClass(), 'afterInsert')) {
|
|
158
162
|
return result;
|
|
159
163
|
}
|
|
160
|
-
const args = StaticHookArguments.create({ builder, result });
|
|
164
|
+
const args = StaticHookArguments_1.StaticHookArguments.create({ builder, result });
|
|
161
165
|
const maybePromise = builder.modelClass().afterInsert(args);
|
|
162
|
-
return after(maybePromise, (maybeResult) => {
|
|
166
|
+
return (0, promiseUtils_1.after)(maybePromise, (maybeResult) => {
|
|
163
167
|
if (maybeResult === undefined) {
|
|
164
168
|
return result;
|
|
165
169
|
}
|
|
@@ -168,6 +172,3 @@ function callStaticAfterInsert(builder, result) {
|
|
|
168
172
|
}
|
|
169
173
|
});
|
|
170
174
|
}
|
|
171
|
-
module.exports = {
|
|
172
|
-
InsertOperation,
|
|
173
|
-
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InstanceDeleteOperation = void 0;
|
|
4
|
+
const whereScopes_1 = require("../whereScopes");
|
|
5
|
+
const DeleteOperation_1 = require("./DeleteOperation");
|
|
6
|
+
const InstanceFindOperation_1 = require("./InstanceFindOperation");
|
|
7
|
+
const assert_1 = require("../../utils/assert");
|
|
8
|
+
class InstanceDeleteOperation extends DeleteOperation_1.DeleteOperation {
|
|
7
9
|
constructor(name, opt) {
|
|
8
10
|
super(name, opt);
|
|
9
11
|
this.instance = opt.instance;
|
|
@@ -15,8 +17,8 @@ class InstanceDeleteOperation extends DeleteOperation {
|
|
|
15
17
|
}
|
|
16
18
|
onBuild(builder) {
|
|
17
19
|
super.onBuild(builder);
|
|
18
|
-
assertHasId(this.instance);
|
|
19
|
-
withWhereScope(builder, () => builder.findById(this.instance.$id()));
|
|
20
|
+
(0, assert_1.assertHasId)(this.instance);
|
|
21
|
+
(0, whereScopes_1.withWhereScope)(builder, () => builder.findById(this.instance.$id()));
|
|
20
22
|
}
|
|
21
23
|
async onAfter2(builder, result) {
|
|
22
24
|
// The result may be an object if `returning` was used.
|
|
@@ -27,11 +29,9 @@ class InstanceDeleteOperation extends DeleteOperation {
|
|
|
27
29
|
return super.onAfter2(builder, result);
|
|
28
30
|
}
|
|
29
31
|
toFindOperation() {
|
|
30
|
-
return new InstanceFindOperation('find', {
|
|
32
|
+
return new InstanceFindOperation_1.InstanceFindOperation('find', {
|
|
31
33
|
instance: this.instance,
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
|
-
|
|
36
|
-
InstanceDeleteOperation,
|
|
37
|
-
};
|
|
37
|
+
exports.InstanceDeleteOperation = InstanceDeleteOperation;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InstanceFindOperation = void 0;
|
|
4
|
+
const whereScopes_1 = require("../whereScopes");
|
|
5
|
+
const FindOperation_1 = require("./FindOperation");
|
|
6
|
+
const assert_1 = require("../../utils/assert");
|
|
7
|
+
class InstanceFindOperation extends FindOperation_1.FindOperation {
|
|
6
8
|
constructor(name, opt) {
|
|
7
9
|
super(name, opt);
|
|
8
10
|
this.instance = opt.instance;
|
|
9
11
|
}
|
|
10
12
|
onBuild(builder) {
|
|
11
|
-
assertHasId(this.instance);
|
|
12
|
-
withWhereScope(builder, () => builder.findById(this.instance.$id()));
|
|
13
|
+
(0, assert_1.assertHasId)(this.instance);
|
|
14
|
+
(0, whereScopes_1.withWhereScope)(builder, () => builder.findById(this.instance.$id()));
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
InstanceFindOperation,
|
|
17
|
-
};
|
|
17
|
+
exports.InstanceFindOperation = InstanceFindOperation;
|