@talosjs/database component is the connection layer for relational and key-value stores. Its public API exports the abstract TypeormDatabase base for your own TypeORM-backed adapters, and the concrete RedisDatabase for Bun’s native Redis client. Every adapter exposes the same open, close, and drop lifecycle and registers with the container through @decorator.database().
What it provides
open, close, and drop mean the same thing whether you target a TypeORM-backed database or Redis, so the lifecycle is one thing to learn across both styles. On TypeORM adapters, open(Entity) returns a TypeORM Repository<Entity> with full query-builder and entity-manager access. You register an adapter with @decorator.database() and resolve it from the container. RedisDatabase reads DATABASE_REDIS_URL (or constructor options); a custom TypeormDatabase subclass decides which env vars it uses.
How it works
You pick (or scaffold) an adapter and register it. Relational adapters extend the abstractTypeormDatabase and implement a single getSource() that builds a TypeORM DataSource; the base class handles initialization, repositories, transactions, and teardown. The Redis adapter constructs a Bun RedisClient from a connection URL.
The public exports differ in what they abstract, not in how you call them:
For vector search and embeddings, a separate
VectorDatabase adapter ships in @talosjs/rag and is scaffolded with vector-database:create (see the CLI command below).
synchronize defaults to false on every relational adapter, so schema changes go through migrations rather than auto-sync. Adapters cache their DataSource, so call close() when you are done to release the pool.
Environment variables
Custom
TypeormDatabase subclasses can read whichever env vars you choose (for example DATABASE_URL or SQLITE_DATABASE_PATH), but that is defined by the subclass rather than by the base package.
Usage
A relational adapter implementsgetSource() and inherits the lifecycle. Resolve it from the container, then open() per entity to get a repository:
RedisDatabase hands you Bun’s native client:
Decorator and usage
@decorator.database()
Registers a database adapter with the container. It accepts an optional scope (defaults to singleton). Use it on an adapter that extends TypeormDatabase (Postgres/SQLite) or RedisDatabase.
Exceptions
The component throwsDatabaseException when an adapter is misconfigured or an operation fails. It carries a machine-readable key, a human-readable message, a data object, and a 500 HTTP status.
Operating safely
Keepsynchronize off and evolve the schema through migrations, so changes stay reviewable and reversible. Resolve adapters from the container as singletons and let them cache the DataSource; building a fresh connection per request defeats the pool. Whatever you open, close on shutdown (or when a one-off adapter is done) to release the pool and the Redis socket.
Be careful with drop(). It destroys data, including a FLUSHDB on Redis, so never point it at a shared or production database. Read connection details from AppEnv so the same code runs across dev, test, and production. Wrap multi-entity writes in manager.transaction() so they commit or roll back together. In custom adapters, throw DatabaseException with a constant key (CONNECTION_FAILED, OPERATION_FAILED) and keep the variable detail in data.
CLI command
Scaffold a database adapter and its test file with the generator. It prompts for the engine (postgres, sqlite, or redis), writes the class under modules/<module>/src/databases/<Name>Database.ts, generates a matching spec, and installs @talosjs/database if it is missing.
The generated SQLite stub starts ready for you to register entities and adjust the
DataSource:
talos vector-database:create scaffolds a VectorDatabase adapter (from @talosjs/rag) with an embedding model and Arrow schema. See database:create and vector-database:create for the full command references.
Use with Claude and Codex
The generator ships matchingdatabase:create and database:migrate skills. They run the scaffold and then guide your AI agent through completing the adapter: registering entities, configuring the DataSource, and applying migrations. Initialize the skills once for your agent:
- Claude
- Codex
Prompt
database:create --name=App with the postgres engine, then registers your entities on the DataSource.