@h-ai/reldb 0.1.0-alpha.28 → 0.1.0-alpha.30

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 CHANGED
@@ -74,6 +74,34 @@ await reldb.init({
74
74
  })
75
75
  ```
76
76
 
77
+ ### 操作日志
78
+
79
+ 可在数据库配置中通过 `operationLog` 开启 SQL 操作日志。日志在 reldb provider-base 的 DML 操作层统一输出,不在 `reldb-main.ts` 或各 raw provider 中重复包装。
80
+
81
+ ```yaml
82
+ # config/_db.yml
83
+ type: ${HAI_RELDB_TYPE:sqlite}
84
+ database: ${HAI_RELDB_DATABASE:./data/app.db}
85
+ operationLog:
86
+ read: false # query / get / queryPage
87
+ write: false # DDL, execute / batch, tx.begin / tx.commit / tx.rollback
88
+ maxLength: 1000 # 参数序列化后的最大输出长度,超出会截断
89
+ level: debug # info | debug | trace,默认 debug
90
+ ```
91
+
92
+ ```ts
93
+ await reldb.init({
94
+ type: 'sqlite',
95
+ database: './data.db',
96
+ operationLog: {
97
+ read: true,
98
+ write: true,
99
+ maxLength: 500,
100
+ level: 'debug',
101
+ },
102
+ })
103
+ ```
104
+
77
105
  ## 事务
78
106
 
79
107
  三种使用方式:
package/dist/index.d.ts CHANGED
@@ -24,6 +24,17 @@ declare const ReldbTypeSchema: z.ZodEnum<{
24
24
  }>;
25
25
  /** 数据库类型 */
26
26
  type DbType = z.infer<typeof ReldbTypeSchema>;
27
+ declare const ReldbOperationLogConfigSchema: z.ZodObject<{
28
+ read: z.ZodDefault<z.ZodBoolean>;
29
+ write: z.ZodDefault<z.ZodBoolean>;
30
+ maxLength: z.ZodDefault<z.ZodNumber>;
31
+ level: z.ZodDefault<z.ZodEnum<{
32
+ info: "info";
33
+ debug: "debug";
34
+ trace: "trace";
35
+ }>>;
36
+ }, z.core.$strip>;
37
+ type ReldbOperationLogConfig = z.infer<typeof ReldbOperationLogConfigSchema>;
27
38
  /**
28
39
  * 连接池配置 Schema
29
40
  *
@@ -119,6 +130,16 @@ declare const MysqlOptionsSchema: z.ZodObject<{
119
130
  * ```
120
131
  */
