def save(self): """ Store user and images in DB, doesn't support update. TODO: save to db shold not be here, other class should be responsible for that """ db.Pcursor().execute( "CALL bv.addUser('{0}', '{1}', {2}, '{3}', '{4}')".format( self.id, self.name, self.age, self.sex, self.country)) self.save_images()
def get_users(): users = [] dbUsers = db.Pcursor().fetchall( 'select name, id, age, sex, country, creation_date, updated_at, is_deleted from bv.users;' ) for row in dbUsers: user = User(row[0], row[1], row[3], row[2], row[4]) users.append(user) return users
def get_all_images(): images = [] dbImages = db.Pcursor().fetchall(""" SELECT img.id, img.name, img.path, img.features, img.emotions, img.user_id, usr.age, usr.sex, usr.country FROM bv.images img, bv.users usr WHERE img.user_id=usr.id """) for row in dbImages: emImage = EmotionalImage(row[0], row[1], row[2], row[3], row[4], row[6], row[7], row[8]) images.append(emImage) return images
def save(self, userId): '''TODO: save to db shold not be here, other class should be responsible for that''' db.Pcursor().execute( "CALL bv.addImage('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')". format(self.id, userId, self.name, self.path, self.features, self.emotions))
import db sql_file = open('migration/create.pgsql', 'r') db.Pcursor().execute(sql_file.read())