orchid-orm 1.9.20 → 1.9.22
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 +6 -4
- package/dist/index.js +21 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +21 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -141,27 +141,28 @@ type TableToDb<T extends Table> = Db<T['table'], T['columns']['shape'], 'relatio
|
|
|
141
141
|
name: string;
|
|
142
142
|
};
|
|
143
143
|
type DbTable<T extends TableClass> = TableToDb<InstanceType<T>> & Omit<MapRelations<InstanceType<T>>, keyof Query>;
|
|
144
|
-
type
|
|
144
|
+
type ColumnsConfig = {
|
|
145
145
|
shape: ColumnsShape;
|
|
146
146
|
type: unknown;
|
|
147
147
|
};
|
|
148
148
|
type ScopeFn<Related extends TableClass, Scope extends Query> = (q: DbTable<Related>) => Scope;
|
|
149
149
|
type Table = {
|
|
150
150
|
table: string;
|
|
151
|
-
columns:
|
|
151
|
+
columns: ColumnsConfig;
|
|
152
152
|
schema?: string;
|
|
153
153
|
columnTypes: ColumnTypesBase;
|
|
154
154
|
noPrimaryKey?: boolean;
|
|
155
155
|
filePath: string;
|
|
156
156
|
};
|
|
157
|
-
declare const createBaseTable: <CT extends Record<string, orchid_core.AnyColumnTypeCreator>>({ columnTypes, snakeCase, filePath, }?: {
|
|
157
|
+
declare const createBaseTable: <CT extends Record<string, orchid_core.AnyColumnTypeCreator>>({ columnTypes, snakeCase, filePath, nowSQL, }?: {
|
|
158
158
|
columnTypes?: CT | ((t: DefaultColumnTypes) => CT) | undefined;
|
|
159
159
|
snakeCase?: boolean | undefined;
|
|
160
160
|
filePath?: string | undefined;
|
|
161
|
+
nowSQL?: string | undefined;
|
|
161
162
|
}) => {
|
|
162
163
|
new (): {
|
|
163
164
|
table: string;
|
|
164
|
-
columns:
|
|
165
|
+
columns: ColumnsConfig;
|
|
165
166
|
schema?: string | undefined;
|
|
166
167
|
noPrimaryKey?: boolean | undefined;
|
|
167
168
|
snakeCase: boolean | undefined;
|
|
@@ -512,6 +513,7 @@ declare const createBaseTable: <CT extends Record<string, orchid_core.AnyColumnT
|
|
|
512
513
|
};
|
|
513
514
|
};
|
|
514
515
|
filePath: string;
|
|
516
|
+
nowSQL: string | undefined;
|
|
515
517
|
};
|
|
516
518
|
|
|
517
519
|
type QueryMethods<T extends Query> = Record<string, (q: T, ...args: any[]) => any>;
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,8 @@ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
|
30
30
|
const createBaseTable = ({
|
|
31
31
|
columnTypes,
|
|
32
32
|
snakeCase,
|
|
33
|
-
filePath
|
|
33
|
+
filePath,
|
|
34
|
+
nowSQL
|
|
34
35
|
} = { columnTypes: pqb.columnTypes }) => {
|
|
35
36
|
const ct = typeof columnTypes === "function" ? columnTypes(pqb.columnTypes) : columnTypes || pqb.columnTypes;
|
|
36
37
|
filePath != null ? filePath : filePath = orchidCore.getCallerFilePath();
|
|
@@ -42,10 +43,11 @@ const createBaseTable = ({
|
|
|
42
43
|
return create(
|
|
43
44
|
ct,
|
|
44
45
|
filePath,
|
|
45
|
-
snakeCase
|
|
46
|
+
snakeCase,
|
|
47
|
+
nowSQL
|
|
46
48
|
);
|
|
47
49
|
};
|
|
48
|
-
const create = (columnTypes, filePath, snakeCase) => {
|
|
50
|
+
const create = (columnTypes, filePath, snakeCase, nowSQL) => {
|
|
49
51
|
var _a;
|
|
50
52
|
const base = (_a = class {
|
|
51
53
|
constructor() {
|
|
@@ -63,7 +65,7 @@ const create = (columnTypes, filePath, snakeCase) => {
|
|
|
63
65
|
this.filePath = filePath2;
|
|
64
66
|
}
|
|
65
67
|
columnTypes[orchidCore.snakeCaseKey] = this.snakeCase;
|
|
66
|
-
const shape = pqb.getColumnTypes(columnTypes, fn);
|
|
68
|
+
const shape = pqb.getColumnTypes(columnTypes, fn, nowSQL);
|
|
67
69
|
if (this.snakeCase) {
|
|
68
70
|
for (const key in shape) {
|
|
69
71
|
const column = shape[key];
|
|
@@ -112,7 +114,7 @@ const create = (columnTypes, filePath, snakeCase) => {
|
|
|
112
114
|
options
|
|
113
115
|
};
|
|
114
116
|
}
|
|
115
|
-
}, _a.filePath = filePath, _a);
|
|
117
|
+
}, _a.filePath = filePath, _a.nowSQL = nowSQL, _a);
|
|
116
118
|
base.prototype.columnTypes = columnTypes;
|
|
117
119
|
return base;
|
|
118
120
|
};
|
|
@@ -275,7 +277,8 @@ const nestedUpdate$3 = ({ query, primaryKey, foreignKey }) => {
|
|
|
275
277
|
if (id !== null) {
|
|
276
278
|
await query.findBy({ [primaryKey]: id })._update(upsert.update);
|
|
277
279
|
} else {
|
|
278
|
-
const
|
|
280
|
+
const data = typeof upsert.create === "function" ? upsert.create() : upsert.create;
|
|
281
|
+
const result = await query.select(primaryKey)._create(data);
|
|
279
282
|
((_a2 = state.updateData) != null ? _a2 : state.updateData = {})[foreignKey] = result[primaryKey];
|
|
280
283
|
}
|
|
281
284
|
});
|
|
@@ -540,8 +543,9 @@ const nestedUpdate$2 = ({ query, primaryKey, foreignKey }) => {
|
|
|
540
543
|
const { update, create } = params.upsert;
|
|
541
544
|
const updatedIds = await currentRelationsQuery._pluck(foreignKey)._update(update);
|
|
542
545
|
if (updatedIds.length < ids.length) {
|
|
546
|
+
const data2 = typeof create === "function" ? create() : create;
|
|
543
547
|
await t.createMany(
|
|
544
|
-
ids.filter((id) => !updatedIds.includes(id)).map((id) => __spreadProps$5(__spreadValues$7({},
|
|
548
|
+
ids.filter((id) => !updatedIds.includes(id)).map((id) => __spreadProps$5(__spreadValues$7({}, data2), {
|
|
545
549
|
[foreignKey]: id
|
|
546
550
|
}))
|
|
547
551
|
);
|
|
@@ -1262,6 +1266,16 @@ const applyRelation = (qb, { relationName, relation, dbTable, otherDbTable }, de
|
|
|
1262
1266
|
}
|
|
1263
1267
|
makeRelationQuery(dbTable, relationName, data, query);
|
|
1264
1268
|
baseQuery.joinQuery = data.joinQuery;
|
|
1269
|
+
const { join: originalJoin } = baseQuery;
|
|
1270
|
+
baseQuery.join = function(...args) {
|
|
1271
|
+
if (args.length) {
|
|
1272
|
+
return originalJoin.apply(this, args);
|
|
1273
|
+
} else {
|
|
1274
|
+
const q = this.clone();
|
|
1275
|
+
q.query.innerJoinLateral = true;
|
|
1276
|
+
return q;
|
|
1277
|
+
}
|
|
1278
|
+
};
|
|
1265
1279
|
dbTable.relations[relationName] = {
|
|
1266
1280
|
type,
|
|
1267
1281
|
key: relationName,
|