add reactions support to thread
This commit is contained in:
25
app/db.py
25
app/db.py
@ -89,6 +89,9 @@ class DB:
|
||||
self.table = table
|
||||
self._where = [] # list of tuples
|
||||
self._select = "*"
|
||||
self._group_by = ""
|
||||
self._order_by = ""
|
||||
self._order_asc = True
|
||||
|
||||
|
||||
def _build_where(self):
|
||||
@ -104,6 +107,17 @@ class DB:
|
||||
return " WHERE " + " AND ".join(conditions), params
|
||||
|
||||
|
||||
def group_by(self, stmt):
|
||||
self._group_by = stmt
|
||||
return self
|
||||
|
||||
|
||||
def order_by(self, stmt, asc = True):
|
||||
self._order_by = stmt
|
||||
self._order_asc = asc
|
||||
return self
|
||||
|
||||
|
||||
def select(self, columns = "*"):
|
||||
self._select = columns
|
||||
return self
|
||||
@ -122,7 +136,16 @@ class DB:
|
||||
def build_select(self):
|
||||
sql = f"SELECT {self._select} FROM {self.table}"
|
||||
where_clause, params = self._build_where()
|
||||
return sql + where_clause, params
|
||||
|
||||
stmt = sql + where_clause
|
||||
|
||||
if self._group_by:
|
||||
stmt += " GROUP BY " + self._group_by
|
||||
|
||||
if self._order_by:
|
||||
stmt += " ORDER BY " + self._order_by + (" ASC" if self._order_asc else " DESC")
|
||||
|
||||
return stmt, params
|
||||
|
||||
|
||||
def build_update(self, data):
|
||||
|
Reference in New Issue
Block a user