Fix tools. Refs #4.
This commit is contained in:
+12
-12
@@ -23,29 +23,29 @@ if (argv.help || argv._.length === 0) {
|
|||||||
|
|
||||||
Step(
|
Step(
|
||||||
function() { mbtiles = new MBTiles(argv._[0], this); },
|
function() { mbtiles = new MBTiles(argv._[0], this); },
|
||||||
function() { mbtiles.integrity(this); },
|
function() { mbtiles._integrity(this); },
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
mbtiles.exists('tiles', function(err, exists) {
|
mbtiles._exists('tiles', function(err, exists) {
|
||||||
if (!exists) throw new Error('`tiles` table does not exist.');
|
if (!exists) throw new Error('`tiles` table does not exist.');
|
||||||
this();
|
this();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
mbtiles.exists('metadata', function(err, exists) {
|
mbtiles._exists('metadata', function(err, exists) {
|
||||||
if (!exists) throw new Error('`metadata` table does not exist.');
|
if (!exists) throw new Error('`metadata` table does not exist.');
|
||||||
this();
|
this();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
mbtiles.metadata('name', this.parallel());
|
mbtiles._metadata('name', this.parallel());
|
||||||
mbtiles.metadata('type', this.parallel());
|
mbtiles._metadata('type', this.parallel());
|
||||||
mbtiles.metadata('desciption', this.parallel());
|
mbtiles._metadata('desciption', this.parallel());
|
||||||
mbtiles.metadata('version', this.parallel());
|
mbtiles._metadata('version', this.parallel());
|
||||||
mbtiles.metadata('format', this.parallel());
|
mbtiles._metadata('format', this.parallel());
|
||||||
mbtiles.metadata('bounds', this.parallel());
|
mbtiles._metadata('bounds', this.parallel());
|
||||||
},
|
},
|
||||||
function(err, name, type, description, version, format, bounds) {
|
function(err, name, type, description, version, format, bounds) {
|
||||||
console.warn('Metadata');
|
console.warn('Metadata');
|
||||||
@@ -64,7 +64,7 @@ Step(
|
|||||||
Step(
|
Step(
|
||||||
function() {
|
function() {
|
||||||
var group = this.group(),
|
var group = this.group(),
|
||||||
query = mbtiles.db.prepare(
|
query = mbtiles._db.prepare(
|
||||||
'SELECT zoom_level AS zoom, ' +
|
'SELECT zoom_level AS zoom, ' +
|
||||||
'COUNT(zoom_level) AS count ' +
|
'COUNT(zoom_level) AS count ' +
|
||||||
'FROM tiles ' +
|
'FROM tiles ' +
|
||||||
@@ -95,7 +95,7 @@ Step(
|
|||||||
Step(
|
Step(
|
||||||
function() {
|
function() {
|
||||||
var group = this.group(),
|
var group = this.group(),
|
||||||
query = mbtiles.db.prepare(
|
query = mbtiles._db.prepare(
|
||||||
'SELECT MAX(tile_column) AS maxx, ' +
|
'SELECT MAX(tile_column) AS maxx, ' +
|
||||||
'MIN(tile_column) AS minx, ' +
|
'MIN(tile_column) AS minx, ' +
|
||||||
'MAX(tile_row) AS maxy, ' +
|
'MAX(tile_row) AS maxy, ' +
|
||||||
@@ -113,7 +113,7 @@ Step(
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
var group = this.group(),
|
var group = this.group(),
|
||||||
query = mbtiles.db.prepare(
|
query = mbtiles._db.prepare(
|
||||||
'SELECT zoom_level AS zoom, ' +
|
'SELECT zoom_level AS zoom, ' +
|
||||||
'COUNT(zoom_level) AS count, ' +
|
'COUNT(zoom_level) AS count, ' +
|
||||||
'? AS expected ' +
|
'? AS expected ' +
|
||||||
|
|||||||
+11
-11
@@ -28,7 +28,7 @@ Step(
|
|||||||
function() { mbtiles = new MBTiles(filename, this); },
|
function() { mbtiles = new MBTiles(filename, this); },
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
mbtiles.db.all('SELECT name, type '
|
mbtiles._db.all('SELECT name, type '
|
||||||
+ 'FROM sqlite_master '
|
+ 'FROM sqlite_master '
|
||||||
+ 'WHERE type IN (?, ?)',
|
+ 'WHERE type IN (?, ?)',
|
||||||
'table',
|
'table',
|
||||||
@@ -47,13 +47,13 @@ Step(
|
|||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
mbtiles.setup(this);
|
mbtiles._setup(this);
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
mbtiles.db.get('SELECT COUNT(*) AS total FROM tiles', this.parallel());
|
mbtiles._db.get('SELECT COUNT(*) AS total FROM tiles', this.parallel());
|
||||||
mbtiles.db.run('PRAGMA locking_mode=EXCLUSIVE', this.parallel());
|
mbtiles._db.run('PRAGMA locking_mode=EXCLUSIVE', this.parallel());
|
||||||
mbtiles.db.run('PRAGMA journal_mode=TRUNCATE', this.parallel());
|
mbtiles._db.run('PRAGMA journal_mode=TRUNCATE', this.parallel());
|
||||||
},
|
},
|
||||||
function(err, row) {
|
function(err, row) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@@ -64,7 +64,7 @@ Step(
|
|||||||
var done = this;
|
var done = this;
|
||||||
var doit = function(limit, offset) {
|
var doit = function(limit, offset) {
|
||||||
process.nextTick(function() {
|
process.nextTick(function() {
|
||||||
mbtiles.db
|
mbtiles._db
|
||||||
.prepare('SELECT tile_data AS tile_data, zoom_level AS z, tile_column AS x, tile_row AS y FROM tiles LIMIT ? OFFSET ?')
|
.prepare('SELECT tile_data AS tile_data, zoom_level AS z, tile_column AS x, tile_row AS y FROM tiles LIMIT ? OFFSET ?')
|
||||||
.all(limit, offset, function(err, rows) {
|
.all(limit, offset, function(err, rows) {
|
||||||
var images = [];
|
var images = [];
|
||||||
@@ -92,8 +92,8 @@ Step(
|
|||||||
}
|
}
|
||||||
Step(
|
Step(
|
||||||
function() {
|
function() {
|
||||||
mbtiles.insert('images', images, this.parallel());
|
mbtiles._insert('images', images, this.parallel());
|
||||||
mbtiles.insert('map', map, this.parallel());
|
mbtiles._insert('map', map, this.parallel());
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@@ -123,17 +123,17 @@ Step(
|
|||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
mbtiles.db.run('DROP TABLE tiles', this);
|
mbtiles._db.run('DROP TABLE tiles', this);
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
mbtiles.db.run('CREATE VIEW IF NOT EXISTS tiles AS '
|
mbtiles._db.run('CREATE VIEW IF NOT EXISTS tiles AS '
|
||||||
+ 'SELECT map.zoom_level AS zoom_level, '
|
+ 'SELECT map.zoom_level AS zoom_level, '
|
||||||
+ 'map.tile_column AS tile_column, '
|
+ 'map.tile_column AS tile_column, '
|
||||||
+ 'map.tile_row AS tile_row, '
|
+ 'map.tile_row AS tile_row, '
|
||||||
+ 'images.tile_data AS tile_data '
|
+ 'images.tile_data AS tile_data '
|
||||||
+ 'FROM map JOIN images ON images.tile_id = map.tile_id;', this.parallel());
|
+ 'FROM map JOIN images ON images.tile_id = map.tile_id;', this.parallel());
|
||||||
mbtiles.db.run('VACUUM', this.parallel());
|
mbtiles._db.run('VACUUM', this.parallel());
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|||||||
+11
-11
@@ -36,22 +36,22 @@ Step(
|
|||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
Step(
|
Step(
|
||||||
function() { mbtiles.db.run('PRAGMA synchronous=0', this); },
|
function() { mbtiles._db.run('PRAGMA synchronous=0', this); },
|
||||||
function() { mbtiles.db.run('PRAGMA locking_mode=EXCLUSIVE', this); },
|
function() { mbtiles._db.run('PRAGMA locking_mode=EXCLUSIVE', this); },
|
||||||
function() { mbtiles.db.run('PRAGMA journal_mode=TRUNCATE', this); },
|
function() { mbtiles._db.run('PRAGMA journal_mode=TRUNCATE', this); },
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
mbtiles.exists('tiles', function(err, exists) {
|
mbtiles._exists('tiles', function(err, exists) {
|
||||||
if (exists) table = 'tiles';
|
if (exists) table = 'tiles';
|
||||||
this();
|
this();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
mbtiles.exists('images', function(err, exists) {
|
mbtiles._exists('images', function(err, exists) {
|
||||||
if (exists) table = 'images';
|
if (exists) table = 'images';
|
||||||
this();
|
this();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
@@ -59,7 +59,7 @@ Step(
|
|||||||
function(err) {
|
function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
if (!table) throw new Error('No usable image table found.');
|
if (!table) throw new Error('No usable image table found.');
|
||||||
mbtiles.db.get('SELECT COUNT(tile_data) AS total FROM ' + table, function(err, row) {
|
mbtiles._db.get('SELECT COUNT(tile_data) AS total FROM ' + table, function(err, row) {
|
||||||
total = row.total;
|
total = row.total;
|
||||||
this();
|
this();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
@@ -73,8 +73,8 @@ Step(
|
|||||||
var doit = function(table, limit, offset) {
|
var doit = function(table, limit, offset) {
|
||||||
process.nextTick(function() {
|
process.nextTick(function() {
|
||||||
var query = table === 'images'
|
var query = table === 'images'
|
||||||
? mbtiles.db.prepare('SELECT tile_data AS tile_data, tile_id AS id FROM images ORDER BY tile_id ASC LIMIT ? OFFSET ?')
|
? mbtiles._db.prepare('SELECT tile_data AS tile_data, tile_id AS id FROM images ORDER BY tile_id ASC LIMIT ? OFFSET ?')
|
||||||
: mbtiles.db.prepare('SELECT tile_data AS tile_data, zoom_level AS z, tile_column AS x, tile_row AS y FROM tiles ORDER BY z, x, y LIMIT ? OFFSET ?');
|
: mbtiles._db.prepare('SELECT tile_data AS tile_data, zoom_level AS z, tile_column AS x, tile_row AS y FROM tiles ORDER BY z, x, y LIMIT ? OFFSET ?');
|
||||||
query.all(limit, offset, function(err, rows) {
|
query.all(limit, offset, function(err, rows) {
|
||||||
Step(
|
Step(
|
||||||
function() {
|
function() {
|
||||||
@@ -95,14 +95,14 @@ Step(
|
|||||||
child.on('exit', function(code) {
|
child.on('exit', function(code) {
|
||||||
if (code) return callback(null, null);
|
if (code) return callback(null, null);
|
||||||
if (table === 'images') {
|
if (table === 'images') {
|
||||||
mbtiles.db.run(
|
mbtiles._db.run(
|
||||||
'INSERT OR REPLACE INTO images (tile_id, tile_data) VALUES(?, ?)',
|
'INSERT OR REPLACE INTO images (tile_id, tile_data) VALUES(?, ?)',
|
||||||
row.id,
|
row.id,
|
||||||
row.piped,
|
row.piped,
|
||||||
callback
|
callback
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
mbtiles.db.run(
|
mbtiles._db.run(
|
||||||
'INSERT OR REPLACE INTO tiles (zoom_level, tile_column, tile_row, tile_data) VALUES(?, ?, ?, ?)',
|
'INSERT OR REPLACE INTO tiles (zoom_level, tile_column, tile_row, tile_data) VALUES(?, ?, ?, ?)',
|
||||||
row.z,
|
row.z,
|
||||||
row.x,
|
row.x,
|
||||||
@@ -126,7 +126,7 @@ Step(
|
|||||||
if (rows.length === limit) {
|
if (rows.length === limit) {
|
||||||
doit(table, limit, offset + limit);
|
doit(table, limit, offset + limit);
|
||||||
} else {
|
} else {
|
||||||
mbtiles.db.run('VACUUM', function() {
|
mbtiles._db.run('VACUUM', function() {
|
||||||
sys.print('\n');
|
sys.print('\n');
|
||||||
console.warn('Pipe complete.');
|
console.warn('Pipe complete.');
|
||||||
done();
|
done();
|
||||||
|
|||||||
Reference in New Issue
Block a user