diff --git a/schema.sql b/schema.sql index 336a63e..79a4f5f 100644 --- a/schema.sql +++ b/schema.sql @@ -21,7 +21,8 @@ create table threads ( title text, -- string last_mod real, -- floating point unix timestamp (of last post or post edit) created real, -- floating point unix timestamp (when thread was made) - reply_count int -- integer (incremental, starting with 0) + reply_count int, -- integer (incremental, starting with 0) + pinned int -- boolean ); diff --git a/src/db.py b/src/db.py index f77a647..38d8cb0 100644 --- a/src/db.py +++ b/src/db.py @@ -78,6 +78,21 @@ def thread_index(connection): return threads +def thread_set_pin(connection, thread_id, pin_bool): + """ + Set the pinned status of thread_id to pin_bool. + """ + # can never be too sure :^) + pin_bool = bool(pin_bool) + connection.execute(""" + UPDATE threads SET + pinned = ? + WHERE thread_id = ? + """, (pin_bool, thread_id)) + connection.commit() + return pin_bool + + def thread_create(connection, author_id, body, title): """ Create a new thread and return it. @@ -91,13 +106,16 @@ def thread_create(connection, author_id, body, title): thread_id = uuid1().hex scheme = schema.thread( thread_id, author_id, title, - now, now, -1) # see below for why i set -1 instead of 0 + now, now, -1, False) # see below for why i set -1 instead of 0 connection.execute(""" INSERT INTO threads - VALUES (?,?,?,?,?,?) + VALUES (?,?,?,?,?,?,?) """, schema_values("thread", scheme)) connection.commit() + # the thread is initially commited with reply_count -1 so that i can + # just pass the message to the reply method, instead of duplicating + # its code here. It then increments to 0. thread_reply(connection, author_id, thread_id, body, time_override=now) # fetch the new thread out of the database instead of reusing the returned # objects, just to be 100% sure what is returned is what was committed diff --git a/src/schema.py b/src/schema.py index a6b6d5f..7529c46 100644 --- a/src/schema.py +++ b/src/schema.py @@ -127,7 +127,8 @@ def thread( title, # string last_mod, # floating point unix timestamp (of last post or post edit) created, # floating point unix timestamp (when thread was made) - reply_count): # integer (incremental, starting with 0) + reply_count, # integer (incremental, starting with 0) + pinned): # boolean return { "thread_id": thread_id, @@ -136,6 +137,7 @@ def thread( "last_mod": last_mod, "created": created, "reply_count": reply_count, + "pinned": bool(pinned) } diff --git a/src/utils.py b/src/utils.py index 4f4ad0b..a193cb4 100644 --- a/src/utils.py +++ b/src/utils.py @@ -22,7 +22,7 @@ def schema_values(scheme, obj): elif scheme == "thread": return ordered_keys(obj, "thread_id", "author", "title", - "last_mod", "created", "reply_count") + "last_mod", "created", "reply_count", "pinned") elif scheme == "message": return ordered_keys(obj,