Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/dewasry/browser-base

A tool to help developer store data ofline on browser
https://github.com/dewasry/browser-base

angular borwser data indexeddb nextjs orm query react typescript vite vue

Last synced: 3 months ago
JSON representation

A tool to help developer store data ofline on browser

Awesome Lists containing this project

README

        

# 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](https://github.com/localForage/localForage).

and browser base inspire by [localbase](https://github.com/samuk190/localbase).

## Badges

[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)

## Getting Started

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

create database and the collection

```typescript
// 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-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-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-collection").add({
name: "some name",
age:10
})

// {name: "somename", age:10, _id: ""}
```

query the data

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

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

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

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

update the data

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

delete data

```typescript
//it will delete data match the id
browserBase.collection("user-collection").byId("").delete();

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

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

## Authors

- [@DewaSRY](https://github.com/DewaSRY)

## License

[MIT](https://choosealicense.com/licenses/mit/)