from sqlalchemy.orm import Session from sqlalchemy import create_engine engine = create_engine('sqlite:///example.db') session = Session(bind=engine)
from sqlalchemy.orm import Session from sqlalchemy import create_engine from models import User engine = create_engine('sqlite:///example.db') session = Session(bind=engine) users = session.query(User).all() for user in users: print(user.name)
from sqlalchemy.orm import Session from sqlalchemy import create_engine from models import User engine = create_engine('sqlite:///example.db') session = Session(bind=engine) new_user = User(name='John Doe', age=30) session.add(new_user) session.commit()In this example, we create a new `User` object and add it to the database using the `add` method of the `session` object. We then commit the transaction using the `commit` method to save the changes to the database.