Hosting SQLite databases on any static file hoster (2021)
phiresky.github.io
phiresky.github.io
This boils down to an ambiguity found in the early days of HTTP: when you ask for a byte range with compression enabled, are you referring to a range in the uncompressed or compressed stream?
The only reasonable answer, in my opinion: a range of bytes in the uncompressed version, which is then compressed on-the-fly to save bandwidth.
I suspect the controversial point was that originally HTTP gzip encoding was used via pre-compression of the static files. On-the-fly encoding was probably too computationally expensive at the time.
Anyway, the result of this choice done decades ago is currently preventing effective use of the ranged HTTP requests. As an example, it is fairly likely that chunks from the SQLite database can be significantly compressed, but both HTTP servers and CDN refuse to compress "206 Partial Content" replies.
Interestingly, another use case of HTTP byte ranges is video streaming, which is not affected by this problem since video is _already_ compressed and there is no redundancy to remove anymore.
There should be a workaround for this using a custom pre-compression scheme, instead of relying on HTTP for the compression. Blocks within the file will have to be compressed separately, and you'll need some kind of index mapping uncompressed block offsets to compressed block offsets.
Unfortunately there doesn't seem to be a common of-the-shelf compression format that does this, and it means that you can't just use a standard SQLite file anymore. But it's definitely possible.
Would think HTTP2.0 is of greater value, to save TCP round trip time.
The RFC is clear on this, different Transfer-Encoding is only for the transfer and does not affect the identity of the resource, while different Content-Encoding does affect the identity of the resource.
Its not sure who did it first, but either Browsers or Web Servers started using the Content-Encoding header (which means, "this file is always compressed" like a tar.gz, user agent not meant to uncompress) with the meaning of Transfer-Encoding (which means, the file is not compressed, compression is just applied for the sake of the transfer and the user agent needs to uncompress first). This is a violation of the HTTP spec.
This fuckup resulted in big confusion and now requires an annoying amount of workarounds:
- E-Tag re-generation [1]
- Ranges and Compression are not usable together
- Browsers's "Resume Download" feature removed
- RFC-compliant behavior being a bug [2]
- Some corporate proxies are still unpacking tarballs on the fly, breaking checksum verification
Contrast this to eMail, which has the Encodings correctly sorted out, while using the same RFC822 encoding technique as HTTP.
[1] https://bz.apache.org/bugzilla/show_bug.cgi?id=39727
[2] https://serverfault.com/questions/915171/apache-server-cause...
tl;dr: HTTP Standard is not being implemented correctly
I think it's possible everywhere, but you'd just need to do more than copy paste the authors work.
so its probably worth just spelling out the thing.
It is here, so you're one of today's lucky 10,000! https://xkcd.com/1053/
Also, this is the search you wanted: https://hn.algolia.com/?dateRange=all&page=0&prefix=false&qu... (12,797 results as I type this).
This is normally used to pause/resume video, resume downloading files etc.
I grafted the enhanced lazyFile implementation from emscripten and then from this implementation to datasette-lite relatively recently as a curious test. Threw in a 18GB CSV from CA's unclaimed property records here
https://www.sco.ca.gov/upd_download_property_records.html
into a FTS5 Sqlite Database which came out to about 28GB after processing:
POC, non-merging Log/Draft PR for the hack:
https://github.com/simonw/datasette-lite/pull/49
You can run queries through to datasette-lite if you URL hack into it and just get to the query dialog, browsing is kind of a dud at the moment since datasette runs a count(*) which downloads everything.
Example: https://datasette-lite-lab.mindflakes.com/index.html?url=htt...
Still, not bad for a $0.42/mo hostable cached CDN'd read-only database. It's on Cloudflare R2, so there's no BW costs.
Unlike paying, which you can easily set to auto pay. Free services can go up and down whenever they wish. In fact, it's probs in their terms of service. The more generous the free service, the more likely it'd get cut down and be unusable later or just more expensive than alternatives. Like heroku free tier.
Paying money means there's an actual incentive and legal contract for the company to provide you service you paid for.
To clarify, Seafowl itself can't be hosted statically (it's a Rust server-side application), but it works well for statically hosted pages. It's basically designed to run analytical SQL queries over HTTP, with caching by a CDN/Varnish for SQL query results. The Web page user downloads just the query result rather than required fragments of the database (which, if you're running aggregation queries, might have to scan through a large part of it).
I've looked doing similar, trying to query a large dataset through ranged lookups on a static file server in the past. I ran into issue of some hosters not providing support for ranged lookups. Or the CDNs I was using having behaviour like they only fetch the origin data source in 8MB blocks meaning there was quite a lot of latency when doing lots of small reads across a massive file.
It would have been interesting to find out a bit more about these topics, and see a bit more on performance.
[error: TypeError: /blog/_next/static/media/sqlite.worker.39534d39.js is not a valid URL.]
The perfect defeated the good?
websql was created in 2010 and IndexedD work started also in 2010 - or around those years.
Sqlite didn’t have this amazing reputation it has now back then and decision to have Indexed DB as a standard looked good.
At least that is what I remember just reading about it from 2010-2013.
In retrospect it’s easier to say that probably the alternative would be better. But I don’t think it was the same decade ago.
Alternatively, you need to pick a small stable subset of SQLite functionality to expose. But that would mean you can't just use plain SQLite anymore - you either need to modify it significantly, or need to wrap it somehow. Which either way adds a lot of overhead again.
Therefore, tying a standard to a reference implementation, especially one as reputed as SQLite, might not have been a bad outcome overall.
[1] https://hacks.mozilla.org/2010/06/beyond-html5-database-apis...
A major advantage over WebSQL is that the developer is in complete control. The developer can pick the latest version of SQLite, enable any custom extensions (standard or additional ones), or use SQLCipher for encryption, instead of just using whatever the browser provides.
The only real disadvantage is the download size of the wasm code, but it's small enough that it won't be a blocker for sizeable interactive web apps. Just don't do this for your static blog.
Why do people bend over backwards to avoid using a server for anything? Its literally 11 lines of code:
Like Geocities?
This isn't just about github pages, it will work on most static hosting systems like Amazon S3 etc.