PyDrocsid.database.database ¶
DB ¶
Source code in PyDrocsid/database/database.py
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 243 244 245 246 247 248 |
|
__init__ ¶
__init__(driver: str, host: str, port: int, database: str, username: str, password: str, pool_recycle: int = 300, pool_size: int = 20, max_overflow: int = 20, echo: bool = False)
Parameters:
-
driver
(
str
) –name of the sql connection driver
-
host
(
str
) –host of the sql server
-
port
(
int
) –port of the sql server
-
database
(
str
) –name of the database
-
username
(
str
) –name of the sql user
-
password
(
str
) –password of the sql user
-
echo
(
bool
) –whether sql queries should be logged
Source code in PyDrocsid/database/database.py
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 |
|
add
async
¶
add(obj: T) -> T
Add a new row to the database
Parameters:
-
obj
(
T
) –the row to insert
Returns:
-
T
–the same row
Source code in PyDrocsid/database/database.py
158 159 160 161 162 163 164 165 166 167 |
|
all
async
¶
all(statement: Executable) -> list[Any]
Execute an sql statement and return all results as a list.
Source code in PyDrocsid/database/database.py
190 191 192 193 |
|
close
async
¶
close() -> None
Close the current session
Source code in PyDrocsid/database/database.py
221 222 223 224 225 226 227 228 |
|
commit
async
¶
commit() -> None
Shortcut for :meth:sqlalchemy.ext.asyncio.AsyncSession.commit
Source code in PyDrocsid/database/database.py
215 216 217 218 219 |
|
count
async
¶
count(statement: Executable, *args: Column[Any]) -> int
Execute an sql statement and return the number of returned rows.
Source code in PyDrocsid/database/database.py
205 206 207 208 |
|
create_session ¶
create_session() -> AsyncSession
Create a new async session and store it in the context variable.
Source code in PyDrocsid/database/database.py
230 231 232 233 234 235 |
|
create_tables
async
¶
create_tables() -> None
Create all tables defined in enabled cog packages.
Source code in PyDrocsid/database/database.py
148 149 150 151 152 153 154 155 156 |
|
delete
async
¶
delete(obj: T) -> T
Remove a row from the database
Parameters:
-
obj
(
T
) –the row to remove
Returns:
-
T
–the same row
Source code in PyDrocsid/database/database.py
169 170 171 172 173 174 175 176 177 178 |
|
exec
async
¶
exec(statement: Executable) -> Any
Execute an sql statement and return the result.
Source code in PyDrocsid/database/database.py
180 181 182 183 |
|
exists
async
¶
exists(statement: Executable, *args: Column[Any], **kwargs: Any) -> bool
Execute an sql statement and return whether it returned at least one row.
Source code in PyDrocsid/database/database.py
200 201 202 203 |
|
first
async
¶
first(statement: Executable) -> Any | None
Execute an sql statement and return the first result.
Source code in PyDrocsid/database/database.py
195 196 197 198 |
|
get
async
¶
get(cls: Type[T], *args: Column[Any], **kwargs: Any) -> T | None
Shortcut for first(filter_by(...))
Source code in PyDrocsid/database/database.py
210 211 212 213 |
|
session
property
¶
session() -> AsyncSession
Get the session object for the current task
Source code in PyDrocsid/database/database.py
237 238 239 240 241 242 243 244 |
|
stream
async
¶
stream(statement: Executable) -> AsyncIterator[Any]
Execute an sql statement and stream the result.
Source code in PyDrocsid/database/database.py
185 186 187 188 |
|
delete ¶
delete(table: Any) -> Delete
Shortcut for :meth:sqlalchemy.sql.expression.delete
Source code in PyDrocsid/database/database.py
79 80 81 82 |
|
exists ¶
exists(statement: Executable, *entities: Column[Any], **kwargs: Any) -> Exists
Shortcut for :meth:sqlalchemy.future.select
Source code in PyDrocsid/database/database.py
73 74 75 76 |
|
filter_by ¶
filter_by(cls: Any, *args: Column[Any], **kwargs: Any) -> Select
Shortcut for :meth:sqlalchemy.future.Select.filter_by
Source code in PyDrocsid/database/database.py
67 68 69 70 |
|
get_database ¶
get_database() -> DB
Create a database connection object using the environment variables
Returns:
-
DB
–The DB object
Source code in PyDrocsid/database/database.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
select ¶
select(entity: Any, *args: Column[Any]) -> Select
Shortcut for :meth:sqlalchemy.future.select
Source code in PyDrocsid/database/database.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|