1.1.21 • Published 1 year ago

rollun-ts-datastore-test v1.1.21

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

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)
    });
1.1.21

1 year ago

1.1.20

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago