@mastra/dsql 0.0.0-branches-as-default-20260512170712
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 +27 -0
- package/LICENSE.md +30 -0
- package/README.md +357 -0
- package/dist/index.cjs +4476 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4467 -0
- package/dist/index.js.map +1 -0
- package/dist/shared/batch.d.ts +55 -0
- package/dist/shared/batch.d.ts.map +1 -0
- package/dist/shared/config.d.ts +129 -0
- package/dist/shared/config.d.ts.map +1 -0
- package/dist/shared/retry.d.ts +207 -0
- package/dist/shared/retry.d.ts.map +1 -0
- package/dist/storage/client.d.ts +91 -0
- package/dist/storage/client.d.ts.map +1 -0
- package/dist/storage/db/index.d.ts +179 -0
- package/dist/storage/db/index.d.ts.map +1 -0
- package/dist/storage/domains/agents/index.d.ts +47 -0
- package/dist/storage/domains/agents/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +80 -0
- package/dist/storage/domains/memory/index.d.ts.map +1 -0
- package/dist/storage/domains/observability/index.d.ts +37 -0
- package/dist/storage/domains/observability/index.d.ts.map +1 -0
- package/dist/storage/domains/scores/index.d.ts +53 -0
- package/dist/storage/domains/scores/index.d.ts.map +1 -0
- package/dist/storage/domains/utils.d.ts +14 -0
- package/dist/storage/domains/utils.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +61 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +46 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/performance-indexes/performance-test.d.ts +47 -0
- package/dist/storage/performance-indexes/performance-test.d.ts.map +1 -0
- package/dist/storage/test-utils.d.ts +14 -0
- package/dist/storage/test-utils.d.ts.map +1 -0
- package/package.json +69 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# @mastra/dsql
|
|
2
|
+
|
|
3
|
+
## 0.0.0-branches-as-default-20260512170712
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added Amazon Aurora DSQL storage provider with IAM authentication support. ([#10930](https://github.com/mastra-ai/mastra/pull/10930))
|
|
8
|
+
|
|
9
|
+
Enables storing threads, messages, workflows, traces, and agent data in Amazon Aurora DSQL clusters.
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { DSQLStore } from '@mastra/dsql';
|
|
13
|
+
|
|
14
|
+
const storage = new DSQLStore({
|
|
15
|
+
id: 'my-dsql-store',
|
|
16
|
+
host: 'abc123.dsql.us-east-1.on.aws',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
await storage.init();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Related: #10929
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [[`9f17410`](https://github.com/mastra-ai/mastra/commit/9f1741080def23d42ee50b39887a385ae316a3c6), [`7ad5585`](https://github.com/mastra-ai/mastra/commit/7ad55856406f1de398dc713f6a9eaa78b2784bb6), [`ac47842`](https://github.com/mastra-ai/mastra/commit/ac478427aa7a5f5fdaed633a911218689b438c60), [`d1fdbd0`](https://github.com/mastra-ai/mastra/commit/d1fdbd012add5623cb7e6b7f882b605ab358bbb4), [`210ea7a`](https://github.com/mastra-ai/mastra/commit/210ea7af559791b73a44fc9c12179908aaa3183f), [`7c275a8`](https://github.com/mastra-ai/mastra/commit/7c275a810595e1a6c41ccc39720531ab65734700), [`bae019e`](https://github.com/mastra-ai/mastra/commit/bae019ecb6694da96909f7ec7b9eb3a0a33aa887), [`890b24c`](https://github.com/mastra-ai/mastra/commit/890b24cc7d32ed6aa4dfe253e54dc6bf4099f690), [`f984b4d`](https://github.com/mastra-ai/mastra/commit/f984b4d6c60bf2ae2a9b156f0e8c35a66fe96c91), [`6742347`](https://github.com/mastra-ai/mastra/commit/6742347d71955d7639adc9ddf6ff8282de7ee3ba), [`b59316f`](https://github.com/mastra-ai/mastra/commit/b59316ffa0f7688165b0f9c81ccdf85da461e5b2), [`0f48ebf`](https://github.com/mastra-ai/mastra/commit/0f48ebfc7ac7897b2092a189f45751924cf56d1c), [`37c0dc5`](https://github.com/mastra-ai/mastra/commit/37c0dc5697d343db98628bf867bf71ce6deec6d7), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`83218c8`](https://github.com/mastra-ai/mastra/commit/83218c88b37773c9424fbe733b37be556e55e94d), [`ef6b584`](https://github.com/mastra-ai/mastra/commit/ef6b5847ac33c0a7e80af3a86e8801e2933dd3ee), [`c6eb39e`](https://github.com/mastra-ai/mastra/commit/c6eb39ea6dca381c6563cb240237fbe608e02f93), [`7b0ad1f`](https://github.com/mastra-ai/mastra/commit/7b0ad1f5c53dc118c6da12ae82ae2587037dc2b8), [`d91ebe2`](https://github.com/mastra-ai/mastra/commit/d91ebe28ee065d8f2ed6df741c3c07f58d359529), [`62666c3`](https://github.com/mastra-ai/mastra/commit/62666c367eaeac3941ead454b1d38810cc855721), [`33f5061`](https://github.com/mastra-ai/mastra/commit/33f5061cd1c0335020c3faae61ce96de822854fa), [`4af2160`](https://github.com/mastra-ai/mastra/commit/4af2160322f4718cac421930cce85641e9512389), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`265ec9f`](https://github.com/mastra-ai/mastra/commit/265ec9f887b5c81255c873a76ff7796f16e4f99b), [`ce01024`](https://github.com/mastra-ai/mastra/commit/ce010242eee9bdfc09e4c26725b9d37998679a8d), [`6ce80bf`](https://github.com/mastra-ai/mastra/commit/6ce80bf4872a891e0bddf8b80561a80584efb14b), [`f984b4d`](https://github.com/mastra-ai/mastra/commit/f984b4d6c60bf2ae2a9b156f0e8c35a66fe96c91), [`136c959`](https://github.com/mastra-ai/mastra/commit/136c9592fb0eeb0cd212f28629d8a29b7557a2fc), [`9268531`](https://github.com/mastra-ai/mastra/commit/9268531e7ec4be98beeba3b3ae8be0a7ea380662), [`13ead79`](https://github.com/mastra-ai/mastra/commit/13ead79149486b88144db7e11e6ff551caef5be1), [`dccd8f1`](https://github.com/mastra-ai/mastra/commit/dccd8f1f8b8f1ad203b77556207e5529567c616d), [`4df7cc7`](https://github.com/mastra-ai/mastra/commit/4df7cc79342fd065fe7fdeef93c094db14b12bcd), [`f180e49`](https://github.com/mastra-ai/mastra/commit/f180e4990e71b04c9a475b523584071712f0048f), [`9260e01`](https://github.com/mastra-ai/mastra/commit/9260e015276fb1b500f7878ee452b47476bf1583), [`2f6c54e`](https://github.com/mastra-ai/mastra/commit/2f6c54e17c041cac1def54baaa6b771647836414), [`aca3121`](https://github.com/mastra-ai/mastra/commit/aca31211233dac25459f140ea4fcfb3a5af64c18), [`e06a159`](https://github.com/mastra-ai/mastra/commit/e06a1598ca07a6c3778aefc2a2d288363c6294ff), [`4dd900d`](https://github.com/mastra-ai/mastra/commit/4dd900d75dfe9be89f8c15188b368a8622aa1e18), [`b560d6f`](https://github.com/mastra-ai/mastra/commit/b560d6f88b9b904b15c10f75c949eb145bc27684), [`99869ec`](https://github.com/mastra-ai/mastra/commit/99869ecb1f2aa6dfcc44fa4e843e5ee0344efa64), [`900d086`](https://github.com/mastra-ai/mastra/commit/900d086bb737b9cf2fcf68f11b0389b801a2738c), [`4c0e286`](https://github.com/mastra-ai/mastra/commit/4c0e28637c9cfb4f416549b55e97ebfa13319dfc), [`55f1e2d`](https://github.com/mastra-ai/mastra/commit/55f1e2d65425b95a49ae788053b266f256e38c96), [`4ff5bdf`](https://github.com/mastra-ai/mastra/commit/4ff5bdfe170cba6dfb5260c6af0f4ba668430772), [`9cdf38e`](https://github.com/mastra-ai/mastra/commit/9cdf38e58506e1109c8b38f97cd7770978a4218e), [`087e413`](https://github.com/mastra-ai/mastra/commit/087e4133e5d6efa36619e9556c16750e4179c047), [`db34bc6`](https://github.com/mastra-ai/mastra/commit/db34bc6fb36cf125bda0c46be4d3fdc774b70cc4), [`990851e`](https://github.com/mastra-ai/mastra/commit/990851edcb0e30be5c2c18b6532f1a876cc2d335), [`bbcd93c`](https://github.com/mastra-ai/mastra/commit/bbcd93cf7d8aa1007d6d84bfd033b8015c912087), [`8373ff4`](https://github.com/mastra-ai/mastra/commit/8373ff46745d77af79f183c4470f80fa2727a6b2), [`d48a705`](https://github.com/mastra-ai/mastra/commit/d48a705ff3dfbdc7a996e07ecd8293b5effd9a2a), [`308bd07`](https://github.com/mastra-ai/mastra/commit/308bd074f35cef0c75d82fc1eb19382fe04ecf6f), [`6068a6c`](https://github.com/mastra-ai/mastra/commit/6068a6c42950fad3ebfc92346417896ba60803d2), [`36b3bbf`](https://github.com/mastra-ai/mastra/commit/36b3bbf5a8d59f7e23d47e29340e76c681b4929c), [`d86f031`](https://github.com/mastra-ai/mastra/commit/d86f031eb6b0b2570145afafea664e59bf688962), [`b275631`](https://github.com/mastra-ai/mastra/commit/b275631dc10541a482b2e2d4a3e3cfa843bd5fa1), [`00106be`](https://github.com/mastra-ai/mastra/commit/00106bede59b81e5b0e9cd6aad8d3b5dbc336387), [`bd36d8e`](https://github.com/mastra-ai/mastra/commit/bd36d8eb6de8c9a0310352649dbd4b06703c2299), [`11c1528`](https://github.com/mastra-ai/mastra/commit/11c152848c5d0ef227184853b5040f5b41ee7b1e), [`e2a079c`](https://github.com/mastra-ai/mastra/commit/e2a079cc3755b1895f7bd5dc36e9be81b11c7c22), [`8ac9141`](https://github.com/mastra-ai/mastra/commit/8ac9141439caa8fdd674944c4d84f29b3c730296), [`25184ff`](https://github.com/mastra-ai/mastra/commit/25184ffaf1293ec95119426eb1a1f8d38831b96c), [`534a456`](https://github.com/mastra-ai/mastra/commit/534a456a25e4df1e5407e7e632f4cb3b1fa14f9d), [`aebde9c`](https://github.com/mastra-ai/mastra/commit/aebde9cfacf56592c6b6350cae721740fe090b8a), [`36bae07`](https://github.com/mastra-ai/mastra/commit/36bae07c0e70b1b3006f2fd20830e8883dcbd066), [`5688881`](https://github.com/mastra-ai/mastra/commit/5688881669c7ed157f31ac77f6fc5f8d95ceea32)]:
|
|
27
|
+
- @mastra/core@0.0.0-branches-as-default-20260512170712
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Portions of this software are licensed as follows:
|
|
2
|
+
|
|
3
|
+
- All content that resides under any directory named "ee/" within this
|
|
4
|
+
repository, including but not limited to:
|
|
5
|
+
- `packages/core/src/auth/ee/`
|
|
6
|
+
- `packages/server/src/server/auth/ee/`
|
|
7
|
+
is licensed under the license defined in `ee/LICENSE`.
|
|
8
|
+
|
|
9
|
+
- All third-party components incorporated into the Mastra Software are
|
|
10
|
+
licensed under the original license provided by the owner of the
|
|
11
|
+
applicable component.
|
|
12
|
+
|
|
13
|
+
- Content outside of the above-mentioned directories or restrictions is
|
|
14
|
+
available under the "Apache License 2.0" as defined below.
|
|
15
|
+
|
|
16
|
+
# Apache License 2.0
|
|
17
|
+
|
|
18
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
19
|
+
|
|
20
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
21
|
+
you may not use this file except in compliance with the License.
|
|
22
|
+
You may obtain a copy of the License at
|
|
23
|
+
|
|
24
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
25
|
+
|
|
26
|
+
Unless required by applicable law or agreed to in writing, software
|
|
27
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
+
See the License for the specific language governing permissions and
|
|
30
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
# @mastra/dsql
|
|
2
|
+
|
|
3
|
+
Amazon Aurora DSQL storage implementation for Mastra, providing thread, message, workflow, and observability storage using Aurora DSQL with IAM authentication.
|
|
4
|
+
|
|
5
|
+
> **Note**
|
|
6
|
+
> Aurora DSQL doesn’t support PostgreSQL extensions (`CREATE EXTENSION`), including `pgvector`.
|
|
7
|
+
> For vector storage, use a separate vector store like `@mastra/s3vectors`.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @mastra/dsql
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Prerequisites
|
|
16
|
+
|
|
17
|
+
- Amazon Aurora DSQL cluster
|
|
18
|
+
- AWS credentials with access to the DSQL cluster (IAM authentication)
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Storage
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { DSQLStore } from '@mastra/dsql';
|
|
26
|
+
|
|
27
|
+
const store = new DSQLStore({
|
|
28
|
+
id: 'my-dsql-store',
|
|
29
|
+
host: 'abc123.dsql.us-east-1.on.aws',
|
|
30
|
+
// region is auto-detected from host, or specify explicitly:
|
|
31
|
+
// region: 'us-east-1',
|
|
32
|
+
// user: 'admin', // default
|
|
33
|
+
// database: 'postgres', // default
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Initialize the store (creates tables if needed)
|
|
37
|
+
await store.init();
|
|
38
|
+
|
|
39
|
+
// Create a thread
|
|
40
|
+
await store.saveThread({
|
|
41
|
+
thread: {
|
|
42
|
+
id: 'thread-123',
|
|
43
|
+
resourceId: 'resource-456',
|
|
44
|
+
title: 'My Thread',
|
|
45
|
+
metadata: { key: 'value' },
|
|
46
|
+
createdAt: new Date(),
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Add messages to thread
|
|
51
|
+
await store.saveMessages({
|
|
52
|
+
messages: [
|
|
53
|
+
{
|
|
54
|
+
id: 'msg-789',
|
|
55
|
+
threadId: 'thread-123',
|
|
56
|
+
role: 'user',
|
|
57
|
+
content: { content: 'Hello' },
|
|
58
|
+
resourceId: 'resource-456',
|
|
59
|
+
createdAt: new Date(),
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Query threads and messages
|
|
65
|
+
const savedThread = await store.getThreadById({ threadId: 'thread-123' });
|
|
66
|
+
const messages = await store.listMessages({ threadId: 'thread-123' });
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Configuration
|
|
70
|
+
|
|
71
|
+
### Connection Methods
|
|
72
|
+
|
|
73
|
+
`DSQLStore` supports multiple connection methods:
|
|
74
|
+
|
|
75
|
+
**1. Host Configuration (Recommended)**
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
import { DSQLStore } from '@mastra/dsql';
|
|
79
|
+
|
|
80
|
+
const store = new DSQLStore({
|
|
81
|
+
id: 'my-dsql-store',
|
|
82
|
+
host: 'abc123.dsql.us-east-1.on.aws',
|
|
83
|
+
// region is auto-detected from host, or specify explicitly
|
|
84
|
+
// user: 'admin', // default
|
|
85
|
+
// database: 'postgres', // default
|
|
86
|
+
schemaName: 'custom_schema', // optional
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**2. Pre-configured pg.Pool**
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { Pool } from 'pg';
|
|
94
|
+
import { AuroraDSQLClient } from '@aws/aurora-dsql-node-postgres-connector';
|
|
95
|
+
import { DSQLStore } from '@mastra/dsql';
|
|
96
|
+
|
|
97
|
+
const pool = new Pool({
|
|
98
|
+
host: 'abc123.dsql.us-east-1.on.aws',
|
|
99
|
+
Client: AuroraDSQLClient,
|
|
100
|
+
region: 'us-east-1',
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const store = new DSQLStore({
|
|
104
|
+
id: 'my-dsql-store',
|
|
105
|
+
pool,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Use store.pool for other libraries that need a pg.Pool
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Custom AWS Credentials
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { DSQLStore } from '@mastra/dsql';
|
|
115
|
+
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
|
|
116
|
+
|
|
117
|
+
const store = new DSQLStore({
|
|
118
|
+
id: 'my-dsql-store',
|
|
119
|
+
host: 'abc123.dsql.us-east-1.on.aws',
|
|
120
|
+
customCredentialsProvider: fromNodeProviderChain(),
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Connection Pool Settings
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
const store = new DSQLStore({
|
|
128
|
+
id: 'my-dsql-store',
|
|
129
|
+
host: 'abc123.dsql.us-east-1.on.aws',
|
|
130
|
+
|
|
131
|
+
// Connection pool settings
|
|
132
|
+
max: 10, // maximum connections (default: 10)
|
|
133
|
+
min: 0, // minimum connections (default: 0)
|
|
134
|
+
idleTimeoutMillis: 600000, // 10 minutes (default)
|
|
135
|
+
maxLifetimeSeconds: 3300, // 55 minutes (default, must be < 3600)
|
|
136
|
+
connectionTimeoutMillis: 5000, // 5 seconds (default)
|
|
137
|
+
allowExitOnIdle: true, // default: true
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Configuration Options
|
|
142
|
+
|
|
143
|
+
| Option | Type | Default | Description |
|
|
144
|
+
| --------------------------- | ----------------------------- | --------------- | --------------------------------------------------------------------------------------------------------- |
|
|
145
|
+
| `id` | string | (required) | Unique identifier for this store instance |
|
|
146
|
+
| `host` | string | (required)\* | DSQL cluster endpoint (e.g., `abc123.dsql.us-east-1.on.aws`) |
|
|
147
|
+
| `pool` | pg.Pool | - | Pre-configured pg.Pool instance (cannot be used with host) |
|
|
148
|
+
| `user` | string | `'admin'` | Database user (Aurora DSQL built-in admin role is `admin`) |
|
|
149
|
+
| `database` | string | `'postgres'` | Database name (Aurora DSQL exposes a single built-in database named `postgres` per cluster) |
|
|
150
|
+
| `region` | string | (auto-detected) | AWS region, extracted from host if not provided |
|
|
151
|
+
| `schemaName` | string | `'public'` | PostgreSQL schema name where Mastra tables/indexes are created |
|
|
152
|
+
| `customCredentialsProvider` | AwsCredentialIdentityProvider | (default chain) | Custom AWS credentials provider |
|
|
153
|
+
| `max` | number | `10` | Maximum connections in the pool |
|
|
154
|
+
| `min` | number | `0` | Minimum connections in the pool |
|
|
155
|
+
| `idleTimeoutMillis` | number | `600000` | Close idle connections after this many milliseconds |
|
|
156
|
+
| `maxLifetimeSeconds` | number | `3300` | Maximum connection lifetime in seconds (must be `< 3600` due to Aurora DSQL’s 60-minute connection limit) |
|
|
157
|
+
| `connectionTimeoutMillis` | number | `5000` | Connection acquisition timeout in milliseconds |
|
|
158
|
+
| `allowExitOnIdle` | boolean | `true` | Allow the process to exit when all connections are idle |
|
|
159
|
+
|
|
160
|
+
\* Either `host` or `pool` is required.
|
|
161
|
+
|
|
162
|
+
### Default Connection Pool Settings
|
|
163
|
+
|
|
164
|
+
The default pool settings are optimized for Aurora DSQL:
|
|
165
|
+
|
|
166
|
+
- Maximum connections: 10
|
|
167
|
+
- Idle timeout: 10 minutes (600,000 ms)
|
|
168
|
+
- Max connection lifetime: 55 minutes (3,300 seconds)
|
|
169
|
+
- Connection timeout: 5 seconds
|
|
170
|
+
|
|
171
|
+
The `maxLifetimeSeconds` is set to 55 minutes to ensure connections are rotated before Aurora DSQL's 60-minute connection duration limit.
|
|
172
|
+
|
|
173
|
+
## Aurora DSQL Specifics
|
|
174
|
+
|
|
175
|
+
`@mastra/dsql` is built on top of [Amazon Aurora DSQL](https://docs.aws.amazon.com/aurora-dsql/) using the official Node.js connector.
|
|
176
|
+
You usually interact with it like any other Mastra store, but there are some important Aurora DSQL characteristics to be aware of:
|
|
177
|
+
|
|
178
|
+
- **IAM-only authentication**
|
|
179
|
+
- Connections are authenticated with IAM (no database passwords).
|
|
180
|
+
- `@mastra/dsql` uses `@aws/aurora-dsql-node-postgres-connector` to generate short-lived auth tokens automatically.
|
|
181
|
+
- You can plug in a custom credentials provider via `customCredentialsProvider`.
|
|
182
|
+
|
|
183
|
+
- **Single database, schema-based isolation**
|
|
184
|
+
- Each cluster exposes a single built-in database named `postgres` (no `CREATE DATABASE`).
|
|
185
|
+
- Logical separation is done via schemas; `schemaName` controls where Mastra tables are created.
|
|
186
|
+
- Typical pattern: initialize as `admin`, optionally create an application schema, then connect as a non-admin role using that schema.
|
|
187
|
+
|
|
188
|
+
- **No PostgreSQL extensions**
|
|
189
|
+
- `CREATE EXTENSION` is not supported (including `pgvector`, `PostGIS`, etc.).
|
|
190
|
+
- For vectors or extension-based features, use a separate store (e.g. `@mastra/s3vectors`) alongside `DSQLStore`.
|
|
191
|
+
|
|
192
|
+
- **JSON stored as text**
|
|
193
|
+
- JSON/JSONB are available as _query_ types but not as column types.
|
|
194
|
+
- `@mastra/dsql` stores structured fields (metadata, content, etc.) in `TEXT` columns and casts to JSON at query time as needed.
|
|
195
|
+
|
|
196
|
+
- **Schema & DDL constraints**
|
|
197
|
+
- Some PostgreSQL features are not available (e.g. foreign key constraints, `TRUNCATE`, synchronous `CREATE INDEX`).
|
|
198
|
+
- Indexes are created asynchronously using `CREATE INDEX ASYNC`; there is a limit on the number of indexes per table.
|
|
199
|
+
- The store’s `init()` and index helper APIs are implemented to respect these constraints.
|
|
200
|
+
|
|
201
|
+
- **Transactions & optimistic concurrency**
|
|
202
|
+
- Aurora DSQL uses optimistic concurrency control (OCC) and may return retriable OCC errors under contention.
|
|
203
|
+
- There are limits on transaction duration and size; large bulk operations should be split into smaller batches at the application level.
|
|
204
|
+
|
|
205
|
+
- **Connection lifetime**
|
|
206
|
+
- Individual connections are limited to about 60 minutes.
|
|
207
|
+
- The default `maxLifetimeSeconds: 3300` ensures connections are recycled before hitting this limit.
|
|
208
|
+
|
|
209
|
+
## Features
|
|
210
|
+
|
|
211
|
+
### Storage Features
|
|
212
|
+
|
|
213
|
+
- Thread and message storage with JSON support
|
|
214
|
+
- Atomic transactions for data consistency
|
|
215
|
+
- Efficient batch operations
|
|
216
|
+
- Rich metadata support
|
|
217
|
+
- Timestamp tracking
|
|
218
|
+
|
|
219
|
+
## Storage Methods
|
|
220
|
+
|
|
221
|
+
### Thread Operations
|
|
222
|
+
|
|
223
|
+
- `saveThread({ thread })`: Create or update a thread
|
|
224
|
+
- `getThreadById({ threadId })`: Get a thread by ID
|
|
225
|
+
- `updateThread({ id, title, metadata })`: Update thread title and/or metadata
|
|
226
|
+
- `deleteThread({ threadId })`: Delete a thread and its messages
|
|
227
|
+
- `listThreadsByResourceId({ resourceId, offset, limit, orderBy? })`: List paginated threads for a resource
|
|
228
|
+
|
|
229
|
+
### Message Operations
|
|
230
|
+
|
|
231
|
+
- `saveMessages({ messages })`: Save multiple messages in a transaction
|
|
232
|
+
- `listMessages({ threadId, resourceId?, perPage?, page?, orderBy?, filter? })`: Get messages for a thread with pagination
|
|
233
|
+
- `listMessagesById({ messageIds })`: Get specific messages by their IDs
|
|
234
|
+
- `updateMessages({ messages })`: Update existing messages
|
|
235
|
+
- `deleteMessages(messageIds)`: Delete specific messages
|
|
236
|
+
|
|
237
|
+
### Resource Operations
|
|
238
|
+
|
|
239
|
+
- `getResourceById({ resourceId })`: Get a resource by ID
|
|
240
|
+
- `saveResource({ resource })`: Create or save a resource
|
|
241
|
+
- `updateResource({ resourceId, workingMemory?, metadata? })`: Update resource working memory and/or metadata
|
|
242
|
+
|
|
243
|
+
### Workflow Operations
|
|
244
|
+
|
|
245
|
+
- `persistWorkflowSnapshot({ workflowName, runId, snapshot })`: Save workflow state
|
|
246
|
+
- `loadWorkflowSnapshot({ workflowName, runId })`: Load workflow state
|
|
247
|
+
- `listWorkflowRuns({ workflowName, pagination })`: List workflow runs with pagination
|
|
248
|
+
- `getWorkflowRunById({ workflowName, runId })`: Get a specific workflow run
|
|
249
|
+
- `updateWorkflowState({ workflowName, runId, state })`: Update workflow state
|
|
250
|
+
- `updateWorkflowResults({ workflowName, runId, results })`: Update workflow results
|
|
251
|
+
|
|
252
|
+
### Observability Operations
|
|
253
|
+
|
|
254
|
+
- `createSpan(span)`: Create a single span
|
|
255
|
+
- `batchCreateSpans({ records })`: Create multiple spans
|
|
256
|
+
- `updateSpan({ traceId, spanId, updates })`: Update a span
|
|
257
|
+
- `batchUpdateSpans({ records })`: Update multiple spans
|
|
258
|
+
- `getTrace(traceId)`: Get a trace by ID
|
|
259
|
+
- `getTracesPaginated({ ...filters, pagination })`: Get paginated traces with filtering
|
|
260
|
+
- `batchDeleteTraces({ traceIds })`: Delete multiple traces
|
|
261
|
+
|
|
262
|
+
### Evaluation/Scoring Operations
|
|
263
|
+
|
|
264
|
+
- `getScoreById({ id })`: Get a score by ID
|
|
265
|
+
- `saveScore(score)`: Save an evaluation score
|
|
266
|
+
- `listScoresByScorerId({ scorerId, pagination })`: List scores by scorer with pagination
|
|
267
|
+
- `listScoresByRunId({ runId, pagination })`: List scores by run with pagination
|
|
268
|
+
- `listScoresByEntityId({ entityId, entityType, pagination })`: List scores by entity with pagination
|
|
269
|
+
- `listScoresBySpan({ traceId, spanId, pagination })`: List scores by span with pagination
|
|
270
|
+
|
|
271
|
+
## Index Management
|
|
272
|
+
|
|
273
|
+
The store creates performance indexes during initialization for common query patterns:
|
|
274
|
+
|
|
275
|
+
- `mastra_threads_resourceid_createdat_idx`: (resourceId, createdAt)
|
|
276
|
+
- `mastra_messages_thread_id_createdat_idx`: (thread_id, createdAt)
|
|
277
|
+
- `mastra_ai_spans_traceid_startedat_idx`: (traceId, startedAt)
|
|
278
|
+
- `mastra_ai_spans_parentspanid_startedat_idx`: (parentSpanId, startedAt)
|
|
279
|
+
- `mastra_ai_spans_name_idx`: (name)
|
|
280
|
+
- `mastra_ai_spans_spantype_startedat_idx`: (spanType, startedAt)
|
|
281
|
+
- `mastra_scores_trace_id_span_id_created_at_idx`: (traceId, spanId, createdAt)
|
|
282
|
+
|
|
283
|
+
Notes:
|
|
284
|
+
|
|
285
|
+
- Aurora DSQL creates these indexes asynchronously using `CREATE INDEX ASYNC`.
|
|
286
|
+
- Because index creation is asynchronous, new indexes may not be immediately available after `init()`. The store will continue to function without them, but queries may be slower until index creation completes.
|
|
287
|
+
|
|
288
|
+
### Custom Indexes
|
|
289
|
+
|
|
290
|
+
Create additional indexes to optimize specific query patterns:
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
await store.createIndex({
|
|
294
|
+
name: 'idx_threads_resource',
|
|
295
|
+
table: 'mastra_threads',
|
|
296
|
+
columns: ['resourceId'],
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
await store.createIndex({
|
|
300
|
+
name: 'idx_messages_composite',
|
|
301
|
+
table: 'mastra_messages',
|
|
302
|
+
columns: ['thread_id', 'createdAt'],
|
|
303
|
+
});
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Under the hood:
|
|
307
|
+
|
|
308
|
+
- `createIndex` uses `CREATE INDEX ASYNC`.
|
|
309
|
+
- Aurora DSQL doesn’t allow `ASC`/`DESC` in `CREATE INDEX ASYNC`, so `columns` should be plain column names.
|
|
310
|
+
|
|
311
|
+
### Managing Indexes
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
// List all indexes
|
|
315
|
+
const allIndexes = await store.listIndexes();
|
|
316
|
+
|
|
317
|
+
// List indexes for a specific table
|
|
318
|
+
const threadIndexes = await store.listIndexes('mastra_threads');
|
|
319
|
+
|
|
320
|
+
// Get detailed statistics for an index
|
|
321
|
+
const stats = await store.describeIndex('idx_threads_resource');
|
|
322
|
+
console.log(stats);
|
|
323
|
+
// {
|
|
324
|
+
// name: 'idx_threads_resource',
|
|
325
|
+
// table: 'mastra_threads',
|
|
326
|
+
// columns: ['resourceId'],
|
|
327
|
+
// unique: false,
|
|
328
|
+
// size: '128 KB',
|
|
329
|
+
// definition: 'CREATE INDEX idx_threads_resource...',
|
|
330
|
+
// method: 'btree',
|
|
331
|
+
// scans: 1542,
|
|
332
|
+
// tuples_read: 45230,
|
|
333
|
+
// tuples_fetched: 12050
|
|
334
|
+
// }
|
|
335
|
+
|
|
336
|
+
// Drop an index
|
|
337
|
+
await store.dropIndex('idx_threads_status');
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### Index Options
|
|
341
|
+
|
|
342
|
+
- `name` (required): Index name
|
|
343
|
+
- `table` (required): Table name
|
|
344
|
+
- `columns` (required): Array of column names (ASC/DESC automatically stripped for Aurora DSQL)
|
|
345
|
+
- `unique`: Create unique index (default: false)
|
|
346
|
+
- `concurrent`: Ignored in Aurora DSQL (indexes are always async)
|
|
347
|
+
- `where`: Partial index condition
|
|
348
|
+
- `method`: Ignored in Aurora DSQL (only btree supported)
|
|
349
|
+
|
|
350
|
+
## Related Links
|
|
351
|
+
|
|
352
|
+
- [Aurora DSQL Documentation](https://docs.aws.amazon.com/aurora-dsql/)
|
|
353
|
+
- [SQL Reference](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-aurora-dsql-sql.html)
|
|
354
|
+
- [Supported SQL Features](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-postgresql-compatibility-supported-sql-features.html)
|
|
355
|
+
- [Unsupported PostgreSQL Features](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-postgresql-compatibility-unsupported-features.html)
|
|
356
|
+
- [Supported Data Types](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-postgresql-compatibility-supported-data-types.html)
|
|
357
|
+
- [Asynchronous Indexes](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-create-index-async.html)
|