@mastra/dsql 1.5.6 → 1.5.7-alpha.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.cjs CHANGED
@@ -85,8 +85,10 @@ function truncateQuery(query, maxLength = 100) {
85
85
  */
86
86
  var PoolAdapter = class {
87
87
  $pool;
88
- constructor($pool) {
88
+ onRollbackError;
89
+ constructor($pool, onRollbackError) {
89
90
  this.$pool = $pool;
91
+ this.onRollbackError = onRollbackError;
90
92
  }
91
93
  connect() {
92
94
  return this.$pool.connect();
@@ -123,8 +125,14 @@ var PoolAdapter = class {
123
125
  }
124
126
  async tx(callback) {
125
127
  const client = await this.$pool.connect();
128
+ let destroyClient = false;
126
129
  try {
127
- await client.query("BEGIN");
130
+ try {
131
+ await client.query("BEGIN");
132
+ } catch (error) {
133
+ destroyClient = true;
134
+ throw error;
135
+ }
128
136
  const txClient = new TransactionClient(client);
129
137
  try {
130
138
  const result = await callback(txClient);
@@ -136,12 +144,16 @@ var PoolAdapter = class {
136
144
  try {
137
145
  await client.query("ROLLBACK");
138
146
  } catch (rollbackError) {
139
- console.error("Transaction rollback failed:", rollbackError);
147
+ destroyClient = true;
148
+ try {
149
+ if (this.onRollbackError) await this.onRollbackError(rollbackError);
150
+ else console.error("Failed to rollback transaction:", rollbackError);
151
+ } catch {}
140
152
  }
141
153
  throw error;
142
154
  }
143
155
  } finally {
144
- client.release();
156
+ client.release(destroyClient || void 0);
145
157
  }
146
158
  }
147
159
  };
@@ -4467,7 +4479,7 @@ var DSQLStore = class extends _mastra_core_storage.MastraStorage {
4467
4479
  this.#pool = this.createPool(config);
4468
4480
  this.#ownsPool = true;
4469
4481
  }
4470
- this.#db = new PoolAdapter(this.#pool);
4482
+ this.#db = new PoolAdapter(this.#pool, (error) => this.logger?.error?.("Transaction rollback failed", { error }));
4471
4483
  const domainConfig = {
4472
4484
  client: this.#db,
4473
4485
  schemaName: this.schema,