Permalink
Browse files

more elaborate test for Database#exec

  • Loading branch information...
1 parent c5cd5ee commit e2305f246ffe982bd5b0e5f386a69bd3e07bb9c5 @kkaefer kkaefer committed Feb 23, 2011
Showing with 86 additions and 17 deletions.
  1. +16 −5 test/exec.test.js
  2. +70 −12 test/support/script.sql
View
@@ -10,14 +10,25 @@ exports['test Database#exec'] = function(beforeExit) {
db.exec(sql, function(err) {
if (err) throw err;
- db.all("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name", function(err, rows) {
+ db.all("SELECT type, name FROM sqlite_master ORDER BY type, name", function(err, rows) {
if (err) throw err;
- assert.ok(rows.length, 3);
assert.deepEqual(rows, [
- { name: 'bar' },
- { name: 'baz' },
- { name: 'foo' }
+ { type: 'index', name: 'grid_key_lookup' },
+ { type: 'index', name: 'grid_utfgrid_lookup' },
+ { type: 'index', name: 'images_id' },
+ { type: 'index', name: 'keymap_lookup' },
+ { type: 'index', name: 'map_index' },
+ { type: 'index', name: 'name' },
+ { type: 'table', name: 'grid_key' },
+ { type: 'table', name: 'grid_utfgrid' },
+ { type: 'table', name: 'images' },
+ { type: 'table', name: 'keymap' },
+ { type: 'table', name: 'map' },
+ { type: 'table', name: 'metadata' },
+ { type: 'view', name: 'grid_data' },
+ { type: 'view', name: 'grids' },
+ { type: 'view', name: 'tiles' }
]);
finished = true;
View
@@ -1,12 +1,70 @@
-CREATE TABLE foo (id INT, txt TEXT);
-
-INSERT INTO foo VALUES (1, 'test');
-INSERT INTO foo VALUES (2, 'test');
-INSERT INTO foo VALUES (3, 'test');
-INSERT INTO foo VALUES (4, 'test');
-INSERT INTO foo VALUES (5, 'test');
-INSERT INTO foo VALUES (6, 'test');
-INSERT INTO foo VALUES (7, 'test');
-
-CREATE TABLE bar (id INT, flt FLOAT);
-CREATE TABLE baz (id INT, blb BLOB);
+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 TEXT
+);
+
+CREATE TABLE IF NOT EXISTS images (
+ tile_data blob,
+ tile_id text
+);
+
+CREATE TABLE IF NOT EXISTS metadata (
+ name text,
+ value text
+);
+
+
+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 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;

0 comments on commit e2305f2

Please sign in to comment.