Advertisement
Guest User

sqlalchemy with existing DB schemma

a guest
Jul 26th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sqlalchemy
  3. from sqlalchemy import create_engine,\
  4.     Table, Column, Integer, String, MetaData, ForeignKey
  5. from sqlalchemy.orm import sessionmaker
  6. from sqlalchemy.ext.declarative import declarative_base
  7.  
  8. engine = create_engine('sqlite:///places.sqlite')
  9. Session = sessionmaker(bind=engine)
  10. metadata = MetaData(engine)
  11. Base = declarative_base()
  12.  
  13. moz_bookmarks = Table('moz_bookmarks', metadata,
  14. #           Column('id', Integer(), primary_key=True, nullable=False),
  15.             autoload=True)
  16.  
  17. class MozBookmarks(Base):
  18.     __table__ = moz_bookmarks
  19.  
  20.  
  21. for bookmark in Session().query(MozBookmarks)\
  22.                 .filter(MozBookmarks.id == 903):
  23.     print bookmark, bookmark.title, bookmark.__dict__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement