Skip to content

Commit 80ad6bd

Browse files
committed
chore(fmt): apply pre-commit formatting fixes
wip update sqlite chore: reuse .sql schema files in code chore: update sqlite queries I ran `just prepare-sqlite` and cleaned up a few queries we should eventually also add `just prepare-sqlite` to CI and validate that git is still clean afterwards chore: force sqlx files to be consistent add a post-processing step to ensure all sqlx' json files are sorted cleaner failure portable mktemp cleanup chore: more sqlx precompiled stmts keeps editors consistent
1 parent a91ddca commit 80ad6bd

32 files changed

Lines changed: 816 additions & 26 deletions

File tree

docs/content/files/init-cache.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../mbtiles/sql/init-cache.sql

docs/content/mbtiles-schema.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ tags:
77

88
# MBTiles Schemas
99

10-
The `mbtiles` tool builds on top of the original [MBTiles specification](https://github.com/mapbox/mbtiles-spec#readme) by specifying three different kinds of schema for `tiles` data: `flat`, `flat-with-hash`, and `normalized`. The `mbtiles` tool can convert between these schemas, and can also generate a diff between two files of any schemas, as well as merge multiple schema files into one file.
10+
The `mbtiles` tool builds on top of the original [MBTiles specification](https://github.com/mapbox/mbtiles-spec#readme) by specifying different kinds of schema for `tiles` data. The `mbtiles` tool can convert between these schemas, and can also generate a diff between two files of any schemas, as well as merge multiple schema files into one file.
1111

1212
## metadata
1313

@@ -65,3 +65,14 @@ Some tools (e.g. [Planetiler](https://github.com/onthegomap/planetiler)) produce
6565
Since tile IDs are integers rather than content hashes, per-tile validation checks foreign key integrity (every `tile_data_id` in `tiles_shallow` must exist in `tiles_data`) instead of recomputing content hashes.
6666
When copying from this schema to a new file, the `mbtiles` tool will produce the standard `map` + `images` normalized schema in the destination.
6767
In our next semver major, we plan to switch this default and produce `tiles_shallow`/`tiles_data` by default as well.
68+
69+
## cache
70+
71+
The `cache` schema is similar to `normalized`, but stores extra cache metadata (`expires` and `etag`) alongside each tile.
72+
Tile blobs are de-duplicated in the `cache_data` table, keyed by an integer `tile_id` that is the [xxh3-64](https://github.com/Cyan4973/xxHash) hash of `tile_data` (stored as an `INTEGER PRIMARY KEY`, i.e. an alias for the rowid, so identical blobs collapse to a single row).
73+
The `tile_cache` table maps tile Z,X,Y coordinates (plus `expires`/`etag`) to a `tile_id`.
74+
A spec-compatible `tiles` view is also created, so the file can still be read by any standard MBTiles reader (the `expires`/`etag` columns are simply invisible to it).
75+
76+
```sql
77+
--8<-- "files/init-cache.sql"
78+
```

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ prepare-sqlite: fetch install-sqlx
532532
trap 'rm -f "$db"' EXIT
533533
# add every possible schema to a dummy temp file so that most queries would compile.
534534
# `init-flat` is listed before the view-defining layouts so `tiles` is a table.
535-
for f in init-metadata init-flat init-flat-with-hash init-normalized init-normalized-dedup-id; do
535+
for f in init-metadata init-flat init-flat-with-hash init-normalized init-normalized-dedup-id init-cache; do
536536
# it is safer to handle NULLs than to expect it to never be there
537537
sed -E -e 's/[[:space:]]+NOT[[:space:]]+NULL//g' \
538538
-e 's/CREATE (TABLE|VIEW) /CREATE \1 IF NOT EXISTS /' \

mbtiles/.sqlx/query-0e8de7a941dbf9de7c5cbc0794b4598d6f209a1dcc560cc0b4e4f8c11351ebc1.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mbtiles/.sqlx/query-15a5a69f55100eb3cd6c23e896c9cb446e7f02d70cd8a61fde66f118c8dd8a79.json

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mbtiles/.sqlx/query-176e99c6945b0789119d0d21a99de564de47dde1d588f17e68ec58115ac73a39.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mbtiles/.sqlx/query-1a0ff474fc7560fb5dda3e4fb0b7acffa1d0a6d594ca169854fcfc0d2ef719a3.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mbtiles/.sqlx/query-208681caa7185b4014e7eda4120962954cdd3d913e8a786599da8a3f9799ed4b.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mbtiles/.sqlx/query-37912e87f53bc64511126b3ec19a1514ffc67e127ad8899b77d7d1e647834d61.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mbtiles/.sqlx/query-386a375cf65c3e5aef51deffc99d23bd852ba445c1058aed380fe83bed618c29.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)