
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
indexeddb-crud
Advanced tools
indexedDB-CRUD packs obscure indexedDB CRUD methods to a really friendly succinct interface. And offer multi-objectStore CRUD handler.
If you want to operate one or more indexedDB objectStore, just DB.open(config).then(successCallback).catch(), and you'll get a indexedDB-crud handler when its DB.open successed.
Hope you keep in mind that:
config's format should be correctstoreName explicitly in API, your config's first sotreName will be the default storeNamenpm install indexeddb-crud --save
yarn add indexeddb-crud
Only you open it, you can use these synchronous&asynchronous API.
indexeddb-crud support for the ES6 Promises API, so you can use then & catch carefree.
get:
add:
remove:
update:
var DB = require('indexeddb-crud');
// or ES6
import DB from 'indexeddb-crud';
key = 0 is just for demo, we only use key >= 1, so we usually begain at key = 1you must have a key(number type), in this following code key is id)config = {
"name": '',
"version": '',
"storeConfig": [
{
"storeName": '',
"key": '',
"storeConfig": [
// must have key property, number type
]
},
// one or more storeConfig object
]
}
correct config just like this:
var DBConfig = {
"name": "JustToDo",
"version": 23,
"storeConfig": [
{
"storeName": "list",
"key": "id",
"initialData": [
{ "id": 0, "event": "JustDemo", "finished": true } // just for demo, not actual use
]
}
]
};
If you need more than 1 ObjectStore:
var DBConfig = {
"name": "JustToDo",
"version": 23,
"storeConfig": [
{
"storeName": "list",
"key": "id",
"initialData": [
{ "id": 1, "event": "JustDemo", "finished": true }
]
},
{
"storeName": "aphorism",
"key": "id",
"initialData": [
{
"id": 1,
"content": "You're better than that"
},
{
"id": 2,
"content": "Yesterday You Said Tomorrow"
}
]
}
]
}
e.g. successCallback:
function addEvents() {
querySelector('#test').addEventlistener('click', clickHandler, false);
}
function clickHandler() {
console.log('test');
}
DB.open(config).then(addEvents);
// If you have only 1 objectSotre, suggest use the default storeName
var randomIndex = Math.floor(DB.getLength() * Math.random());
// or pass storeName explicitly
var storeName = 'list';
var randomIndex = Math.floor(DB.getLength(storeName) * Math.random());
// If you have only 1 objectSotre, suggest use the default storeName
DB.getNewKey();
// or pass storeName explicitly
var storeName = 'list';
DB.getNewKey(storeName);
You will need it in addItem().
function doSomething(data) {
console.log(data);
}
// If you have only 1 objectSotre, suggest use the default storeName
DB.getItem(1).then(doSomething);
// or pass storeName explicitly
var storeName = 'list';
DB.getItem(1, storeName).then(doSomething);
Boolean typecondition should be a boolean-condition, for example:var DBConfig = {
"name": "JustToDo",
"version": 23,
"storeConfig": [
{
"storeName": "list",
"key": "id",
"initialData": [
{ "id": 0, "event": "JustDemo", "finished": true } // just for demo, not actual use
]
}
]
};
// If you have only 1 objectSotre, suggest use the default storeName
DB.getConditionItem('finished', false).then(doSomething);
// or pass storeName explicitly
var storeName = 'list';
DB.getConditionItem('finished', false,storeName).then(doSomething);
function doSomething(dataArr) {
console.log(dataArr);
}
// If you have only 1 objectSotre, suggest use the default storeName
DB.getAll(doSomething);
// or pass storeName explicitly
var storeName = 'list';
DB.getAll(doSomething, storeName);
e.g.
var data = {
"id": DB.getNewKey(storeName),
"event": 'play soccer',
"finished": false
};
// If you have only 1 objectSotre, suggest use the default storeName
DB.addItem(data);
// or pass storeName explicitly
var storeName = 'list';
DB.addItem(data, storeName);
// If you have only 1 objectSotre, suggest use the default storeName
DB.removeItem(1).then(doSomething);
// or pass storeName explicitly
var storeName = 'list';
DB.removeItem(1, storeName).then(doSomething);
condition should be a boolean-condition, for example:var DBConfig = {
"name": "JustToDo",
"version": 23,
"storeConfig": [
{
"storeName": "list",
"key": "id",
"initialData": [
{ "id": 0, "event": "JustDemo", "finished": true } // just for demo, not actual use
]
}
]
};
// If you have only 1 objectSotre, suggest use the default storeName
DB.removeConditionItem('true').then(successCallback);
// or pass storeName explicitly
var storeName = 'list';
DB.removeConditionItem('true', storeName).then(successCallback);
// If you have only 1 objectSotre, suggest use the default storeName
DB.clear().then(doSomething);
// or pass storeName explicitly
var storeName = 'list';
DB.clear(storeName).then(doSomething);
var DBConfig = {
"name": "JustToDo",
"version": 23,
"storeConfig": [
{
"storeName": "list",
"key": "id",
"initialData": [
{ "id": 0, "event": "JustDemo", "finished": true } // just for demo, not actual use
]
}
]
};
// If you have only 1 objectSotre, suggest use the default storeName
DB.updateItem(newData).then(doSomething);
// or pass storeName explicitly
var storeName = 'list';
DB.updateItem(newData, storeName).then(doSomething);
a simple todolist web-app, storage data in indexedDB (use indexeddb-crud to handler 2 different objectStores): https://github.com/RayJune/JustToDo/blob/gh-pages/src/scripts/main.js
RayJune: a CS university student from Fuzhou, Fujian, China
MIT
FAQs
pack complex indexedDB CRUD methods to a friendly simple interface
We found that indexeddb-crud demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.