orchid-orm 1.71.1 → 1.72.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/bun.d.ts +17 -0
- package/dist/bun.js +31 -0
- package/dist/bun.js.map +1 -0
- package/dist/bun.mjs +21 -0
- package/dist/bun.mjs.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +23 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -20
- package/dist/index.mjs.map +1 -1
- package/dist/migrations/bun.d.ts +14 -0
- package/dist/migrations/bun.js +12 -0
- package/dist/migrations/bun.js.map +1 -0
- package/dist/migrations/bun.mjs +5 -0
- package/dist/migrations/bun.mjs.map +1 -0
- package/dist/migrations/index.js +4 -4
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs +5 -5
- package/dist/migrations/index.mjs.map +1 -1
- package/dist/node-postgres.d.ts +2 -2
- package/dist/node-postgres.js +6 -0
- package/dist/node-postgres.js.map +1 -1
- package/dist/node-postgres.mjs +2 -2
- package/dist/node-postgres.mjs.map +1 -1
- package/package.json +28 -17
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { DynamicRawSQL, QueryHooks, RawSql, VirtualColumn, _appendQuery, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, applyMixins, cloneQueryBaseUnscoped, defaultSchemaConfig, emptyArray, emptyObject, getCallerFilePath, getClonedQueryData, getColumnTypes, getFreeAlias, getPrimaryKeys, getQueryAs, getShapeFromSelect, getStackTrace, isExpression, isQueryReturnsAll, makeColumnTypes, noop, objectHasValues, parseTableData, pick, prepareSubQueryForSql, pushQueryOnForOuter, setQueryObjectValueImmutable, toArray, toSnakeCase } from "pqb/internal";
|
|
1
|
+
import { DynamicRawSQL, QueryHooks, RawSql, VirtualColumn, _appendQuery, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, applyMixins, cloneQueryBaseUnscoped, defaultSchemaConfig, emptyArray, emptyObject, getCallerFilePath, getClonedQueryData, getColumnTypes, getFreeAlias, getPrimaryKeys, getQueryAs, getShapeFromSelect, getStackTrace, internalSchemaConfig, isExpression, isQueryReturnsAll, makeColumnTypes, noop, objectHasValues, parseTableData, pick, prepareSubQueryForSql, pushQueryOnForOuter, setQueryObjectValueImmutable, toArray, toSnakeCase } from "pqb/internal";
|
|
2
2
|
import { Db, NotFoundError, OrchidOrmInternalError } from "pqb";
|
|
3
3
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
4
|
export * from "pqb";
|
|
5
5
|
function createBaseTable({ schemaConfig = defaultSchemaConfig, columnTypes: columnTypesArg, snakeCase, filePath: filePathArg, nowSQL, exportAs = "BaseTable", language, autoForeignKeys } = {}) {
|
|
6
|
-
const
|
|
6
|
+
const schema = schemaConfig();
|
|
7
|
+
const columnTypes = typeof columnTypesArg === "function" ? columnTypesArg(makeColumnTypes(schema)) : columnTypesArg || makeColumnTypes(schema);
|
|
7
8
|
const filePathOrStack = filePathArg || getStackTrace();
|
|
8
9
|
let filePath;
|
|
9
10
|
const defaultColumns = {
|
|
@@ -33,27 +34,27 @@ function createBaseTable({ schemaConfig = defaultSchemaConfig, columnTypes: colu
|
|
|
33
34
|
}
|
|
34
35
|
static inputSchema() {
|
|
35
36
|
this.instance();
|
|
36
|
-
return this._inputSchema === void 0 ? this._inputSchema =
|
|
37
|
+
return this._inputSchema === void 0 ? this._inputSchema = schema.inputSchema.call(this) : this._inputSchema;
|
|
37
38
|
}
|
|
38
39
|
static outputSchema() {
|
|
39
40
|
this.instance();
|
|
40
|
-
return this._outputSchema === void 0 ? this._outputSchema =
|
|
41
|
+
return this._outputSchema === void 0 ? this._outputSchema = schema.outputSchema.call(this) : this._outputSchema;
|
|
41
42
|
}
|
|
42
43
|
static querySchema() {
|
|
43
44
|
this.instance();
|
|
44
|
-
return this._querySchema === void 0 ? this._querySchema =
|
|
45
|
+
return this._querySchema === void 0 ? this._querySchema = schema.querySchema.call(this) : this._querySchema;
|
|
45
46
|
}
|
|
46
47
|
static createSchema() {
|
|
47
48
|
this.instance();
|
|
48
|
-
return this._createSchema === void 0 ? this._createSchema =
|
|
49
|
+
return this._createSchema === void 0 ? this._createSchema = schema.createSchema.call(this) : this._createSchema;
|
|
49
50
|
}
|
|
50
51
|
static updateSchema() {
|
|
51
52
|
this.instance();
|
|
52
|
-
return this._updateSchema === void 0 ? this._updateSchema =
|
|
53
|
+
return this._updateSchema === void 0 ? this._updateSchema = schema.updateSchema.call(this) : this._updateSchema;
|
|
53
54
|
}
|
|
54
55
|
static pkeySchema() {
|
|
55
56
|
this.instance();
|
|
56
|
-
return this._pkeySchema === void 0 ? this._pkeySchema =
|
|
57
|
+
return this._pkeySchema === void 0 ? this._pkeySchema = schema.pkeySchema.call(this) : this._pkeySchema;
|
|
57
58
|
}
|
|
58
59
|
static getFilePath() {
|
|
59
60
|
if (filePath) return filePath;
|
|
@@ -390,7 +391,7 @@ const makeBelongsToMethod = (tableConfig, table, relation, relationName, query)
|
|
|
390
391
|
for (let i = 0; i < len; i++) obj[primaryKeys[i]] = params[foreignKeys[i]];
|
|
391
392
|
return query.where(obj);
|
|
392
393
|
},
|
|
393
|
-
virtualColumn: new BelongsToVirtualColumn(
|
|
394
|
+
virtualColumn: new BelongsToVirtualColumn(internalSchemaConfig, relationName, state),
|
|
394
395
|
joinQuery: joinQueryChainHOF(getPrimaryKeys(query), reverseJoin, (joiningQuery, baseQuery) => join(baseQuery, joiningQuery, primaryKeys, foreignKeys)),
|
|
395
396
|
reverseJoin
|
|
396
397
|
};
|
|
@@ -632,7 +633,7 @@ const makeHasOneMethod = (tableConfig, table, relation, relationName, query) =>
|
|
|
632
633
|
...values
|
|
633
634
|
});
|
|
634
635
|
},
|
|
635
|
-
virtualColumn: new HasOneVirtualColumn(
|
|
636
|
+
virtualColumn: new HasOneVirtualColumn(internalSchemaConfig, relationName, state),
|
|
636
637
|
joinQuery: joinQueryChainHOF(relPKeys, reverseJoin, (joiningQuery, baseQuery) => joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len)),
|
|
637
638
|
reverseJoin,
|
|
638
639
|
modifyRelatedQuery(relationQuery) {
|
|
@@ -817,7 +818,7 @@ const makeHasManyMethod = (tableConfig, table, relation, relationName, query) =>
|
|
|
817
818
|
...values
|
|
818
819
|
});
|
|
819
820
|
},
|
|
820
|
-
virtualColumn: new HasManyVirtualColumn(
|
|
821
|
+
virtualColumn: new HasManyVirtualColumn(internalSchemaConfig, relationName, state),
|
|
821
822
|
joinQuery: joinQueryChainHOF(relPKeys, reverseJoin, (joiningQuery, baseQuery) => joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len)),
|
|
822
823
|
reverseJoin,
|
|
823
824
|
modifyRelatedQuery(relationQuery) {
|
|
@@ -1057,7 +1058,7 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
|
|
|
1057
1058
|
});
|
|
1058
1059
|
return on ? _queryDefaults(q, on) : q;
|
|
1059
1060
|
},
|
|
1060
|
-
virtualColumn: new HasAndBelongsToManyVirtualColumn(subQuery,
|
|
1061
|
+
virtualColumn: new HasAndBelongsToManyVirtualColumn(subQuery, internalSchemaConfig, relationName, state),
|
|
1061
1062
|
joinQuery: joinQueryChainHOF(getPrimaryKeys(query), reverseJoin, (joiningQuery, baseQuery) => joinQuery(joiningQuery, getQueryAs(baseQuery), getQueryAs(joiningQuery), {
|
|
1062
1063
|
...joiningQuery.q.joinedShapes,
|
|
1063
1064
|
[baseQuery.q.as || baseQuery.table]: baseQuery.q.shape
|
|
@@ -1419,13 +1420,16 @@ const assignTablesToOrm = (tables, result, adapter, qb, asyncStorage, commonOpti
|
|
|
1419
1420
|
const bundleOrchidORMTables = (tables) => {
|
|
1420
1421
|
const result = {};
|
|
1421
1422
|
let dbAwareInstance;
|
|
1422
|
-
for (const key in tables) result[key] = {
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
return
|
|
1427
|
-
|
|
1428
|
-
|
|
1423
|
+
for (const key in tables) result[key] = {
|
|
1424
|
+
table: tables[key].instance().table,
|
|
1425
|
+
makeHelper(arg) {
|
|
1426
|
+
let fn;
|
|
1427
|
+
return (...args) => {
|
|
1428
|
+
if (!fn) fn = dbAwareInstance[key].makeHelper(arg);
|
|
1429
|
+
return fn(...args);
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
};
|
|
1429
1433
|
Object.defineProperty(result, orchidORMBundleMetadataKey, {
|
|
1430
1434
|
enumerable: false,
|
|
1431
1435
|
value: {
|
|
@@ -1463,7 +1467,7 @@ const privateOrchidORMWithAdapter = ({ log, logger, autoPreparedStatements, noPr
|
|
|
1463
1467
|
} else {
|
|
1464
1468
|
adapter = options.adapter;
|
|
1465
1469
|
asyncStorage = new AsyncLocalStorage();
|
|
1466
|
-
qb = _initQueryBuilder(adapter, makeColumnTypes(defaultSchemaConfig), asyncStorage, commonOptions, options);
|
|
1470
|
+
qb = _initQueryBuilder(adapter, makeColumnTypes(defaultSchemaConfig(adapter.driverAdapter.schemaConfig)), asyncStorage, commonOptions, options);
|
|
1467
1471
|
}
|
|
1468
1472
|
qb.internal.rls = options.rls;
|
|
1469
1473
|
const result = {
|