Comparing version 0.5.1 to 0.5.2
28
db64.js
const { isArray } = Array | ||
const err = console.error | ||
const openDBErrMessage = e => err(`Error creating database: ${e}`) | ||
const setDataError = e => err('Error setting data', e) | ||
const getDataError = e => err('Error retrieving data', e) | ||
let lastDBName | ||
let lastStoreName | ||
const openDB = (name = 'default', storeNames) => new Promise((resolve, reject) => { | ||
@@ -13,3 +8,3 @@ let db | ||
} catch (e) { | ||
reject(openDBErrMessage) | ||
reject(e) | ||
} | ||
@@ -108,4 +103,3 @@ | ||
if(!isArray(storeNames)) return console.error('storeNames should be an array') | ||
lastDBName = name | ||
lastStoreName = storeNames[0] | ||
await openDB(name, storeNames, hasDBandStores) | ||
@@ -116,4 +110,2 @@ return db64 | ||
if(!hasDBandStores) return console.error('A database and store needs to be created first') | ||
lastDBName = name | ||
lastStoreName = storeName | ||
@@ -127,11 +119,11 @@ return { | ||
.then(db => setData(db, storeName, null, value, 'entries')) | ||
.catch(setDataError) | ||
.catch(console.error) | ||
, | ||
get: async key => openDB(name, storeName) | ||
.then(db => getData(db, storeName, key)) | ||
.catch(getDataError) | ||
.catch(console.error) | ||
, | ||
getEntries: async (keys) => openDB(name, storeName) | ||
.then(db => getData(db, storeName, keys, 'entries')) | ||
.catch(getDataError) | ||
.catch(console.error) | ||
, | ||
@@ -142,3 +134,2 @@ delete: async (keys) => openDB(name, storeName) | ||
} | ||
}, | ||
@@ -150,9 +141,2 @@ clear: async (name, storeName) => openDB(name, storeName) | ||
// const getLastDBandStore = () => db64.use(lastDBName,lastStoreName) | ||
// db64.set = (key, value) => getLastDBandStore().set(key, value) | ||
// db64.setEntries = entries => getLastDBandStore().setEntries(entries) | ||
// db64.get = key => getLastDBandStore().get(key) | ||
// db64.getEntries = entries => getLastDBandStore().getEntries(entries) | ||
// db64.delete = keys => getLastDBandStore().delete(keys) | ||
export default db64 |
{ | ||
"name": "db64", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "A Practical IndexedDB API", | ||
@@ -5,0 +5,0 @@ "main": "db64.js", |
@@ -94,3 +94,3 @@ # db64 | ||
**Clear a store** _(string, string)_ | ||
```javascirpt | ||
```javascript | ||
await db64.clear('game-consoles', 'n64') // All data in n64 is deleted | ||
@@ -97,0 +97,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9669
132