Database
Orionis separates query construction from execution. The database module manages named SQL connections, compiles ORM plans, executes parameterized SQL, and controls transactions, schemas, migrations, and seeders. Models are optional when querying a table.
Start with SQLite, included in the base installation. Database I/O is asynchronous; declaring columns, selecting a connection, and composing a query are synchronous operations. Python 3.14 or later is required.
Build your first data-backed feature
Section titled “Build your first data-backed feature”In an installed application, begin with these steps:
- Set
DB_CONNECTION=sqlitein.envand check the location selected byDB_DATABASEinconfig/database.py. SQLite needs no separate database server. - Add a migration under
database/migrationsto create your tables. Runuv run python -B reactor migratefrom the application root; the command boots the application before applying changes. - In an async controller, command, or service, import
DBfromorionis.support.facades, compose a query, and await its terminal operation. For example,await DB.table("notes").where("id", note_id).first()returns a dictionary orNoneonce thenotestable exists. - Add a transaction when several writes must succeed together. Introduce models when the feature needs domain behavior or relationships.
The connections guide also includes a complete in-memory SQLite program. Use it to learn SQL execution without changing your application’s database.
- Configure connections and execute SQL: driver installation, connection selection, bindings, and results.
- Transactions and concurrency: atomicity, savepoints, task ownership, and cancellation.
- Create schemas: blueprints, constraints, and versioned definitions.
- Evolve and populate the database: migrations, batches, reversal, and tracked seeder execution.
- Backends and production operation: dialect differences, Redshift, security, and troubleshooting.
A booted application receives services through providers and can use the DB and Schema facades. Examples constructing Connection directly are standalone programs and close the resources they own. Facade fragments require Foundation bootstrap.