Slide 24
Slide 24 text
“Traditional” Example
from sqlalchemy import Table, Column, Integer, String, MetaData
from sqlalchemy.orm import mapper
# the object that stores sqlalchemy's understanding of the schema
metadata = MetaData()
# traditional way to define tables
users_table = Table('users', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(255)),
Column('fullname', String(255)),
Column('password', String(255))
)
class User(object):
'''Example User object, note it's a 'regular' object. '''
def __init__(self, name, fullname, password):
self.name = name
self.fullname = fullname
self.password = password
# here's the 'magic' User now connected to database
mapper(User, users_table)