GithubHelp home page GithubHelp logo

jinhduong / phodb Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 18 KB

phodb - a simple chrome extension storage database

Home Page: https://jinhduong.github.io/phodb/

JavaScript 6.38% TypeScript 93.62%
chrome-extension storage-engine database-adapter typescript-library

phodb's Introduction

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
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

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

class ChromeExtTable<T> implements ITable<T> {
  constructor(
    name: string,
    setFunc: (localData: any) => void,
    getFunc: (res: any) => void
  );
  add(model: T): Promise<T & BaseModel>;
  remove(id: string): Promise<boolean>;
  update(id: string, model: T & BaseModel): Promise<T & BaseModel | null>;
  findOne(pre: (model: T & BaseModel) => boolean): Promise<T & BaseModel>;
  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

var peopleTable = ChromeExt.table("people");

phodb's People

Contributors

jinhduong avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.