browser-base

A tool to help developer store data ofline on browser

MIT License

Downloads
575
Stars
2

Browser base

BrowserBase is a TypeScript-based tool designed to work with offline data in the browser. It provides an easy-to-use interface for storing and managing data in the browser's IndexedDB database, making it simple to handle offline storage efficiently.

Browser base build on top LocalForage.

and browser base inspire by localbase.

Badges

Getting Started

// run for instalation
npm i @sdewa/browser-base

create database and the collection

// create database instance
let browserBase new BrowserBase("first-db");

// create an interface of data
interface user {
  name: string;
  age: number;
}
// create the collection
browserBase.collection<user>("user-collection");

//the broser base will store data on 'user collection',
//if you don't pass a key on the key param its will generate uuid
browserBase.collection<user>("user-collection").add({
    name: "some name",
    age:10
}, "some key")

// {name: "somename", age:10, _id: "some key"}

//recomended to not pass anything on the key param
//so the data guaranted to be unique
browserBase.collection<user>("user-collection").add({
    name: "some name",
    age:10
})

// {name: "somename", age:10, _id: "<uuid>"}

query the data

//use get will query all data on the collection
browserBase.collection<user>("user-collection").get()
//[
//  {name: "somename", age:10, _id: "<uuid>"}
//  {name: "somename", age:10, _id: "<uuid>"}
//  {name: "somename", age:10, _id: "<uuid>"}
//]

//it's can alos use by specify the key will query
browserBase.collection<user>("user-collection".).byId('<uuid>').get()
//{name: "somename", age:10, _id: "<uuid>"}

//browserbase also have limit and skip interface
browserBase.collection<user>("user-collection".).limit(5).skip(5).get();
//[
//  {name: "somename", age:10, _id: "<uuid>"}
//  {name: "somename", age:10, _id: "<uuid>"}
//  {name: "somename", age:10, _id: "<uuid>"}
//]

//browser base alos have interface ot order the data
browserBase.collection<user>("user-collection".)
            .orderBy("age", "desc").get();
//[
//  {name: "somename", age:3, _id: "<uuid>"}
//  {name: "somename", age:2, _id: "<uuid>"}
//  {name: "somename", age:1, _id: "<uuid>"}
//]

update the data

//use set to update the data
browserBase.collection<user>("user-collection").byId("<uuid>").set({
  name: "new name",
  age: 11,
});
//  {name: "new name", age:11, _id: "<uuid>"}

delete data

//it will delete data match the id
browserBase.collection<user>("user-collection").byId("<uuid>").delete();

//it will delete the collection
browserBase.collection<user>("user-collection").delete();

//it will delete the database
browserBase.delete();

Authors

License

MIT

Package Rankings
Top 31.71% on Npmjs.org
Badges
Extracted from project README
MIT License