database
This module is concerned with database related operations.
create_tables
create_tables() -> None
populates database with all tables defined in models.py
Source code in api/core/database.py
14 15 16 |
|
get_session
get_session() -> Generator[Session, None, None]
Yields a temporary session to the database.
Yields:
Type | Description |
---|---|
Session
|
A temporary session to interact with the database. |
Source code in api/core/database.py
19 20 21 22 23 24 25 26 27 28 29 |
|
add_user
add_user(user_create: models.UserCreate, session: Session) -> models.User
Adds a user to the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_create |
UserCreate
|
The data required to create a new user. |
required |
session |
Session
|
The session to interact with the database. |
required |
Returns:
Type | Description |
---|---|
User
|
The user added to the database. |
Source code in api/core/database.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
get_all_users
get_all_users(session: Session) -> list[models.User]
Retrieve all users from the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
Session
|
The session to interact with the database. |
required |
Returns:
Type | Description |
---|---|
list[User]
|
A list of all users in the database. |
Source code in api/core/database.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
get_user
get_user(email: str, session: Session) -> models.User | None
Retrieve one user from the database based on email match.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
email |
str
|
The email address of the user to retrieve. |
required |
session |
Session
|
The session to interact with the database. |
required |
Returns:
Type | Description |
---|---|
User | None
|
The user with the specified email if found, otherwise None. |
Source code in api/core/database.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|