@mastra/mssql 1.0.0-beta.1 → 1.0.0-beta.10
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/CHANGELOG.md +440 -0
- package/dist/docs/README.md +31 -0
- package/dist/docs/SKILL.md +32 -0
- package/dist/docs/SOURCE_MAP.json +6 -0
- package/dist/docs/storage/01-reference.md +141 -0
- package/dist/index.cjs +2513 -2110
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2522 -2123
- package/dist/index.js.map +1 -1
- package/dist/storage/{domains/operations → db}/index.d.ts +73 -15
- package/dist/storage/db/index.d.ts.map +1 -0
- package/dist/storage/db/utils.d.ts +21 -0
- package/dist/storage/db/utils.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +25 -10
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +32 -30
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +30 -26
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/domains/utils.d.ts +2 -2
- package/dist/storage/domains/utils.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +32 -17
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +114 -204
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +11 -9
- package/dist/storage/domains/operations/index.d.ts.map +0 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Storage API Reference
|
|
2
|
+
|
|
3
|
+
> API reference for storage - 1 entries
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Reference: MSSQL Storage
|
|
9
|
+
|
|
10
|
+
> Documentation for the MSSQL storage implementation in Mastra.
|
|
11
|
+
|
|
12
|
+
The MSSQL storage implementation provides a production-ready storage solution using Microsoft SQL Server databases.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @mastra/mssql@beta
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { MSSQLStore } from "@mastra/mssql";
|
|
24
|
+
|
|
25
|
+
const storage = new MSSQLStore({
|
|
26
|
+
id: 'mssql-storage',
|
|
27
|
+
connectionString: process.env.DATABASE_URL,
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Parameters
|
|
32
|
+
|
|
33
|
+
## Constructor Examples
|
|
34
|
+
|
|
35
|
+
You can instantiate `MSSQLStore` in the following ways:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { MSSQLStore } from "@mastra/mssql";
|
|
39
|
+
|
|
40
|
+
// Using a connection string only
|
|
41
|
+
const store1 = new MSSQLStore({
|
|
42
|
+
id: 'mssql-storage-1',
|
|
43
|
+
connectionString: "Server=localhost,1433;Database=mydb;User Id=sa;Password=password;Encrypt=true;TrustServerCertificate=true",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Using a connection string with a custom schema name
|
|
47
|
+
const store2 = new MSSQLStore({
|
|
48
|
+
id: 'mssql-storage-2',
|
|
49
|
+
connectionString: "Server=localhost,1433;Database=mydb;User Id=sa;Password=password;Encrypt=true;TrustServerCertificate=true",
|
|
50
|
+
schemaName: "custom_schema", // optional
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Using individual connection parameters
|
|
54
|
+
const store4 = new MSSQLStore({
|
|
55
|
+
id: 'mssql-storage-3',
|
|
56
|
+
server: "localhost",
|
|
57
|
+
port: 1433,
|
|
58
|
+
database: "mydb",
|
|
59
|
+
user: "user",
|
|
60
|
+
password: "password",
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Individual parameters with schemaName
|
|
64
|
+
const store5 = new MSSQLStore({
|
|
65
|
+
id: 'mssql-storage-4',
|
|
66
|
+
server: "localhost",
|
|
67
|
+
port: 1433,
|
|
68
|
+
database: "mydb",
|
|
69
|
+
user: "user",
|
|
70
|
+
password: "password",
|
|
71
|
+
schemaName: "custom_schema", // optional
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Additional Notes
|
|
76
|
+
|
|
77
|
+
### Schema Management
|
|
78
|
+
|
|
79
|
+
The storage implementation handles schema creation and updates automatically. It creates the following tables:
|
|
80
|
+
|
|
81
|
+
- `mastra_workflow_snapshot`: Stores workflow state and execution data
|
|
82
|
+
- `mastra_evals`: Stores evaluation results and metadata
|
|
83
|
+
- `mastra_threads`: Stores conversation threads
|
|
84
|
+
- `mastra_messages`: Stores individual messages
|
|
85
|
+
- `mastra_traces`: Stores telemetry and tracing data
|
|
86
|
+
- `mastra_scorers`: Stores scoring and evaluation data
|
|
87
|
+
- `mastra_resources`: Stores resource working memory data
|
|
88
|
+
|
|
89
|
+
### Initialization
|
|
90
|
+
|
|
91
|
+
When you pass storage to the Mastra class, `init()` is called automatically before any storage operation:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { Mastra } from "@mastra/core";
|
|
95
|
+
import { MSSQLStore } from "@mastra/mssql";
|
|
96
|
+
|
|
97
|
+
const storage = new MSSQLStore({
|
|
98
|
+
connectionString: process.env.DATABASE_URL,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const mastra = new Mastra({
|
|
102
|
+
storage, // init() is called automatically
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
If you're using storage directly without Mastra, you must call `init()` explicitly to create the tables:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { MSSQLStore } from "@mastra/mssql";
|
|
110
|
+
|
|
111
|
+
const storage = new MSSQLStore({
|
|
112
|
+
id: 'mssql-storage',
|
|
113
|
+
connectionString: process.env.DATABASE_URL,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Required when using storage directly
|
|
117
|
+
await storage.init();
|
|
118
|
+
|
|
119
|
+
// Access domain-specific stores via getStore()
|
|
120
|
+
const memoryStore = await storage.getStore('memory');
|
|
121
|
+
const thread = await memoryStore?.getThreadById({ threadId: "..." });
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
> **Note:**
|
|
125
|
+
If `init()` is not called, tables won't be created and storage operations will fail silently or throw errors.
|
|
126
|
+
|
|
127
|
+
### Direct Database and Pool Access
|
|
128
|
+
|
|
129
|
+
`MSSQLStore` exposes the mssql connection pool as public fields:
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
store.pool; // mssql connection pool instance
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
This enables direct queries and custom transaction management. When using these fields:
|
|
136
|
+
|
|
137
|
+
- You are responsible for proper connection and transaction handling.
|
|
138
|
+
- Closing the store (`store.close()`) will destroy the associated connection pool.
|
|
139
|
+
- Direct access bypasses any additional logic or validation provided by MSSQLStore methods.
|
|
140
|
+
|
|
141
|
+
This approach is intended for advanced scenarios where low-level access is required.
|