GithubHelp home page GithubHelp logo

williamragstad / lavastore.js Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 1.0 885 KB

LavaStore is a flexible and scalable local database for the web

Home Page: https://www.npmjs.com/package/lavastore

TypeScript 100.00%
lavastore firestore store storage data database local localstore localstorage localstorage-wrapper

lavastore.js's Introduction

LavaStore

A flexible and scalable local database for the web


NPM NPM
GitHub GitHub
NPM

About

LavaStore is a flexible and scalable local database for web development. It uses a document-oriented data model to store persistent data safely with our built-in powerful storage structure.

Features

  • Easy to learn
  • Intuitive data modeling structure inspired from Firestore (Firebase)
  • Simple and readable API
  • TypeScript types Support

Third-party extensions

  • Query Language Support
  • Asynchronous (in-progress)

Install

LavaStore can be installed using npm (or directly downloaded from the official GitHub repo).

npm i lavastore

View the project on NPM or GitHub.

Usage

Documents contains sub-collections and fields (data), and Collections contains sub-documents.

Always start with creating a new LavaStore('my_store') class and give it a unique ID. The next step is to either setup a store document and collection structure using either the InsurePath() method, or chained Add() methods. Alternatively, use SetPath() if you already have data to store in a specific subdocument.

The image below is an example of an Firestore structure which is easily replicable locally using LavaStore.

Structure

Here, spotify is a document containing no data but a users collection, where user-related data might be stored between sessions.

Data model

The way we store data using LavaStore is heavily inspired by the Cloud Firestore data model.

Unlike a SQL database, there are no tables or rows. Instead, you store data in documents, which are organized into collections.

Each document contains a set of key-value pairs. Cloud Firestore is optimized for storing large collections of small documents.

All documents must be stored in collections. Documents can contain subcollections and nested objects, both of which can include primitive fields like strings or complex objects like lists.

Read more about structuring data and data modeling from the Firebase documentation.

Examples

The code below initializes a new LavaStore document root called app. When first running this code in the browser, we'll see a empty object being logged, but after a reload it contains the data { value: "Test" }.

// TypeScript
import { LavaStore } from "lavastore";

const AppDocument = new LavaStore("app");

console.log(AppDocument.Get());

AppDocument.Set({
    value: "Test"
});

The true power of

Specification

Description Value
Package Size 24 kB
Semi-colons ~80

Public API

LavaStore

This is a regular LSDocument with the only exception that it strictly must be root of a Document/Collection tree.

LSDocument

class LSDocument {
    id: string;
    parent: LSCollection | undefined;
    Collection(id: string): LSCollection | undefined;
    Contains(id: string): boolean;
    Add(collection: LSCollection): void;
    Remove(id: string): void;
    InsurePath(path: string | string[]): void;
    Load(): void;
    Save(): void;
    Set(data: object): void;
    Get(): object;
    HasData(): boolean;
    SetPath(path: string | string[], data: object): void;
    GetPath(path: string | string[]): object;
    CollectionPath(path: string | string[]): LSCollection;
    DocumentPath(path: string | string[]): LSDocument;
    PassTo(callback: ((data: object) => any)): void;
}

LSCollection

class LSCollection {
    id: string;
    parent: LSDocument | undefined;
    Contains(id: string): boolean;
    Document(id: string): LSDocument | undefined;
    Add(document: LSDocument): void;
    Remove(id: string): void;
}

Want to help?

All help is very much appreciated! You can fork the repo right now and start building your own modified version right away, and if you happen to create something interesting and useful, don't hesitate to file a pull request!

Sponsor this project

You can also help by supporting the project financially, all gifts are appreciated with great reverence and gratitude.

Developer: paypal.me/williamragstad

lavastore.js's People

Contributors

williamragstad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

alexlaforge

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.