diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-01-25 01:00:18 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-01-25 01:00:18 +0100 |
commit | 346b22ddf795f9a5a10ddc6b83bfa3bc15c8d30a (patch) | |
tree | f9d9251ea08bc8ad57e7234ca451bcc3eeccc7b5 /db.py |
Initial commit.
Diffstat (limited to 'db.py')
-rw-r--r-- | db.py | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -0,0 +1,32 @@ +from sqlalchemy import create_engine, Column, Integer, String, DateTime, Text, Index +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import sessionmaker, relation, backref + +engine = create_engine('sqlite:////home/snakebite/pastepy/db') + +Base = declarative_base(engine = engine) + +class Paste(Base): + __tablename__ = 'paste' + + id = Column(Integer, primary_key = True) + hash = Column(String, unique = True, index = True) + nick = Column(String) + date = Column(DateTime, nullable = False) + syntax = Column(String) + title = Column(String) + text = Column(Text) + + def __init__(self, hash, nick, date, syntax, title, text): + self.nick = nick + self.hash = hash + self.date = date + self.syntax = syntax + self.title = title + self.text = text + + def __repr__(self): + return '<Paste(%d, "%s", "%s", "%s", "%s")>' % (self.id, self.hash, self.nick, self.date.ctime(), self.title) + +Base.metadata.create_all() +Session = sessionmaker(bind = engine, autoflush = True, autocommit = False) |