rollun-ts-datastore
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

Coverage badge Coverage badge Coverage badge Coverage badge

rollun-ts-datastore

Basically rollun-datastore, but in TS. For now contains only HTTP Datastore. Supports either Node and Browser environment. Datastore clients use fetch and node-fetch for http requests.

Installation

preferred way to install this library is via npm. Run

npm install rollun-ts-datastore

or add

"rollun-ts-datastore": "*",

to the dependencies section of your package.json

Important to know

To query data from client.query() method from datastore, you need to use query object from rollun-ts-rql library.

Basic usage

import HttpDatastore from "rollun-ts-datastore/dist/HttpDatastore";
import {Query, And, Le, Ge} from "rollun-ts-rql";

// keep in mind, using HttpDatastore server side (node.js), 
// You MUST spesify absolute path to your api
const datastore = new HttpDatastore('my/users/datastore');

const newItem = {id: '123', name: 'Alex', age: 23};
//add item to store
datastore
    .create(newItem)
    .then((item) => {
        console.log(item);
        // will log newly created item
        // useful when using autogenerated IDs
    });

//read item from store
datastore
    .read('123')
    .then((item) => {
        // do something with item
        // ...
    })
    .catch((error) => {
        console.warn('an error occurred while reading from datastore', error)
    });

//update item (by id)
datastore
    .update({id: '123', age: 24})
    .then((item) => {
        console.log(item);
        // will log updated item;
    });

//delete item
datastore
    .delete('123')
    .then((item) => {
        console.log(item);
        // will log deleted item;
    });

//get items for query
const query = new Query({
    query: new And([
        new Le('age', 25),
        new Ge('age', 18),
    ])
});

datastore
    .query(query)
    .then((items) => {
        //do something with result
        //...
    })
    .catch((error) => {
        console.warn(error)
    });

Readme

Keywords

Package Sidebar

Install

npm i rollun-ts-datastore

Weekly Downloads

9

Version

1.2.0

License

ISC

Unpacked Size

82.3 kB

Total Files

32

Last publish

Collaborators

  • rollun-com