orchid-orm 1.9.29 → 1.9.31

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.mjs CHANGED
@@ -1,8 +1,17 @@
1
- import { columnTypes, getColumnTypes, addQueryOn, VirtualColumn, pushQueryValue, isQueryReturnsAll, getQueryAs, toSqlCacheKey, NotFoundError, relationQueryKey, Adapter, Db, anyShape, getClonedQueryData } from 'pqb';
1
+ import { addQueryHook, columnTypes, getColumnTypes, addQueryOn, VirtualColumn, pushQueryValue, isQueryReturnsAll, getQueryAs, toSqlCacheKey, NotFoundError, relationQueryKey, Adapter, Db, anyShape, getClonedQueryData } from 'pqb';
2
2
  export { OrchidOrmError, OrchidOrmInternalError, columnTypes, testTransaction } from 'pqb';
3
3
  import { getCallerFilePath, snakeCaseKey, toSnakeCase } from 'orchid-core';
4
4
  import { AsyncLocalStorage } from 'node:async_hooks';
5
5
 
6
+ const addTableHooks = (table, hooks) => {
7
+ for (const key in hooks) {
8
+ addQueryHook(
9
+ table.baseQuery,
10
+ key,
11
+ hooks[key]
12
+ );
13
+ }
14
+ };
6
15
  const createBaseTable = ({
7
16
  columnTypes: columnTypes$1,
8
17
  snakeCase,
@@ -32,6 +41,9 @@ const create = (columnTypes, filePath, snakeCase, nowSQL, exportAs = "BaseTable"
32
41
  this.snakeCase = snakeCase;
33
42
  this.columnTypes = columnTypes;
34
43
  }
44
+ setHooks(callbacks) {
45
+ return callbacks;
46
+ }
35
47
  setColumns(fn) {
36
48
  if (!this.filePath) {
37
49
  const filePath2 = getCallerFilePath();
@@ -1407,6 +1419,8 @@ const orchidORM = (_a, tables) => {
1407
1419
  dbTable.db = result;
1408
1420
  dbTable.filePath = table.filePath;
1409
1421
  dbTable.name = table.constructor.name;
1422
+ if (table.hooks)
1423
+ addTableHooks(dbTable, table.hooks);
1410
1424
  result[key] = dbTable;
1411
1425
  }
1412
1426
  applyRelations(qb, tableInstances, result);
@@ -1456,5 +1470,5 @@ const createRepo = (table, methods) => {
1456
1470
  });
1457
1471
  };
1458
1472
 
1459
- export { createBaseTable, createRepo, orchidORM };
1473
+ export { addTableHooks, createBaseTable, createRepo, orchidORM };
1460
1474
  //# sourceMappingURL=index.mjs.map