orchid-orm 1.19.0 → 1.20.0
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 +10 -9
- package/dist/index.js +52 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -6
package/dist/index.mjs
CHANGED
|
@@ -1,35 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { makeColumnTypes, defaultSchemaConfig, QueryHooks, getColumnTypes, getQueryAs, setQueryObjectValue, pushQueryOn, VirtualColumn, pushQueryValue, isQueryReturnsAll, toSQLCacheKey, OrchidOrmInternalError, NotFoundError, Adapter, Db, anyShape, addComputedColumns, getClonedQueryData } from 'pqb';
|
|
2
2
|
export * from 'pqb';
|
|
3
3
|
import { getStackTrace, applyMixins, getCallerFilePath, snakeCaseKey, toSnakeCase, emptyArray, toArray } from 'orchid-core';
|
|
4
4
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
5
|
|
|
6
6
|
function createBaseTable({
|
|
7
|
+
schemaConfig = defaultSchemaConfig,
|
|
7
8
|
columnTypes: columnTypesArg,
|
|
8
9
|
snakeCase,
|
|
9
10
|
filePath: filePathArg,
|
|
10
11
|
nowSQL,
|
|
11
12
|
exportAs = "BaseTable",
|
|
12
|
-
language
|
|
13
|
-
schemaProvider: schemaProviderArg
|
|
13
|
+
language
|
|
14
14
|
} = {}) {
|
|
15
15
|
var _a;
|
|
16
|
-
const columnTypes
|
|
17
|
-
columnTypes
|
|
18
|
-
) : columnTypesArg || columnTypes;
|
|
16
|
+
const columnTypes = typeof columnTypesArg === "function" ? columnTypesArg(makeColumnTypes(schemaConfig)) : columnTypesArg || makeColumnTypes(defaultSchemaConfig);
|
|
19
17
|
const filePathOrStack = filePathArg || getStackTrace();
|
|
20
18
|
let filePath;
|
|
21
|
-
function schemaProvider() {
|
|
22
|
-
const schema = schemaProviderArg.call(this);
|
|
23
|
-
this.schema = () => schema;
|
|
24
|
-
return schema;
|
|
25
|
-
}
|
|
26
19
|
const base = (_a = class {
|
|
27
20
|
constructor() {
|
|
28
21
|
this.snakeCase = snakeCase;
|
|
29
|
-
this.types = columnTypes
|
|
22
|
+
this.types = columnTypes;
|
|
30
23
|
this.q = {};
|
|
31
24
|
this.language = language;
|
|
32
25
|
}
|
|
26
|
+
static inputSchema() {
|
|
27
|
+
return this._inputSchema === void 0 ? this._inputSchema = schemaConfig.inputSchema.call(this) : this._inputSchema;
|
|
28
|
+
}
|
|
29
|
+
static outputSchema() {
|
|
30
|
+
return this._outputSchema === void 0 ? this._outputSchema = schemaConfig.outputSchema.call(this) : this._outputSchema;
|
|
31
|
+
}
|
|
32
|
+
static querySchema() {
|
|
33
|
+
return this._querySchema === void 0 ? this._querySchema = schemaConfig.querySchema.call(this) : this._querySchema;
|
|
34
|
+
}
|
|
35
|
+
static updateSchema() {
|
|
36
|
+
return this._updateSchema === void 0 ? this._updateSchema = schemaConfig.updateSchema.call(this) : this._updateSchema;
|
|
37
|
+
}
|
|
38
|
+
static pkeySchema() {
|
|
39
|
+
return this._pkeySchema === void 0 ? this._pkeySchema = schemaConfig.pkeySchema.call(this) : this._pkeySchema;
|
|
40
|
+
}
|
|
33
41
|
static getFilePath() {
|
|
34
42
|
if (filePath)
|
|
35
43
|
return filePath;
|
|
@@ -63,8 +71,8 @@ function createBaseTable({
|
|
|
63
71
|
);
|
|
64
72
|
}
|
|
65
73
|
setColumns(fn) {
|
|
66
|
-
columnTypes
|
|
67
|
-
const shape = getColumnTypes(columnTypes
|
|
74
|
+
columnTypes[snakeCaseKey] = this.snakeCase;
|
|
75
|
+
const shape = getColumnTypes(columnTypes, fn, nowSQL, this.language);
|
|
68
76
|
if (this.snakeCase) {
|
|
69
77
|
for (const key in shape) {
|
|
70
78
|
const column = shape[key];
|
|
@@ -76,7 +84,7 @@ function createBaseTable({
|
|
|
76
84
|
}
|
|
77
85
|
}
|
|
78
86
|
}
|
|
79
|
-
return shape;
|
|
87
|
+
return this.constructor.prototype.columns = shape;
|
|
80
88
|
}
|
|
81
89
|
setComputed(computed) {
|
|
82
90
|
return computed;
|
|
@@ -112,9 +120,9 @@ function createBaseTable({
|
|
|
112
120
|
options
|
|
113
121
|
};
|
|
114
122
|
}
|
|
115
|
-
}, _a.nowSQL = nowSQL, _a.exportAs = exportAs, _a
|
|
123
|
+
}, _a.nowSQL = nowSQL, _a.exportAs = exportAs, _a);
|
|
116
124
|
applyMixins(base, [QueryHooks]);
|
|
117
|
-
base.prototype.types = columnTypes
|
|
125
|
+
base.prototype.types = columnTypes;
|
|
118
126
|
return base;
|
|
119
127
|
}
|
|
120
128
|
|
|
@@ -225,8 +233,8 @@ const joinQueryChainingHOF = (reverseJoin, joinQuery) => (joiningQuery, baseQuer
|
|
|
225
233
|
};
|
|
226
234
|
|
|
227
235
|
class BelongsToVirtualColumn extends VirtualColumn {
|
|
228
|
-
constructor(key, state) {
|
|
229
|
-
super();
|
|
236
|
+
constructor(schema, key, state) {
|
|
237
|
+
super(schema);
|
|
230
238
|
this.key = key;
|
|
231
239
|
this.state = state;
|
|
232
240
|
this.nestedInsert = nestedInsert$3(this.state);
|
|
@@ -303,7 +311,11 @@ const makeBelongsToMethod = (relation, relationName, query) => {
|
|
|
303
311
|
method(params) {
|
|
304
312
|
return query.where(makeWhere(params));
|
|
305
313
|
},
|
|
306
|
-
virtualColumn: new BelongsToVirtualColumn(
|
|
314
|
+
virtualColumn: new BelongsToVirtualColumn(
|
|
315
|
+
defaultSchemaConfig,
|
|
316
|
+
relationName,
|
|
317
|
+
state
|
|
318
|
+
),
|
|
307
319
|
joinQuery: joinQueryChainingHOF(
|
|
308
320
|
reverseJoin,
|
|
309
321
|
(joiningQuery, baseQuery) => join(baseQuery, joiningQuery, primaryKeys, foreignKeys)
|
|
@@ -504,8 +516,8 @@ var __spreadValues$5 = (a, b) => {
|
|
|
504
516
|
return a;
|
|
505
517
|
};
|
|
506
518
|
class HasOneVirtualColumn extends VirtualColumn {
|
|
507
|
-
constructor(key, state) {
|
|
508
|
-
super();
|
|
519
|
+
constructor(schema, key, state) {
|
|
520
|
+
super(schema);
|
|
509
521
|
this.key = key;
|
|
510
522
|
this.state = state;
|
|
511
523
|
this.nestedInsert = nestedInsert$2(state);
|
|
@@ -602,7 +614,11 @@ const makeHasOneMethod = (table, relation, relationName, query) => {
|
|
|
602
614
|
}
|
|
603
615
|
return query.where(values)._defaults(values);
|
|
604
616
|
},
|
|
605
|
-
virtualColumn: new HasOneVirtualColumn(
|
|
617
|
+
virtualColumn: new HasOneVirtualColumn(
|
|
618
|
+
defaultSchemaConfig,
|
|
619
|
+
relationName,
|
|
620
|
+
state
|
|
621
|
+
),
|
|
606
622
|
joinQuery: joinQueryChainingHOF(
|
|
607
623
|
reverseJoin,
|
|
608
624
|
(joiningQuery, baseQuery) => joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len)
|
|
@@ -748,8 +764,8 @@ var __spreadValues$4 = (a, b) => {
|
|
|
748
764
|
return a;
|
|
749
765
|
};
|
|
750
766
|
class HasManyVirtualColumn extends VirtualColumn {
|
|
751
|
-
constructor(key, state) {
|
|
752
|
-
super();
|
|
767
|
+
constructor(schema, key, state) {
|
|
768
|
+
super(schema);
|
|
753
769
|
this.key = key;
|
|
754
770
|
this.state = state;
|
|
755
771
|
this.nestedInsert = nestedInsert$1(state);
|
|
@@ -850,7 +866,11 @@ const makeHasManyMethod = (table, relation, relationName, query) => {
|
|
|
850
866
|
}
|
|
851
867
|
return query.where(values)._defaults(values);
|
|
852
868
|
},
|
|
853
|
-
virtualColumn: new HasManyVirtualColumn(
|
|
869
|
+
virtualColumn: new HasManyVirtualColumn(
|
|
870
|
+
defaultSchemaConfig,
|
|
871
|
+
relationName,
|
|
872
|
+
state
|
|
873
|
+
),
|
|
854
874
|
joinQuery: joinQueryChainingHOF(
|
|
855
875
|
reverseJoin,
|
|
856
876
|
(joiningQuery, baseQuery) => joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len)
|
|
@@ -1041,8 +1061,8 @@ var __spreadValues$3 = (a, b) => {
|
|
|
1041
1061
|
};
|
|
1042
1062
|
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
1043
1063
|
class HasAndBelongsToManyVirtualColumn extends VirtualColumn {
|
|
1044
|
-
constructor(key, state) {
|
|
1045
|
-
super();
|
|
1064
|
+
constructor(schema, key, state) {
|
|
1065
|
+
super(schema);
|
|
1046
1066
|
this.key = key;
|
|
1047
1067
|
this.state = state;
|
|
1048
1068
|
this.nestedInsert = nestedInsert(state);
|
|
@@ -1111,7 +1131,9 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
1111
1131
|
baseQuery.table = joinTable;
|
|
1112
1132
|
const shape = {};
|
|
1113
1133
|
for (let i = 0; i < len; i++) {
|
|
1114
|
-
shape[foreignKeys[i]] = removeColumnName(
|
|
1134
|
+
shape[foreignKeys[i]] = removeColumnName(
|
|
1135
|
+
table.shape[primaryKeys[i]]
|
|
1136
|
+
);
|
|
1115
1137
|
}
|
|
1116
1138
|
for (let i = 0; i < throughLen; i++) {
|
|
1117
1139
|
shape[throughForeignKeys[i]] = removeColumnName(
|
|
@@ -1175,7 +1197,11 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
1175
1197
|
return q._where(where);
|
|
1176
1198
|
});
|
|
1177
1199
|
},
|
|
1178
|
-
virtualColumn: new HasAndBelongsToManyVirtualColumn(
|
|
1200
|
+
virtualColumn: new HasAndBelongsToManyVirtualColumn(
|
|
1201
|
+
defaultSchemaConfig,
|
|
1202
|
+
relationName,
|
|
1203
|
+
state
|
|
1204
|
+
),
|
|
1179
1205
|
joinQuery: joinQueryChainingHOF(reverseJoin, (joiningQuery, baseQuery2) => {
|
|
1180
1206
|
const joined = joinQuery(
|
|
1181
1207
|
joiningQuery,
|
|
@@ -1734,7 +1760,7 @@ const orchidORM = (_a, tables) => {
|
|
|
1734
1760
|
void 0,
|
|
1735
1761
|
void 0,
|
|
1736
1762
|
anyShape,
|
|
1737
|
-
|
|
1763
|
+
makeColumnTypes(defaultSchemaConfig),
|
|
1738
1764
|
transactionStorage,
|
|
1739
1765
|
commonOptions
|
|
1740
1766
|
);
|