<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>sqlite3 &amp;mdash; Nat Knight</title>
    <link>http://natknight.xyz/tag:sqlite3</link>
    <description>Reflections, diversions, and opinions from a progressive ex-physicist programmer dad with a sore back.</description>
    <pubDate>Sat, 23 May 2026 15:51:34 -0700</pubDate>
    <item>
      <title>todo-sqlite3 v0.1</title>
      <link>http://natknight.xyz/todo-sqlite3-v0-1</link>
      <description>&lt;![CDATA[#release #sqlite3&#xA;&#xA;I wrote a spec for a SQLite-based todo database and just release version 0.1.&#xA;&#xA;!--more--&#xA;&#xA;todo.txt is an obvious inspiration, but I wanted to put my data in SQLite for a couple of reasons:&#xA;&#xA;SQLite is very stable, nearly as stable as plain text.&#xA;Having your todos in a database opens up possibilities for querying, viewing, and extending that data much more easily than if it&#39;s in plain text.&#xA;Having the data in SQLite in particular means multiple apps can interact with the database simultaneously, so I can have a CLI, a web app, and automation scripts touching the same todo list without risking corruption or data loss.&#xA;&#xA;Now that the database schema is ready I just have to build the rest of the app...&#xA;&#xA;The schema (not counting a tagging extension) in full:&#xA;&#xA;-- todo-sqlite3&#xA;-- https://github.com/nathanielknight/todo-sqlite3&#xA;&#xA;-- Foreign Key constraints are required.&#xA;PRAGMA foreignkeys = ON;&#xA;&#xA;-- Core Items table&#xA;CREATE TABLE items (&#xA;    id INTEGER PRIMARY KEY,&#xA;    -- Every item has a title (not necessarily unique)&#xA;    title TEXT NOT NULL,&#xA;    -- Body can be markdown, plaintext, asciidoc, etc.&#xA;    body TEXT,&#xA;    -- Items can be archived to support soft-deletion&#xA;    isarchived BOOLEAN NOT NULL DEFAULT 0,&#xA;    archivedstatuschangedat TIMESTAMP,&#xA;    -- Items have automatically updating createdat and changedat timestamps&#xA;    createdat TIMESTAMP NOT NULL DEFAULT (unixepoch(&#39;now&#39;, &#39;subsec&#39;)),&#xA;    changedat TIMESTAMP NOT NULL DEFAULT (unixepoch(&#39;now&#39;, &#39;subsec&#39;))&#xA;);&#xA;&#xA;-- The changedat and archivedstatuschangedat fields are automatically updated.&#xA;CREATE TRIGGER updateitemschangedat &#xA;AFTER UPDATE ON items&#xA;BEGIN&#xA;    UPDATE items SET changedat = unixepoch(&#39;now&#39;, &#39;subsec&#39;)&#xA;    WHERE id = NEW.id;&#xA;END;&#xA;&#xA;CREATE TRIGGER updatearchivedstatustimestamp&#xA;AFTER UPDATE OF isarchived ON items&#xA;WHEN NEW.isarchived != OLD.isarchived&#xA;BEGIN&#xA;    UPDATE items &#xA;    SET archivedstatuschangedat = unixepoch(&#39;now&#39;, &#39;subsec&#39;)&#xA;    WHERE id = NEW.id;&#xA;END;&#xA;`]]&gt;</description>
      <content:encoded><![CDATA[<p><a href="http://natknight.xyz/tag:release" class="hashtag"><span>#</span><span class="p-category">release</span></a> <a href="http://natknight.xyz/tag:sqlite3" class="hashtag"><span>#</span><span class="p-category">sqlite3</span></a></p>

<p>I wrote a spec for a <a href="https://github.com/nathanielknight/todo-sqlite3">SQLite-based todo database</a> and just release <a href="https://github.com/nathanielknight/todo-sqlite3/releases/tag/v0.1">version 0.1</a>.</p>



<p><a href="http://todotxt.org/">todo.txt</a> is an obvious inspiration, but I wanted to put my data in SQLite for a couple of reasons:</p>
<ul><li>SQLite is <em>very</em> stable, nearly as stable as plain text.</li>
<li>Having your todos in a database opens up possibilities for querying, viewing, and extending that data much more easily than if it&#39;s in plain text.</li>
<li>Having the data in SQLite in particular means multiple apps can interact with the database simultaneously, so I can have a CLI, a web app, and automation scripts touching the same todo list without risking corruption or data loss.</li></ul>

<p>Now that the database schema is ready I just have to build the rest of the app...</p>

<p>The schema (not counting a tagging extension) in full:</p>

<pre><code class="language-sql">-- todo-sqlite3
-- https://github.com/nathanielknight/todo-sqlite3

-- Foreign Key constraints are required.
PRAGMA foreign_keys = ON;


-- Core Items table
CREATE TABLE items (
    id INTEGER PRIMARY KEY,
    -- Every item has a title (not necessarily unique)
    title TEXT NOT NULL,
    -- Body can be markdown, plaintext, asciidoc, etc.
    body TEXT,
    -- Items can be archived to support soft-deletion
    is_archived BOOLEAN NOT NULL DEFAULT 0,
    archived_status_changed_at TIMESTAMP,
    -- Items have automatically updating created_at and changed_at timestamps
    created_at TIMESTAMP NOT NULL DEFAULT (unixepoch(&#39;now&#39;, &#39;subsec&#39;)),
    changed_at TIMESTAMP NOT NULL DEFAULT (unixepoch(&#39;now&#39;, &#39;subsec&#39;))
);

-- The changed_at and archived_status_changed_at fields are automatically updated.
CREATE TRIGGER update_items_changed_at 
AFTER UPDATE ON items
BEGIN
    UPDATE items SET changed_at = unixepoch(&#39;now&#39;, &#39;subsec&#39;)
    WHERE id = NEW.id;
END;

CREATE TRIGGER update_archived_status_timestamp
AFTER UPDATE OF is_archived ON items
WHEN NEW.is_archived != OLD.is_archived
BEGIN
    UPDATE items 
    SET archived_status_changed_at = unixepoch(&#39;now&#39;, &#39;subsec&#39;)
    WHERE id = NEW.id;
END;
</code></pre>
]]></content:encoded>
      <guid>http://natknight.xyz/todo-sqlite3-v0-1</guid>
      <pubDate>Thu, 27 Feb 2025 05:57:45 +0000</pubDate>
    </item>
  </channel>
</rss>