database
Database configuration definitions and loading utilities.
This module defines configuration dataclasses for supported database backends
used by the application. It includes SQLiteConfig for file-based SQLite
storage, PostgreSQLConfig for PostgreSQL connection settings, and
load_database_config for constructing the appropriate configuration object
from a dictionary.
PostgreSQLConfig
dataclass
Configuration for PostgreSQL database.
When connecting to PostgreSQL, we use a connection string. This class allows you to provide the connection string yourself or individual settings that will eventually be converted to a connection string.
If both a connection string and individual settings are provided, the connection string will take precedence.
These entries can all include shell variables.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
str
|
The type of database that this config is used for. |
session_id |
str
|
An optional session ID to connect to. If no session ID is provided, a new session (chat) will be created. |
connection_string |
str | None
|
A PostgreSQL connection string. |
host |
str | None
|
The service host. In LaunchIT, this is the 'service-host' setting. |
port |
int
|
The service port. In LaunchIT, this is the 'service-port' setting. |
database |
str | None
|
The database name. In LaunchIT, this is the 'database-name' setting. |
user |
str | None
|
The database user. In LaunchIT, this is the 'database-user' setting. |
password |
str | None
|
The database password. In LaunchIT, this is the 'database-password' setting. You will likely want to store this as an environment variable and then pass in a reference to that environment variable. |
sslmode |
str
|
Controls how the client uses SSL/TLS when connecting to PostgreSQL. Common values include "require" for production or HPC environments where encrypted connections are required, and "disable" for local or containerized test databases that do not have SSL configured. |
Methods:
| Name | Description |
|---|---|
get_connection_string |
Get the connection string for the database. |
Source code in src/mada/core/config/database.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
__post_init__()
After initialization, expand variables and ensure required settings have been provided (if necessary).
Raises:
| Type | Description |
|---|---|
ValueError
|
If a required setting is missing. |
Source code in src/mada/core/config/database.py
get_connection_string()
Build the connection string (if necessary) and return it.
Returns:
| Type | Description |
|---|---|
str
|
The connection string for the database. |
Source code in src/mada/core/config/database.py
SQLiteConfig
dataclass
Configuration for SQLite database.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
str
|
The type of database that this config is used for. |
path |
str | Path
|
The path for SQLite to use as the store. |
session_id |
str
|
An optional session ID to connect to. If no session ID is provided, a new session (chat) will be created. |
Source code in src/mada/core/config/database.py
__post_init__()
After initialization, expand variables in the path and make sure it exists.
Source code in src/mada/core/config/database.py
load_database_config(config_dict)
Factory function to create the appropriate config from a dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dict
|
dict
|
The configuration for the database provided by the user. |
required |
Returns:
| Type | Description |
|---|---|
DatabaseConfig
|
An instance of the appropriate database class. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the database type is unsupported. |