-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobals.py
50 lines (39 loc) · 1.17 KB
/
globals.py
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
43
44
45
46
47
48
49
50
try:
from . import BASE, SESSION
except ImportError as e:
raise AttributeError from e
from sqlalchemy import Column, String, UnicodeText
class Globals(BASE):
__tablename__ = "globals"
variable = Column(String, primary_key=True, nullable=False)
value = Column(UnicodeText, primary_key=True, nullable=False)
def __init__(self, variable, value):
self.variable = str(variable)
self.value = value
Globals.__table__.create(checkfirst=True)
def gvarstatus(variable):
try:
return (
SESSION.query(Globals)
.filter(Globals.variable == str(variable))
.first()
.value
)
except BaseException:
return None
finally:
SESSION.close()
def addgvar(variable, value):
if SESSION.query(Globals).filter(Globals.variable == str(variable)).one_or_none():
delgvar(variable)
adder = Globals(str(variable), value)
SESSION.add(adder)
SESSION.commit()
def delgvar(variable):
rem = (
SESSION.query(Globals)
.filter(Globals.variable == str(variable))
.delete(synchronize_session="fetch")
)
if rem:
SESSION.commit()