update database requirements

This commit is contained in:
posativ 2012-10-17 11:42:21 +02:00
parent ca79ee5b67
commit 3d398341a3

View File

@ -14,24 +14,35 @@ class Abstract:
def __init__(self, conf): def __init__(self, conf):
return return
@abc.abstractmethod
def shutdown(self):
return
@abc.abstractmethod @abc.abstractmethod
def add(path, comment): def add(path, comment):
"""Add a new comment to the database. Returns a Comment object."""
return return
@abc.abstractmethod @abc.abstractmethod
def update(self, path, id, comment): def update(self, path, id, comment):
"""
Update an existing comment, but only writeable fields such as text,
author, email, website and parent. This method should set the modified
field to the current time.
"""
return return
@abc.abstractmethod @abc.abstractmethod
def delete(self, path): def delete(self, path, id):
"""
Delete a comment. There are two distinctions: a comment is referenced
by another valid comment's parent attribute or stand-a-lone. In this
case the comment can't be removed without losing depending comments.
Hence, delete removes all visible data such as text, author, email,
website sets the mode field to 2.
In the second case this comment can be safely removed without any side
effects."""
return return
@abc.abstractmethod @abc.abstractmethod
def retrieve(self, path, limit): def retrieve(self, path, limit=20):
return return
@ -67,9 +78,6 @@ class SQLite(Abstract):
WHERE rowid=NEW.rowid; WHERE rowid=NEW.rowid;
END;""") END;""")
def shutdown(self):
return
def query2comment(self, query): def query2comment(self, query):
if query is None: if query is None:
return None return None
@ -111,8 +119,7 @@ class SQLite(Abstract):
with sqlite3.connect(self.dbpath) as con: with sqlite3.connect(self.dbpath) as con:
con.execute('UPDATE comments SET text=? WHERE path=? AND id=?', ('', path, id)) con.execute('UPDATE comments SET text=? WHERE path=? AND id=?', ('', path, id))
con.execute('UPDATE comments SET mode=? WHERE path=? AND id=?', (2, path, id)) con.execute('UPDATE comments SET mode=? WHERE path=? AND id=?', (2, path, id))
for field in Comment.fields: for field in set(Comment.fields) - set(['text', 'parent']):
if field == 'text': continue
con.execute('UPDATE comments SET %s=? WHERE path=? AND id=?' % field, con.execute('UPDATE comments SET %s=? WHERE path=? AND id=?' % field,
(None, path, id)) (None, path, id))
return path, id return path, id