https://dev.kronoz.win/r/marzneshin.git
| 1 |
a47eb4c |
Dawsh |
2y ago |
from sqlalchemy.exc import SQLAlchemyError |
| 2 |
a47eb4c |
Dawsh |
2y ago |
from sqlalchemy.orm import Session |
| 3 |
a47eb4c |
Dawsh |
2y ago |
|
| 4 |
a47eb4c |
Dawsh |
2y ago |
from .base import Base, SessionLocal, engine # noqa |
| 5 |
01cdf2e |
Dawsh |
2y ago |
from .crud import ( |
| 6 |
01cdf2e |
Dawsh |
2y ago |
create_admin, |
| 7 |
01cdf2e |
Dawsh |
2y ago |
create_notification_reminder, # noqa |
| 8 |
01cdf2e |
Dawsh |
2y ago |
create_user, |
| 9 |
01cdf2e |
Dawsh |
2y ago |
delete_notification_reminder, |
| 10 |
01cdf2e |
Dawsh |
2y ago |
get_admin, |
| 11 |
01cdf2e |
Dawsh |
2y ago |
get_admins, |
| 12 |
01cdf2e |
Dawsh |
2y ago |
get_jwt_secret_key, |
| 13 |
01cdf2e |
Dawsh |
2y ago |
get_notification_reminder, |
| 14 |
01cdf2e |
Dawsh |
2y ago |
assure_node_inbounds, |
| 15 |
01cdf2e |
Dawsh |
2y ago |
get_system_usage, |
| 16 |
01cdf2e |
Dawsh |
2y ago |
get_tls_certificate, |
| 17 |
01cdf2e |
Dawsh |
2y ago |
get_user, |
| 18 |
01cdf2e |
Dawsh |
2y ago |
get_user_by_id, |
| 19 |
01cdf2e |
Dawsh |
2y ago |
get_users, |
| 20 |
01cdf2e |
Dawsh |
2y ago |
get_users_count, |
| 21 |
01cdf2e |
Dawsh |
2y ago |
remove_admin, |
| 22 |
01cdf2e |
Dawsh |
2y ago |
remove_user, |
| 23 |
01cdf2e |
Dawsh |
2y ago |
revoke_user_sub, |
| 24 |
01cdf2e |
Dawsh |
2y ago |
set_owner, |
| 25 |
01cdf2e |
Dawsh |
2y ago |
update_admin, |
| 26 |
01cdf2e |
Dawsh |
2y ago |
update_user, |
| 27 |
01cdf2e |
Dawsh |
2y ago |
update_user_status, |
| 28 |
01cdf2e |
Dawsh |
2y ago |
update_user_sub, |
| 29 |
01cdf2e |
Dawsh |
2y ago |
) |
| 30 |
f7af2b3 |
Dawsh |
2y ago |
from .models import JWT, System, User # noqa |
| 31 |
a47eb4c |
Dawsh |
2y ago |
|
| 32 |
c13a1aa |
Dawsh |
2y ago |
|
| 33 |
a47eb4c |
Dawsh |
2y ago |
class GetDB: # Context Manager |
| 34 |
a47eb4c |
Dawsh |
2y ago |
def __init__(self): |
| 35 |
a47eb4c |
Dawsh |
2y ago |
self.db = SessionLocal() |
| 36 |
a47eb4c |
Dawsh |
2y ago |
|
| 37 |
a47eb4c |
Dawsh |
2y ago |
def __enter__(self): |
| 38 |
a47eb4c |
Dawsh |
2y ago |
return self.db |
| 39 |
a47eb4c |
Dawsh |
2y ago |
|
| 40 |
a47eb4c |
Dawsh |
2y ago |
def __exit__(self, _, exc_value, traceback): |
| 41 |
a47eb4c |
Dawsh |
2y ago |
if isinstance(exc_value, SQLAlchemyError): |
| 42 |
a47eb4c |
Dawsh |
2y ago |
self.db.rollback() # rollback on exception |
| 43 |
a47eb4c |
Dawsh |
2y ago |
|
| 44 |
a47eb4c |
Dawsh |
2y ago |
self.db.close() |
| 45 |
a47eb4c |
Dawsh |
2y ago |
|
| 46 |
a47eb4c |
Dawsh |
2y ago |
|
| 47 |
a47eb4c |
Dawsh |
2y ago |
__all__ = [ |
| 48 |
a47eb4c |
Dawsh |
2y ago |
"get_user", |
| 49 |
a47eb4c |
Dawsh |
2y ago |
"get_user_by_id", |
| 50 |
a47eb4c |
Dawsh |
2y ago |
"get_users", |
| 51 |
a47eb4c |
Dawsh |
2y ago |
"get_users_count", |
| 52 |
a47eb4c |
Dawsh |
2y ago |
"create_user", |
| 53 |
a47eb4c |
Dawsh |
2y ago |
"remove_user", |
| 54 |
a47eb4c |
Dawsh |
2y ago |
"update_user", |
| 55 |
a47eb4c |
Dawsh |
2y ago |
"update_user_status", |
| 56 |
a47eb4c |
Dawsh |
2y ago |
"update_user_sub", |
| 57 |
a47eb4c |
Dawsh |
2y ago |
"revoke_user_sub", |
| 58 |
a47eb4c |
Dawsh |
2y ago |
"set_owner", |
| 59 |
a47eb4c |
Dawsh |
2y ago |
"get_system_usage", |
| 60 |
a47eb4c |
Dawsh |
2y ago |
"get_jwt_secret_key", |
| 61 |
a47eb4c |
Dawsh |
2y ago |
"get_tls_certificate", |
| 62 |
a47eb4c |
Dawsh |
2y ago |
"get_admin", |
| 63 |
a47eb4c |
Dawsh |
2y ago |
"create_admin", |
| 64 |
a47eb4c |
Dawsh |
2y ago |
"update_admin", |
| 65 |
a47eb4c |
Dawsh |
2y ago |
"remove_admin", |
| 66 |
a47eb4c |
Dawsh |
2y ago |
"get_admins", |
| 67 |
a47eb4c |
Dawsh |
2y ago |
"create_notification_reminder", |
| 68 |
a47eb4c |
Dawsh |
2y ago |
"get_notification_reminder", |
| 69 |
a47eb4c |
Dawsh |
2y ago |
"delete_notification_reminder", |
| 70 |
a47eb4c |
Dawsh |
2y ago |
"GetDB", |
| 71 |
a47eb4c |
Dawsh |
2y ago |
"User", |
| 72 |
a47eb4c |
Dawsh |
2y ago |
"System", |
| 73 |
a47eb4c |
Dawsh |
2y ago |
"JWT", |
| 74 |
a47eb4c |
Dawsh |
2y ago |
"Base", |
| 75 |
a47eb4c |
Dawsh |
2y ago |
"Session", |
| 76 |
a47eb4c |
Dawsh |
2y ago |
] |