1. javajuneau
  2. JythonBook


JythonBook / src / chapter15 / RosterTool / rostertool / model / __init__.py

from pylons import config
from sqlalchemy import create_engine, MetaData
from sqlalchemy import String, Integer
from sqlalchemy.schema import Sequence, Table, Column, UniqueConstraint
from sqlalchemy.orm import mapper
from sqlalchemy.orm import sessionmaker

engine = create_engine(config['sqlalchemy.url'])
Session = sessionmaker(bind=engine)
connection = engine.connect()
metadata = MetaData()
player_table = Table('player', metadata,
        Column('id', Integer, primary_key=True),
        Column('first', String(50)),
        Column('last', String(50)),
        Column('position', String(30)),
        UniqueConstraint('first', 'last'), # setup a unique key with first and lastname

class Player(object):
    def __init__(self, first, last, position):
        self.first = first
        self.last = last
        self.position = position

    def __repr__(self):
        return "<Player('%s', '%s', '%s')>" %(self.first, self.last, self.position)

player_mapper = mapper(Player, player_table)

def create_table():

if __name__ == '__main__':