0.0.7 • Published 1 year ago

@shubhodeep9/localstorm v0.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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
0.0.5

1 year ago

0.0.4

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago