Database
ConnectionConfig
Bases: BaseModel
Configuration for creating sqlalchemy engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pool_size
|
int
|
Number of connections to maintain in the connection pool. Establishing connections is expensive and maintaining multiple connections in a pool allows for availability. |
required |
pool_pre_ping
|
bool
|
Performs liveliness check and expires all existing connections if the database is unreachable. |
required |
Source code in lume_services/services/models/db/db.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
ModelDB
DBService client responsible for handling connections to the model database.
Source code in lume_services/services/models/db/db.py
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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
__init__(config)
Initialize client service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
ModelDBConfig
|
Connection configuration. |
required |
Source code in lume_services/services/models/db/db.py
62 63 64 65 66 67 68 69 70 |
|
connection()
Context manager for operations. Will clean up connections on exit of scope.
Source code in lume_services/services/models/db/db.py
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 |
|
execute(sql)
Execute sql inside a managed session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sql
|
Executable
|
SQL query to execute. |
required |
Results
list: Results of query operation
Source code in lume_services/services/models/db/db.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
from_config_init(**kwargs)
classmethod
Initialize database handler from ModelDBConfig kwargs.
Source code in lume_services/services/models/db/db.py
238 239 240 241 242 |
|
insert(sql)
Execute and insert operation inside a managed session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sql
|
Insert
|
Sqlalchemy insert operation |
required |
Returns:
Type | Description |
---|---|
Union[str, int]: primary key returned from insert operation |
Source code in lume_services/services/models/db/db.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
|
insert_many(sql)
Execute many inserts within a managed session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sql
|
List[Insert]
|
Execute a sqlalchemy insert operation |
required |
Returns:
Type | Description |
---|---|
List[Union[str, int]]
|
List[Union[str, int]]: List of primary keys returned from insert operation |
Source code in lume_services/services/models/db/db.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
select(sql)
Execute sql query inside a managed session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sql
|
Select
|
Selection query to execute. |
required |
Results
list: Results of selection operation
Source code in lume_services/services/models/db/db.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
session()
Establishes Session with active connection.
Note: Setting expire_on_commit to False allows us to access objects after session closing.
Source code in lume_services/services/models/db/db.py
141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
ModelDBConfig
Bases: BaseModel
Configuration for SQL connection using sqlalchemy.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host
|
str
|
Host of SQL server. |
required |
port
|
str
|
Port of SQL server on host. |
required |
user
|
str
|
User for connecting to SQL server. |
required |
password
|
SecretStr
|
Password for auth. |
required |
database
|
str
|
Name of database. |
required |
connection
|
ConnectionConfig
|
Configuration options for creating sqlalchemy engine. |
required |
Source code in lume_services/services/models/db/db.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|