Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/jinhduong/phodb
- Owner: jinhduong
- Created: 2019-05-11T15:15:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-05-14T02:11:18.000Z (over 5 years ago)
- Last Synced: 2024-10-13T13:23:12.085Z (2 months ago)
- Topics: chrome-extension, database-adapter, storage-engine, typescript-library
- Language: TypeScript
- Homepage: https://jinhduong.github.io/phodb/
- Size: 17.6 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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");
```