Skip to content

Utilities API

Utility functions and helpers.

Connection Management

connect()

Establish a connection to the database.

from ferro import connect

# SQLite
await connect("sqlite:example.db?mode=rwc")

# PostgreSQL
await connect("postgresql://user:password@localhost/dbname")

# Auto-migrate during development
await connect("postgresql://localhost/dbname", auto_migrate=True)

See Database Setup Guide for complete connection options.

disconnect()

This function is not implemented yet.

# Current pattern: connect once during startup
await connect("sqlite:example.db?mode=rwc")

create_tables()

Manually create all registered model tables.

from ferro import create_tables

await create_tables()

Note

With auto_migrate=True, tables are created automatically on connect.

Identity Map Management

evict_instance()

Remove an instance from the identity map, forcing a fresh database fetch on next access.

from ferro import evict_instance

# Evict user with ID=1
evict_instance("User", 1)

# Next fetch will hit database (raises ModelDoesNotExist if row was removed)
user = await User.get(1)

If the row may no longer exist, use User.get_or_none(1) or handle ModelDoesNotExist.

See Identity Map Concept for when and why to evict instances.

See Also