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