@mastra/mysql 0.8.5-alpha.1 → 0.8.5-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 -123
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,51 +8,9 @@ MySQL storage implementation for Mastra, providing persistent storage for thread
|
|
|
8
8
|
npm install @mastra/mysql
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## Prerequisites
|
|
12
|
-
|
|
13
|
-
- MySQL 8.0 or higher
|
|
14
|
-
|
|
15
11
|
## Usage
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
import { MySQLStore } from '@mastra/mysql';
|
|
19
|
-
|
|
20
|
-
const store = new MySQLStore({
|
|
21
|
-
connectionString: 'mysql://user:password@localhost:3306/mastra',
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// Create a thread
|
|
25
|
-
await store.saveThread({
|
|
26
|
-
thread: {
|
|
27
|
-
id: 'thread-123',
|
|
28
|
-
resourceId: 'resource-456',
|
|
29
|
-
title: 'My Thread',
|
|
30
|
-
metadata: { key: 'value' },
|
|
31
|
-
createdAt: new Date(),
|
|
32
|
-
updatedAt: new Date(),
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// Add messages to thread
|
|
37
|
-
await store.saveMessages({
|
|
38
|
-
messages: [
|
|
39
|
-
{
|
|
40
|
-
id: 'msg-789',
|
|
41
|
-
threadId: 'thread-123',
|
|
42
|
-
role: 'user',
|
|
43
|
-
content: { content: 'Hello' },
|
|
44
|
-
resourceId: 'resource-456',
|
|
45
|
-
createdAt: new Date(),
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// Query threads and messages
|
|
51
|
-
const savedThread = await store.getThreadById({ threadId: 'thread-123' });
|
|
52
|
-
const messages = await store.listMessages({ threadId: 'thread-123' });
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
### With Mastra
|
|
13
|
+
Configure the database credentials required by your provider.
|
|
56
14
|
|
|
57
15
|
```typescript
|
|
58
16
|
import { Mastra } from '@mastra/core';
|
|
@@ -65,88 +23,14 @@ export const mastra = new Mastra({
|
|
|
65
23
|
});
|
|
66
24
|
```
|
|
67
25
|
|
|
68
|
-
##
|
|
69
|
-
|
|
70
|
-
`MySQLStore` supports two connection methods:
|
|
71
|
-
|
|
72
|
-
**1. Connection String**
|
|
73
|
-
|
|
74
|
-
```typescript
|
|
75
|
-
const store = new MySQLStore({
|
|
76
|
-
connectionString: 'mysql://user:password@localhost:3306/mastra',
|
|
77
|
-
});
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
**2. Host/Port/Database**
|
|
26
|
+
## Documentation
|
|
81
27
|
|
|
82
|
-
|
|
83
|
-
const store = new MySQLStore({
|
|
84
|
-
host: 'localhost',
|
|
85
|
-
port: 3306,
|
|
86
|
-
user: 'mastra',
|
|
87
|
-
password: 'mastra',
|
|
88
|
-
database: 'mastra',
|
|
89
|
-
});
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### Optional Configuration
|
|
93
|
-
|
|
94
|
-
- `ssl`: Enable SSL or provide custom SSL options (`true` | `false` | object)
|
|
95
|
-
- `max`: Maximum pool connections (default: `10`)
|
|
96
|
-
- `database`: Override the database name parsed from the connection string
|
|
97
|
-
- `waitForConnections`: Queue requests when the pool is full (default: `true`, host config only)
|
|
98
|
-
- `queueLimit`: Maximum queued connection requests, `0` for unlimited (default: `0`, host config only)
|
|
99
|
-
- `skipDefaultIndexes`: Skip creating the built-in performance indexes during setup (default: `false`)
|
|
100
|
-
- `indexes`: Additional custom indexes to create during setup
|
|
101
|
-
|
|
102
|
-
## Features
|
|
103
|
-
|
|
104
|
-
- Persistent storage for threads, messages, workflows, scores, datasets, and experiments
|
|
105
|
-
- Full observability/tracing storage (spans and traces)
|
|
106
|
-
- Atomic transactions for data consistency
|
|
107
|
-
- Efficient batch operations
|
|
108
|
-
- Connection pooling via `mysql2`
|
|
109
|
-
- Automatic table and index setup on first use
|
|
110
|
-
- Rich metadata support with JSON columns
|
|
111
|
-
- Timestamp tracking and cascading deletes
|
|
112
|
-
|
|
113
|
-
## Storage Methods
|
|
114
|
-
|
|
115
|
-
- `saveThread({ thread })`: Create or update a thread
|
|
116
|
-
- `getThreadById({ threadId })`: Get a thread by ID
|
|
117
|
-
- `deleteThread({ threadId })`: Delete a thread and its messages
|
|
118
|
-
- `saveMessages({ messages })`: Save multiple messages in a transaction
|
|
119
|
-
- `listMessages({ threadId, perPage?, page? })`: Get messages for a thread with pagination
|
|
120
|
-
- `deleteMessages(messageIds)`: Delete specific messages
|
|
121
|
-
|
|
122
|
-
## Development
|
|
28
|
+
This README is the package guide. `MySQLStore` provides Mastra's storage domains through a MySQL connection pool, including agents, messages, workflows, observability, scores, datasets, prompt blocks, MCP records, and workspaces.
|
|
123
29
|
|
|
124
|
-
|
|
30
|
+
## Changelog
|
|
125
31
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
- `MYSQL_HOST` (default: `localhost`)
|
|
129
|
-
- `MYSQL_PORT` (default: `3306`)
|
|
130
|
-
- `MYSQL_USER` (default: `mastra`)
|
|
131
|
-
- `MYSQL_PASSWORD` (default: `mastra`)
|
|
132
|
-
- `MYSQL_DB` (default: `mastra`)
|
|
133
|
-
|
|
134
|
-
### Running Tests
|
|
135
|
-
|
|
136
|
-
Unit tests run without a database:
|
|
137
|
-
|
|
138
|
-
```bash
|
|
139
|
-
pnpm test src/storage/index.unit.test.ts
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
Integration tests use Docker to start a MySQL instance, run the suite, and clean up afterward:
|
|
143
|
-
|
|
144
|
-
```bash
|
|
145
|
-
# Ensure Docker is running
|
|
146
|
-
pnpm test
|
|
147
|
-
```
|
|
32
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/stores/mysql/CHANGELOG.md) for version history and release notes.
|
|
148
33
|
|
|
149
|
-
##
|
|
34
|
+
## Support
|
|
150
35
|
|
|
151
|
-
|
|
152
|
-
- [MySQL Documentation](https://dev.mysql.com/doc/)
|
|
36
|
+
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mysql",
|
|
3
|
-
"version": "0.8.5-alpha.
|
|
3
|
+
"version": "0.8.5-alpha.2",
|
|
4
4
|
"description": "MySQL provider for Mastra - db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@internal/lint": "0.0.129",
|
|
35
35
|
"@internal/storage-test-utils": "0.0.125",
|
|
36
36
|
"@internal/types-builder": "0.0.104",
|
|
37
|
-
"@mastra/core": "1.64.0-alpha.
|
|
37
|
+
"@mastra/core": "1.64.0-alpha.7"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@mastra/core": ">=1.63.1-0 <2.0.0-0"
|