Load schema at require time and use transactions.
This commit is contained in:
@@ -22,6 +22,7 @@ function hash(z, x, y) {
|
||||
// insertion, etc.)
|
||||
module.exports = MBTiles;
|
||||
MBTiles.utils = require('./utils');
|
||||
MBTiles.schema = fs.readFileSync(__dirname + '/schema.sql', 'utf8');
|
||||
|
||||
// Provides access to an mbtiles database file.
|
||||
// - 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.
|
||||
// - @param {Function(err)} callback
|
||||
MBTiles.prototype._setup = function(callback) {
|
||||
var mbtiles = this;
|
||||
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);
|
||||
});
|
||||
});
|
||||
this._db.exec(MBTiles.schema, callback);
|
||||
};
|
||||
|
||||
// Select a tile from an mbtiles database. Scheme is XYZ.
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
-- MBTiles schema
|
||||
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS map (
|
||||
zoom_level INTEGER,
|
||||
tile_column INTEGER,
|
||||
@@ -70,3 +72,5 @@ CREATE VIEW IF NOT EXISTS grid_data AS
|
||||
FROM map
|
||||
JOIN grid_key ON map.grid_id = grid_key.grid_id
|
||||
JOIN keymap ON grid_key.key_name = keymap.key_name;
|
||||
|
||||
COMMIT;
|
||||
|
||||
Reference in New Issue
Block a user