def get_all(self): sql.execute('select %s from %s' % (self.make_string(self.visible), self.table)) response = [] for i in sql.fetchall(): response.append(self.list_json(i, self.visible)) return response
def update(self, id, data): update = 'update ' + self.table + ' set ' for i in self.filables: update += i + ' = "' + data[i] + '"' if i != self.filables[-1]: update += ', ' update += ' where id = ' + str(id) sql.execute(update) db.commit() sql.execute('select %s from %s where id = %s' % (self.make_string(self.visible), self.table, id)) return self.list_json(sql.fetchone(), self.visible)
def create(self, data): data = self.json_list(data, self.filables) insert = 'insert into ' + self.table + ' (' for filable in self.filables: insert += filable if self.filables[-1] != filable: insert += ',' insert += ') values (' for d in data: if type(d) == type(1): insert += d else: insert += '"' + d + '"' if data[-1] != d: insert += ',' insert += ')' sql.execute(insert) db.commit() sql.execute('select %s from %s' % (self.make_string(self.visible), self.table)) return self.list_json(sql.fetchall()[-1], self.visible)
def auth(self, token): sql.execute('select * from %s where token = "%s"' % (self.table, token)) return sql.fetchone()
def refresh_token(self, id, new_token): sql.execute('update %s set token = "%s" where id = %s' % (self.table, new_token, id)) db.commit() sql.execute('select * from %s where id = %s' % (self.table, id)) return sql.fetchone()
def get_by_email(self, email): sql.execute('select * from %s where email = "%s"' % (self.table, email)) return sql.fetchone()
def get_token(self, id): sql.execute('select token from %s where id = %s' % (self.table, id)) return sql.fetchone()[0]
def delete(self, id): sql.execute('delete from %s where id = %s' % (self.table, id)) db.commit() return None
def read(self, id): sql.execute('select %s from %s where id = %s' % (self.make_string(self.visible), self.table, id)) return self.list_json(sql.fetchone(), self.visible)