Add mbcheck.

This commit is contained in:
Young Hahn
2011-05-19 14:42:17 -04:00
parent c31d820313
commit 528fdf2625
5 changed files with 197 additions and 0 deletions

View File

@@ -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
View 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;