sqlmodel
apex_utils.sqlmodel
#
URLConfig
#
Bases: BaseModel
A Pydantic model for the configuration of a SQLAlchemy URL.
Attributes:
| Name | Type | Description |
|---|---|---|
drivername |
str
|
The name of the database driver, e.g. "postgresql". |
username |
str
|
The username to connect to the database. |
password |
str
|
The password to connect to the database. |
host |
str
|
The host of the database. |
port |
int
|
The port of the database. |
database |
str
|
The name of the database to connect to. |
to_url
#
Convert the URLConfig model to a SQLAlchemy URL.
Returns:
| Name | Type | Description |
|---|---|---|
URL |
URL
|
The SQLAlchemy URL object. |
initialize_schemas
#
Initialize the schemas for the Wright Way database.
This function is used to create the necessary schemas in the database if they do not already exist. It checks each table's schema and creates it if it is not present. It is inspired by sqlalchemy/sqlalchemy #3914.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine | None
|
SQLAlchemy engine, if not provided, the default engine will be used. Defaults to None. |
None
|
Source code in apex_utils/sqlmodel.py
resolve_engine
#
Build a duckdb engine for the Wright Way database.
If the engine is provided, it is returned. If a config is provided, it is used as to
build the sqlalchemy.engine.URL object. If neither are provided, the config is
attempted to be pulled from the environment variable APEX_DB_CONFIG. This could
also be from APEX_DB_CONFIG in Doppler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine | None
|
An existing engine to use. Defaults to None. |
None
|
config
|
URLConfig | dict | None
|
The configuration for the engine. Defaults to None. |
None
|