TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

JSON Changelog with SQLite

113 pointsby iffycanover 6 years ago

6 comments

derefrover 6 years ago
I&#x27;ve seen this pattern a couple of times (e.g. for broadcasting changes using Postgres&#x27;s LISTEN&#x2F;NOTIFY.)<p>Each time, I wonder why people are recreating the database&#x27;s journal, within the database, where this meta-journal will <i>itself</i> be getting journaled.<p>Why not just consume the actual DB journal?<p>I&#x27;m not sure how that&#x27;d work for SQLite—it&#x27;d probably require a hack of some sort, since SQLite&#x27;s journal is an ephemeral part of the DB file. But for more full-fledged RDBMSes, this would just be a matter of hijacking a streaming-replication-based backup system to act as a store of record for events. E.g., in the case of Postgres, you&#x27;d just have an ETL pipeline pointed at your WAL-E bucket, parsing through your WAL files either to load into a separate OLAP store, or for stateless map-reduction whenever you need to answer a question.
评论 #17855647 未加载
评论 #17855865 未加载
评论 #17856714 未加载
评论 #17855841 未加载
评论 #17856146 未加载
评论 #17856409 未加载
评论 #17855654 未加载
cannadayrover 6 years ago
I solved this problem by wrapping sqldiff (included w&#x2F; sqlite src) as a custom git diff driver.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;cannadayr&#x2F;git-sqlite" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cannadayr&#x2F;git-sqlite</a>
radiospielover 6 years ago
The sqlite sessions extension seems to be a good foundation for getting changelogs out of a sqlite database. It is sadly not too well known: <a href="https:&#x2F;&#x2F;www.sqlite.org&#x2F;sessionintro.html" rel="nofollow">https:&#x2F;&#x2F;www.sqlite.org&#x2F;sessionintro.html</a>
groueover 6 years ago
Related article: &quot;Automatic Undo&#x2F;Redo Using SQLite&quot; <a href="https:&#x2F;&#x2F;www.sqlite.org&#x2F;undoredo.html" rel="nofollow">https:&#x2F;&#x2F;www.sqlite.org&#x2F;undoredo.html</a>
评论 #17859884 未加载
Scaevolusover 6 years ago
Neat! If you wanted to extend this more (string diffs, non-json encodings), a custom function would be the next logical step. In Python it might be:<p><pre><code> import sqlite3 def delta(*args): ret = {} for name, old, new in zip(args[::3], args[1::3], args[2::3]): if old != new: ret[name] = old if ret: return ret db = sqlite3.connect(&#x27;:memory:&#x27;) db.create_function(&#x27;delta1&#x27;, delta, 3) db.create_function(&#x27;delta2&#x27;, delta, 6) db.create_function(&#x27;delta3&#x27;, delta, 9) print db.execute(&#x27;select delta2(&quot;b&quot;, &quot;20&quot;, &quot;20&quot;, &quot;c&quot;, 3.4, 3.6)&#x27;).fetchone() &gt;&gt; (u&#x27;{&quot;c&quot;: 3.4}&#x27;,)</code></pre>
评论 #17856785 未加载
janemanosover 6 years ago
ArangoDB also has a first tool to listen to changes in the database and execute actions or queries. It is limited to a single node. Question is how scalable all of these tools are <a href="https:&#x2F;&#x2F;www.arangodb.com&#x2F;2017&#x2F;03&#x2F;arangochair-tool-listening-changes-arangodb&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.arangodb.com&#x2F;2017&#x2F;03&#x2F;arangochair-tool-listening-...</a>