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: about 1 month 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 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-14T02:11:18.000Z (over 6 years ago)
- Last Synced: 2025-09-24T05:18:40.458Z (about 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: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# phodb

[](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");
```