orchid-orm 1.25.3 → 1.26.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/dist/index.d.ts +54 -35
- package/dist/index.js +26 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -11
- package/dist/index.mjs.map +1 -1
- package/dist/migrations.js +62 -56
- package/dist/migrations.js.map +1 -1
- package/dist/migrations.mjs +63 -57
- package/dist/migrations.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { makeColumnTypes,
|
|
1
|
+
import { makeColumnTypes, QueryHooks, defaultSchemaConfig, getColumnTypes, parseTableData, _queryHookAfterCreate, _queryHookAfterUpdate, getQueryAs, setQueryObjectValue, pushQueryOn, VirtualColumn, pushQueryValue, _queryCreateMany, isQueryReturnsAll, _queryHookBeforeUpdate, _queryFindBy, _queryCreate, _queryRows, _queryUpdate, _queryDelete, _queryDefaults, _queryUpdateOrThrow, _queryWhere, toSQLCacheKey, _queryJoinOn, OrchidOrmInternalError, _queryCreateFrom, NotFoundError, _queryFindByOptional, _querySelect, _queryWhereExists, _queryTake, _queryTakeOptional, _queryAll, Adapter, _initQueryBuilder, Db, addComputedColumns, getClonedQueryData } from 'pqb';
|
|
2
2
|
export * from 'pqb';
|
|
3
|
-
import { getStackTrace, applyMixins, getCallerFilePath, snakeCaseKey, toSnakeCase, emptyArray, objectHasValues, toArray } from 'orchid-core';
|
|
3
|
+
import { getStackTrace, applyMixins, getCallerFilePath, snakeCaseKey, toSnakeCase, emptyObject, emptyArray, objectHasValues, toArray } from 'orchid-core';
|
|
4
4
|
export * from 'orchid-core';
|
|
5
5
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
6
6
|
|
|
@@ -14,29 +14,39 @@ function createBaseTable({
|
|
|
14
14
|
language
|
|
15
15
|
} = {}) {
|
|
16
16
|
var _a;
|
|
17
|
-
const columnTypes = typeof columnTypesArg === "function" ? columnTypesArg(makeColumnTypes(schemaConfig)) : columnTypesArg || makeColumnTypes(
|
|
17
|
+
const columnTypes = typeof columnTypesArg === "function" ? columnTypesArg(makeColumnTypes(schemaConfig)) : columnTypesArg || makeColumnTypes(schemaConfig);
|
|
18
18
|
const filePathOrStack = filePathArg || getStackTrace();
|
|
19
19
|
let filePath;
|
|
20
|
+
const defaultColumns = {
|
|
21
|
+
shape: emptyObject,
|
|
22
|
+
data: emptyArray
|
|
23
|
+
};
|
|
20
24
|
const base = (_a = class {
|
|
21
25
|
constructor() {
|
|
26
|
+
this.columns = defaultColumns;
|
|
22
27
|
this.snakeCase = snakeCase;
|
|
23
28
|
this.types = columnTypes;
|
|
24
29
|
this.q = {};
|
|
25
30
|
this.language = language;
|
|
26
31
|
}
|
|
27
32
|
static inputSchema() {
|
|
33
|
+
this.instance();
|
|
28
34
|
return this._inputSchema === void 0 ? this._inputSchema = schemaConfig.inputSchema.call(this) : this._inputSchema;
|
|
29
35
|
}
|
|
30
36
|
static outputSchema() {
|
|
37
|
+
this.instance();
|
|
31
38
|
return this._outputSchema === void 0 ? this._outputSchema = schemaConfig.outputSchema.call(this) : this._outputSchema;
|
|
32
39
|
}
|
|
33
40
|
static querySchema() {
|
|
41
|
+
this.instance();
|
|
34
42
|
return this._querySchema === void 0 ? this._querySchema = schemaConfig.querySchema.call(this) : this._querySchema;
|
|
35
43
|
}
|
|
36
44
|
static updateSchema() {
|
|
45
|
+
this.instance();
|
|
37
46
|
return this._updateSchema === void 0 ? this._updateSchema = schemaConfig.updateSchema.call(this) : this._updateSchema;
|
|
38
47
|
}
|
|
39
48
|
static pkeySchema() {
|
|
49
|
+
this.instance();
|
|
40
50
|
return this._pkeySchema === void 0 ? this._pkeySchema = schemaConfig.pkeySchema.call(this) : this._pkeySchema;
|
|
41
51
|
}
|
|
42
52
|
static getFilePath() {
|
|
@@ -71,10 +81,10 @@ function createBaseTable({
|
|
|
71
81
|
`Failed to determine file path for table ${this.constructor.name}. Please set \`filePath\` property manually`
|
|
72
82
|
);
|
|
73
83
|
}
|
|
74
|
-
setColumns(fn) {
|
|
84
|
+
setColumns(fn, dataFn) {
|
|
75
85
|
columnTypes[snakeCaseKey] = this.snakeCase;
|
|
76
86
|
const shape = getColumnTypes(columnTypes, fn, nowSQL, this.language);
|
|
77
|
-
this.constructor.prototype.tableData =
|
|
87
|
+
const tableData = this.constructor.prototype.tableData = parseTableData(dataFn);
|
|
78
88
|
if (this.snakeCase) {
|
|
79
89
|
for (const key in shape) {
|
|
80
90
|
const column = shape[key];
|
|
@@ -86,7 +96,10 @@ function createBaseTable({
|
|
|
86
96
|
}
|
|
87
97
|
}
|
|
88
98
|
}
|
|
89
|
-
return this.constructor.prototype.columns =
|
|
99
|
+
return this.constructor.prototype.columns = {
|
|
100
|
+
shape,
|
|
101
|
+
data: tableData
|
|
102
|
+
};
|
|
90
103
|
}
|
|
91
104
|
setComputed(computed) {
|
|
92
105
|
return computed;
|
|
@@ -169,7 +182,7 @@ const hasRelationHandleUpdate = (q, set, key, primaryKeys, nestedUpdate) => {
|
|
|
169
182
|
return;
|
|
170
183
|
selectIfNotSelected(q, primaryKeys);
|
|
171
184
|
q.q.wrapInTransaction = true;
|
|
172
|
-
_queryHookAfterUpdate(q,
|
|
185
|
+
_queryHookAfterUpdate(q, primaryKeys, (rows, q2) => {
|
|
173
186
|
return nestedUpdate(
|
|
174
187
|
q2,
|
|
175
188
|
rows,
|
|
@@ -443,7 +456,6 @@ const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
|
|
|
443
456
|
}
|
|
444
457
|
if (upsert) {
|
|
445
458
|
((_a = state.queries) != null ? _a : state.queries = []).push(async (queryResult) => {
|
|
446
|
-
var _a2;
|
|
447
459
|
const row = queryResult.rows[0];
|
|
448
460
|
let obj = {};
|
|
449
461
|
for (let i = 0; i < len; i++) {
|
|
@@ -462,8 +474,13 @@ const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
|
|
|
462
474
|
} else {
|
|
463
475
|
const data = typeof upsert.create === "function" ? upsert.create() : upsert.create;
|
|
464
476
|
const result = await _queryCreate(query.select(...primaryKeys), data);
|
|
477
|
+
const collectData = {};
|
|
478
|
+
state.collect = {
|
|
479
|
+
keys: primaryKeys,
|
|
480
|
+
data: collectData
|
|
481
|
+
};
|
|
465
482
|
for (let i = 0; i < len; i++) {
|
|
466
|
-
|
|
483
|
+
collectData[foreignKeys[i]] = result[primaryKeys[i]];
|
|
467
484
|
}
|
|
468
485
|
}
|
|
469
486
|
});
|
|
@@ -1871,11 +1888,11 @@ const orchidORM = (_a, tables) => {
|
|
|
1871
1888
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1872
1889
|
qb,
|
|
1873
1890
|
table.table,
|
|
1874
|
-
table.columns,
|
|
1891
|
+
table.columns.shape,
|
|
1875
1892
|
table.types,
|
|
1876
1893
|
transactionStorage,
|
|
1877
1894
|
options2,
|
|
1878
|
-
(_a2 = table.constructor.prototype.tableData) != null ? _a2 :
|
|
1895
|
+
(_a2 = table.constructor.prototype.tableData) != null ? _a2 : emptyObject
|
|
1879
1896
|
);
|
|
1880
1897
|
dbTable.definedAs = key;
|
|
1881
1898
|
dbTable.db = result;
|