Mateusz Burniak, 218321
>>> from sqlalchemy import (
... create_engine)
>>> engine = create_engine(
... ''postgresql+psycopg2:''
... ''//user:password@host:port/dbname'')
>>> from sqlalchemy.ext.declarative import (
... declarative_base)
>>> from sqlalchemy import Column, Integer, Text
>>> Base = declarative_base()
>>> class User(Base):
... __tablename__ = ''users''
... id = Column(Integer, primary_key=True)
... name = Column(Text)
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name TEXT
);
>>> from sqlalchemy.orm import (
... sessionmaker)
>>> Session = sessionmaker(bind=engine)
>>> session = Session()
>>> new_user = User(name=''jan'')
>>> session.add(new_user)
>>> users = session.query(User).\
... filter_by(name=''jan'')
>>> list(users)
[<User(name=''jan'')>]
i zatwierdzanie zmian
>>> users[0].name = ''jasiek''
>>> session.commit()
>>> session.delete(new_user)
>>> session.query(User).\
... filter_by(name=''jasiek'').count()
0