Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jinhduong/phodb

phodb - a simple chrome extension storage database
https://github.com/jinhduong/phodb

chrome-extension database-adapter storage-engine typescript-library

Last synced: 8 days ago
JSON representation

phodb - a simple chrome extension storage database

Awesome Lists containing this project

README

        

# phodb

![](https://api.travis-ci.org/jinhduong/phodb.svg?branch=dev)

[![](https://badge.fury.io/js/phodb.svg)](https://www.npmjs.com/package/phodb)

## Simplest database interface for chrome extension storage

- Simple built-in methods
- Faster with storage cached of table
- Support UUID
- Support @types
- Can extend for other simple storages

## Usage

```
npm i phodb -S
```

```ts
import { ChromeExtDb } from "phodb";

const db = new ChromeExtDb();
const peopleTable = db.table("people");

peopleTable.where(x => !!x).then(res => console.log(res));
peopleTable
.findOne(x => new Date(x.createdAt) < new Date())
.then(res => console.log(res));
```

## Documents

```ts
class ChromeExtDb implements IPhoDb {
constructor(options?: {
setFunc: (localData: any) => void;
getFunc: (callback: (data: any) => void) => void;
});
table(name: string): ITable;
}

class ChromeExtTable implements ITable {
constructor(
name: string,
setFunc: (localData: any) => void,
getFunc: (res: any) => void
);
add(model: T): Promise;
remove(id: string): Promise;
update(id: string, model: T & BaseModel): Promise;
findOne(pre: (model: T & BaseModel) => boolean): Promise;
where(pre: (model: T & BaseModel) => boolean): Promise<(T & BaseModel)[]>;
list(): Promise<(T & BaseModel)[]>;
getName(): string;
}

interface BaseModel {
id: string;
createdAt: number;
updateAt: number;
}
```

## Browser & js built file
https://github.com/jinhduong/phodb/blob/master/build/release/phodb.chrome.js
```js
var peopleTable = ChromeExt.table("people");
```