跳到主要内容
非官方简体中文翻译,内容版权归 Mastra 所有,遵循 Apache-2.0 许可。

Storage

Mastra sets the project's default storage from a storage.ts file directly under src/mastra/. The file default-exports a store, which replaces the built-in in-memory store used for memory, workflows, observability, and other storage domains.

Use this page for the file-based convention. For backend choice, storage domains, retention, and provider details, see storage overview.

Quickstart
Quickstart的直接链接

Use LibSQLStore for a local file-backed store:

src/mastra/storage.ts
import { LibSQLStore } from '@mastra/libsql'

export default new LibSQLStore({
id: 'mastra-storage',
url: 'file:./mastra.db',
})

Mastra registers the store before file-based agents and workflows, so storage-dependent primitives bind to this store instead of the default in-memory store.

Production backends
Production backends的直接链接

storage.ts can export any Mastra storage adapter, such as LibSQL, PostgreSQL, or MongoDB. For setup patterns, provider support, and schema details, see storage overview, observability signal support, and the storage reference.

Precedence with code
Precedence with code的直接链接

Code-registered storage wins over storage.ts. Use storage.ts when one project-wide store is enough. Use code registration when setup depends on runtime wiring in src/mastra/index.ts.

On this page