@n1md7/indexeddb-promise
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "@n1md7/indexeddb-promise", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Indexed DB", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"minify": "browserify ./src/index.js -o ./dist/indexeddb-promise.min.js --standalone=indexedDBModel" | ||
}, | ||
@@ -13,4 +13,5 @@ "author": "Bitchiko Kodua", | ||
"db", | ||
"indexed-db" | ||
"indexed-db", | ||
"promise" | ||
] | ||
} |
124
README.md
@@ -1,2 +0,124 @@ | ||
# Indexed DB for any browser | ||
# Indexed DB with promises | ||
## Usage example | ||
```html | ||
<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 | ||
```javascript | ||
const { | ||
ModelConfig, | ||
Model | ||
} = indexedDBModel; | ||
// or | ||
const ModelConfig = indexedDBModel.ModelConfig; | ||
const Model = indexedDBModel.Model; | ||
``` | ||
### Create example config | ||
```javascript | ||
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 } | ||
} | ||
}; | ||
} | ||
} | ||
``` | ||
### Create connector | ||
```javascript | ||
const db = new Model(new Rooms); | ||
``` | ||
### Full example | ||
```html | ||
<html> | ||
<head> | ||
<title>IndexedDB app</title> | ||
<script src="./dist/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> | ||
``` | ||
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
33193
12
569
1
125
3