Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
asyncTest("Dexie.getDatabaseNames", 13, function () {
var defaultDatabases = [];
var db1, db2;
Dexie.getDatabaseNames(function (names) {
defaultDatabases = [].slice.call(names, 0);
ok(true, "Current databases: " + (defaultDatabases.length ? defaultDatabases.join(',') : "(none)"));
db1 = new Dexie("TestDB1");
db1.version(1).stores({});
return db1.open();
}).then(function () {
// One DB created
ok(true, "TestDB1 successfully created");
return Dexie.getDatabaseNames();
}).then(function (names) {
equal(names.length, defaultDatabases.length + 1, "Another DB has been created");
ok(names.indexOf("TestDB1") !== -1, "Database names now contains TestDB1");
db2 = new Dexie("TestDB2");
db2.version(1).stores({});
return db2.open();
}).then(function () {
clearAllLocalData() {
// Clear indexedDb
Dexie.getDatabaseNames()
.then(names => {
names.forEach(name => {
const db = new Dexie(name);
db.delete().catch(() => {});
});
});
localStorage.clear();
}
}).then(function () {
return Dexie.getDatabaseNames();
}).then(function(names){
equal(names.length, defaultDatabases.length + 1, "A database has been deleted");
static async clearProjectDatabases() {
const dbNames = new Set(await Dexie.getDatabaseNames());
const projects = await (await JdxDatabase.getProjects()).toArray();
dbNames.delete(JdxDatabase.GLOBAL_DB_NAME);
projects.forEach(project => {
dbNames.delete(this.projectToDbName(project));
});
dbNames.forEach(dbName => {
console.log('Deleting ' + dbName);
Dexie.delete(dbName);
});
}
export const getUsernames = async () => {
let dbs = await Dexie.getDatabaseNames()
return dbs.filter(dbname => dbname.startsWith('userdata_')).map(dbname => dbname.replace('userdata_', ''))
}
static async getAllDatabases() {
return Dexie.getDatabaseNames();
}