Commit | Line | Data |
---|---|---|
18cab06a O |
1 | from sqlalchemy import create_engine |
2 | from sqlalchemy.orm import sessionmaker | |
3 | from table_def import Map | |
4 | ||
5 | ||
6 | class RainbowDB(): | |
7 | ||
8 | engine=None | |
9 | ||
10 | def __init__(self): | |
11 | self.engine = create_engine('sqlite:///rainbow.db', echo=False) | |
12 | ||
13 | def store(self, tweet_id): | |
14 | Session = sessionmaker(bind=self.engine) | |
15 | session = Session() | |
16 | m = Map(tweet_id) | |
17 | session.add(m) | |
18 | session.commit() | |
19 | ||
20 | def rainbow_query(self, rid): | |
21 | Session = sessionmaker(bind=self.engine) | |
22 | session = Session() | |
23 | res = session.query(Map).filter("rainbow_id =:rid").params(rid=rid).all() | |
24 | return res | |
25 | ||
26 | def tweet_query(self, tid): | |
27 | Session = sessionmaker(bind=self.engine) | |
28 | session = Session() | |
29 | res = session.query(Map).filter("tweet_id =:tid").params(tid=tid).all() | |
30 | return res |