orchid-orm 1.9.30 → 1.9.32
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/README.md +1 -1
- package/dist/index.d.ts +11 -2
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as pqb from 'pqb';
|
|
2
|
-
import { BelongsToRelation, HasManyRelation, HasOneRelation, Db, IsolationLevel, TransactionOptions, Adapter, FromArgs, Query, FromResult, AdapterOptions, QueryLogOptions, NoPrimaryKeyOption, HasAndBelongsToManyRelation, SetQueryTableAlias, BaseRelation, RelationQuery, SetQueryReturnsOne, SetQueryReturnsOneOptional, SetQueryReturnsAll, DefaultColumnTypes, ColumnsShape, WhereResult, MergeQuery, SetQueryReturns, QueryReturnType } from 'pqb';
|
|
2
|
+
import { BelongsToRelation, HasManyRelation, HasOneRelation, Db, IsolationLevel, TransactionOptions, Adapter, FromArgs, Query, FromResult, AdapterOptions, QueryLogOptions, NoPrimaryKeyOption, HasAndBelongsToManyRelation, SetQueryTableAlias, BaseRelation, RelationQuery, SetQueryReturnsOne, SetQueryReturnsOneOptional, SetQueryReturnsAll, BeforeHookKey, BeforeHook, AfterHookKey, AfterHook, DefaultColumnTypes, ColumnsShape, WhereResult, MergeQuery, SetQueryReturns, QueryReturnType } from 'pqb';
|
|
3
3
|
export { OrchidOrmError, OrchidOrmInternalError, columnTypes, testTransaction } from 'pqb';
|
|
4
4
|
import * as orchid_core from 'orchid-core';
|
|
5
5
|
import { StringKey, EmptyObject, ColumnTypesBase, ColumnShapeOutput } from 'orchid-core';
|
|
@@ -148,11 +148,18 @@ type ScopeFn<Related extends TableClass, Scope extends Query> = (q: DbTable<Rela
|
|
|
148
148
|
type Table = {
|
|
149
149
|
table: string;
|
|
150
150
|
columns: ColumnsConfig;
|
|
151
|
+
hooks?: TableHooks;
|
|
151
152
|
schema?: string;
|
|
152
153
|
columnTypes: ColumnTypesBase;
|
|
153
154
|
noPrimaryKey?: boolean;
|
|
154
155
|
filePath: string;
|
|
155
156
|
};
|
|
157
|
+
type TableHooks = {
|
|
158
|
+
[K in BeforeHookKey]?: BeforeHook;
|
|
159
|
+
} & {
|
|
160
|
+
[K in AfterHookKey]?: AfterHook;
|
|
161
|
+
};
|
|
162
|
+
declare const addTableHooks: (table: Query, hooks: TableHooks) => void;
|
|
156
163
|
declare const createBaseTable: <CT extends Record<string, orchid_core.AnyColumnTypeCreator>>({ columnTypes, snakeCase, filePath, nowSQL, exportAs, }?: {
|
|
157
164
|
columnTypes?: CT | ((t: DefaultColumnTypes) => CT) | undefined;
|
|
158
165
|
snakeCase?: boolean | undefined;
|
|
@@ -310,6 +317,8 @@ declare const createBaseTable: <CT extends Record<string, orchid_core.AnyColumnT
|
|
|
310
317
|
check(check: orchid_core.RawExpression): {};
|
|
311
318
|
} : CT;
|
|
312
319
|
filePath: string;
|
|
320
|
+
callbacks?: TableHooks | undefined;
|
|
321
|
+
setHooks(callbacks: TableHooks): TableHooks;
|
|
313
322
|
setColumns<T_20 extends ColumnsShape>(fn: (t: Record<string, orchid_core.AnyColumnTypeCreator> extends CT ? {
|
|
314
323
|
timestamps<T extends orchid_core.ColumnTypeBase<unknown, orchid_core.BaseOperators, unknown, orchid_core.ColumnDataBase>>(this: {
|
|
315
324
|
name(name: string): {
|
|
@@ -536,4 +545,4 @@ type Repo<T extends Query, Methods extends MethodsBase<T>, Mapped = MapMethods<T
|
|
|
536
545
|
}>(q: Q) => Q & Mapped) & T & Mapped;
|
|
537
546
|
declare const createRepo: <T extends Query, Methods extends MethodsBase<T>>(table: T, methods: Methods) => Repo<T, Methods, MapMethods<T, Methods>>;
|
|
538
547
|
|
|
539
|
-
export { DbTable, MapMethods, MapQueryMethods, MethodsBase, OrchidORM, QueryMethods, Repo, Table, TableClass, TableClasses, TableToDb, createBaseTable, createRepo, orchidORM };
|
|
548
|
+
export { DbTable, MapMethods, MapQueryMethods, MethodsBase, OrchidORM, QueryMethods, Repo, Table, TableClass, TableClasses, TableHooks, TableToDb, addTableHooks, createBaseTable, createRepo, orchidORM };
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,15 @@ var pqb = require('pqb');
|
|
|
4
4
|
var orchidCore = require('orchid-core');
|
|
5
5
|
var node_async_hooks = require('node:async_hooks');
|
|
6
6
|
|
|
7
|
+
const addTableHooks = (table, hooks) => {
|
|
8
|
+
for (const key in hooks) {
|
|
9
|
+
pqb.addQueryHook(
|
|
10
|
+
table.baseQuery,
|
|
11
|
+
key,
|
|
12
|
+
hooks[key]
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
7
16
|
const createBaseTable = ({
|
|
8
17
|
columnTypes,
|
|
9
18
|
snakeCase,
|
|
@@ -33,6 +42,9 @@ const create = (columnTypes, filePath, snakeCase, nowSQL, exportAs = "BaseTable"
|
|
|
33
42
|
this.snakeCase = snakeCase;
|
|
34
43
|
this.columnTypes = columnTypes;
|
|
35
44
|
}
|
|
45
|
+
setHooks(callbacks) {
|
|
46
|
+
return callbacks;
|
|
47
|
+
}
|
|
36
48
|
setColumns(fn) {
|
|
37
49
|
if (!this.filePath) {
|
|
38
50
|
const filePath2 = orchidCore.getCallerFilePath();
|
|
@@ -1408,6 +1420,8 @@ const orchidORM = (_a, tables) => {
|
|
|
1408
1420
|
dbTable.db = result;
|
|
1409
1421
|
dbTable.filePath = table.filePath;
|
|
1410
1422
|
dbTable.name = table.constructor.name;
|
|
1423
|
+
if (table.hooks)
|
|
1424
|
+
addTableHooks(dbTable, table.hooks);
|
|
1411
1425
|
result[key] = dbTable;
|
|
1412
1426
|
}
|
|
1413
1427
|
applyRelations(qb, tableInstances, result);
|
|
@@ -1473,6 +1487,7 @@ Object.defineProperty(exports, 'testTransaction', {
|
|
|
1473
1487
|
enumerable: true,
|
|
1474
1488
|
get: function () { return pqb.testTransaction; }
|
|
1475
1489
|
});
|
|
1490
|
+
exports.addTableHooks = addTableHooks;
|
|
1476
1491
|
exports.createBaseTable = createBaseTable;
|
|
1477
1492
|
exports.createRepo = createRepo;
|
|
1478
1493
|
exports.orchidORM = orchidORM;
|