![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
@n1md7/indexeddb-promise
Advanced tools
Readme
npm install @n1md7/indexeddb-promise --save
# or
yarn add @n1md7/indexeddb-promise
or
<script src="https://bundle.run/@n1md7/indexeddb-promise@5.0.21"></script>
<script src="https://unpkg.com/@n1md7/indexeddb-promise@5.0.21/src/index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@n1md7/indexeddb-promise@5.0.21/dist/indexed-db.min.js"></script>
Gets all the data from db and returns promise with response data
Gets data from the 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
const props = {
limit: 10,
where: (dataArray) => {
return dataArray;
},
orderByDESC: true,
sortBy: 'comments', // ['comments', 'date']
};
@where property can filter out data like
const props = {
where: (data) => data.filter((item) => item.username === 'admin'),
};
or it can be an object, which gets data with AND(&&) comparison
const props = {
where: {
username: 'admin',
password: 'admin123',
},
};
Has two parameters pkey
and keyValue
pair of updated data
updateByPk(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/indexed-db.min.js"></script>
</head>
<body>
<script>
// Your script here
</script>
</body>
</html>
Once you add indexed-db.min.js in your document then you will be able to access
IndexedDBModel
variable globally which contains Model
. They can be extracted as following
const { Database } = IndexedDBModel;
// or
const Database = IndexedDBModel.Database;
const db = new IndexedDBModel.Database({
databaseVersion: 1,
databaseName: 'myNewDatabase',
tables: [
{
name: 'myNewTable',
primaryKey: {
name: 'id',
autoIncrement: false,
unique: true,
},
initData: [],
indexes: {
username: { unique: false, autoIncrement: false },
password: { unique: false, autoIncrement: false },
},
timestamps: true,
},
],
});
<html>
<head>
<title>IndexedDB app</title>
<script src="./dist/indexed-db.min.js"></script>
</head>
<body>
<script>
const db = new IndexedDBModel.Database({
databaseVersion: 1,
databaseName: 'myNewDatabase',
tables: [
{
name: 'myNewTable',
primaryKey: {
name: 'id',
autoIncrement: false,
unique: true,
},
initData: [],
indexes: {
username: { unique: false, autoIncrement: false },
password: { unique: false, autoIncrement: false },
},
},
],
});
// add a new record
const model = db.useModel('myNewTable');
model
.insert({
id: Math.random() * 10,
username: 'admin',
password: 'nimda',
createdAt: new Date(),
updatedAt: new Date(),
})
.then(function () {
console.info('Yay, you have saved the data.');
})
.catch(function (error) {
console.error(error);
});
// Get all results from the database
model.selectAll().then(function (results) {
console.log(...results);
});
</script>
</body>
</html>
const IndexedDBModel = require('@n1md7/indexeddb-promise');
const { Database } = IndexedDBModel;
// or
import { Database } from '@n1md7/indexeddb-promise';
Typescript example
import { Database } from '@n1md7/indexeddb-promise';
interface Users {
id?: number;
username: string;
password: string;
}
enum Priority {
LOW = 'LOW',
MEDIUM = 'MEDIUM',
HIGH = 'HIGH',
}
interface ToDos {
id?: number;
userId: number;
title: string;
description: string;
done: boolean;
priority: Priority;
}
const database = new Database({
version: 1,
name: 'Todo-list',
tables: [
{
name: 'users',
primaryKey: {
name: 'id',
autoIncrement: true,
unique: true,
},
indexes: {
username: {
unique: false,
},
},
timestamps: true,
},
{
name: 'todos',
primaryKey: {
name: 'id',
autoIncrement: true,
unique: true,
},
indexes: {
userId: {
unique: true,
},
},
timestamps: true,
},
],
});
(async () => {
const users = database.useModel<Users>('users');
await users.insert({
username: 'admin',
password: 'admin',
});
const todos = database.useModel<ToDos>('todos');
await todos.insert({
userId: user.id,
title: 'Todo 1',
description: 'Description 1',
done: false,
priority: Priority.LOW,
});
})();
FAQs
Indexed DB wrapper with promises
The npm package @n1md7/indexeddb-promise receives a total of 1 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
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.