|
|
|
@ -52,8 +52,21 @@ class Abstract:
|
|
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
|
def retrieve(self, path, mode):
|
|
|
|
|
"""
|
|
|
|
|
Return all comments for `path` with `mode`.
|
|
|
|
|
"""
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
|
def recent(self, mode=7, limit=None):
|
|
|
|
|
"""
|
|
|
|
|
Return most recent comments with `mode`. If `limit` is None, return
|
|
|
|
|
*all* comments that are currently stored, otherwise limit by `limit`.
|
|
|
|
|
"""
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SQLite(Abstract):
|
|
|
|
|
"""A basic :class:`Abstract` implementation using SQLite3. All comments
|
|
|
|
@ -152,3 +165,18 @@ class SQLite(Abstract):
|
|
|
|
|
|
|
|
|
|
for item in rv:
|
|
|
|
|
yield self.query2comment(item)
|
|
|
|
|
|
|
|
|
|
def recent(self, mode=7, limit=None):
|
|
|
|
|
|
|
|
|
|
sql = 'SELECT * FROM comments WHERE (? | mode) = ? ORDER BY created ASC'
|
|
|
|
|
args = [mode, mode]
|
|
|
|
|
|
|
|
|
|
if limit:
|
|
|
|
|
sql += ' LIMIT ?'
|
|
|
|
|
args.append(limit)
|
|
|
|
|
|
|
|
|
|
with sqlite3.connect(self.dbpath) as con:
|
|
|
|
|
rv = con.execute(sql + ';', args).fetchall()
|
|
|
|
|
|
|
|
|
|
for item in rv:
|
|
|
|
|
yield self.query2comment(item)
|
|
|
|
|