@mastra/mssql 0.2.3 → 0.3.0-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/.turbo/turbo-build.log +2 -21
- package/CHANGELOG.md +28 -1
- package/dist/index.cjs +1568 -1104
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1568 -1104
- package/dist/index.js.map +1 -0
- package/dist/storage/domains/legacy-evals/index.d.ts +20 -0
- package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +90 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -0
- package/dist/storage/domains/operations/index.d.ts +51 -0
- package/dist/storage/domains/operations/index.d.ts.map +1 -0
- package/dist/storage/domains/scores/index.d.ts +46 -0
- package/dist/storage/domains/scores/index.d.ts.map +1 -0
- package/dist/storage/domains/traces/index.d.ts +37 -0
- package/dist/storage/domains/traces/index.d.ts.map +1 -0
- package/dist/storage/domains/utils.d.ts +6 -0
- package/dist/storage/domains/utils.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +36 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -0
- package/dist/{_tsup-dts-rollup.d.cts → storage/index.d.ts} +81 -117
- package/dist/storage/index.d.ts.map +1 -0
- package/package.json +6 -6
- package/src/storage/domains/legacy-evals/index.ts +175 -0
- package/src/storage/domains/memory/index.ts +1024 -0
- package/src/storage/domains/operations/index.ts +401 -0
- package/src/storage/domains/scores/index.ts +315 -0
- package/src/storage/domains/traces/index.ts +212 -0
- package/src/storage/domains/utils.ts +12 -0
- package/src/storage/domains/workflows/index.ts +259 -0
- package/src/storage/index.ts +147 -1835
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +22 -0
- package/dist/_tsup-dts-rollup.d.ts +0 -251
- package/dist/index.d.cts +0 -4
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';
|
|
2
|
+
import { StoreOperations, TABLE_WORKFLOW_SNAPSHOT } from '@mastra/core/storage';
|
|
3
|
+
import type { StorageColumn, TABLE_NAMES } from '@mastra/core/storage';
|
|
4
|
+
import { parseSqlIdentifier } from '@mastra/core/utils';
|
|
5
|
+
import sql from 'mssql';
|
|
6
|
+
import { getSchemaName, getTableName } from '../utils';
|
|
7
|
+
|
|
8
|
+
export class StoreOperationsMSSQL extends StoreOperations {
|
|
9
|
+
public pool: sql.ConnectionPool;
|
|
10
|
+
public schemaName?: string;
|
|
11
|
+
private setupSchemaPromise: Promise<void> | null = null;
|
|
12
|
+
private schemaSetupComplete: boolean | undefined = undefined;
|
|
13
|
+
|
|
14
|
+
protected getSqlType(type: StorageColumn['type'], isPrimaryKey = false): string {
|
|
15
|
+
switch (type) {
|
|
16
|
+
case 'text':
|
|
17
|
+
return isPrimaryKey ? 'NVARCHAR(255)' : 'NVARCHAR(MAX)';
|
|
18
|
+
case 'timestamp':
|
|
19
|
+
return 'DATETIME2(7)';
|
|
20
|
+
case 'uuid':
|
|
21
|
+
return 'UNIQUEIDENTIFIER';
|
|
22
|
+
case 'jsonb':
|
|
23
|
+
return 'NVARCHAR(MAX)';
|
|
24
|
+
case 'integer':
|
|
25
|
+
return 'INT';
|
|
26
|
+
case 'bigint':
|
|
27
|
+
return 'BIGINT';
|
|
28
|
+
case 'float':
|
|
29
|
+
return 'FLOAT';
|
|
30
|
+
default:
|
|
31
|
+
throw new MastraError({
|
|
32
|
+
id: 'MASTRA_STORAGE_MSSQL_STORE_TYPE_NOT_SUPPORTED',
|
|
33
|
+
domain: ErrorDomain.STORAGE,
|
|
34
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
constructor({ pool, schemaName }: { pool: sql.ConnectionPool; schemaName?: string }) {
|
|
40
|
+
super();
|
|
41
|
+
this.pool = pool;
|
|
42
|
+
this.schemaName = schemaName;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async hasColumn(table: string, column: string): Promise<boolean> {
|
|
46
|
+
const schema = this.schemaName || 'dbo';
|
|
47
|
+
const request = this.pool.request();
|
|
48
|
+
request.input('schema', schema);
|
|
49
|
+
request.input('table', table);
|
|
50
|
+
request.input('column', column);
|
|
51
|
+
request.input('columnLower', column.toLowerCase());
|
|
52
|
+
const result = await request.query(
|
|
53
|
+
`SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = @schema AND TABLE_NAME = @table AND (COLUMN_NAME = @column OR COLUMN_NAME = @columnLower)`,
|
|
54
|
+
);
|
|
55
|
+
return result.recordset.length > 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private async setupSchema() {
|
|
59
|
+
if (!this.schemaName || this.schemaSetupComplete) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!this.setupSchemaPromise) {
|
|
64
|
+
this.setupSchemaPromise = (async () => {
|
|
65
|
+
try {
|
|
66
|
+
const checkRequest = this.pool.request();
|
|
67
|
+
checkRequest.input('schemaName', this.schemaName);
|
|
68
|
+
const checkResult = await checkRequest.query(`
|
|
69
|
+
SELECT 1 AS found FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = @schemaName
|
|
70
|
+
`);
|
|
71
|
+
const schemaExists = Array.isArray(checkResult.recordset) && checkResult.recordset.length > 0;
|
|
72
|
+
|
|
73
|
+
if (!schemaExists) {
|
|
74
|
+
try {
|
|
75
|
+
await this.pool.request().query(`CREATE SCHEMA [${this.schemaName}]`);
|
|
76
|
+
this.logger?.info?.(`Schema "${this.schemaName}" created successfully`);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
this.logger?.error?.(`Failed to create schema "${this.schemaName}"`, { error });
|
|
79
|
+
throw new Error(
|
|
80
|
+
`Unable to create schema "${this.schemaName}". This requires CREATE privilege on the database. ` +
|
|
81
|
+
`Either create the schema manually or grant CREATE privilege to the user.`,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this.schemaSetupComplete = true;
|
|
87
|
+
this.logger?.debug?.(`Schema "${this.schemaName}" is ready for use`);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
this.schemaSetupComplete = undefined;
|
|
90
|
+
this.setupSchemaPromise = null;
|
|
91
|
+
throw error;
|
|
92
|
+
} finally {
|
|
93
|
+
this.setupSchemaPromise = null;
|
|
94
|
+
}
|
|
95
|
+
})();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
await this.setupSchemaPromise;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async insert({ tableName, record }: { tableName: TABLE_NAMES; record: Record<string, any> }): Promise<void> {
|
|
102
|
+
try {
|
|
103
|
+
const columns = Object.keys(record).map(col => parseSqlIdentifier(col, 'column name'));
|
|
104
|
+
const values = Object.values(record);
|
|
105
|
+
const paramNames = values.map((_, i) => `@param${i}`);
|
|
106
|
+
const insertSql = `INSERT INTO ${getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })} (${columns.map(c => `[${c}]`).join(', ')}) VALUES (${paramNames.join(', ')})`;
|
|
107
|
+
const request = this.pool.request();
|
|
108
|
+
values.forEach((value, i) => {
|
|
109
|
+
if (value instanceof Date) {
|
|
110
|
+
request.input(`param${i}`, sql.DateTime2, value);
|
|
111
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
112
|
+
request.input(`param${i}`, JSON.stringify(value));
|
|
113
|
+
} else {
|
|
114
|
+
request.input(`param${i}`, value);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
await request.query(insertSql);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
throw new MastraError(
|
|
121
|
+
{
|
|
122
|
+
id: 'MASTRA_STORAGE_MSSQL_STORE_INSERT_FAILED',
|
|
123
|
+
domain: ErrorDomain.STORAGE,
|
|
124
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
125
|
+
details: {
|
|
126
|
+
tableName,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
error,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async clearTable({ tableName }: { tableName: TABLE_NAMES }): Promise<void> {
|
|
135
|
+
const fullTableName = getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) });
|
|
136
|
+
try {
|
|
137
|
+
// First try TRUNCATE for better performance
|
|
138
|
+
try {
|
|
139
|
+
await this.pool.request().query(`TRUNCATE TABLE ${fullTableName}`);
|
|
140
|
+
} catch (truncateError: any) {
|
|
141
|
+
// If TRUNCATE fails due to foreign key constraints, fall back to DELETE
|
|
142
|
+
if (truncateError.message && truncateError.message.includes('foreign key')) {
|
|
143
|
+
await this.pool.request().query(`DELETE FROM ${fullTableName}`);
|
|
144
|
+
} else {
|
|
145
|
+
throw truncateError;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} catch (error) {
|
|
149
|
+
throw new MastraError(
|
|
150
|
+
{
|
|
151
|
+
id: 'MASTRA_STORAGE_MSSQL_STORE_CLEAR_TABLE_FAILED',
|
|
152
|
+
domain: ErrorDomain.STORAGE,
|
|
153
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
154
|
+
details: {
|
|
155
|
+
tableName,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
error,
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
protected getDefaultValue(type: StorageColumn['type']): string {
|
|
164
|
+
switch (type) {
|
|
165
|
+
case 'timestamp':
|
|
166
|
+
return 'DEFAULT SYSDATETIMEOFFSET()';
|
|
167
|
+
case 'jsonb':
|
|
168
|
+
return "DEFAULT N'{}'";
|
|
169
|
+
default:
|
|
170
|
+
return super.getDefaultValue(type);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async createTable({
|
|
175
|
+
tableName,
|
|
176
|
+
schema,
|
|
177
|
+
}: {
|
|
178
|
+
tableName: TABLE_NAMES;
|
|
179
|
+
schema: Record<string, StorageColumn>;
|
|
180
|
+
}): Promise<void> {
|
|
181
|
+
try {
|
|
182
|
+
const uniqueConstraintColumns = tableName === TABLE_WORKFLOW_SNAPSHOT ? ['workflow_name', 'run_id'] : [];
|
|
183
|
+
|
|
184
|
+
const columns = Object.entries(schema)
|
|
185
|
+
.map(([name, def]) => {
|
|
186
|
+
const parsedName = parseSqlIdentifier(name, 'column name');
|
|
187
|
+
const constraints = [];
|
|
188
|
+
if (def.primaryKey) constraints.push('PRIMARY KEY');
|
|
189
|
+
if (!def.nullable) constraints.push('NOT NULL');
|
|
190
|
+
const isIndexed = !!def.primaryKey || uniqueConstraintColumns.includes(name);
|
|
191
|
+
return `[${parsedName}] ${this.getSqlType(def.type, isIndexed)} ${constraints.join(' ')}`.trim();
|
|
192
|
+
})
|
|
193
|
+
.join(',\n');
|
|
194
|
+
|
|
195
|
+
if (this.schemaName) {
|
|
196
|
+
await this.setupSchema();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const checkTableRequest = this.pool.request();
|
|
200
|
+
checkTableRequest.input(
|
|
201
|
+
'tableName',
|
|
202
|
+
getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })
|
|
203
|
+
.replace(/[[\]]/g, '')
|
|
204
|
+
.split('.')
|
|
205
|
+
.pop(),
|
|
206
|
+
);
|
|
207
|
+
const checkTableSql = `SELECT 1 AS found FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = @schema AND TABLE_NAME = @tableName`;
|
|
208
|
+
checkTableRequest.input('schema', this.schemaName || 'dbo');
|
|
209
|
+
const checkTableResult = await checkTableRequest.query(checkTableSql);
|
|
210
|
+
const tableExists = Array.isArray(checkTableResult.recordset) && checkTableResult.recordset.length > 0;
|
|
211
|
+
|
|
212
|
+
if (!tableExists) {
|
|
213
|
+
const createSql = `CREATE TABLE ${getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })} (\n${columns}\n)`;
|
|
214
|
+
await this.pool.request().query(createSql);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const columnCheckSql = `
|
|
218
|
+
SELECT 1 AS found
|
|
219
|
+
FROM INFORMATION_SCHEMA.COLUMNS
|
|
220
|
+
WHERE TABLE_SCHEMA = @schema AND TABLE_NAME = @tableName AND COLUMN_NAME = 'seq_id'
|
|
221
|
+
`;
|
|
222
|
+
const checkColumnRequest = this.pool.request();
|
|
223
|
+
checkColumnRequest.input('schema', this.schemaName || 'dbo');
|
|
224
|
+
checkColumnRequest.input(
|
|
225
|
+
'tableName',
|
|
226
|
+
getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })
|
|
227
|
+
.replace(/[[\]]/g, '')
|
|
228
|
+
.split('.')
|
|
229
|
+
.pop(),
|
|
230
|
+
);
|
|
231
|
+
const columnResult = await checkColumnRequest.query(columnCheckSql);
|
|
232
|
+
const columnExists = Array.isArray(columnResult.recordset) && columnResult.recordset.length > 0;
|
|
233
|
+
|
|
234
|
+
if (!columnExists) {
|
|
235
|
+
const alterSql = `ALTER TABLE ${getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })} ADD seq_id BIGINT IDENTITY(1,1)`;
|
|
236
|
+
await this.pool.request().query(alterSql);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (tableName === TABLE_WORKFLOW_SNAPSHOT) {
|
|
240
|
+
const constraintName = 'mastra_workflow_snapshot_workflow_name_run_id_key';
|
|
241
|
+
const checkConstraintSql = `SELECT 1 AS found FROM sys.key_constraints WHERE name = @constraintName`;
|
|
242
|
+
const checkConstraintRequest = this.pool.request();
|
|
243
|
+
checkConstraintRequest.input('constraintName', constraintName);
|
|
244
|
+
const constraintResult = await checkConstraintRequest.query(checkConstraintSql);
|
|
245
|
+
const constraintExists = Array.isArray(constraintResult.recordset) && constraintResult.recordset.length > 0;
|
|
246
|
+
if (!constraintExists) {
|
|
247
|
+
const addConstraintSql = `ALTER TABLE ${getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })} ADD CONSTRAINT ${constraintName} UNIQUE ([workflow_name], [run_id])`;
|
|
248
|
+
await this.pool.request().query(addConstraintSql);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
} catch (error) {
|
|
252
|
+
throw new MastraError(
|
|
253
|
+
{
|
|
254
|
+
id: 'MASTRA_STORAGE_MSSQL_STORE_CREATE_TABLE_FAILED',
|
|
255
|
+
domain: ErrorDomain.STORAGE,
|
|
256
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
257
|
+
details: {
|
|
258
|
+
tableName,
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
error,
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Alters table schema to add columns if they don't exist
|
|
268
|
+
* @param tableName Name of the table
|
|
269
|
+
* @param schema Schema of the table
|
|
270
|
+
* @param ifNotExists Array of column names to add if they don't exist
|
|
271
|
+
*/
|
|
272
|
+
async alterTable({
|
|
273
|
+
tableName,
|
|
274
|
+
schema,
|
|
275
|
+
ifNotExists,
|
|
276
|
+
}: {
|
|
277
|
+
tableName: TABLE_NAMES;
|
|
278
|
+
schema: Record<string, StorageColumn>;
|
|
279
|
+
ifNotExists: string[];
|
|
280
|
+
}): Promise<void> {
|
|
281
|
+
const fullTableName = getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) });
|
|
282
|
+
try {
|
|
283
|
+
for (const columnName of ifNotExists) {
|
|
284
|
+
if (schema[columnName]) {
|
|
285
|
+
const columnCheckRequest = this.pool.request();
|
|
286
|
+
columnCheckRequest.input('tableName', fullTableName.replace(/[[\]]/g, '').split('.').pop());
|
|
287
|
+
columnCheckRequest.input('columnName', columnName);
|
|
288
|
+
columnCheckRequest.input('schema', this.schemaName || 'dbo');
|
|
289
|
+
const checkSql = `SELECT 1 AS found FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = @schema AND TABLE_NAME = @tableName AND COLUMN_NAME = @columnName`;
|
|
290
|
+
const checkResult = await columnCheckRequest.query(checkSql);
|
|
291
|
+
const columnExists = Array.isArray(checkResult.recordset) && checkResult.recordset.length > 0;
|
|
292
|
+
if (!columnExists) {
|
|
293
|
+
const columnDef = schema[columnName];
|
|
294
|
+
const sqlType = this.getSqlType(columnDef.type);
|
|
295
|
+
const nullable = columnDef.nullable === false ? 'NOT NULL' : '';
|
|
296
|
+
const defaultValue = columnDef.nullable === false ? this.getDefaultValue(columnDef.type) : '';
|
|
297
|
+
const parsedColumnName = parseSqlIdentifier(columnName, 'column name');
|
|
298
|
+
const alterSql =
|
|
299
|
+
`ALTER TABLE ${fullTableName} ADD [${parsedColumnName}] ${sqlType} ${nullable} ${defaultValue}`.trim();
|
|
300
|
+
await this.pool.request().query(alterSql);
|
|
301
|
+
this.logger?.debug?.(`Ensured column ${parsedColumnName} exists in table ${fullTableName}`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
} catch (error) {
|
|
306
|
+
throw new MastraError(
|
|
307
|
+
{
|
|
308
|
+
id: 'MASTRA_STORAGE_MSSQL_STORE_ALTER_TABLE_FAILED',
|
|
309
|
+
domain: ErrorDomain.STORAGE,
|
|
310
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
311
|
+
details: {
|
|
312
|
+
tableName,
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
error,
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
async load<R>({ tableName, keys }: { tableName: TABLE_NAMES; keys: Record<string, string> }): Promise<R | null> {
|
|
321
|
+
try {
|
|
322
|
+
const keyEntries = Object.entries(keys).map(([key, value]) => [parseSqlIdentifier(key, 'column name'), value]);
|
|
323
|
+
const conditions = keyEntries.map(([key], i) => `[${key}] = @param${i}`).join(' AND ');
|
|
324
|
+
const values = keyEntries.map(([_, value]) => value);
|
|
325
|
+
const sql = `SELECT * FROM ${getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })} WHERE ${conditions}`;
|
|
326
|
+
const request = this.pool.request();
|
|
327
|
+
values.forEach((value, i) => {
|
|
328
|
+
request.input(`param${i}`, value);
|
|
329
|
+
});
|
|
330
|
+
const resultSet = await request.query(sql);
|
|
331
|
+
const result = resultSet.recordset[0] || null;
|
|
332
|
+
if (!result) {
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
if (tableName === TABLE_WORKFLOW_SNAPSHOT) {
|
|
336
|
+
const snapshot = result as any;
|
|
337
|
+
if (typeof snapshot.snapshot === 'string') {
|
|
338
|
+
snapshot.snapshot = JSON.parse(snapshot.snapshot);
|
|
339
|
+
}
|
|
340
|
+
return snapshot;
|
|
341
|
+
}
|
|
342
|
+
return result;
|
|
343
|
+
} catch (error) {
|
|
344
|
+
throw new MastraError(
|
|
345
|
+
{
|
|
346
|
+
id: 'MASTRA_STORAGE_MSSQL_STORE_LOAD_FAILED',
|
|
347
|
+
domain: ErrorDomain.STORAGE,
|
|
348
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
349
|
+
details: {
|
|
350
|
+
tableName,
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
error,
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
async batchInsert({ tableName, records }: { tableName: TABLE_NAMES; records: Record<string, any>[] }): Promise<void> {
|
|
359
|
+
const transaction = this.pool.transaction();
|
|
360
|
+
try {
|
|
361
|
+
await transaction.begin();
|
|
362
|
+
for (const record of records) {
|
|
363
|
+
await this.insert({ tableName, record });
|
|
364
|
+
}
|
|
365
|
+
await transaction.commit();
|
|
366
|
+
} catch (error) {
|
|
367
|
+
await transaction.rollback();
|
|
368
|
+
throw new MastraError(
|
|
369
|
+
{
|
|
370
|
+
id: 'MASTRA_STORAGE_MSSQL_STORE_BATCH_INSERT_FAILED',
|
|
371
|
+
domain: ErrorDomain.STORAGE,
|
|
372
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
373
|
+
details: {
|
|
374
|
+
tableName,
|
|
375
|
+
numberOfRecords: records.length,
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
error,
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
async dropTable({ tableName }: { tableName: TABLE_NAMES }): Promise<void> {
|
|
384
|
+
try {
|
|
385
|
+
const tableNameWithSchema = getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) });
|
|
386
|
+
await this.pool.request().query(`DROP TABLE IF EXISTS ${tableNameWithSchema}`);
|
|
387
|
+
} catch (error) {
|
|
388
|
+
throw new MastraError(
|
|
389
|
+
{
|
|
390
|
+
id: 'MASTRA_STORAGE_MSSQL_STORE_DROP_TABLE_FAILED',
|
|
391
|
+
domain: ErrorDomain.STORAGE,
|
|
392
|
+
category: ErrorCategory.THIRD_PARTY,
|
|
393
|
+
details: {
|
|
394
|
+
tableName,
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
error,
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|