TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Using the SQLite-over-HTTP “hack” to make back end-less, offline-friendly apps

94 点作者 sekao超过 3 年前

9 条评论

hitekker超过 3 年前
&gt; Despite the title, we do still need a small backend for writes. Every time a user modifies the data, they will need the POST to your server, which will modify the SQLite database. This leads us to the big question: how do we update the database? Cloud object stores like S3 do not allow partial file updates, so what happens when your database becomes 1 GB or larger?<p>&gt; For me, the solution was lying inconspicuously in the SQLite source tree: an optional extension that allows you to multiplex a SQLite database across multiple files. Choose a chunk size, and your database will be automatically broken into multiple files as you add data to it. Now, you can just use a tool like rclone to copy the parts that have changed, instead of the entire 1+ GB database.<p>&gt; This is not just theoretical. The technique above is how I built ANSIWAVE BBS. The entire BBS is hosted on S3, and every time someone writes a post, the SQLite database is updated there.<p>I strongly recommend authoring a tutorial on your discovery and submitting it to HN. I don&#x27;t think most folks, myself included, realized that AnsiBBS was using SQLite range requests, or that you figured out how to update a multi-gigabyte SQL file in production.<p>You’re on the cusp of something big.
评论 #29766315 未加载
feep超过 3 年前
Pretty slick.<p>It extends the post[0] from a year-ish ago with read-only sqlite on a static server with a tiny backend that allows writes.<p>I am going to have to take a closer look at some point:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;ansiwave&#x2F;wavecore&#x2F;search?q=sqlite" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ansiwave&#x2F;wavecore&#x2F;search?q=sqlite</a><p>[0] <a href="https:&#x2F;&#x2F;phiresky.github.io&#x2F;blog&#x2F;2021&#x2F;hosting-sqlite-databases-on-github-pages&#x2F;" rel="nofollow">https:&#x2F;&#x2F;phiresky.github.io&#x2F;blog&#x2F;2021&#x2F;hosting-sqlite-database...</a>
评论 #29760304 未加载
ninkendo超过 3 年前
So there’s a server which accepts arbitrary writes to the database? And maps HTTP ranges to arbitrary database chunks?<p>Are we just completely relying on the client for security here? (i.e. no security at all?) Is this only for use cases where you have a whole database per user, and effectively a single security domain for the whole db? Because otherwise it smells very insecure to me…
评论 #29762810 未加载
xg15超过 3 年前
Interesting idea - but like some other posts here I&#x27;m wondering how exactly writes and concurrency would work - after all, a good amount of the complexity in traditional RDBMS stem from handling concurrent reads and writes.<p>Also of course data validation - the main reason why there is usually a layer between browser and DB is to restrict what a user can see and do. This seems difficult to implement here.<p>Also, if we&#x27;re already exposing the DB directly to the world, why take the detour through SQLite and a custom file system layer?<p>Why not just use a traditional DB like MySQL or Postgres on the backend and a WASM SQL client on the frontend?
评论 #29762731 未加载
samwillis超过 3 年前
Oh now that’s interesting! It potentially solves SQLite on serverless platforms like CloudFlare Workers, like what I was talking about the the other day:<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=29728702" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=29728702</a><p>I truly believe 2022 is the year or SQLite on the front end and serverless.
damiankennedy超过 3 年前
This may be a stupid question but what happens when two users update data in the same block? Also, does every update send an entire block over the wire?
评论 #29762649 未加载
sharps_xp超过 3 年前
when I saw that post a year ago, i thought that you can postpone scale issues with a cdn for a good long while if you could find a mechanism to update the sqlite chunks in a predictable user-friendly way. it’s quite an innovation.<p>after some meditation, i opted to do something simpler. if i was going to delay the the write consistency anyway, it’s just easier for the user to just download a lagging html file. this definitely depends on the use case, but i avoid a lot of this wasm js complexity by just having the browser download a static eventually updated html file
评论 #29762699 未加载
zubairq超过 3 年前
Actually visual JavaScript which you can find at yazz.com has done this for over two years where you can save a full html backed SQLite database app as a single page html file
schemescape超过 3 年前
Is the offline version read only? If not, do you just queue the update POSTs for when you’re back online?<p>I’m also not seeing how you synchronize reads against writes with this technique.
评论 #29764407 未加载