Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LocalStorm

An ORM for window.localStorage which no one asked for.

Downloads on npm

Installation

npm install @shubhodeep9/localstorm

Usage

import { Model, Schema } from '@shubhodeep9/localstorm';

const UserSchema = new Schema({
    id: {
        required: true, // validates the field as mandatory
        type: Number
    },
    name: {
        required: true,
        type: String
    },
    phone: {
        required: true,
        type: String
    },
    hobbies: Array // will assume field as optional
});

const UserStore = Model('user', UserSchema);

// to save an entry
UserStore.save({
    id: 123,
    name: "Shubho",
    phone: "91xxxxx934",
    hobbies: ['sleeping']
});

// if you want to bypass validations
UserStore.save({
    id: 123,
    name: "Shubho",
    phone: "91xxxxx934",
    hobbies: ['sleeping']
}, true) // pass skipValidation as true

// to retrieve
const response = UserStore.get();

// to flush the key
UserStore.flush();

// hooks
UserSchema.pre('save', (saveObj) => {
    // will be executed before saving
    // do something with saveObj
})

UserSchema.post('save', (saveObj) => {
    // will be executed post saving
    // do something with saveObj
})

To-Do

  • Global Store fetch and flush
  • Dynamic Schema
  • Triggers
    • Pre and Post Save
    • Pre and Post Flush
    • Pre and Post validate
    • Async hooks

About

A local storage ORM which no one asked for

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages