Created
March 27, 2013 14:38
-
-
Save anonymous/5254675 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import create_engine, Column, Integer, String, ForeignKey | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import relationship, sessionmaker, backref | |
from sqlalchemy import event | |
#enforce foreign keys, snippet from SO | |
def _fk_pragma_on_connect(dbapi_con, con_record): | |
dbapi_con.execute('pragma foreign_keys=ON') | |
event.listen(engine, 'connect', _fk_pragma_on_connect) | |
engine = create_engine('sqlite:///lexi.db', echo=True) | |
Base = declarative_base() | |
class Words(Base): | |
__tablename__ = 'words' | |
word = Column(String, primary_key=True) | |
defination = relationship("Definations", backref='words') | |
def __init__(self, word): | |
self.word = word | |
def __repr__(self): | |
return "<Words('%s')>" % self.word | |
class Definations(Base): | |
__tablename__ = 'definations' | |
id = Column(Integer, primary_key=True) | |
word = Column(String, ForeignKey('words.word')) | |
part_of_speech = Column(String) | |
pronunciation = Column(String) | |
defination = Column(String) | |
def __init__(self, part_of_speech, pronunciation, defination): | |
self.part_of_speech = part_of_speech | |
self.pronunciation = pronunciation | |
self.defination = defination | |
def __repr__(self): | |
return "<Definations('%s', '%s', '%s')>" % (self.part_of_speech, | |
self.pronunciation, | |
self.defination) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment