orchid-orm 1.19.0 → 1.20.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 +10 -9
- package/dist/index.js +52 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Query, QueryWithTable, SetQueryTableAlias, RelationJoinQuery, WhereArg, UpdateData, CreateData, AddQueryDefaults, Db, IsolationLevel, TransactionOptions, Adapter, FromArgs, FromResult, AdapterOptions, QueryLogOptions, NoPrimaryKeyOption, RelationQuery, RelationConfigBase, RelationQueryBase, ComputedColumnsBase, MapTableScopesOption, QueryData, QueryBase, DbTableOptionScopes, DefaultColumnTypes, QueryBeforeHook, QueryAfterHook, AfterHook, WhereResult, MergeQuery, SetQueryReturns, QueryReturnType } from 'pqb';
|
|
1
|
+
import { Query, QueryWithTable, SetQueryTableAlias, RelationJoinQuery, WhereArg, UpdateData, CreateData, AddQueryDefaults, Db, IsolationLevel, TransactionOptions, Adapter, FromArgs, FromResult, AdapterOptions, QueryLogOptions, NoPrimaryKeyOption, RelationQuery, RelationConfigBase, RelationQueryBase, ComputedColumnsBase, MapTableScopesOption, QueryData, QueryBase, DbTableOptionScopes, DefaultSchemaConfig, DefaultColumnTypes, QueryBeforeHook, QueryAfterHook, AfterHook, WhereResult, MergeQuery, SetQueryReturns, QueryReturnType } from 'pqb';
|
|
2
2
|
export * from 'pqb';
|
|
3
|
-
import { ColumnsShapeBase, EmptyObject, MaybeArray, StringKey, CoreQueryScopes, ColumnShapeQueryType, ColumnShapeOutput, ColumnShapeInput } from 'orchid-core';
|
|
3
|
+
import { ColumnsShapeBase, EmptyObject, MaybeArray, StringKey, CoreQueryScopes, ColumnShapeQueryType, ColumnShapeOutput, ColumnShapeInput, ColumnSchemaConfig } from 'orchid-core';
|
|
4
4
|
|
|
5
5
|
type RelationCommonOptions<Related extends TableClass = TableClass, Scope extends Query = Query> = {
|
|
6
6
|
scope?: ScopeFn<Related, Scope>;
|
|
@@ -374,7 +374,6 @@ type Updateable<T extends Table> = Partial<Insertable<T>>;
|
|
|
374
374
|
type BeforeHookMethod = <T extends Table>(cb: QueryBeforeHook) => T;
|
|
375
375
|
type AfterHookMethod = <T extends Table>(cb: QueryAfterHook) => T;
|
|
376
376
|
type AfterSelectableHookMethod = <T extends Table, S extends (keyof T['columns'])[]>(this: T, select: S, cb: AfterHook<S, T['columns']>) => T;
|
|
377
|
-
type SchemaProviderBase = any;
|
|
378
377
|
interface BaseTableInstance<ColumnTypes> {
|
|
379
378
|
table: string;
|
|
380
379
|
columns: ColumnsShapeBase;
|
|
@@ -530,23 +529,25 @@ interface BaseTableInstance<ColumnTypes> {
|
|
|
530
529
|
afterDelete: AfterSelectableHookMethod;
|
|
531
530
|
afterDeleteCommit: AfterSelectableHookMethod;
|
|
532
531
|
}
|
|
533
|
-
interface BaseTableClass<
|
|
532
|
+
interface BaseTableClass<SchemaConfig extends ColumnSchemaConfig, ColumnTypes> {
|
|
534
533
|
nowSQL: string | undefined;
|
|
535
534
|
exportAs: string;
|
|
536
|
-
schema: SchemaProvider;
|
|
537
535
|
getFilePath(): string;
|
|
538
536
|
new (): BaseTableInstance<ColumnTypes>;
|
|
539
537
|
instance(): BaseTableInstance<ColumnTypes>;
|
|
538
|
+
inputSchema: SchemaConfig['inputSchema'];
|
|
539
|
+
outputSchema: SchemaConfig['outputSchema'];
|
|
540
|
+
querySchema: SchemaConfig['querySchema'];
|
|
540
541
|
}
|
|
541
|
-
declare function createBaseTable<
|
|
542
|
-
|
|
542
|
+
declare function createBaseTable<SchemaConfig extends ColumnSchemaConfig = DefaultSchemaConfig, ColumnTypes = DefaultColumnTypes<SchemaConfig>>({ schemaConfig, columnTypes: columnTypesArg, snakeCase, filePath: filePathArg, nowSQL, exportAs, language, }?: {
|
|
543
|
+
schemaConfig?: SchemaConfig;
|
|
544
|
+
columnTypes?: ColumnTypes | ((t: DefaultColumnTypes<SchemaConfig>) => ColumnTypes);
|
|
543
545
|
snakeCase?: boolean;
|
|
544
546
|
filePath?: string;
|
|
545
547
|
nowSQL?: string;
|
|
546
548
|
exportAs?: string;
|
|
547
549
|
language?: string;
|
|
548
|
-
|
|
549
|
-
}): BaseTableClass<ColumnTypes, SchemaProvider>;
|
|
550
|
+
}): BaseTableClass<SchemaConfig, ColumnTypes>;
|
|
550
551
|
|
|
551
552
|
type QueryMethods<T extends Query> = Record<string, (q: T, ...args: any[]) => any>;
|
|
552
553
|
type QueryOne<T extends Query> = SetQueryReturns<T, Exclude<QueryReturnType, 'all'>>;
|
package/dist/index.js
CHANGED
|
@@ -5,25 +5,18 @@ var orchidCore = require('orchid-core');
|
|
|
5
5
|
var node_async_hooks = require('node:async_hooks');
|
|
6
6
|
|
|
7
7
|
function createBaseTable({
|
|
8
|
+
schemaConfig = pqb.defaultSchemaConfig,
|
|
8
9
|
columnTypes: columnTypesArg,
|
|
9
10
|
snakeCase,
|
|
10
11
|
filePath: filePathArg,
|
|
11
12
|
nowSQL,
|
|
12
13
|
exportAs = "BaseTable",
|
|
13
|
-
language
|
|
14
|
-
schemaProvider: schemaProviderArg
|
|
14
|
+
language
|
|
15
15
|
} = {}) {
|
|
16
16
|
var _a;
|
|
17
|
-
const columnTypes = typeof columnTypesArg === "function" ? columnTypesArg(
|
|
18
|
-
pqb.columnTypes
|
|
19
|
-
) : columnTypesArg || pqb.columnTypes;
|
|
17
|
+
const columnTypes = typeof columnTypesArg === "function" ? columnTypesArg(pqb.makeColumnTypes(schemaConfig)) : columnTypesArg || pqb.makeColumnTypes(pqb.defaultSchemaConfig);
|
|
20
18
|
const filePathOrStack = filePathArg || orchidCore.getStackTrace();
|
|
21
19
|
let filePath;
|
|
22
|
-
function schemaProvider() {
|
|
23
|
-
const schema = schemaProviderArg.call(this);
|
|
24
|
-
this.schema = () => schema;
|
|
25
|
-
return schema;
|
|
26
|
-
}
|
|
27
20
|
const base = (_a = class {
|
|
28
21
|
constructor() {
|
|
29
22
|
this.snakeCase = snakeCase;
|
|
@@ -31,6 +24,21 @@ function createBaseTable({
|
|
|
31
24
|
this.q = {};
|
|
32
25
|
this.language = language;
|
|
33
26
|
}
|
|
27
|
+
static inputSchema() {
|
|
28
|
+
return this._inputSchema === void 0 ? this._inputSchema = schemaConfig.inputSchema.call(this) : this._inputSchema;
|
|
29
|
+
}
|
|
30
|
+
static outputSchema() {
|
|
31
|
+
return this._outputSchema === void 0 ? this._outputSchema = schemaConfig.outputSchema.call(this) : this._outputSchema;
|
|
32
|
+
}
|
|
33
|
+
static querySchema() {
|
|
34
|
+
return this._querySchema === void 0 ? this._querySchema = schemaConfig.querySchema.call(this) : this._querySchema;
|
|
35
|
+
}
|
|
36
|
+
static updateSchema() {
|
|
37
|
+
return this._updateSchema === void 0 ? this._updateSchema = schemaConfig.updateSchema.call(this) : this._updateSchema;
|
|
38
|
+
}
|
|
39
|
+
static pkeySchema() {
|
|
40
|
+
return this._pkeySchema === void 0 ? this._pkeySchema = schemaConfig.pkeySchema.call(this) : this._pkeySchema;
|
|
41
|
+
}
|
|
34
42
|
static getFilePath() {
|
|
35
43
|
if (filePath)
|
|
36
44
|
return filePath;
|
|
@@ -77,7 +85,7 @@ function createBaseTable({
|
|
|
77
85
|
}
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
|
-
return shape;
|
|
88
|
+
return this.constructor.prototype.columns = shape;
|
|
81
89
|
}
|
|
82
90
|
setComputed(computed) {
|
|
83
91
|
return computed;
|
|
@@ -113,7 +121,7 @@ function createBaseTable({
|
|
|
113
121
|
options
|
|
114
122
|
};
|
|
115
123
|
}
|
|
116
|
-
}, _a.nowSQL = nowSQL, _a.exportAs = exportAs, _a
|
|
124
|
+
}, _a.nowSQL = nowSQL, _a.exportAs = exportAs, _a);
|
|
117
125
|
orchidCore.applyMixins(base, [pqb.QueryHooks]);
|
|
118
126
|
base.prototype.types = columnTypes;
|
|
119
127
|
return base;
|
|
@@ -226,8 +234,8 @@ const joinQueryChainingHOF = (reverseJoin, joinQuery) => (joiningQuery, baseQuer
|
|
|
226
234
|
};
|
|
227
235
|
|
|
228
236
|
class BelongsToVirtualColumn extends pqb.VirtualColumn {
|
|
229
|
-
constructor(key, state) {
|
|
230
|
-
super();
|
|
237
|
+
constructor(schema, key, state) {
|
|
238
|
+
super(schema);
|
|
231
239
|
this.key = key;
|
|
232
240
|
this.state = state;
|
|
233
241
|
this.nestedInsert = nestedInsert$3(this.state);
|
|
@@ -304,7 +312,11 @@ const makeBelongsToMethod = (relation, relationName, query) => {
|
|
|
304
312
|
method(params) {
|
|
305
313
|
return query.where(makeWhere(params));
|
|
306
314
|
},
|
|
307
|
-
virtualColumn: new BelongsToVirtualColumn(
|
|
315
|
+
virtualColumn: new BelongsToVirtualColumn(
|
|
316
|
+
pqb.defaultSchemaConfig,
|
|
317
|
+
relationName,
|
|
318
|
+
state
|
|
319
|
+
),
|
|
308
320
|
joinQuery: joinQueryChainingHOF(
|
|
309
321
|
reverseJoin,
|
|
310
322
|
(joiningQuery, baseQuery) => join(baseQuery, joiningQuery, primaryKeys, foreignKeys)
|
|
@@ -505,8 +517,8 @@ var __spreadValues$5 = (a, b) => {
|
|
|
505
517
|
return a;
|
|
506
518
|
};
|
|
507
519
|
class HasOneVirtualColumn extends pqb.VirtualColumn {
|
|
508
|
-
constructor(key, state) {
|
|
509
|
-
super();
|
|
520
|
+
constructor(schema, key, state) {
|
|
521
|
+
super(schema);
|
|
510
522
|
this.key = key;
|
|
511
523
|
this.state = state;
|
|
512
524
|
this.nestedInsert = nestedInsert$2(state);
|
|
@@ -603,7 +615,11 @@ const makeHasOneMethod = (table, relation, relationName, query) => {
|
|
|
603
615
|
}
|
|
604
616
|
return query.where(values)._defaults(values);
|
|
605
617
|
},
|
|
606
|
-
virtualColumn: new HasOneVirtualColumn(
|
|
618
|
+
virtualColumn: new HasOneVirtualColumn(
|
|
619
|
+
pqb.defaultSchemaConfig,
|
|
620
|
+
relationName,
|
|
621
|
+
state
|
|
622
|
+
),
|
|
607
623
|
joinQuery: joinQueryChainingHOF(
|
|
608
624
|
reverseJoin,
|
|
609
625
|
(joiningQuery, baseQuery) => joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len)
|
|
@@ -749,8 +765,8 @@ var __spreadValues$4 = (a, b) => {
|
|
|
749
765
|
return a;
|
|
750
766
|
};
|
|
751
767
|
class HasManyVirtualColumn extends pqb.VirtualColumn {
|
|
752
|
-
constructor(key, state) {
|
|
753
|
-
super();
|
|
768
|
+
constructor(schema, key, state) {
|
|
769
|
+
super(schema);
|
|
754
770
|
this.key = key;
|
|
755
771
|
this.state = state;
|
|
756
772
|
this.nestedInsert = nestedInsert$1(state);
|
|
@@ -851,7 +867,11 @@ const makeHasManyMethod = (table, relation, relationName, query) => {
|
|
|
851
867
|
}
|
|
852
868
|
return query.where(values)._defaults(values);
|
|
853
869
|
},
|
|
854
|
-
virtualColumn: new HasManyVirtualColumn(
|
|
870
|
+
virtualColumn: new HasManyVirtualColumn(
|
|
871
|
+
pqb.defaultSchemaConfig,
|
|
872
|
+
relationName,
|
|
873
|
+
state
|
|
874
|
+
),
|
|
855
875
|
joinQuery: joinQueryChainingHOF(
|
|
856
876
|
reverseJoin,
|
|
857
877
|
(joiningQuery, baseQuery) => joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len)
|
|
@@ -1042,8 +1062,8 @@ var __spreadValues$3 = (a, b) => {
|
|
|
1042
1062
|
};
|
|
1043
1063
|
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
1044
1064
|
class HasAndBelongsToManyVirtualColumn extends pqb.VirtualColumn {
|
|
1045
|
-
constructor(key, state) {
|
|
1046
|
-
super();
|
|
1065
|
+
constructor(schema, key, state) {
|
|
1066
|
+
super(schema);
|
|
1047
1067
|
this.key = key;
|
|
1048
1068
|
this.state = state;
|
|
1049
1069
|
this.nestedInsert = nestedInsert(state);
|
|
@@ -1112,7 +1132,9 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
1112
1132
|
baseQuery.table = joinTable;
|
|
1113
1133
|
const shape = {};
|
|
1114
1134
|
for (let i = 0; i < len; i++) {
|
|
1115
|
-
shape[foreignKeys[i]] = removeColumnName(
|
|
1135
|
+
shape[foreignKeys[i]] = removeColumnName(
|
|
1136
|
+
table.shape[primaryKeys[i]]
|
|
1137
|
+
);
|
|
1116
1138
|
}
|
|
1117
1139
|
for (let i = 0; i < throughLen; i++) {
|
|
1118
1140
|
shape[throughForeignKeys[i]] = removeColumnName(
|
|
@@ -1176,7 +1198,11 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
1176
1198
|
return q._where(where);
|
|
1177
1199
|
});
|
|
1178
1200
|
},
|
|
1179
|
-
virtualColumn: new HasAndBelongsToManyVirtualColumn(
|
|
1201
|
+
virtualColumn: new HasAndBelongsToManyVirtualColumn(
|
|
1202
|
+
pqb.defaultSchemaConfig,
|
|
1203
|
+
relationName,
|
|
1204
|
+
state
|
|
1205
|
+
),
|
|
1180
1206
|
joinQuery: joinQueryChainingHOF(reverseJoin, (joiningQuery, baseQuery2) => {
|
|
1181
1207
|
const joined = joinQuery(
|
|
1182
1208
|
joiningQuery,
|
|
@@ -1735,7 +1761,7 @@ const orchidORM = (_a, tables) => {
|
|
|
1735
1761
|
void 0,
|
|
1736
1762
|
void 0,
|
|
1737
1763
|
pqb.anyShape,
|
|
1738
|
-
pqb.
|
|
1764
|
+
pqb.makeColumnTypes(pqb.defaultSchemaConfig),
|
|
1739
1765
|
transactionStorage,
|
|
1740
1766
|
commonOptions
|
|
1741
1767
|
);
|