Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 def auth(self, token):
     sql.execute('select * from %s where token = "%s"' %
                 (self.table, token))
     return sql.fetchone()
Ejemplo n.º 5
0
 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()
Ejemplo n.º 6
0
 def get_by_email(self, email):
     sql.execute('select * from %s where email = "%s"' %
                 (self.table, email))
     return sql.fetchone()
Ejemplo n.º 7
0
 def get_token(self, id):
     sql.execute('select token from %s where id = %s' % (self.table, id))
     return sql.fetchone()[0]
Ejemplo n.º 8
0
 def delete(self, id):
     sql.execute('delete from %s where id = %s' % (self.table, id))
     db.commit()
     return None
Ejemplo n.º 9
0
 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)