121
132
  declare const SqliteConfigSchema: z.ZodObject<{
133
+ operationLog: z.ZodOptional<z.ZodObject<{
134
+ read: z.ZodDefault<z.ZodBoolean>;
135
+ write: z.ZodDefault<z.ZodBoolean>;
136
+ maxLength: z.ZodDefault<z.ZodNumber>;
137
+ level: z.ZodDefault<z.ZodEnum<{
138
+ info: "info";
139
+ debug: "debug";
140
+ trace: "trace";
141
+ }>>;
142
+ }, z.core.$strip>>;
122
143
  type: z.ZodLiteral<"sqlite">;
123
144
  database: z.ZodString;
124
145
  sqlite: z.ZodOptional<z.ZodObject<{
@@ -165,6 +186,16 @@ declare const PostgresqlConfigSchema: z.ZodObject<{
165
186
  idleTimeout: z.ZodDefault<z.ZodNumber>;
166
187
  acquireTimeout: z.ZodDefault<z.ZodNumber>;
167
188
  }, z.core.$strip>>;
189
+ operationLog: z.ZodOptional<z.ZodObject<{
190
+ read: z.ZodDefault<z.ZodBoolean>;
191
+ write: z.ZodDefault<z.ZodBoolean>;
192
+ maxLength: z.ZodDefault<z.ZodNumber>;
193
+ level: z.ZodDefault<z.ZodEnum<{
194
+ info: "info";
195
+ debug: "debug";
196
+ trace: "trace";
197
+ }>>;
198
+ }, z.core.$strip>>;
168
199
  type: z.ZodLiteral<"postgresql">;
169
200
  }, z.core.$strip>;
170
201
  /**
@@ -206,6 +237,16 @@ declare const MysqlConfigSchema: z.ZodObject<{
206
237
  idleTimeout: z.ZodDefault<z.ZodNumber>;
207
238
  acquireTimeout: z.ZodDefault<z.ZodNumber>;
208
239
  }, z.core.$strip>>;
240
+ operationLog: z.ZodOptional<z.ZodObject<{
241
+ read: z.ZodDefault<z.ZodBoolean>;
242
+ write: z.ZodDefault<z.ZodBoolean>;
243
+ maxLength: z.ZodDefault<z.ZodNumber>;
244
+ level: z.ZodDefault<z.ZodEnum<{
245
+ info: "info";
246
+ debug: "debug";
247
+ trace: "trace";
248
+ }>>;
249
+ }, z.core.$strip>>;
209
250
  type: z.ZodLiteral<"mysql">;
210
251
  mysql: z.ZodOptional<z.ZodObject<{
211
252
  charset: z.ZodDefault<z.ZodString>;
@@ -218,6 +259,16 @@ declare const MysqlConfigSchema: z.ZodObject<{
218
259
  * 根据 `type` 字段区分不同数据库类型的配置。
219
260
  */
220
261
  declare const ReldbConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
262
+ operationLog: z.ZodOptional<z.ZodObject<{
263
+ read: z.ZodDefault<z.ZodBoolean>;
264
+ write: z.ZodDefault<z.ZodBoolean>;
265
+ maxLength: z.ZodDefault<z.ZodNumber>;
266
+ level: z.ZodDefault<z.ZodEnum<{
267
+ info: "info";
268
+ debug: "debug";
269
+ trace: "trace";
270
+ }>>;
271
+ }, z.core.$strip>>;
221
272
  type: z.ZodLiteral<"sqlite">;
222
273
  database: z.ZodString;
223
274
  sqlite: z.ZodOptional<z.ZodObject<{
@@ -243,6 +294,16 @@ declare const ReldbConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
243
294
  idleTimeout: z.ZodDefault<z.ZodNumber>;
244
295
  acquireTimeout: z.ZodDefault<z.ZodNumber>;
245
296
  }, z.core.$strip>>;
297
+ operationLog: z.ZodOptional<z.ZodObject<{
298
+ read: z.ZodDefault<z.ZodBoolean>;
299
+ write: z.ZodDefault<z.ZodBoolean>;
300
+ maxLength: z.ZodDefault<z.ZodNumber>;
301
+ level: z.ZodDefault<z.ZodEnum<{
302
+ info: "info";
303
+ debug: "debug";
304
+ trace: "trace";
305
+ }>>;
306
+ }, z.core.$strip>>;
246
307
  type: z.ZodLiteral<"postgresql">;
247
308
  }, z.core.$strip>, z.ZodObject<{
248
309
  url: z.ZodOptional<z.ZodString>;
@@ -263,6 +324,16 @@ declare const ReldbConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
263
324
  idleTimeout: z.ZodDefault<z.ZodNumber>;
264
325
  acquireTimeout: z.ZodDefault<z.ZodNumber>;
265
326
  }, z.core.$strip>>;
327
+ operationLog: z.ZodOptional<z.ZodObject<{
328
+ read: z.ZodDefault<z.ZodBoolean>;
329
+ write: z.ZodDefault<z.ZodBoolean>;
330
+ maxLength: z.ZodDefault<z.ZodNumber>;
331
+ level: z.ZodDefault<z.ZodEnum<{
332
+ info: "info";
333
+ debug: "debug";
334
+ trace: "trace";
335
+ }>>;
336
+ }, z.core.$strip>>;
266
337
  type: z.ZodLiteral<"mysql">;
