orchid-orm 1.56.5 → 1.57.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 +15 -5
- package/dist/index.js +13 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -15
- package/dist/index.mjs.map +1 -1
- package/dist/migrations/node-postgres.js +5 -21
- package/dist/migrations/node-postgres.js.map +1 -1
- package/dist/migrations/node-postgres.mjs +6 -22
- package/dist/migrations/node-postgres.mjs.map +1 -1
- package/dist/migrations/postgres-js.js +5 -21
- package/dist/migrations/postgres-js.js.map +1 -1
- package/dist/migrations/postgres-js.mjs +6 -22
- package/dist/migrations/postgres-js.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { TableData, Query, SelectableFromShape,
|
|
1
|
+
import { TableData, Query, SelectableFromShape, CreateData, CreateBelongsToData, AddQueryDefaults, QueryTake, QueryTakeOptional, UpdateData, WhereArg, CreateMethodsNames, JoinQueryMethod, DeleteMethodsNames, Db, IsolationLevel, TransactionOptions, FromArg, FromResult, DbSharedOptions, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, TableDataItem, ComputedOptionsFactory, ComputedOptionsConfig, QueryData, TableDataFn, DbTableOptionScopes, RawSQL, DynamicRawSQL, DefaultSchemaConfig, DefaultColumnTypes, QueryBeforeHookInternal, QueryAfterHook, AfterHook, WhereResult, MergeQuery } from 'pqb';
|
|
2
2
|
export * from 'pqb';
|
|
3
3
|
import { ColumnsShapeBase, ColumnShapeInputPartial, RelationConfigBase, EmptyObject, MaybeArray, AfterCommitStandaloneHook, AdapterBase, RelationsBase, RecordUnknown, ShallowSimplify, ColumnShapeOutput, DefaultSelectColumns, QueryOrExpression, QueryColumn, ColumnShapeInput, IsQuery, CoreQueryScopes, ColumnSchemaConfig, StaticSQLArgs, DynamicSQLArg, QueryColumns, QueryReturnType } from 'orchid-core';
|
|
4
4
|
export * from 'orchid-core';
|
|
5
|
+
import { CreateManyMethodsNames } from 'pqb/src/queryMethods/mutate/create';
|
|
5
6
|
|
|
6
7
|
interface RelationRefsOptions<Column extends PropertyKey = string, Shape extends ColumnsShapeBase = ColumnsShapeBase> {
|
|
7
8
|
required?: boolean;
|
|
@@ -27,20 +28,21 @@ type HasOneParams<T extends RelationConfigSelf, Relation extends RelationThunkBa
|
|
|
27
28
|
[Name in Relation['options']['columns'][number]]: T['columns']['shape'][Name]['type'];
|
|
28
29
|
} : Relation['options'] extends RelationThroughOptions ? RelationConfigParams<T, T['relations'][Relation['options']['through']]> : never;
|
|
29
30
|
type HasOnePopulate<T extends RelationConfigSelf, Name extends string> = T['relations'][Name]['options'] extends RelationRefsOptions ? Record<T['relations'][Name]['options']['references'][number], true> : never;
|
|
30
|
-
type
|
|
31
|
+
type HasOneQueryThrough<T extends RelationConfigSelf, Name extends string, TableQuery extends Query> = {
|
|
31
32
|
[K in keyof TableQuery]: K extends 'meta' ? Omit<TableQuery['meta'], 'selectable'> & {
|
|
32
33
|
as: Name;
|
|
33
34
|
defaults: HasOnePopulate<T, Name>;
|
|
34
35
|
hasWhere: true;
|
|
35
36
|
selectable: SelectableFromShape<TableQuery['shape'], Name>;
|
|
36
37
|
} : K extends 'join' ? RelJoin : K extends CreateMethodsNames ? never : TableQuery[K];
|
|
37
|
-
}
|
|
38
|
+
};
|
|
39
|
+
type HasOneQuery<T extends RelationConfigSelf, Name extends string, TableQuery extends Query> = T['relations'][Name]['options'] extends RelationThroughOptions ? HasOneQueryThrough<T, Name, TableQuery> : {
|
|
38
40
|
[K in keyof TableQuery]: K extends 'meta' ? Omit<TableQuery['meta'], 'selectable'> & {
|
|
39
41
|
as: Name;
|
|
40
42
|
defaults: HasOnePopulate<T, Name>;
|
|
41
43
|
hasWhere: true;
|
|
42
44
|
selectable: SelectableFromShape<TableQuery['shape'], Name>;
|
|
43
|
-
} : K extends 'join' ? RelJoin : TableQuery[K];
|
|
45
|
+
} : K extends 'join' ? RelJoin : K extends CreateManyMethodsNames ? never : TableQuery[K];
|
|
44
46
|
};
|
|
45
47
|
interface HasOneInfo<T extends RelationConfigSelf, Name extends string, Rel extends HasOne, Q extends Query, CD = T['relations'][Name]['options'] extends RelationThroughOptions ? CreateData<Q, CreateBelongsToData<Q>> : CreateData<AddQueryDefaults<Q, HasOnePopulate<T, Name>>, CreateBelongsToData<Q>>> extends RelationConfigBase {
|
|
46
48
|
returnsOne: true;
|
|
@@ -84,6 +86,14 @@ interface HasMany extends RelationThunkBase {
|
|
|
84
86
|
type: 'hasMany';
|
|
85
87
|
options: HasOneOptions;
|
|
86
88
|
}
|
|
89
|
+
type HasManyQuery<T extends RelationConfigSelf, Name extends string, TableQuery extends Query> = T['relations'][Name]['options'] extends RelationThroughOptions ? HasOneQueryThrough<T, Name, TableQuery> : {
|
|
90
|
+
[K in keyof TableQuery]: K extends 'meta' ? Omit<TableQuery['meta'], 'selectable'> & {
|
|
91
|
+
as: Name;
|
|
92
|
+
defaults: HasOnePopulate<T, Name>;
|
|
93
|
+
hasWhere: true;
|
|
94
|
+
selectable: SelectableFromShape<TableQuery['shape'], Name>;
|
|
95
|
+
} : K extends 'join' ? RelJoin : TableQuery[K];
|
|
96
|
+
};
|
|
87
97
|
interface HasManyInfo<T extends RelationConfigSelf, Name extends string, Rel extends HasMany, Q extends Query> extends RelationConfigBase {
|
|
88
98
|
returnsOne: false;
|
|
89
99
|
query: Q;
|
|
@@ -443,7 +453,7 @@ interface TableToDb<T extends ORMTableInput, Relations extends RelationsBase> ex
|
|
|
443
453
|
relations: Relations;
|
|
444
454
|
}
|
|
445
455
|
type ORMTableInputToQueryBuilder<T extends ORMTableInput> = T extends RelationConfigSelf ? TableToDb<T, T extends RelationConfigSelf ? {
|
|
446
|
-
[K in keyof T['relations'] & string]: T['relations'][K] extends BelongsTo ? BelongsToInfo<T, K, T['relations'][K], T['relations'][K]['options']['columns'][number] & string, T['relations'][K]['options']['required'], BelongsToQuery<RelationTableToQuery<T['relations'][K]>, K>> : T['relations'][K] extends HasOne ? HasOneInfo<T, K, T['relations'][K], HasOneQuery<T, K, RelationTableToQuery<T['relations'][K]>>> : T['relations'][K] extends HasMany ? HasManyInfo<T, K, T['relations'][K],
|
|
456
|
+
[K in keyof T['relations'] & string]: T['relations'][K] extends BelongsTo ? BelongsToInfo<T, K, T['relations'][K], T['relations'][K]['options']['columns'][number] & string, T['relations'][K]['options']['required'], BelongsToQuery<RelationTableToQuery<T['relations'][K]>, K>> : T['relations'][K] extends HasOne ? HasOneInfo<T, K, T['relations'][K], HasOneQuery<T, K, RelationTableToQuery<T['relations'][K]>>> : T['relations'][K] extends HasMany ? HasManyInfo<T, K, T['relations'][K], HasManyQuery<T, K, RelationTableToQuery<T['relations'][K]>>> : T['relations'][K] extends HasAndBelongsToMany ? HasAndBelongsToManyInfo<T, K, T['relations'][K], HasAndBelongsToManyQuery<K, RelationTableToQuery<T['relations'][K]>>> : never;
|
|
447
457
|
} : EmptyObject> : TableToDb<T, EmptyObject>;
|
|
448
458
|
interface ORMTableInput {
|
|
449
459
|
table: string;
|
package/dist/index.js
CHANGED
|
@@ -858,7 +858,8 @@ const makeHasOneMethod = (tableConfig, table, relation, relationName, query) =>
|
|
|
858
858
|
const baseQuery = query2.clone();
|
|
859
859
|
baseQuery.q.select = fromQuerySelect;
|
|
860
860
|
const q = relationQuery.q;
|
|
861
|
-
q.
|
|
861
|
+
q.insertFrom = baseQuery;
|
|
862
|
+
q.values = [];
|
|
862
863
|
};
|
|
863
864
|
}
|
|
864
865
|
};
|
|
@@ -1135,7 +1136,8 @@ const makeHasManyMethod = (tableConfig, table, relation, relationName, query) =>
|
|
|
1135
1136
|
const baseQuery = query2.clone();
|
|
1136
1137
|
baseQuery.q.select = fromQuerySelect;
|
|
1137
1138
|
const q = relationQuery.q;
|
|
1138
|
-
q.
|
|
1139
|
+
q.insertFrom = baseQuery;
|
|
1140
|
+
q.values = [];
|
|
1139
1141
|
};
|
|
1140
1142
|
}
|
|
1141
1143
|
};
|
|
@@ -1531,19 +1533,16 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
|
|
|
1531
1533
|
relationQuery,
|
|
1532
1534
|
[],
|
|
1533
1535
|
async (result) => {
|
|
1534
|
-
if (result.length > 1) {
|
|
1535
|
-
throw new orchidCore.OrchidOrmInternalError(
|
|
1536
|
-
relationQuery,
|
|
1537
|
-
"Creating multiple `hasAndBelongsToMany` records is not yet supported"
|
|
1538
|
-
);
|
|
1539
|
-
}
|
|
1540
1536
|
const baseQuery2 = ref.q.clone();
|
|
1541
1537
|
baseQuery2.q.select = selectPrimaryKeysAsForeignKeys;
|
|
1542
|
-
const data = {
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1538
|
+
const data = result.map((resultRow) => {
|
|
1539
|
+
const dataRow = {};
|
|
1540
|
+
for (let i = 0; i < throughLen; i++) {
|
|
1541
|
+
dataRow[throughForeignKeys[i]] = resultRow[throughPrimaryKeys[i]];
|
|
1542
|
+
}
|
|
1543
|
+
return dataRow;
|
|
1544
|
+
});
|
|
1545
|
+
const createdCount = await pqb._queryCreateManyFrom(
|
|
1547
1546
|
subQuery.count(),
|
|
1548
1547
|
baseQuery2,
|
|
1549
1548
|
data
|
|
@@ -1819,7 +1818,7 @@ const nestedUpdate = (state) => {
|
|
|
1819
1818
|
...state.throughForeignKeys
|
|
1820
1819
|
];
|
|
1821
1820
|
try {
|
|
1822
|
-
const count = await state.joinTableQuery.
|
|
1821
|
+
const count = await state.joinTableQuery.insertForEachFrom(
|
|
1823
1822
|
pqb._querySelect(
|
|
1824
1823
|
state.relatedTableQuery.whereOneOf(...relatedWheres),
|
|
1825
1824
|
[
|