blob: ee958ace1b113199c8d58916491fabf8d9ed9a60 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
const idb = require("@isomorphic-git/idb-keyval");
module.exports = class IdbBackend {
constructor(dbname, storename) {
this._database = dbname;
this._storename = storename;
this._store = new idb.Store(this._database, this._storename);
}
saveSuperblock(superblock) {
return idb.set("!root", superblock, this._store);
}
loadSuperblock() {
return idb.get("!root", this._store);
}
readFile(inode) {
return idb.get(inode, this._store);
}
writeFile(inode, data) {
return idb.set(inode, data, this._store);
}
unlink(inode) {
return idb.del(inode, this._store);
}
wipe() {
return idb.clear(this._store);
}
close() {
return idb.close(this._store);
}
};