Compare commits

..

8 Commits

Author SHA1 Message Date
ef141659e2 1.0.6 2020-07-11 16:26:36 +00:00
0b3dec53dd fix(core): update 2020-07-11 16:26:35 +00:00
1d5cb914ac 1.0.5 2020-07-09 23:03:47 +00:00
ce7a457509 fix(core): update 2020-07-09 23:03:46 +00:00
89875393ef 1.0.4 2020-07-09 23:03:02 +00:00
fe2c6f312b fix(core): update 2020-07-09 23:03:01 +00:00
905238a962 1.0.3 2020-07-09 22:39:36 +00:00
e7cd65fbae fix(core): update 2020-07-09 22:39:35 +00:00
4 changed files with 61 additions and 7 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/webstore", "name": "@pushrocks/webstore",
"version": "1.0.2", "version": "1.0.6",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/webstore", "name": "@pushrocks/webstore",
"version": "1.0.2", "version": "1.0.6",
"private": false, "private": false,
"description": "high performance storage in the browser using indexed db", "description": "high performance storage in the browser using indexed db",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -8,8 +8,8 @@
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/ --web)",
"build": "(tsbuild)", "build": "(tsbuild --web)",
"format": "(gitzone format)" "format": "(gitzone format)"
}, },
"devDependencies": { "devDependencies": {

View File

@ -1,11 +1,25 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@pushrocks/tapbundle';
import * as webstore from '../ts/index'; import * as webstore from '../ts/index';
let testWebstore = new webstore.WebStore(); let testWebstore: webstore.WebStore;
tap.test('first test', async () => { tap.test('first test', async () => {
testWebstore = new webstore.WebStore(); testWebstore = new webstore.WebStore({
dbName: 'mytestdb',
storeName: 'myteststore'
});
expect(testWebstore).to.be.instanceOf(webstore.WebStore); expect(testWebstore).to.be.instanceOf(webstore.WebStore);
}); });
tap.test('should init the database', async () => {
await testWebstore.init();
});
tap.test('should store a value', async () => {
await testWebstore.set('testProp1', {
wow: 'wowVal'
});
console.log(JSON.stringify(await testWebstore.get('testProp1')));
});
tap.start(); tap.start();

View File

@ -1,5 +1,45 @@
import * as plugins from './webstore.plugins'; import * as plugins from './webstore.plugins';
export class WebStore { export interface IWebStoreOptions {
dbName: string;
storeName: string;
}
export class WebStore<T = any> {
public db: plugins.idb.IDBPDatabase;
public objectStore: plugins.idb.IDBPObjectStore;
public options: IWebStoreOptions;
constructor(optionsArg: IWebStoreOptions) {
this.options = optionsArg;
}
public async init () {
this.db = await plugins.idb.openDB(this.options.dbName, 1, {
upgrade: (db) => {
db.createObjectStore(this.options.storeName);
},
});
}
async get(key) {
return this.db.get(this.options.storeName, key);
}
async set(key, val) {
return this.db.put(this.options.storeName, val, key);
}
async delete(key) {
return this.db.delete(this.options.storeName, key);
}
async clear() {
return this.db.clear(this.options.storeName);
}
async keys() {
return this.db.getAllKeys(this.options.storeName);
}
} }