X-Git-Url: https://vcs.fsf.org/?p=rainbowstream.git;a=blobdiff_plain;f=rainbowstream%2Fdb.py;h=5bfb04081c715ad1b8f2690b1527a42987e9222a;hp=ce299c9559f7e219c75118ba8135cd6b57c88e10;hb=37ae740ef2ad0b2a7f2af68d9116c1bc268cbe00;hpb=78b81730b2f2be93408cedf2bf9cab223956a443 diff --git a/rainbowstream/db.py b/rainbowstream/db.py index ce299c9..5bfb040 100644 --- a/rainbowstream/db.py +++ b/rainbowstream/db.py @@ -1,7 +1,6 @@ import os from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker -from table_def import Map from .table_def import * @@ -14,39 +13,88 @@ class RainbowDB(): init_db() self.engine = create_engine('sqlite:///rainbow.db', echo=False) - def store(self, tweet_id): + def tweet_store(self, tweet_id): """ Store tweet id """ Session = sessionmaker(bind=self.engine) session = Session() - m = Map(tweet_id) - session.add(m) + t = Tweet(tweet_id) + session.add(t) session.commit() - def rainbow_query(self, rid): + def rainbow_to_tweet_query(self, rid): """ Query base of rainbow id """ Session = sessionmaker(bind=self.engine) session = Session() - res = session.query(Map).filter("rainbow_id =:rid").params(rid=rid).all() + res = session.query(Tweet).filter_by(rainbow_id=rid).all() return res - def tweet_query(self, tid): + def tweet_to_rainbow_query(self, tid): """ Query base of tweet id """ Session = sessionmaker(bind=self.engine) session = Session() - res = session.query(Map).filter("tweet_id =:tid").params(tid=tid).all() + res = session.query(Tweet).filter_by(tweet_id=tid).all() return res - def truncate(self): + def message_store(self, message_id): """ - Truncate table + Store message id """ Session = sessionmaker(bind=self.engine) session = Session() - session.query(Map).delete() + m = Message(message_id) + session.add(m) session.commit() + + def rainbow_to_message_query(self, rid): + """ + Query base of rainbow id + """ + Session = sessionmaker(bind=self.engine) + session = Session() + res = session.query(Message).filter_by(rainbow_id=rid).all() + return res + + def message_to_rainbow_query(self, mid): + """ + Query base of message id + """ + Session = sessionmaker(bind=self.engine) + session = Session() + res = session.query(Message).filter_by(message_id=mid).all() + return res + + def theme_store(self, theme_name): + """ + Store theme + """ + Session = sessionmaker(bind=self.engine) + session = Session() + th = Theme(theme_name) + session.add(th) + session.commit() + + def theme_update(self, theme_name): + """ + Update theme + """ + Session = sessionmaker(bind=self.engine) + session = Session() + res = session.query(Theme).all() + for r in res: + r.theme_name = theme_name + session.commit() + + def theme_query(self): + """ + Query theme + """ + Session = sessionmaker(bind=self.engine) + session = Session() + res = session.query(Theme).all() + return res