summaryrefslogtreecommitdiff
path: root/db.py
diff options
context:
space:
mode:
Diffstat (limited to 'db.py')
-rw-r--r--db.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/db.py b/db.py
index 8d96b4d..b5c5a3f 100644
--- a/db.py
+++ b/db.py
@@ -1,4 +1,4 @@
-from sqlalchemy import create_engine, Column, Integer, String, DateTime, Text, Index
+from sqlalchemy import create_engine, Column, Integer, String, DateTime, Text, Index, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relation, backref
import settings
@@ -29,5 +29,22 @@ class Paste(Base):
def __repr__(self):
return '<Paste(%d, "%s", "%s", "%s", "%s")>' % (self.id, self.hash, self.nick, self.date.ctime(), self.title)
+class Cache(Base):
+ __tablename__ = 'cache'
+
+ id = Column(Integer, primary_key = True)
+ paste_hash = Column(String, ForeignKey('paste.hash'), index = True)
+ paste = relation(Paste, primaryjoin = paste_hash == Paste.hash, lazy = False)
+ syntax_name = Column(String)
+ text = Column(Text)
+
+ def __init__(self, hash, syntax_name, text):
+ self.paste_hash = hash
+ self.syntax_name = syntax_name
+ self.text = text
+
+ def __repr__(self):
+ return '<Cache(%d, "%s")>' % (self.id, self.paste_hash)
+
Base.metadata.create_all()
Session = sessionmaker(bind = engine, autoflush = True, autocommit = False)