Database¶
It can be imported from fluid.db:
It requires the db extra to be installed:
fluid.db.Database
dataclass
¶
Database(
dsn,
echo=(lambda: DBECHO)(),
pool_size=(lambda: DBPOOL_MAX_SIZE)(),
max_overflow=(lambda: DBPOOL_MAX_OVERFLOW)(),
metadata=MetaData(),
migration_path="",
app_name=(lambda: APP_NAME)(),
_engine=None,
)
A container for tables in a database and a manager of asynchronous connections to a postgresql database
dsn
instance-attribute
¶
data source name, aka connection string
Example: postgresql+asyncpg://user:password@localhost/dbname
Note that the +asyncpg part is important for the async engine.
Currently, only postgresql+asyncpg is supported, but other databases may
be supported in the future.
echo
class-attribute
instance-attribute
¶
Echo SQL queries to stdout
It defaults to the DBECHO setting in the settings module
pool_size
class-attribute
instance-attribute
¶
max_overflow
class-attribute
instance-attribute
¶
migration_path
class-attribute
instance-attribute
¶
Path to the directory containing migration files. If empty, migrations will
be stored in the default location migrations in the current working directory.
engine
property
¶
The :class:sqlalchemy.ext.asyncio.AsyncEngine creating connection
and transactions
from_env
classmethod
¶
from_env(
*,
dsn=None,
schema=None,
migration_path=None,
app_name=None,
max_overflow=None,
pool_size=None,
db_name=None
)
Create a new database container from environment variables as defaults
Source code in fluid/db/container.py
connection
async
¶
Context manager for obtaining an asynchronous connection
ensure_connection
async
¶
Context manager for obtaining an asynchronous connection
Source code in fluid/db/container.py
transaction
async
¶
Context manager for initializing an asynchronous database transaction
ensure_transaction
async
¶
Context manager for ensuring we a connection has initialized a database transaction