Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
@n1md7/indexeddb-promise
Advanced tools
npm install @n1md7/indexeddb-promise --save
Gets all the data from db and returns promise with response data
Has one parameter pkey
as primaryKey and returns promise with data
Has one parameter props
which can be
props = {
limit: 10,
where: (dataArray) => {return dataArray},
orderByDESC: true,
sortBy: 'comments'// ['comments', 'date']
}
@where property can filter out data
like where: data => data.filter(dt.username === 'admin')
Has two parameters pkey
and keyValue
pair of updated data
.updateWhere(123, {username: 'admin'})
Has one parameter pKey
which record to delete based on primary key
note primary key is type sensitive. If it is saved as integer then should pass as integer and vice versa
<html>
<head>
<title>IndexedDB app</title>
<script src="./dist/indexeddb-promise.min.js"></script>
</head>
<body>
<script>
// Your script here
</script>
</body>
</html>
Once you add indexeddb-promise.min.js in your document then you will be able to access
indexedDBModel
variable globally which contains Model
and ModelConfig
.
They can be extracted as following
const {
ModelConfig,
Model
} = indexedDBModel;
// or
const ModelConfig = indexedDBModel.ModelConfig;
const Model = indexedDBModel.Model;
class Rooms extends ModelConfig{
//@overrides default method
get config() {
return {
version: 1,
databaseName: 'myNewDatabase',
tableName: 'myNewTable',
primaryKey: {
name: 'id',
autoIncrement: false
},
initData: [],
structure: {
roomId: { unique: false, autoIncrement: true },
roomName: { unique: false, autoIncrement: false },
comments: { unique: false, autoIncrement: false }
}
};
}
}
const db = new Model(new Rooms);
<html>
<head>
<title>IndexedDB app</title>
<script src="indexeddb-promise.min.js"></script>
</head>
<body>
<script>
const {
ModelConfig,
Model
} = indexedDBModel;
class Rooms extends ModelConfig{
//@overrides default method
get config() {
return {
version: 1,
databaseName: 'myNewDatabase',
tableName: 'myNewTable',
primaryKey: {
name: 'id',
autoIncrement: false
},
initData: [],
structure: {
roomId: { unique: false, autoIncrement: true },
roomName: { unique: false, autoIncrement: false },
comment: { unique: false, autoIncrement: false }
}
};
}
}
const db = new Model(new Rooms);
// add new record
db.insertData({
'id': Math.random() * 10,
'roomName': 'My room name',
'roomId': 1,
'comment': 'This room is awesome'
})
.then(function(){
//when done click update button
console.info('Yay, you have saved the data.');
}).catch(function(error){
console.error(error);
});
// Get all results from DB
db.selectAll()
.then(function(results){
console.log(...results);
});
</script>
</body>
</html>
FAQs
Indexed DB wrapper with promises
The npm package @n1md7/indexeddb-promise receives a total of 34 weekly downloads. As such, @n1md7/indexeddb-promise popularity was classified as not popular.
We found that @n1md7/indexeddb-promise demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.