@mastra/mssql 1.7.4-alpha.0 → 1.7.4-alpha.2
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 +7 -348
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +13 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/workflow-definitions/index.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -8,11 +8,6 @@ Microsoft SQL Server implementation for Mastra, providing general storage capabi
|
|
|
8
8
|
npm install @mastra/mssql
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## Prerequisites
|
|
12
|
-
|
|
13
|
-
- Microsoft SQL Server 2016 or higher
|
|
14
|
-
- User with privileges to create tables and schemas (if needed)
|
|
15
|
-
|
|
16
11
|
## Usage
|
|
17
12
|
|
|
18
13
|
### Storage
|
|
@@ -33,351 +28,15 @@ const store = new MSSQLStore({
|
|
|
33
28
|
});
|
|
34
29
|
```
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
```typescript
|
|
39
|
-
const store = new MSSQLStore({
|
|
40
|
-
id: 'mssql-storage',
|
|
41
|
-
server: 'localhost',
|
|
42
|
-
port: 1433,
|
|
43
|
-
database: 'mastra',
|
|
44
|
-
user: 'sa',
|
|
45
|
-
password: 'yourStrong(!)Password',
|
|
46
|
-
options: { encrypt: true, trustServerCertificate: true }, // Optional
|
|
47
|
-
});
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
#### Advanced Options
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
const store = new MSSQLStore({
|
|
54
|
-
id: 'mssql-storage',
|
|
55
|
-
connectionString:
|
|
56
|
-
'Server=localhost,1433;Database=mastra;User Id=sa;Password=yourPassword;Encrypt=true;TrustServerCertificate=true',
|
|
57
|
-
schemaName: 'custom_schema', // Use custom schema (default: dbo)
|
|
58
|
-
options: {
|
|
59
|
-
encrypt: true,
|
|
60
|
-
trustServerCertificate: true,
|
|
61
|
-
connectTimeout: 30000,
|
|
62
|
-
requestTimeout: 30000,
|
|
63
|
-
pool: {
|
|
64
|
-
max: 20,
|
|
65
|
-
min: 0,
|
|
66
|
-
idleTimeoutMillis: 30000,
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
#### Usage Example
|
|
73
|
-
|
|
74
|
-
```typescript
|
|
75
|
-
// Create a thread
|
|
76
|
-
await store.saveThread({
|
|
77
|
-
thread: {
|
|
78
|
-
id: 'thread-123',
|
|
79
|
-
resourceId: 'resource-456',
|
|
80
|
-
title: 'My Thread',
|
|
81
|
-
metadata: { key: 'value' },
|
|
82
|
-
createdAt: new Date(),
|
|
83
|
-
updatedAt: new Date(),
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// Add messages to thread
|
|
88
|
-
await store.saveMessages({
|
|
89
|
-
messages: [
|
|
90
|
-
{
|
|
91
|
-
id: 'msg-789',
|
|
92
|
-
threadId: 'thread-123',
|
|
93
|
-
role: 'user',
|
|
94
|
-
type: 'text',
|
|
95
|
-
content: [{ type: 'text', text: 'Hello' }],
|
|
96
|
-
resourceId: 'resource-456',
|
|
97
|
-
createdAt: new Date(),
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// Query threads and messages
|
|
103
|
-
const savedThread = await store.getThreadById({ threadId: 'thread-123' });
|
|
104
|
-
const messages = await store.listMessages({ threadId: 'thread-123' });
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
## Configuration
|
|
108
|
-
|
|
109
|
-
### Identifier
|
|
110
|
-
|
|
111
|
-
- `id`: Unique identifier for this store instance (required)
|
|
112
|
-
|
|
113
|
-
### Connection Methods
|
|
114
|
-
|
|
115
|
-
MSSQLStore supports multiple connection methods:
|
|
116
|
-
|
|
117
|
-
1. **Connection String**
|
|
118
|
-
|
|
119
|
-
```typescript
|
|
120
|
-
{
|
|
121
|
-
id: 'mssql-storage',
|
|
122
|
-
connectionString: 'Server=localhost,1433;Database=mastra;User Id=sa;Password=yourPassword;Encrypt=true;TrustServerCertificate=true';
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
2. **Server/Port/Database**
|
|
127
|
-
```typescript
|
|
128
|
-
{
|
|
129
|
-
id: 'mssql-storage',
|
|
130
|
-
server: 'localhost',
|
|
131
|
-
port: 1433,
|
|
132
|
-
database: 'mastra',
|
|
133
|
-
user: 'sa',
|
|
134
|
-
password: 'password'
|
|
135
|
-
}
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### Optional Configuration
|
|
139
|
-
|
|
140
|
-
- `schemaName`: Custom SQL Server schema (default: `dbo`)
|
|
141
|
-
- `options.encrypt`: Enable encryption (default: `true`)
|
|
142
|
-
- `options.trustServerCertificate`: Trust self-signed certificates (default: `true`)
|
|
143
|
-
- `options.connectTimeout`: Connection timeout in milliseconds (default: `15000`)
|
|
144
|
-
- `options.requestTimeout`: Request timeout in milliseconds (default: `15000`)
|
|
145
|
-
- `options.pool.max`: Maximum pool connections (default: `10`)
|
|
146
|
-
- `options.pool.min`: Minimum pool connections (default: `0`)
|
|
147
|
-
- `options.pool.idleTimeoutMillis`: Idle connection timeout (default: `30000`)
|
|
148
|
-
|
|
149
|
-
### Default Connection Pool Settings
|
|
150
|
-
|
|
151
|
-
- Maximum connections: 10
|
|
152
|
-
- Minimum connections: 0
|
|
153
|
-
- Idle timeout: 30 seconds
|
|
154
|
-
- Connection timeout: 15 seconds
|
|
155
|
-
- Request timeout: 15 seconds
|
|
156
|
-
|
|
157
|
-
## Features
|
|
158
|
-
|
|
159
|
-
### Storage Features
|
|
160
|
-
|
|
161
|
-
- **Thread and Message Management**
|
|
162
|
-
- Thread and message storage with JSON support
|
|
163
|
-
- Message format versioning (v1 and v2)
|
|
164
|
-
- Pagination support for threads and messages
|
|
165
|
-
- Atomic transactions for batch operations (save, update, delete)
|
|
166
|
-
- Automatic thread timestamp updates
|
|
167
|
-
- Cascading deletes
|
|
168
|
-
- **Resources**
|
|
169
|
-
- Resource storage with working memory
|
|
170
|
-
- Rich metadata support
|
|
171
|
-
- Update working memory and metadata independently
|
|
172
|
-
|
|
173
|
-
- **Tracing & Observability**
|
|
174
|
-
- Trace AI agent execution with spans
|
|
175
|
-
- Query traces with pagination and filtering
|
|
176
|
-
- Batch operations for high-volume tracing
|
|
177
|
-
- Parent-child span relationships
|
|
178
|
-
- Span metadata and timing information
|
|
179
|
-
|
|
180
|
-
- **Workflow Management**
|
|
181
|
-
- Persist and restore workflow execution state
|
|
182
|
-
- Track workflow run history
|
|
183
|
-
- Step-by-step result tracking with row-level locking
|
|
184
|
-
- Workflow status management with row-level locking
|
|
185
|
-
- Query workflow runs by date range or resource
|
|
186
|
-
- Concurrent update protection for parallel workflow execution
|
|
187
|
-
|
|
188
|
-
- **Scoring & Evaluation**
|
|
189
|
-
- Store evaluation scores and metrics
|
|
190
|
-
- Query scores by scorer, run, entity, or span
|
|
191
|
-
- Support for multiple scoring sources
|
|
192
|
-
- Pagination support for large score datasets
|
|
193
|
-
|
|
194
|
-
- **Performance & Scalability**
|
|
195
|
-
- Connection pooling with configurable limits
|
|
196
|
-
- Atomic transactions for all batch operations
|
|
197
|
-
- Efficient batch insert/update/delete with transaction safety
|
|
198
|
-
- Row-level locking for concurrent updates
|
|
199
|
-
- Automatic performance indexes
|
|
200
|
-
- Index management (create, list, describe, drop)
|
|
201
|
-
- Timestamp tracking with high precision
|
|
202
|
-
- **Data Management**
|
|
203
|
-
- Custom schema support
|
|
204
|
-
- Table operations (create, alter, clear, drop)
|
|
205
|
-
- Low-level insert and load operations
|
|
206
|
-
- JSON data type support
|
|
207
|
-
|
|
208
|
-
## Storage Methods
|
|
209
|
-
|
|
210
|
-
### Initialization & Connection
|
|
31
|
+
## Documentation
|
|
211
32
|
|
|
212
|
-
-
|
|
213
|
-
-
|
|
33
|
+
- [Microsoft SQL Server integration guide](https://mastra.ai/integrations/databases/mssql)
|
|
34
|
+
- [Storage reference](https://mastra.ai/reference/storage/overview)
|
|
214
35
|
|
|
215
|
-
|
|
36
|
+
## Changelog
|
|
216
37
|
|
|
217
|
-
|
|
218
|
-
- `getThreadById({ threadId })`: Get a thread by ID
|
|
219
|
-
- `updateThread({ id, title, metadata })`: Update thread title and metadata
|
|
220
|
-
- `deleteThread({ threadId })`: Delete a thread and its messages
|
|
221
|
-
- `listThreadsByResourceId({ resourceId, offset, limit, orderBy? })`: List paginated threads for a resource
|
|
222
|
-
|
|
223
|
-
### Messages
|
|
224
|
-
|
|
225
|
-
- `saveMessages({ messages })`: Save multiple messages with atomic transaction
|
|
226
|
-
- `listMessagesById({ messageIds })`: Get messages by their IDs
|
|
227
|
-
- `listMessages({ threadId, resourceId?, page?, perPage?, orderBy?, filter? })`: Get paginated messages for a thread with filtering and sorting
|
|
228
|
-
- `updateMessages({ messages })`: Update existing messages with atomic transaction
|
|
229
|
-
- `deleteMessages(messageIds)`: Delete specific messages with atomic transaction
|
|
230
|
-
|
|
231
|
-
### Resources
|
|
232
|
-
|
|
233
|
-
- `saveResource({ resource })`: Save a resource with working memory
|
|
234
|
-
- `getResourceById({ resourceId })`: Get a resource by ID
|
|
235
|
-
- `updateResource({ resourceId, workingMemory?, metadata? })`: Update resource working memory and metadata
|
|
236
|
-
|
|
237
|
-
### Tracing & Observability
|
|
238
|
-
|
|
239
|
-
- `createSpan(span)`: Create a trace span
|
|
240
|
-
- `updateSpan({ spanId, traceId, updates })`: Update an existing span
|
|
241
|
-
- `getTrace(traceId)`: Get complete trace with all spans
|
|
242
|
-
- `getTracesPaginated({ filters?, pagination? })`: Query traces with pagination and filters
|
|
243
|
-
- `batchCreateSpans({ records })`: Batch create multiple spans
|
|
244
|
-
- `batchUpdateSpans({ records })`: Batch update multiple spans
|
|
245
|
-
- `batchDeleteTraces({ traceIds })`: Batch delete traces
|
|
246
|
-
|
|
247
|
-
### Index Management
|
|
248
|
-
|
|
249
|
-
- `createIndex({ name, table, columns, unique?, where? })`: Create a new index
|
|
250
|
-
- `listIndexes(tableName?)`: List all indexes or indexes for a specific table
|
|
251
|
-
- `describeIndex(indexName)`: Get detailed index statistics and information
|
|
252
|
-
- `dropIndex(indexName)`: Drop an existing index
|
|
253
|
-
|
|
254
|
-
### Workflows
|
|
255
|
-
|
|
256
|
-
- `persistWorkflowSnapshot({ workflowName, runId, resourceId?, snapshot })`: Save workflow execution state
|
|
257
|
-
- `loadWorkflowSnapshot({ workflowName, runId })`: Load workflow execution state
|
|
258
|
-
- `updateWorkflowResults({ workflowName, runId, stepId, result, runtimeContext })`: Update step results (transaction + row locking)
|
|
259
|
-
- `updateWorkflowState({ workflowName, runId, opts })`: Update workflow run status (transaction + row locking)
|
|
260
|
-
- `listWorkflowRuns({ workflowName?, fromDate?, toDate?, limit?, offset?, resourceId? })`: Query workflow runs
|
|
261
|
-
- `getWorkflowRunById({ runId, workflowName? })`: Get specific workflow run
|
|
262
|
-
|
|
263
|
-
### Scores & Evaluation
|
|
264
|
-
|
|
265
|
-
- `saveScore(score)`: Save evaluation score
|
|
266
|
-
- `getScoreById({ id })`: Get score by ID
|
|
267
|
-
- `listScoresByScorerId({ scorerId, pagination, entityId?, entityType?, source? })`: Get scores by scorer
|
|
268
|
-
- `listScoresByRunId({ runId, pagination })`: Get scores for a run
|
|
269
|
-
- `listScoresByEntityId({ entityId, entityType, pagination })`: Get scores for an entity
|
|
270
|
-
- `listScoresBySpan({ traceId, spanId, pagination })`: Get scores for a trace span
|
|
271
|
-
|
|
272
|
-
### Traces (Legacy)
|
|
273
|
-
|
|
274
|
-
- `getTracesPaginated({ filters?, pagination? })`: Get paginated legacy traces
|
|
275
|
-
- `batchTraceInsert({ records })`: Batch insert legacy trace records
|
|
276
|
-
|
|
277
|
-
### Evals (Legacy)
|
|
278
|
-
|
|
279
|
-
- `getEvals({ agentName?, type?, page?, perPage? })`: Get paginated evaluations
|
|
280
|
-
|
|
281
|
-
### Low-level Operations
|
|
282
|
-
|
|
283
|
-
- `createTable({ tableName, schema })`: Create a new table
|
|
284
|
-
- `alterTable({ tableName, schema, ifNotExists })`: Add columns to existing table
|
|
285
|
-
- `clearTable({ tableName })`: Remove all rows from a table
|
|
286
|
-
- `dropTable({ tableName })`: Drop a table
|
|
287
|
-
- `insert({ tableName, record })`: Insert a single record
|
|
288
|
-
- `batchInsert({ tableName, records })`: Batch insert multiple records
|
|
289
|
-
- `load<R>({ tableName, keys })`: Load a record by key(s)
|
|
290
|
-
|
|
291
|
-
## Index Management
|
|
292
|
-
|
|
293
|
-
The MSSQL store provides comprehensive index management capabilities to optimize query performance.
|
|
294
|
-
|
|
295
|
-
### Automatic Performance Indexes
|
|
296
|
-
|
|
297
|
-
MSSQL storage automatically creates composite indexes during initialization for common query patterns. These indexes significantly improve performance for filtered queries with sorting.
|
|
298
|
-
|
|
299
|
-
### Creating Custom Indexes
|
|
300
|
-
|
|
301
|
-
```typescript
|
|
302
|
-
// Basic index for common queries
|
|
303
|
-
await store.createIndex({
|
|
304
|
-
name: 'idx_threads_resource',
|
|
305
|
-
table: 'mastra_threads',
|
|
306
|
-
columns: ['resourceId'],
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
// Composite index with sort order for filtering + sorting
|
|
310
|
-
await store.createIndex({
|
|
311
|
-
name: 'idx_messages_composite',
|
|
312
|
-
table: 'mastra_messages',
|
|
313
|
-
columns: ['thread_id', 'seq_id DESC'],
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
// Unique index for constraints
|
|
317
|
-
await store.createIndex({
|
|
318
|
-
name: 'idx_unique_constraint',
|
|
319
|
-
table: 'mastra_resources',
|
|
320
|
-
columns: ['id'],
|
|
321
|
-
unique: true,
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
// Filtered index (partial indexing)
|
|
325
|
-
await store.createIndex({
|
|
326
|
-
name: 'idx_active_threads',
|
|
327
|
-
table: 'mastra_threads',
|
|
328
|
-
columns: ['resourceId'],
|
|
329
|
-
where: "status = 'active'",
|
|
330
|
-
});
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
### Managing Indexes
|
|
334
|
-
|
|
335
|
-
```typescript
|
|
336
|
-
// List all indexes
|
|
337
|
-
const allIndexes = await store.listIndexes();
|
|
338
|
-
|
|
339
|
-
// List indexes for specific table
|
|
340
|
-
const threadIndexes = await store.listIndexes('mastra_threads');
|
|
341
|
-
|
|
342
|
-
// Get detailed statistics for an index
|
|
343
|
-
const stats = await store.describeIndex('idx_threads_resource');
|
|
344
|
-
console.log(stats);
|
|
345
|
-
// {
|
|
346
|
-
// name: 'idx_threads_resource',
|
|
347
|
-
// table: 'mastra_threads',
|
|
348
|
-
// columns: ['resourceId', 'seq_id'],
|
|
349
|
-
// unique: false,
|
|
350
|
-
// size: '128 KB',
|
|
351
|
-
// method: 'nonclustered',
|
|
352
|
-
// scans: 1542, // Number of index seeks
|
|
353
|
-
// tuples_read: 45230, // Tuples read via index
|
|
354
|
-
// tuples_fetched: 12050 // Tuples fetched via index
|
|
355
|
-
// }
|
|
356
|
-
|
|
357
|
-
// Drop an index
|
|
358
|
-
await store.dropIndex('idx_threads_resource');
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
### Monitoring Index Performance
|
|
362
|
-
|
|
363
|
-
```typescript
|
|
364
|
-
// Check index usage statistics
|
|
365
|
-
const stats = await store.describeIndex('idx_threads_resource');
|
|
366
|
-
|
|
367
|
-
// Identify unused indexes
|
|
368
|
-
if (stats.scans === 0) {
|
|
369
|
-
console.log(`Index ${stats.name} is unused - consider removing`);
|
|
370
|
-
await store.dropIndex(stats.name);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// Monitor index efficiency
|
|
374
|
-
const efficiency = stats.tuples_fetched / stats.tuples_read;
|
|
375
|
-
if (efficiency < 0.5) {
|
|
376
|
-
console.log(`Index ${stats.name} has low efficiency: ${efficiency}`);
|
|
377
|
-
}
|
|
378
|
-
```
|
|
38
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/stores/mssql/CHANGELOG.md) for version history and release notes.
|
|
379
39
|
|
|
380
|
-
##
|
|
40
|
+
## Support
|
|
381
41
|
|
|
382
|
-
|
|
383
|
-
- [node-mssql Documentation](https://www.npmjs.com/package/mssql)
|
|
42
|
+
We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
|
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -4156,6 +4156,12 @@ function rowToDefinition(row) {
|
|
|
4156
4156
|
if (stateSchema != null) def.stateSchema = stateSchema;
|
|
4157
4157
|
const requestContextSchema = parseJson(row.requestContextSchema, "requestContextSchema", row.id);
|
|
4158
4158
|
if (requestContextSchema != null) def.requestContextSchema = requestContextSchema;
|
|
4159
|
+
try {
|
|
4160
|
+
const schedule = parseJson(row.schedule, "schedule", row.id);
|
|
4161
|
+
if (schedule != null) def.schedule = schedule;
|
|
4162
|
+
} catch {
|
|
4163
|
+
def.schedule = row.schedule;
|
|
4164
|
+
}
|
|
4159
4165
|
if (row.authorId != null) def.authorId = String(row.authorId);
|
|
4160
4166
|
return def;
|
|
4161
4167
|
}
|
|
@@ -4190,6 +4196,11 @@ var WorkflowDefinitionsMSSQL = class WorkflowDefinitionsMSSQL extends _mastra_co
|
|
|
4190
4196
|
tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
|
|
4191
4197
|
schema: _mastra_core_storage.WORKFLOW_DEFINITIONS_SCHEMA
|
|
4192
4198
|
});
|
|
4199
|
+
await this.db.alterTable({
|
|
4200
|
+
tableName: _mastra_core_storage.TABLE_WORKFLOW_DEFINITIONS,
|
|
4201
|
+
schema: _mastra_core_storage.WORKFLOW_DEFINITIONS_SCHEMA,
|
|
4202
|
+
ifNotExists: ["schedule"]
|
|
4203
|
+
});
|
|
4193
4204
|
await this.createDefaultIndexes();
|
|
4194
4205
|
await this.createCustomIndexes();
|
|
4195
4206
|
}
|
|
@@ -4234,6 +4245,7 @@ var WorkflowDefinitionsMSSQL = class WorkflowDefinitionsMSSQL extends _mastra_co
|
|
|
4234
4245
|
stateSchema: input.stateSchema ?? null,
|
|
4235
4246
|
requestContextSchema: input.requestContextSchema ?? null,
|
|
4236
4247
|
graph: input.graph,
|
|
4248
|
+
schedule: "schedule" in input ? input.schedule ?? null : null,
|
|
4237
4249
|
status: "active",
|
|
4238
4250
|
source: "storage",
|
|
4239
4251
|
authorId: "authorId" in input ? input.authorId ?? null : null,
|
|
@@ -4264,6 +4276,7 @@ var WorkflowDefinitionsMSSQL = class WorkflowDefinitionsMSSQL extends _mastra_co
|
|
|
4264
4276
|
if ("stateSchema" in input && input.stateSchema !== void 0) data.stateSchema = input.stateSchema;
|
|
4265
4277
|
if ("requestContextSchema" in input && input.requestContextSchema !== void 0) data.requestContextSchema = input.requestContextSchema;
|
|
4266
4278
|
if ("graph" in input && input.graph !== void 0) data.graph = input.graph;
|
|
4279
|
+
if ("schedule" in input && input.schedule !== void 0) data.schedule = input.schedule;
|
|
4267
4280
|
if ("status" in input && input.status !== void 0) data.status = input.status;
|
|
4268
4281
|
if ("authorId" in input && input.authorId !== void 0) data.authorId = input.authorId;
|
|
4269
4282
|
await this.db.update({
|