add putInfo method
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user