add putInfo method

This commit is contained in:
Konstantin Käfer
2011-07-18 19:45:17 +02:00
parent 64888c7e56
commit 1afaec43d7
2 changed files with 69 additions and 3 deletions

View File

@@ -602,3 +602,22 @@ MBTiles.prototype.putGrid = function(z, x, y, data, callback) {
if (++this._pending < 100) return this._commit(callback);
else return callback(null);
};
MBTiles.prototype.putInfo = function(data, callback) {
if (typeof callback !== 'function') throw new Error('Callback needed');
if (!this.open) return callback(new Error('MBTiles not yet loaded'));
if (!this._isWritable) return callback(new Error('MBTiles not in write mode'));
// Valid keys.
var keys = [ 'name', 'type', 'description', 'version', 'formatter',
'bounds', 'center', 'minzoom', 'maxzoom' ];
for (var key in data) {
if (keys.indexOf(key) < 0) return callback("Can't set key " + key);
}
var stmt = this._db.prepare('REPLACE INTO metadata (name, value) VALUES (?, ?)');
stmt.on('error', callback);
for (var key in data) {
stmt.run(key, String(data[key]));
}
stmt.finalize(callback);
};