# rollun-ts-datastore

> rollun-datastore written in TS

Latest version **1.2.0** (published 2024-01-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install rollun-ts-datastore
pnpm add rollun-ts-datastore
yarn add rollun-ts-datastore
bun add rollun-ts-datastore
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2024-01-10 |
| First published | 2018-12-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 80.4 KB |
| Known vulnerabilities | 0 (+25 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | rollun-com |
| Keywords | rollun |

## Links

- npm: https://www.npmjs.com/package/rollun-ts-datastore
- npm.io page: https://npm.io/package/rollun-ts-datastore

## Dependencies (5)

- [axios](https://npm.io/package/axios.md) ^0.19.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.19
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.1
- [rollun-ts-rql](https://npm.io/package/rollun-ts-rql.md) ^0.10
- [rollun-ts-utils](https://npm.io/package/rollun-ts-utils.md) ^0.0.2

## Recent versions

- 1.2.0 (latest) — 2024-01-10
- 1.1.0 — 2023-06-27
- 1.0.5 — 2023-03-19
- 1.0.4 — 2023-03-19
- 1.0.3 — 2023-03-19
- 1.0.2 — 2023-03-19
- 1.0.1 — 2023-03-19
- 1.0.0 — 2023-03-19
- 0.5.13 — 2023-03-05
- 0.5.11 — 2022-09-29
- 0.5.10 — 2022-09-29
- 0.5.9 — 2022-09-28
- 0.5.8 — 2021-08-25
- 0.5.7 — 2021-01-14
- 0.5.6 — 2020-11-20
- … 30 more at https://npm.io/package/rollun-ts-datastore/versions

## README

![Coverage badge](https://img.shields.io/badge/Coverage%20Statements-83.56%25-green.svg)
![Coverage badge](https://img.shields.io/badge/Coverage%20Lines-83.64%25-green.svg)
![Coverage badge](https://img.shields.io/badge/Coverage%20Functions-79.83%25-orange.svg)
![Coverage badge](https://img.shields.io/badge/Coverage%20Branches-69.92%25-red.svg)


# rollun-ts-datastore
Basically [rollun-datastore](https://github.com/rollun-com/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](https://www.npmjs.com/package/rollun-ts-rql) library.

## Basic usage
```js
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)
    });
```

---
_Source: https://npm.io/package/rollun-ts-datastore · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
