def save(self): if self.id: db.query( "UPDATE `triggers` SET `request` = %s, `response` = %s, `type` = %s, `enable` = %s WHERE `id` = %s", (self.request, self.response, str( self.type), self.enable, self.id)) else: db.query( "INSERT INTO `triggers` (`request`, `response`, `type`) VALUES (%s, %s, %s)", (self.request, self.response, str(self.type))) self.id = db.query( "SELECT `id` FROM `triggers` WHERE `request` = %s ORDER BY `id` DESC LIMIT 1", self.request, fetch=True)['id']
def get_all_enabled(): result = db.query("SELECT * FROM `triggers` WHERE `enable` = True", fetch=True, as_list=True) triggers = list(map(Trigger, result)) return triggers
def get_by_request(request): result = db.query( "SELECT * FROM `triggers` WHERE `enable` = True and `request` = %s", request, fetch=True, as_list=True) triggers = list(map(Trigger, result)) return triggers
def get_by_id(_id): result = db.query( "SELECT * FROM `triggers` WHERE `enable` = True and `id` = %s", _id, fetch=True) if result: return Trigger(result) else: return None