LibSQL Storage
The LibSQL storage implementation provides a SQLite-compatible storage solution that can run both in-memory and as a persistent database.
Installation
npm install @mastra/storage-libsql
Usage
import { DefaultStorage } from "@mastra/core/storage";
// In-memory database (development)
const storage = new DefaultStorage({
url: ":memory:",
});
// Persistent database (production)
const storage = new DefaultStorage({
url: process.env.DATABASE_URL,
});
Parameters
url:
string
Database URL. Use ':memory:' for in-memory database or a LibSQL-compatible connection string for persistent storage.
authToken?:
string
Authentication token for remote LibSQL databases.
Additional Notes
In-Memory vs Persistent Storage
The in-memory configuration (:memory:
) is useful for:
- Development and testing
- Temporary storage that doesn’t need to persist
- Quick prototyping
For production use cases, use a persistent database URL:
- Local file:
file:local.db
- Remote LibSQL:
libsql://your-database.turso.io
Schema Management
The storage implementation handles schema creation and updates automatically. It creates the following tables:
threads
: Stores conversation threadsmessages
: Stores individual messagesmetadata
: Stores additional metadata for threads and messages