Load schema at require time and use transactions.
This commit is contained in:
+2
-8
@@ -22,6 +22,7 @@ function hash(z, x, y) {
|
|||||||
// insertion, etc.)
|
// insertion, etc.)
|
||||||
module.exports = MBTiles;
|
module.exports = MBTiles;
|
||||||
MBTiles.utils = require('./utils');
|
MBTiles.utils = require('./utils');
|
||||||
|
MBTiles.schema = fs.readFileSync(__dirname + '/schema.sql', 'utf8');
|
||||||
|
|
||||||
// Provides access to an mbtiles database file.
|
// Provides access to an mbtiles database file.
|
||||||
// - uri: A parsed URL hash, the only relevant part is `pathname`.
|
// - uri: A parsed URL hash, the only relevant part is `pathname`.
|
||||||
@@ -124,14 +125,7 @@ MBTiles.prototype._integrity = function(callback) {
|
|||||||
// Setup schema, indices, views for a new mbtiles database.
|
// Setup schema, indices, views for a new mbtiles database.
|
||||||
// - @param {Function(err)} callback
|
// - @param {Function(err)} callback
|
||||||
MBTiles.prototype._setup = function(callback) {
|
MBTiles.prototype._setup = function(callback) {
|
||||||
var mbtiles = this;
|
this._db.exec(MBTiles.schema, callback);
|
||||||
mbtiles._exists('tiles', function(err, exists) {
|
|
||||||
if (exists) return callback(null);
|
|
||||||
fs.readFile(__dirname + '/schema.sql', 'utf8', function(err, sql) {
|
|
||||||
if (err) return callback(err);
|
|
||||||
mbtiles._db.exec(sql, callback);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Select a tile from an mbtiles database. Scheme is XYZ.
|
// Select a tile from an mbtiles database. Scheme is XYZ.
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
-- MBTiles schema
|
-- MBTiles schema
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS map (
|
CREATE TABLE IF NOT EXISTS map (
|
||||||
zoom_level INTEGER,
|
zoom_level INTEGER,
|
||||||
tile_column INTEGER,
|
tile_column INTEGER,
|
||||||
@@ -70,3 +72,5 @@ CREATE VIEW IF NOT EXISTS grid_data AS
|
|||||||
FROM map
|
FROM map
|
||||||
JOIN grid_key ON map.grid_id = grid_key.grid_id
|
JOIN grid_key ON map.grid_id = grid_key.grid_id
|
||||||
JOIN keymap ON grid_key.key_name = keymap.key_name;
|
JOIN keymap ON grid_key.key_name = keymap.key_name;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
|||||||
Reference in New Issue
Block a user