orchid-orm 1.60.4 → 1.61.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 +6 -6
- package/dist/index.js +12 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -15
- package/dist/index.mjs.map +1 -1
- package/dist/migrations/index.js +14 -6
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs +16 -8
- package/dist/migrations/index.mjs.map +1 -1
- package/dist/migrations/node-postgres.js +14 -6
- package/dist/migrations/node-postgres.js.map +1 -1
- package/dist/migrations/node-postgres.mjs +16 -8
- package/dist/migrations/node-postgres.mjs.map +1 -1
- package/dist/migrations/postgres-js.js +14 -6
- package/dist/migrations/postgres-js.js.map +1 -1
- package/dist/migrations/postgres-js.mjs +16 -8
- package/dist/migrations/postgres-js.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Column, TableData, ColumnsShape, Query, SelectableFromShape, CreateManyMethodsNames, QueryHasWhere, RelationConfigBase, QueryManyTake, QueryManyTakeOptional, EmptyObject, CreateData, UpdateData, WhereArg, CreateMethodsNames, MaybeArray, JoinQueryMethod, DeleteMethodsNames, Db, IsolationLevel, TransactionOptions, AfterCommitStandaloneHook, AdapterBase, FromArg, FromResult, DbSharedOptions, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, TableDataItem, ComputedOptionsFactory, RecordUnknown, ShallowSimplify, ComputedOptionsConfig, QueryOrExpression, QueryData, IsQuery, TableDataFn, DbTableOptionScopes, QueryScopes, ColumnSchemaConfig,
|
|
1
|
+
import { Column, TableData, ColumnsShape, Query, SelectableFromShape, CreateManyMethodsNames, QueryHasWhere, RelationConfigBase, QueryManyTake, QueryManyTakeOptional, EmptyObject, CreateData, UpdateData, WhereArg, CreateMethodsNames, MaybeArray, JoinQueryMethod, DeleteMethodsNames, Db, IsolationLevel, TransactionOptions, AfterCommitStandaloneHook, AdapterBase, FromArg, FromResult, DbSharedOptions, QuerySchema, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, TableDataItem, ComputedOptionsFactory, RecordUnknown, ShallowSimplify, ComputedOptionsConfig, QueryOrExpression, QueryData, IsQuery, TableDataFn, DbTableOptionScopes, QueryScopes, ColumnSchemaConfig, DbSqlMethod, DefaultSchemaConfig, DefaultColumnTypes, QueryBeforeHook, QueryBeforeActionHook, QueryAfterHook, AfterHook, MergeQuery, QueryReturnType } from 'pqb';
|
|
2
2
|
export * from 'pqb';
|
|
3
3
|
|
|
4
4
|
interface RelationRefsOptions<Column extends PropertyKey = string, Shape extends Column.Shape.QueryInit = Column.Shape.QueryInit> {
|
|
@@ -292,7 +292,7 @@ interface OrchidORMMethods {
|
|
|
292
292
|
$close(): Promise<void>;
|
|
293
293
|
}
|
|
294
294
|
type OrchidOrmParam<Options> = true | null extends true ? 'Set strict: true to tsconfig' : Options;
|
|
295
|
-
declare const orchidORMWithAdapter: <T extends TableClasses>({ log, logger, autoPreparedStatements, noPrimaryKey, ...options }: OrchidOrmParam<({
|
|
295
|
+
declare const orchidORMWithAdapter: <T extends TableClasses>({ log, logger, autoPreparedStatements, noPrimaryKey, schema, ...options }: OrchidOrmParam<({
|
|
296
296
|
db: Query;
|
|
297
297
|
} | {
|
|
298
298
|
adapter: AdapterBase;
|
|
@@ -308,6 +308,7 @@ interface HasAndBelongsToManyOptions<Columns extends Column.Shape.QueryInit = Co
|
|
|
308
308
|
references: string[];
|
|
309
309
|
foreignKey?: boolean | TableData.References.Options;
|
|
310
310
|
through: {
|
|
311
|
+
schema?: QuerySchema;
|
|
311
312
|
table: string;
|
|
312
313
|
columns: string[];
|
|
313
314
|
references: (keyof Related['columns']['shape'])[];
|
|
@@ -442,7 +443,7 @@ interface ORMTableInput {
|
|
|
442
443
|
shape: Column.Shape.QueryInit;
|
|
443
444
|
data: MaybeArray<TableDataItem>;
|
|
444
445
|
};
|
|
445
|
-
schema?:
|
|
446
|
+
schema?: QuerySchema;
|
|
446
447
|
types: unknown;
|
|
447
448
|
noPrimaryKey?: boolean;
|
|
448
449
|
filePath: string;
|
|
@@ -487,7 +488,7 @@ interface BaseTableInstance<ColumnTypes> {
|
|
|
487
488
|
shape: Column.Shape.QueryInit;
|
|
488
489
|
data: MaybeArray<TableDataItem>;
|
|
489
490
|
};
|
|
490
|
-
schema?:
|
|
491
|
+
schema?: QuerySchema;
|
|
491
492
|
noPrimaryKey?: boolean;
|
|
492
493
|
snakeCase?: boolean;
|
|
493
494
|
types: ColumnTypes;
|
|
@@ -666,8 +667,7 @@ interface BaseTableClass<SchemaConfig extends ColumnSchemaConfig, ColumnTypes> {
|
|
|
666
667
|
exportAs: string;
|
|
667
668
|
columnTypes: ColumnTypes;
|
|
668
669
|
getFilePath(): string;
|
|
669
|
-
sql
|
|
670
|
-
sql<T>(...args: [DynamicSQLArg<Column.Pick.QueryColumnOfType<T>>]): DynamicRawSQL<Column.Pick.QueryColumnOfType<T>, ColumnTypes>;
|
|
670
|
+
sql: DbSqlMethod<ColumnTypes>;
|
|
671
671
|
new (): BaseTableInstance<ColumnTypes>;
|
|
672
672
|
instance(): BaseTableInstance<ColumnTypes>;
|
|
673
673
|
/**
|
package/dist/index.js
CHANGED
|
@@ -29,11 +29,6 @@ function createBaseTable({
|
|
|
29
29
|
this.q = {};
|
|
30
30
|
this.language = language;
|
|
31
31
|
}
|
|
32
|
-
static sql(...args) {
|
|
33
|
-
const sql = pqb.raw(...args);
|
|
34
|
-
sql.columnTypes = columnTypes;
|
|
35
|
-
return sql;
|
|
36
|
-
}
|
|
37
32
|
static inputSchema() {
|
|
38
33
|
this.instance();
|
|
39
34
|
return this._inputSchema === void 0 ? this._inputSchema = schemaConfig.inputSchema.call(this) : this._inputSchema;
|
|
@@ -138,7 +133,7 @@ function createBaseTable({
|
|
|
138
133
|
options
|
|
139
134
|
};
|
|
140
135
|
}
|
|
141
|
-
}, _a.nowSQL = nowSQL, _a.exportAs = exportAs, _a.columnTypes = columnTypes, _a);
|
|
136
|
+
}, _a.nowSQL = nowSQL, _a.exportAs = exportAs, _a.columnTypes = columnTypes, _a.sql = pqb._createDbSqlMethod(columnTypes), _a);
|
|
142
137
|
pqb.applyMixins(base, [pqb.QueryHooks]);
|
|
143
138
|
base.prototype.types = columnTypes;
|
|
144
139
|
base.prototype.snakeCase = snakeCase;
|
|
@@ -1309,7 +1304,7 @@ const removeColumnName = (column) => {
|
|
|
1309
1304
|
cloned.data = { ...column.data, name: void 0 };
|
|
1310
1305
|
return cloned;
|
|
1311
1306
|
};
|
|
1312
|
-
const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relationName, query) => {
|
|
1307
|
+
const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relationName, query, schema) => {
|
|
1313
1308
|
const { options } = relation;
|
|
1314
1309
|
const { snakeCase } = table.internal;
|
|
1315
1310
|
const primaryKeys = options.columns;
|
|
@@ -1358,6 +1353,7 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
|
|
|
1358
1353
|
baseQuery.shape = shape;
|
|
1359
1354
|
baseQuery.q = {
|
|
1360
1355
|
...baseQuery.q,
|
|
1356
|
+
schema: options.through.schema || schema,
|
|
1361
1357
|
shape: baseQuery.shape
|
|
1362
1358
|
};
|
|
1363
1359
|
const subQuery = Object.create(baseQuery);
|
|
@@ -1838,7 +1834,7 @@ const nestedUpdate = (state) => {
|
|
|
1838
1834
|
};
|
|
1839
1835
|
};
|
|
1840
1836
|
|
|
1841
|
-
const applyRelations = (qb, tables, result) => {
|
|
1837
|
+
const applyRelations = (qb, tables, result, schema) => {
|
|
1842
1838
|
const tableEntries = Object.entries(tables);
|
|
1843
1839
|
const delayedRelations = /* @__PURE__ */ new Map();
|
|
1844
1840
|
for (const name in tables) {
|
|
@@ -1888,7 +1884,7 @@ const applyRelations = (qb, tables, result) => {
|
|
|
1888
1884
|
continue;
|
|
1889
1885
|
}
|
|
1890
1886
|
}
|
|
1891
|
-
applyRelation(table, qb, data, delayedRelations);
|
|
1887
|
+
applyRelation(table, qb, data, delayedRelations, schema);
|
|
1892
1888
|
}
|
|
1893
1889
|
}
|
|
1894
1890
|
if (delayedRelations.size) {
|
|
@@ -1924,7 +1920,7 @@ const delayRelation = (delayedRelations, table, relationName, data) => {
|
|
|
1924
1920
|
tableRelations[relationName] = [data];
|
|
1925
1921
|
}
|
|
1926
1922
|
};
|
|
1927
|
-
const applyRelation = (table, qb, { relationName, relation, dbTable, otherDbTable }, delayedRelations) => {
|
|
1923
|
+
const applyRelation = (table, qb, { relationName, relation, dbTable, otherDbTable }, delayedRelations, schema) => {
|
|
1928
1924
|
const baseQuery = Object.create(otherDbTable);
|
|
1929
1925
|
baseQuery.baseQuery = baseQuery;
|
|
1930
1926
|
const query = baseQuery.as(relationName);
|
|
@@ -1949,7 +1945,8 @@ const applyRelation = (table, qb, { relationName, relation, dbTable, otherDbTabl
|
|
|
1949
1945
|
qb,
|
|
1950
1946
|
relation,
|
|
1951
1947
|
relationName,
|
|
1952
|
-
query
|
|
1948
|
+
query,
|
|
1949
|
+
schema
|
|
1953
1950
|
);
|
|
1954
1951
|
} else {
|
|
1955
1952
|
throw new Error(`Unknown relation type ${type}`);
|
|
@@ -1988,7 +1985,7 @@ const applyRelation = (table, qb, { relationName, relation, dbTable, otherDbTabl
|
|
|
1988
1985
|
const tableRelations = delayedRelations.get(dbTable);
|
|
1989
1986
|
if (!tableRelations) return;
|
|
1990
1987
|
tableRelations[relationName]?.forEach((data2) => {
|
|
1991
|
-
applyRelation(table, qb, data2, delayedRelations);
|
|
1988
|
+
applyRelation(table, qb, data2, delayedRelations, schema);
|
|
1992
1989
|
});
|
|
1993
1990
|
};
|
|
1994
1991
|
|
|
@@ -2013,6 +2010,7 @@ const orchidORMWithAdapter = ({
|
|
|
2013
2010
|
logger,
|
|
2014
2011
|
autoPreparedStatements,
|
|
2015
2012
|
noPrimaryKey = "error",
|
|
2013
|
+
schema,
|
|
2016
2014
|
...options
|
|
2017
2015
|
}, tables) => {
|
|
2018
2016
|
const commonOptions = {
|
|
@@ -2066,7 +2064,7 @@ const orchidORMWithAdapter = ({
|
|
|
2066
2064
|
tableInstances[key] = table;
|
|
2067
2065
|
const options2 = {
|
|
2068
2066
|
...commonOptions,
|
|
2069
|
-
schema: table.schema,
|
|
2067
|
+
schema: table.schema || schema,
|
|
2070
2068
|
language: table.language,
|
|
2071
2069
|
scopes: table.scopes,
|
|
2072
2070
|
softDelete: table.softDelete,
|
|
@@ -2093,7 +2091,7 @@ const orchidORMWithAdapter = ({
|
|
|
2093
2091
|
dbTable.name = table.constructor.name;
|
|
2094
2092
|
result[key] = dbTable;
|
|
2095
2093
|
}
|
|
2096
|
-
applyRelations(qb, tableInstances, result);
|
|
2094
|
+
applyRelations(qb, tableInstances, result, schema);
|
|
2097
2095
|
for (const key in tables) {
|
|
2098
2096
|
const table = tableInstances[key];
|
|
2099
2097
|
if (table.init) {
|