0.0.10 • Published 5 years ago

@syrflover/simple-store v0.0.10

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

simply-store

Build Status

Installation

npm install @syrflover/simple-store

Usage

import { createStore } from '@syrflover/simple-store';

const store = createStore('./store.json');
// or use generic
const store = createStore<SomeObjectType>('./store.json');

store
    .initialize({ init: 'init' }) // if not exists store file, initialize store with init value
    .then(async () => {
        const read0 = await store.read();
        // { init: 'init' }

        // overwrite the store
        await store.write({ user: [{ id: 1, name: 'syr' }] });

        const read1 = await store.read();
        // { user: [{ id: 1, name: 'syr' }] }

        // overwrite the store
        await store.write({ post: [{ id: 1, content: 'content' }] });

        const read2 = await store.read();
        // { post: [{ id: 1, content: 'content' }] }
    })
    .catch(() => {
        // some error handle
    });