267
338
  mysql: z.ZodOptional<z.ZodObject<{
268
339
  charset: z.ZodDefault<z.ZodString>;
@@ -1489,4 +1560,4 @@ declare function quoteIdentifier(name: string): string;
1489
1560
  */
1490
1561
  declare function escapeSqlString(value: string): string;
1491
1562
 
1492
- export { BaseReldbCrudRepository, type BaseReldbCrudRepositoryConfig, type ColumnType, type CrudConfig, type CrudManager, type CrudPageOptions, type CrudQueryOptions, type DbType, type DdlOperations, type DmlOperations, type DmlWithTxOperations, type ExecuteResult, HaiReldbError, type JsonSqlExpr, type MysqlConfig, MysqlConfigSchema, MysqlOptionsSchema, type NormalizedPagination, type PaginationOverrides, type PaginationQueryOptions, type PoolConfig, PoolConfigSchema, type PostgresqlConfig, PostgresqlConfigSchema, type QueryRow, type ReldbColumnDef, type ReldbConfig, type ReldbConfigInput, ReldbConfigSchema, type ReldbCrudCountOptions, type ReldbCrudFieldDefinition, type ReldbCrudRepository, type ReldbFunctions, type ReldbIndexDef, type ReldbJsonOps, type ReldbProvider, type ReldbTableDef, ReldbTypeSchema, type SqliteConfig, SqliteConfigSchema, SqliteOptionsSchema, type SslConfig, SslConfigSchema, type TxManager, type TxWrapCallback, createJsonOps, escapeSqlString, parseJsonPath, quoteIdentifier, reldb, validateIdentifier, validateIdentifiers };
1563
+ export { BaseReldbCrudRepository, type BaseReldbCrudRepositoryConfig, type ColumnType, type CrudConfig, type CrudManager, type CrudPageOptions, type CrudQueryOptions, type DbType, type DdlOperations, type DmlOperations, type DmlWithTxOperations, type ExecuteResult, HaiReldbError, type JsonSqlExpr, type MysqlConfig, MysqlConfigSchema, MysqlOptionsSchema, type NormalizedPagination, type PaginationOverrides, type PaginationQueryOptions, type PoolConfig, PoolConfigSchema, type PostgresqlConfig, PostgresqlConfigSchema, type QueryRow, type ReldbColumnDef, type ReldbConfig, type ReldbConfigInput, ReldbConfigSchema, type ReldbCrudCountOptions, type ReldbCrudFieldDefinition, type ReldbCrudRepository, type ReldbFunctions, type ReldbIndexDef, type ReldbJsonOps, type ReldbOperationLogConfig, ReldbOperationLogConfigSchema, type ReldbProvider, type ReldbTableDef, ReldbTypeSchema, type SqliteConfig, SqliteConfigSchema, SqliteOptionsSchema, type SslConfig, SslConfigSchema, type TxManager, type TxWrapCallback, createJsonOps, escapeSqlString, parseJsonPath, quoteIdentifier, reldb, validateIdentifier, validateIdentifiers };
package/dist/index.js CHANGED
@@ -9,6 +9,15 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
9
9
  throw Error('Dynamic require of "' + x + '" is not supported');
10
10
  });
11
11
  var ReldbTypeSchema = z.enum(["sqlite", "postgresql", "mysql"]);
