orchid-orm 1.49.1 → 1.49.3
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 +8 -4
- package/dist/index.js +11 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -6
- package/dist/index.mjs.map +1 -1
- package/dist/migrations.js +3 -0
- package/dist/migrations.js.map +1 -1
- package/dist/migrations.mjs +3 -0
- package/dist/migrations.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TableData, Query, SelectableFromShape, CreateMethodsNames, CreateData, CreateBelongsToData, AddQueryDefaults, RelationConfigBase, QueryTake, QueryTakeOptional, UpdateData, WhereArg, JoinQueryMethod, DeleteMethodsNames, Db, IsolationLevel, TransactionOptions, Adapter, FromArg, FromResult, AdapterOptions, DbSharedOptions, RelationsBase, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, TableDataItem, ComputedOptionsFactory, QueryData, TableDataFn, DbTableOptionScopes, RawSQL, DynamicRawSQL, DefaultSchemaConfig, DefaultColumnTypes, QueryBeforeHook, QueryAfterHook, AfterHook, WhereResult, MergeQuery } from 'pqb';
|
|
1
|
+
import { TableData, Query, SelectableFromShape, CreateMethodsNames, CreateData, CreateBelongsToData, AddQueryDefaults, RelationConfigBase, QueryTake, QueryTakeOptional, UpdateData, WhereArg, JoinQueryMethod, DeleteMethodsNames, Db, IsolationLevel, TransactionOptions, Adapter, FromArg, FromResult, AdapterOptions, DbSharedOptions, RelationsBase, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, TableDataItem, ComputedOptionsFactory, ComputedOptionsConfig, QueryOrExpression, QueryData, TableDataFn, DbTableOptionScopes, RawSQL, DynamicRawSQL, DefaultSchemaConfig, DefaultColumnTypes, QueryBeforeHook, QueryAfterHook, AfterHook, WhereResult, MergeQuery } from 'pqb';
|
|
2
2
|
export * from 'pqb';
|
|
3
|
-
import { ColumnsShapeBase, ColumnShapeInputPartial, EmptyObject, MaybeArray, RecordUnknown, ShallowSimplify, ColumnShapeOutput, DefaultSelectColumns, ColumnShapeInput, IsQuery, CoreQueryScopes, ColumnSchemaConfig, StaticSQLArgs,
|
|
3
|
+
import { ColumnsShapeBase, ColumnShapeInputPartial, EmptyObject, MaybeArray, RecordUnknown, ShallowSimplify, ColumnShapeOutput, DefaultSelectColumns, QueryColumn, ColumnShapeInput, IsQuery, CoreQueryScopes, ColumnSchemaConfig, StaticSQLArgs, DynamicSQLArg, QueryColumns, QueryReturnType } from 'orchid-core';
|
|
4
4
|
export * from 'orchid-core';
|
|
5
5
|
|
|
6
6
|
interface RelationRefsOptions<Column extends PropertyKey = string, Shape extends ColumnsShapeBase = ColumnsShapeBase> {
|
|
@@ -468,8 +468,12 @@ type Queryable<T extends ORMTableInput> = ShallowSimplify<{
|
|
|
468
468
|
[K in keyof T['columns']['shape']]?: T['columns']['shape'][K]['queryType'];
|
|
469
469
|
}>;
|
|
470
470
|
type DefaultSelect<T extends ORMTableInput> = ShallowSimplify<Pick<ColumnShapeOutput<T['columns']['shape']>, DefaultSelectColumns<T['columns']['shape']>>>;
|
|
471
|
-
type Selectable<T extends ORMTableInput> = T['computed'] extends
|
|
472
|
-
[K in keyof
|
|
471
|
+
type Selectable<T extends ORMTableInput> = T['computed'] extends ((t: never) => infer R extends ComputedOptionsConfig) ? ShallowSimplify<ColumnShapeOutput<T['columns']['shape']> & {
|
|
472
|
+
[K in keyof R]: R[K] extends QueryOrExpression<unknown> ? R[K]['result']['value']['outputType'] : R[K] extends () => {
|
|
473
|
+
result: {
|
|
474
|
+
value: infer Value extends QueryColumn;
|
|
475
|
+
};
|
|
476
|
+
} ? Value['outputType'] : never;
|
|
473
477
|
}> : ShallowSimplify<ColumnShapeOutput<T['columns']['shape']>>;
|
|
474
478
|
type Insertable<T extends ORMTableInput> = ShallowSimplify<ColumnShapeInput<T['columns']['shape']>>;
|
|
475
479
|
type Updatable<T extends ORMTableInput> = ShallowSimplify<ColumnShapeInputPartial<T['columns']['shape']>>;
|
package/dist/index.js
CHANGED
|
@@ -234,7 +234,7 @@ function joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len)
|
|
|
234
234
|
}
|
|
235
235
|
return q;
|
|
236
236
|
}
|
|
237
|
-
const addAutoForeignKey = (tableConfig, from, to, primaryKeys, foreignKeys, options) => {
|
|
237
|
+
const addAutoForeignKey = (tableConfig, from, to, primaryKeys, foreignKeys, options, originalForeignKeys) => {
|
|
238
238
|
var _a;
|
|
239
239
|
const toTable = to.table;
|
|
240
240
|
let fkeyOptions = options.foreignKey !== void 0 ? options.foreignKey : tableConfig.autoForeignKeys;
|
|
@@ -273,7 +273,7 @@ const addAutoForeignKey = (tableConfig, from, to, primaryKeys, foreignKeys, opti
|
|
|
273
273
|
}
|
|
274
274
|
((_a = from.internal.tableData).constraints ?? (_a.constraints = [])).push({
|
|
275
275
|
references: {
|
|
276
|
-
columns: foreignKeys,
|
|
276
|
+
columns: originalForeignKeys || foreignKeys,
|
|
277
277
|
fnOrTable: toTable,
|
|
278
278
|
foreignColumns: primaryKeys,
|
|
279
279
|
options: fkeyOptions
|
|
@@ -307,6 +307,7 @@ const joinQueryChainHOF = (relPKeys, reverseJoin, joinQuery) => (joiningQuery, b
|
|
|
307
307
|
}
|
|
308
308
|
const item = selectRowNumber(result, relPKeys);
|
|
309
309
|
combineOrdering(result, query);
|
|
310
|
+
if (!result.q.select) result.q.select = ["*"];
|
|
310
311
|
return wrapQuery(jq, result, item);
|
|
311
312
|
};
|
|
312
313
|
const selectRowNumber = (result, relPKeys) => {
|
|
@@ -1317,17 +1318,19 @@ const removeColumnName = (column) => {
|
|
|
1317
1318
|
};
|
|
1318
1319
|
const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relationName, query) => {
|
|
1319
1320
|
const { options } = relation;
|
|
1321
|
+
const { snakeCase } = table.internal;
|
|
1320
1322
|
const primaryKeys = options.columns;
|
|
1321
1323
|
const foreignKeys = options.references;
|
|
1324
|
+
const originalForeignKeys = snakeCase ? [...foreignKeys] : foreignKeys;
|
|
1322
1325
|
const joinTable = options.through.table;
|
|
1323
1326
|
const throughForeignKeys = options.through.columns;
|
|
1327
|
+
const originalThroughForeignKeys = snakeCase ? [...throughForeignKeys] : throughForeignKeys;
|
|
1324
1328
|
const throughPrimaryKeys = options.through.references;
|
|
1325
1329
|
const { on } = options;
|
|
1326
1330
|
if (on) {
|
|
1327
1331
|
pqb._queryWhere(query, [on]);
|
|
1328
1332
|
pqb._queryDefaults(query, on);
|
|
1329
1333
|
}
|
|
1330
|
-
const { snakeCase } = table.internal;
|
|
1331
1334
|
const foreignKeysFull = foreignKeys.map((key, i) => {
|
|
1332
1335
|
if (snakeCase) key = foreignKeys[i] = orchidCore.toSnakeCase(key);
|
|
1333
1336
|
return `${joinTable}.${key}`;
|
|
@@ -1369,7 +1372,8 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
|
|
|
1369
1372
|
table,
|
|
1370
1373
|
primaryKeys,
|
|
1371
1374
|
foreignKeys,
|
|
1372
|
-
relation.options
|
|
1375
|
+
relation.options,
|
|
1376
|
+
originalForeignKeys
|
|
1373
1377
|
);
|
|
1374
1378
|
addAutoForeignKey(
|
|
1375
1379
|
tableConfig,
|
|
@@ -1377,7 +1381,8 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
|
|
|
1377
1381
|
query,
|
|
1378
1382
|
throughPrimaryKeys,
|
|
1379
1383
|
throughForeignKeys,
|
|
1380
|
-
relation.options.through
|
|
1384
|
+
relation.options.through,
|
|
1385
|
+
originalThroughForeignKeys
|
|
1381
1386
|
);
|
|
1382
1387
|
const state = {
|
|
1383
1388
|
relatedTableQuery: query,
|
|
@@ -2080,7 +2085,7 @@ const orchidORM = ({
|
|
|
2080
2085
|
table.types,
|
|
2081
2086
|
transactionStorage,
|
|
2082
2087
|
options2,
|
|
2083
|
-
table.constructor.prototype.tableData ??
|
|
2088
|
+
table.constructor.prototype.tableData ?? {}
|
|
2084
2089
|
);
|
|
2085
2090
|
dbTable.definedAs = key;
|
|
2086
2091
|
dbTable.db = result;
|