Esempio n. 1
0
    def delete(self):
        """delete one record from the table

        sql: delete from users where id=2
        """
        sql = 'delete from %s %s' %(self.model.table_name, self.where_expr)
        logging.info("delete sql: ".format(sql))
        db.execute(sql, self.params)
        db.commit()
        db.cleanup()
Esempio n. 2
0
    def insert(self):
        """insert one record to the table

        sql: insert into users (name, password, email) values ()
        """
        sql = 'insert into %s(%s) values (%s);' % (
            self.model.table_name, ', '.join(self.model.keys()), ', '.join(['%s'] * len(self.model.values())))
        logging.info("insert sql: ".format(sql))
        db.execute(sql, self.model.values())
        db.commit()
        db.cleanup()
Esempio n. 3
0
 def update(self, **kwargs):
     # update students set tel=default where id=5
     _keys = []
     _params = []
     for key, val in kwargs.iteritems():
         if val == None or key not in self.model.fields:
             continue
         _keys.append(key)
         _params.append(val)
     _params.extend(self.params)
     sql = 'update %s set %s %s' %(
         self.model.table_name, ','.join([key + '=%s' for key in _keys]), self.where_expr
         )
     logging.info(sql)
     db.execute(sql, _params)
     db.commit()
     db.cleanup()