-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathusers_sql.py
More file actions
42 lines (34 loc) · 960 Bytes
/
users_sql.py
File metadata and controls
42 lines (34 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from sqlalchemy import Column, String
from main_db import *
from _utils import *
class users_sudo_db(BASE):
__tablename__ = "users_sudo"
user_id = Column(String(14), primary_key=True)
def __init__(self, user_id):
self.user_id = user_id
users_sudo_db.__table__.create(checkfirst=True)
@run_in_exc
def is_users_sudo(user_id):
if not str(user_id).isdigit:
return
try:
return SESSION.query(users_sudo_db).filter(users_sudo_db.user_id == str(user_id)).one()
except:
return None
finally:
SESSION.close()
@run_in_exc
def add_user_(user_id):
adder = users_sudo_db(str(user_id))
SESSION.add(adder)
SESSION.commit()
@run_in_exc
def rm_user(user_id):
if rem := SESSION.query(users_sudo_db).get(str(user_id)):
SESSION.delete(rem)
SESSION.commit()
@run_in_exc
def get_all_users_sudo():
rem = SESSION.query(users_sudo_db).all()
SESSION.close()
return rem