-
Notifications
You must be signed in to change notification settings - Fork 83
/
schema.sql
83 lines (70 loc) · 2.16 KB
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
-- MBTiles schema
BEGIN;
CREATE TABLE IF NOT EXISTS map (
zoom_level INTEGER,
tile_column INTEGER,
tile_row INTEGER,
tile_id TEXT,
grid_id TEXT
);
CREATE TABLE IF NOT EXISTS grid_key (
grid_id TEXT,
key_name TEXT
);
CREATE TABLE IF NOT EXISTS keymap (
key_name TEXT,
key_json TEXT
);
CREATE TABLE IF NOT EXISTS grid_utfgrid (
grid_id TEXT,
grid_utfgrid BLOB
);
CREATE TABLE IF NOT EXISTS images (
tile_data blob,
tile_id text
);
CREATE TABLE IF NOT EXISTS metadata (
name text,
value text
);
CREATE TABLE IF NOT EXISTS geocoder_data (
type TEXT,
shard INTEGER,
data BLOB
);
CREATE UNIQUE INDEX IF NOT EXISTS map_index ON map (zoom_level, tile_column, tile_row);
CREATE UNIQUE INDEX IF NOT EXISTS grid_key_lookup ON grid_key (grid_id, key_name);
CREATE UNIQUE INDEX IF NOT EXISTS keymap_lookup ON keymap (key_name);
CREATE UNIQUE INDEX IF NOT EXISTS grid_utfgrid_lookup ON grid_utfgrid (grid_id);
CREATE UNIQUE INDEX IF NOT EXISTS images_id ON images (tile_id);
CREATE UNIQUE INDEX IF NOT EXISTS name ON metadata (name);
CREATE INDEX IF NOT EXISTS map_grid_id ON map (grid_id);
CREATE INDEX IF NOT EXISTS geocoder_type_index ON geocoder_data (type);
CREATE UNIQUE INDEX IF NOT EXISTS geocoder_shard_index ON geocoder_data (type, shard);
CREATE VIEW IF NOT EXISTS tiles AS
SELECT
map.zoom_level AS zoom_level,
map.tile_column AS tile_column,
map.tile_row AS tile_row,
images.tile_data AS tile_data
FROM map
JOIN images ON images.tile_id = map.tile_id;
CREATE VIEW IF NOT EXISTS grids AS
SELECT
map.zoom_level AS zoom_level,
map.tile_column AS tile_column,
map.tile_row AS tile_row,
grid_utfgrid.grid_utfgrid AS grid
FROM map
JOIN grid_utfgrid ON grid_utfgrid.grid_id = map.grid_id;
CREATE VIEW IF NOT EXISTS grid_data AS
SELECT
map.zoom_level AS zoom_level,
map.tile_column AS tile_column,
map.tile_row AS tile_row,
keymap.key_name AS key_name,
keymap.key_json AS key_json
FROM map
JOIN grid_key ON map.grid_id = grid_key.grid_id
JOIN keymap ON grid_key.key_name = keymap.key_name;
COMMIT;