12
+ var ReldbOperationLogConfigSchema = z.object({
13
+ read: z.boolean().default(false),
14
+ write: z.boolean().default(false),
15
+ maxLength: z.number().int().min(0).default(1e3),
16
+ level: z.enum(["info", "debug", "trace"]).default("debug")
17
+ });
18
+ var OperationLogConfigFieldSchema = {
19
+ operationLog: ReldbOperationLogConfigSchema.optional()
20
+ };
12
21
  var PoolConfigSchema = z.object({
13
22
  /** 最小连接数(默认 1) */
14
23
  min: z.number().int().min(0).default(1),
@@ -66,15 +75,18 @@ var SqliteConfigSchema = z.object({
66
75
  /** 数据库文件路径(如 './data.db')或 ':memory:'(内存数据库) */
67
76
  database: z.string(),
68
77
  /** SQLite 特定选项 */
69
- sqlite: SqliteOptionsSchema.optional()
78
+ sqlite: SqliteOptionsSchema.optional(),
79
+ ...OperationLogConfigFieldSchema
70
80
  });
71
81
  var PostgresqlConfigSchema = NetworkConfigSchema.extend({
72
- type: z.literal("postgresql")
82
+ type: z.literal("postgresql"),
83
+ ...OperationLogConfigFieldSchema
73
84
  });
74
85
  var MysqlConfigSchema = NetworkConfigSchema.extend({
75
86
  type: z.literal("mysql"),
76
87
  /** MySQL 特定选项 */
77
- mysql: MysqlOptionsSchema.optional()
88
+ mysql: MysqlOptionsSchema.optional(),
89
+ ...OperationLogConfigFieldSchema
78
90
  });
79
91
  var ReldbConfigSchema = z.discriminatedUnion("type", [
80
92
  SqliteConfigSchema,
@@ -1415,6 +1427,37 @@ function createTxWrap(beginTx) {
1415
1427
  }
1416
1428
 
1417
1429
  // src/providers/reldb-provider-base.ts
1430
+ function stringifyOperationPayload(payload, maxLength) {
1431
+ if (maxLength <= 0) {
1432
+ return "";
1433
+ }
1434
+ try {
1435
+ const text = JSON.stringify(payload, (_key, value) => {
1436
+ if (typeof value === "bigint") {
1437
+ return value.toString();
1438
+ }
1439
+ if (typeof value === "function") {
1440
+ return "[Function]";
1441
+ }
1442
+ return value;
1443
+ });
1444
+ return text.length > maxLength ? `${text.slice(0, maxLength)}...` : text;
1445
+ } catch {
1446
+ const text = String(payload);
1447
+ return text.length > maxLength ? `${text.slice(0, maxLength)}...` : text;
1448
+ }
1449
+ }
1450
+ function logReldbOperation(ctx, category, operation, payload) {
1451
+ const config = ctx.operationLog?.();
1452
+ if (!config?.[category]) {
1453
+ return;
1454
+ }
1455
+ ctx.logger[config.level]("RelDB operation executed", {
1456
+ category,
1457
+ operation,
1458
+ payload: stringifyOperationPayload(payload, config.maxLength)
1459
+ });
1460
+ }
1418
1461
  async function wrapOp(ctx, fn, errorDef, errorLabel, errorMeta) {
1419
1462
  if (!ctx.isConnected()) {
1420
1463
  return err(HaiReldbError.NOT_INITIALIZED, reldbM("reldb_notInitialized"));
@@ -1435,12 +1478,14 @@ function createBaseDdlOps(ctx, raw) {
1435
1478
  const v2 = validateIdentifiers(Object.keys(columns));
1436
1479
  if (!v2.success)
1437
1480
  return Promise.resolve(v2);
1481
+ logReldbOperation(ctx, "write", "ddl.createTable", { tableName, columns, ifNotExists });
1438
1482
  return wrapOp(ctx, () => raw.createTable(tableName, columns, ifNotExists), HaiReldbError.DDL_FAILED, "DDL: createTable failed", { tableName });
1439
1483
  },
1440
1484
  dropTable(tableName, ifExists = true) {
1441
1485
  const v = validateIdentifier(tableName);
1442
1486
  if (!v.success)
1443
1487
  return Promise.resolve(v);
1488
+ logReldbOperation(ctx, "write", "ddl.dropTable", { tableName, ifExists });
1444
1489
  return wrapOp(ctx, () => raw.dropTable(tableName, ifExists), HaiReldbError.DDL_FAILED, "DDL: dropTable failed", { tableName });
1445
1490
  },
1446
1491
  addColumn(tableName, columnName, columnDef) {
@@ -1450,6 +1495,7 @@ function createBaseDdlOps(ctx, raw) {
1450
1495
  const v2 = validateIdentifier(columnName);
1451
1496
  if (!v2.success)
1452
1497
  return Promise.resolve(v2);
1498
+ logReldbOperation(ctx, "write", "ddl.addColumn", { tableName, columnName, columnDef });
1453
1499
  return wrapOp(ctx, () => raw.addColumn(tableName, columnName, columnDef), HaiReldbError.DDL_FAILED, "DDL: addColumn failed", { tableName, columnName });
1454
1500
  },
1455
1501
  dropColumn(tableName, columnName) {
@@ -1459,6 +1505,7 @@ function createBaseDdlOps(ctx, raw) {
1459
1505
  const v2 = validateIdentifier(columnName);
1460
1506
  if (!v2.success)
1461
1507
  return Promise.resolve(v2);
1508
+ logReldbOperation(ctx, "write", "ddl.dropColumn", { tableName, columnName });
1462
1509
  return wrapOp(ctx, () => raw.dropColumn(tableName, columnName), HaiReldbError.DDL_FAILED, "DDL: dropColumn failed", { tableName, columnName });
1463
1510
  },
1464
1511
  renameTable(oldName, newName) {
@@ -1468,6 +1515,7 @@ function createBaseDdlOps(ctx, raw) {
1468
1515
  const v2 = validateIdentifier(newName);
1469
1516
  if (!v2.success)
1470
1517
  return Promise.resolve(v2);
1518
+ logReldbOperation(ctx, "write", "ddl.renameTable", { oldName, newName });
1471
1519
  return wrapOp(ctx, () => raw.renameTable(oldName, newName), HaiReldbError.DDL_FAILED, "DDL: renameTable failed", { oldName, newName });
1472
1520
  },
1473
1521
  createIndex(tableName, indexName, indexDef) {
@@ -1480,30 +1528,66 @@ function createBaseDdlOps(ctx, raw) {
1480
1528
  const v3 = validateIdentifiers(indexDef.columns);
1481
1529
  if (!v3.success)
1482
1530
  return Promise.resolve(v3);
1531
+ logReldbOperation(ctx, "write", "ddl.createIndex", { tableName, indexName, indexDef });
1483
1532
  return wrapOp(ctx, () => raw.createIndex(tableName, indexName, indexDef), HaiReldbError.DDL_FAILED, "DDL: createIndex failed", { tableName, indexName });
1484
1533
  },
1485
1534
  dropIndex(indexName, ifExists = true) {
1486
1535
  const v = validateIdentifier(indexName);
1487
1536
  if (!v.success)
1488
1537
  return Promise.resolve(v);
1538
+ logReldbOperation(ctx, "write", "ddl.dropIndex", { indexName, ifExists });
1489
1539
  return wrapOp(ctx, () => raw.dropIndex(indexName, ifExists), HaiReldbError.DDL_FAILED, "DDL: dropIndex failed", { indexName });
1490
1540
  },
1491
1541
  raw(sql) {
1542
+ logReldbOperation(ctx, "write", "ddl.raw", { sql });
1492
1543
  return wrapOp(ctx, () => raw.raw(sql), HaiReldbError.DDL_FAILED, "DDL: raw failed");
1493
1544
  }
1494
1545
  };
1495
1546
  }
1496
1547
  function createBaseDmlOps(ctx, raw) {
1497
1548
  return {
1498
- query: (sql, params) => wrapOp(ctx, () => raw.query(sql, params), HaiReldbError.QUERY_FAILED, "DML: query failed"),
1499
- get: (sql, params) => wrapOp(ctx, () => raw.get(sql, params), HaiReldbError.QUERY_FAILED, "DML: get failed"),
1500
- execute: (sql, params) => wrapOp(ctx, () => raw.execute(sql, params), HaiReldbError.QUERY_FAILED, "DML: execute failed"),
1501
- batch: (stmts) => wrapOp(ctx, () => raw.batch(stmts), HaiReldbError.QUERY_FAILED, "DML: batch failed"),
1502
- queryPage: (options) => wrapOp(ctx, () => raw.queryPage(options), HaiReldbError.QUERY_FAILED, "DML: queryPage failed")
1549
+ query: (sql, params) => {
1550
+ logReldbOperation(ctx, "read", "query", { sql, params });
1551
+ return wrapOp(ctx, () => raw.query(sql, params), HaiReldbError.QUERY_FAILED, "DML: query failed");
1552
+ },
1553
+ get: (sql, params) => {
1554
+ logReldbOperation(ctx, "read", "get", { sql, params });
1555
+ return wrapOp(ctx, () => raw.get(sql, params), HaiReldbError.QUERY_FAILED, "DML: get failed");
1556
+ },
1557
+ execute: (sql, params) => {
1558
+ logReldbOperation(ctx, "write", "execute", { sql, params });
1559
+ return wrapOp(ctx, () => raw.execute(sql, params), HaiReldbError.QUERY_FAILED, "DML: execute failed");
1560
+ },
1561
+ batch: (statements) => {
1562
+ logReldbOperation(ctx, "write", "batch", { count: statements.length, statements });
1563
+ return wrapOp(ctx, () => raw.batch(statements), HaiReldbError.QUERY_FAILED, "DML: batch failed");
1564
+ },
1565
+ queryPage: (options) => {
1566
+ logReldbOperation(ctx, "read", "queryPage", options);
1567
+ return wrapOp(ctx, () => raw.queryPage(options), HaiReldbError.QUERY_FAILED, "DML: queryPage failed");
1568
+ }
1503
1569
  };
1504
1570
  }
1505
1571
  function createBaseTxManager(ctx, beginTx) {
1506
- const begin = () => wrapOp(ctx, beginTx, HaiReldbError.TRANSACTION_FAILED, "TX: begin failed");
1572
+ const begin = async () => {
1573
+ logReldbOperation(ctx, "write", "tx.begin", {});
1574
+ const result = await wrapOp(ctx, beginTx, HaiReldbError.TRANSACTION_FAILED, "TX: begin failed");
1575
+ if (!result.success) {
1576
+ return result;
1577
+ }
1578
+ const tx = result.data;
1579
+ return ok({
1580
+ ...tx,
1581
+ commit: async () => {
1582
+ logReldbOperation(ctx, "write", "tx.commit", {});
1583
+ return tx.commit();
1584
+ },
1585
+ rollback: async () => {
1586
+ logReldbOperation(ctx, "write", "tx.rollback", {});
1587
+ return tx.rollback();
1588
+ }
1589
+ });
1590
+ };
1507
1591
  return {
1508
1592
  begin,
1509
1593
  wrap: createTxWrap(begin)
@@ -1591,9 +1675,11 @@ function buildDefaultDropIndexSql(quoteId, indexName, ifExists) {
1591
1675
  var logger2 = core.logger.child({ module: "reldb", scope: "mysql" });
1592
1676
  function createMysqlProvider() {
1593
1677
  let pool = null;
1678
+ let currentConfig2 = null;
1594
1679
  const ctx = {
1595
1680
  isConnected: () => pool !== null,
1596
- logger: logger2
1681
+ logger: logger2,
1682
+ operationLog: () => currentConfig2?.operationLog
1597
1683
  };
1598
1684
  function mysqlQuoteId(name) {
1599
1685
  return `\`${name}\``;
@@ -1826,7 +1912,8 @@ function createMysqlProvider() {
1826
1912
  return err(HaiReldbError.TRANSACTION_FAILED, mysqlTxErrorMessage(String(error)), error);
1827
1913
  }
1828
1914
  const txDmlOps = createMysqlTxDmlOps(connection);
1829
- return ok(createTxHandle(txDmlOps, {
1915
+ const guardedTxDmlOps = createBaseDmlOps(ctx, txDmlOps);
1916
+ return ok(createTxHandle(guardedTxDmlOps, {
1830
1917
  commit: async () => {
1831
1918
  await connection.commit();
1832
1919
  },
@@ -1859,9 +1946,11 @@ function createMysqlProvider() {
1859
1946
  charset: config.mysql?.charset ?? "utf8mb4"
1860
1947
  });
1861
1948
  await pool.query("SELECT 1");
1949
+ currentConfig2 = config;
1862
1950
  logger2.info("Connected to MySQL", { host: config.host, port: config.port, database: config.database });
1863
1951
  return ok(void 0);
1864
1952
  } catch (error) {
1953
+ currentConfig2 = null;
1865
1954
  pool = null;
1866
1955
  return err(HaiReldbError.CONNECTION_FAILED, reldbM("reldb_mysqlConnectionFailed", { params: { error: String(error) } }), error);
1867
1956
  }
@@ -1871,9 +1960,11 @@ function createMysqlProvider() {
1871
1960
  try {
1872
1961
  await pool.end();
1873
1962
  } catch (error) {
1963
+ currentConfig2 = null;
1874
1964
  pool = null;
1875
1965
  return err(HaiReldbError.CONNECTION_FAILED, reldbM("reldb_mysqlConnectionFailed", { params: { error: String(error) } }), error);
1876
1966
  }
1967
+ currentConfig2 = null;
1877
1968
  pool = null;
1878
1969
  logger2.info("Disconnected from MySQL");
1879
1970
  }
@@ -1890,9 +1981,11 @@ var logger3 = core.logger.child({ module: "reldb", scope: "postgres" });
1890
1981
  var PG_DOLLAR_TAG_REGEX = /^\$([A-Z_]\w*)?\$/i;
1891
1982
  function createPostgresProvider() {
1892
1983
  let pool = null;
1984
+ let currentConfig2 = null;
1893
1985
  const ctx = {
1894
1986
  isConnected: () => pool !== null,
1895
- logger: logger3
1987
+ logger: logger3,
1988
+ operationLog: () => currentConfig2?.operationLog
1896
1989
  };
1897
1990
  function convertPlaceholders(sql) {
1898
1991
  let out = "";
@@ -2157,7 +2250,8 @@ function createPostgresProvider() {
2157
2250
  return err(HaiReldbError.TRANSACTION_FAILED, pgTxErrorMessage(String(error)), error);
2158
2251
  }
2159
2252
  const txDmlOps = createPgTxDmlOps(client);
2160
- return ok(createTxHandle(txDmlOps, {
2253
+ const guardedTxDmlOps = createBaseDmlOps(ctx, txDmlOps);
2254
+ return ok(createTxHandle(guardedTxDmlOps, {
2161
2255
  commit: async () => {
2162
2256
  await client.query("COMMIT");
2163
2257
  },
@@ -2190,9 +2284,11 @@ function createPostgresProvider() {
2190
2284
  connectionTimeoutMillis: config.pool?.acquireTimeout
2191
2285
  });
2192
2286
  await pool.query("SELECT 1");
2287
+ currentConfig2 = config;
2193
2288
  logger3.info("Connected to PostgreSQL", { host: config.host, port: config.port, database: config.database });
2194
2289
  return ok(void 0);
2195
2290
  } catch (error) {
2291
+ currentConfig2 = null;
2196
2292
  pool = null;
2197
2293
  return err(HaiReldbError.CONNECTION_FAILED, reldbM("reldb_postgresConnectionFailed", { params: { error: String(error) } }), error);
2198
2294
  }
@@ -2202,9 +2298,11 @@ function createPostgresProvider() {
2202
2298
  try {
2203
2299
  await pool.end();
2204
2300
  } catch (error) {
2301
+ currentConfig2 = null;
2205
2302
  pool = null;
2206
2303
  return err(HaiReldbError.CONNECTION_FAILED, reldbM("reldb_postgresConnectionFailed", { params: { error: String(error) } }), error);
2207
2304
  }
2305
+ currentConfig2 = null;
2208
2306
  pool = null;
2209
2307
  logger3.info("Disconnected from PostgreSQL");
2210
2308
  }
@@ -2221,6 +2319,7 @@ var require2 = createRequire(import.meta.url);
2221
2319
  var logger4 = core.logger.child({ module: "reldb", scope: "sqlite" });
2222
2320
  function createSqliteProvider() {
2223
2321
  let database = null;
2322
+ let currentConfig2 = null;
2224
2323
  let txChain = Promise.resolve();
2225
2324
  const TX_LOCK_TIMEOUT_MS = 3e4;
2226
2325
  async function acquireTxLock() {
@@ -2248,7 +2347,8 @@ function createSqliteProvider() {
2248
2347
  }
2249
2348
  const ctx = {
2250
2349
  isConnected: () => database !== null && database.open,
2251
- logger: logger4
2350
+ logger: logger4,
2351
+ operationLog: () => currentConfig2?.operationLog
2252
2352
  };
2253
2353
  function mapSqliteType(def) {
2254
2354
  switch (def.type) {
@@ -2425,7 +2525,8 @@ function createSqliteProvider() {
2425
2525
  return err(HaiReldbError.TRANSACTION_FAILED, sqliteTxErrorMessage(String(error)), error);
2426
2526
  }
2427
2527
  const txDmlOps = createSqliteTxDmlOps(db);
2428
- return ok(createTxHandle(txDmlOps, {
2528
+ const guardedTxDmlOps = createBaseDmlOps(ctx, txDmlOps);
2529
+ return ok(createTxHandle(guardedTxDmlOps, {
2429
2530
  commit: async () => {
2430
2531
  db.exec("COMMIT");
2431
2532
  },
@@ -2458,6 +2559,7 @@ function createSqliteProvider() {
2458
2559
  if (sqliteOptions.walMode !== false) {
2459
2560
  database.pragma("journal_mode = WAL");
2460
2561
  }
2562
+ currentConfig2 = config;
2461
2563
  logger4.info("Connected to SQLite", { database: config.database });
2462
2564
  return ok(void 0);
2463
2565
  } catch (error) {
@@ -2473,9 +2575,11 @@ function createSqliteProvider() {
2473
2575
  }
2474
2576
  database.close();
2475
2577
  } catch (error) {
2578
+ currentConfig2 = null;
2476
2579
  database = null;
2477
2580
  return err(HaiReldbError.CONNECTION_FAILED, reldbM("reldb_sqliteConnectionFailed", { params: { error: String(error) } }), error);
2478
2581
  }
2582
+ currentConfig2 = null;
2479
2583
  database = null;
2480
2584
  logger4.info("Disconnected from SQLite");
2481
2585
  }
@@ -2671,6 +2775,6 @@ var reldb = {
2671
2775
  }
2672
2776
  };
2673
2777
 
2674
- export { BaseReldbCrudRepository, HaiReldbError, MysqlConfigSchema, MysqlOptionsSchema, PoolConfigSchema, PostgresqlConfigSchema, ReldbConfigSchema, ReldbTypeSchema, SqliteConfigSchema, SqliteOptionsSchema, SslConfigSchema, createJsonOps, escapeSqlString, parseJsonPath, quoteIdentifier, reldb, validateIdentifier, validateIdentifiers };
2778
+ export { BaseReldbCrudRepository, HaiReldbError, MysqlConfigSchema, MysqlOptionsSchema, PoolConfigSchema, PostgresqlConfigSchema, ReldbConfigSchema, ReldbOperationLogConfigSchema, ReldbTypeSchema, SqliteConfigSchema, SqliteOptionsSchema, SslConfigSchema, createJsonOps, escapeSqlString, parseJsonPath, quoteIdentifier, reldb, validateIdentifier, validateIdentifiers };
2675
2779
  //# sourceMappingURL=index.js.map
2676
2780
  //# sourceMappingURL=index.js.map