Upload
pythonsd
View
104
Download
2
Embed Size (px)
DESCRIPTION
This was a talk on SQL Alchemy and Alembic given by Nick MacInnis at San Diego Python on June 26, 2014.
Citation preview
SQLAlchemyand also alembic
what is it
Core
ORM
Core
Flexible DB Tool
Core
so powerful
users = Table('users', metadata, Column('id', Integer, Sequence('user_id_seq'),
primary_key=True), Column('name', String(50)))
ins = users.insert().values(name='jack')
Core Example
work directly with sql etc
ORM
Data Mapping to Classes
ORM
so declarative
class User(Base): __tablename__ = 'users'
id = Column(Integer, primary_key=True) name = Column(String)
ed_user = User(name='ed')session.add(ed_user)
ORM Example
abstractions of database tables in domain objects
some other things
Unit of Work
different from Active Record
user1 = User(name='user1')user2 = User(name='user2')session.add(user1)session.add(user2)
session.commit()
Unit of Work Example
alembic
version your db, sort of