def Populate(self): session = Session() if self.table == None: return query = session.query(self.table) for item in query: self.Append(item.name, item.id) self.SetSelection(0) session.close()
def get_data(): ses = Session() rs = ses.query(Car).all() # you have to serialize the data from data object to serail data here #rs is the data output in data object format, global data data = [{"car": Car.Name, "price": Car.Price} for Car in rs] #json.dump(rs) return jsonify([data])
def home(): ses = Session() ses.add_all([ Car(Id=1, Name='Audi', Price=52642), Car(Id=2, Name='Mercedes', Price=57127), Car(Id=3, Name='Skoda', Price=9000), Car(Id=4, Name='Volvo', Price=29000), Car(Id=5, Name='Bentley', Price=350000), Car(Id=6, Name='Citroen', Price=21000), Car(Id=7, Name='Hummer', Price=41400), Car(Id=8, Name='Volkswagen', Price=21600) ]) ses.commit() rs = ses.query(Car).all() for Car in rs: print(Car.Name, Car.Price) return rs
def get_all_users(): session = Session() listUsers = [] users = session.query(User).all() for user in users: listUsers.append({"id": user.id, "firstname": user.firstname, "lastname": user.lastname, "username": user.username, "status": user.status, "email": user.email, "created_at" : user.created_at }) session.close() return listUsers
from Database import engine, Base, Session from models import User Base.metadata.create_all(engine) session = Session() session.commit() session.close()
def __init__(self, userSession, peripherals): self.userSession = userSession self.peripherals = peripherals self.session = Session()
def __init__(self): self.dbsession = Session()