Add mbcheck.
This commit is contained in:
@@ -34,6 +34,17 @@ MBTiles.prototype.exists = function(table, callback) {
|
||||
}
|
||||
};
|
||||
|
||||
// DB integrity check.
|
||||
MBTiles.prototype.integrity = function(callback) {
|
||||
this.db.get('PRAGMA quick_check(1)', function(err, row) {
|
||||
if (!(row && row.integrity_check && row.integrity_check === 'ok')) {
|
||||
callback(new Error('Corrupted database.'));
|
||||
} else {
|
||||
callback(null, true);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Setup schema, indices, views for a new mbtiles database.
|
||||
// Sets the synchronous flag to OFF for (much) faster inserts.
|
||||
// See http://www.sqlite3.org/pragma.html#pragma_synchronous
|
||||
|
||||
21
lib/utils.js
Normal file
21
lib/utils.js
Normal file
@@ -0,0 +1,21 @@
|
||||
var utils = {};
|
||||
|
||||
utils.table = function(fields) {
|
||||
if (!fields[0]) return;
|
||||
var lengths = fields[0].map(function(val, i) {
|
||||
return Math.max.apply(Math, fields.map(function(field) {
|
||||
if (field[i] === undefined) field[i] = '';
|
||||
return field[i].toString().length;
|
||||
}));
|
||||
});
|
||||
fields.forEach(function(field) {
|
||||
console.warn(
|
||||
' ' + field.map(function(val, i) {
|
||||
if (i >= lengths.length - 1) return val;
|
||||
return val + Array(lengths[i] - val.toString().length + 1).join(' ');
|
||||
}).join(' ')
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = utils;
|
||||
Reference in New Issue
Block a user