orchid-orm 1.11.0 → 1.11.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/codegen/index.d.ts +1 -1
- package/codegen/index.js +8 -4
- package/codegen/index.js.map +1 -1
- package/codegen/index.mjs +8 -4
- package/codegen/index.mjs.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +30 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { columnTypes, QueryHooks, getColumnTypes, addQueryOn, VirtualColumn, pushQueryValue, isQueryReturnsAll, getQueryAs, toSqlCacheKey, OrchidOrmInternalError, NotFoundError, relationQueryKey, Adapter, Db, anyShape, getClonedQueryData } from 'pqb';
|
|
2
2
|
export { OrchidOrmError, OrchidOrmInternalError, columnTypes, testTransaction } from 'pqb';
|
|
3
|
-
import {
|
|
3
|
+
import { getStackTrace, applyMixins, getCallerFilePath, snakeCaseKey, toSnakeCase } from 'orchid-core';
|
|
4
4
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
5
|
|
|
6
6
|
const createBaseTable = ({
|
|
@@ -11,41 +11,52 @@ const createBaseTable = ({
|
|
|
11
11
|
exportAs
|
|
12
12
|
} = { columnTypes: columnTypes }) => {
|
|
13
13
|
const ct = typeof columnTypes$1 === "function" ? columnTypes$1(columnTypes) : columnTypes$1 || columnTypes;
|
|
14
|
-
filePath != null ? filePath : filePath = getCallerFilePath();
|
|
15
|
-
if (!filePath) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
`Failed to determine file path of a base table. Please set the \`filePath\` option of \`createBaseTable\` manually.`
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
14
|
return create(
|
|
21
15
|
ct,
|
|
22
|
-
filePath
|
|
16
|
+
// stack is needed only if filePath wasn't given
|
|
17
|
+
filePath || getStackTrace(),
|
|
23
18
|
snakeCase,
|
|
24
19
|
nowSQL,
|
|
25
20
|
exportAs
|
|
26
21
|
);
|
|
27
22
|
};
|
|
28
|
-
const create = (columnTypes,
|
|
23
|
+
const create = (columnTypes, filePathOrStack, snakeCase, nowSQL, exportAs = "BaseTable") => {
|
|
29
24
|
var _a;
|
|
25
|
+
let filePath;
|
|
30
26
|
const base = (_a = class {
|
|
31
27
|
constructor() {
|
|
32
28
|
this.snakeCase = snakeCase;
|
|
33
|
-
this.query = {};
|
|
34
29
|
this.columnTypes = columnTypes;
|
|
30
|
+
this.query = {};
|
|
31
|
+
}
|
|
32
|
+
static getFilePath() {
|
|
33
|
+
if (filePath)
|
|
34
|
+
return filePath;
|
|
35
|
+
if (typeof filePathOrStack === "string")
|
|
36
|
+
return filePath = filePathOrStack;
|
|
37
|
+
filePath = getCallerFilePath(filePathOrStack);
|
|
38
|
+
if (filePath)
|
|
39
|
+
return filePath;
|
|
40
|
+
throw new Error(
|
|
41
|
+
`Failed to determine file path of a base table. Please set the \`filePath\` option of \`createBaseTable\` manually.`
|
|
42
|
+
);
|
|
35
43
|
}
|
|
36
44
|
clone() {
|
|
37
45
|
return this;
|
|
38
46
|
}
|
|
47
|
+
getFilePath() {
|
|
48
|
+
if (this.filePath)
|
|
49
|
+
return this.filePath;
|
|
50
|
+
if (typeof filePathOrStack === "string")
|
|
51
|
+
return this.filePath = filePathOrStack;
|
|
52
|
+
const filePath2 = getCallerFilePath(filePathOrStack);
|
|
53
|
+
if (filePath2)
|
|
54
|
+
return this.filePath = filePath2;
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Failed to determine file path for table ${this.constructor.name}. Please set \`filePath\` property manually`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
39
59
|
setColumns(fn) {
|
|
40
|
-
if (!this.filePath) {
|
|
41
|
-
const filePath2 = getCallerFilePath();
|
|
42
|
-
if (!filePath2) {
|
|
43
|
-
throw new Error(
|
|
44
|
-
`Failed to determine file path for table ${this.constructor.name}. Please set \`filePath\` property manually`
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
this.filePath = filePath2;
|
|
48
|
-
}
|
|
49
60
|
columnTypes[snakeCaseKey] = this.snakeCase;
|
|
50
61
|
const shape = getColumnTypes(columnTypes, fn, nowSQL);
|
|
51
62
|
if (this.snakeCase) {
|
|
@@ -96,7 +107,7 @@ const create = (columnTypes, filePath, snakeCase, nowSQL, exportAs = "BaseTable"
|
|
|
96
107
|
options
|
|
97
108
|
};
|
|
98
109
|
}
|
|
99
|
-
}, _a.
|
|
110
|
+
}, _a.nowSQL = nowSQL, _a.exportAs = exportAs, _a);
|
|
100
111
|
applyMixins(base, [QueryHooks]);
|
|
101
112
|
base.prototype.columnTypes = columnTypes;
|
|
102
113
|
return base;
|