Add min() and max() methods to Database
This commit is contained in:
parent
1a89ceaa5b
commit
2d66000b7d
1 changed files with 14 additions and 0 deletions
|
@ -117,6 +117,20 @@ class Database():
|
|||
def get(self, table, values: dict=dict()):
|
||||
return self.query(table, values).fetchone()
|
||||
|
||||
def min(self, table, column: str) -> int:
|
||||
sql = f"select min({column}) as _min from {table.name}"
|
||||
|
||||
row = self.db.execute(sql).fetchone()
|
||||
|
||||
return row[0] if row is not None else None
|
||||
|
||||
def max(self, table, column: str) -> int:
|
||||
sql = f"select max({column}) as _max from {table.name}"
|
||||
|
||||
row = self.db.execute(sql).fetchone()
|
||||
|
||||
return row[0] if row is not None else None
|
||||
|
||||
def count(self, table, values: dict=dict()):
|
||||
sql = f"select count(id) as num from {table.name}"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue