# loystore

> Make your firestore quickly and easily.

Latest version **0.2.8** (published 2018-08-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install loystore
pnpm add loystore
yarn add loystore
bun add loystore
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.8 |
| Published | 2018-08-27 |
| First published | 2018-08-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Seung Yeon Kim |
| Maintainers | loycord |
| Keywords | firebase, firestore |

## Links

- npm: https://www.npmjs.com/package/loystore
- Repository: https://github.com/loycord/loystore
- Homepage: https://github.com/loycord/loystore#readme
- Issues: https://github.com/loycord/loystore/issues
- npm.io page: https://npm.io/package/loystore

## Recent versions

- 0.2.8 (latest) — 2018-08-27
- 0.2.7 — 2018-08-27
- 0.2.6 — 2018-08-27
- 0.2.5 — 2018-08-18
- 0.2.4 — 2018-08-18
- 0.2.3 — 2018-08-08
- 0.2.2 — 2018-08-08
- 0.1.2 — 2018-08-08
- 0.1.1 — 2018-08-07
- 0.1.0 — 2018-08-07

## README

# Loystore

## Make your firestore quickly and easily.

### Example

```javascript
import firebase from 'firebase';
import 'firebase/firestore';
import Loystore from 'loystore';

const db = firebase.firestore();

type Post = {
  title: string;
  description: string;
  rating: number;
  author: string;
};

const post = new Loystore(db, 'posts');

async function get(documentID: string) {
  try {
    const data = await post.get(documentID);
    return data; /**
                  * {
                  *   id: documentID,
                  *   data: {
                  *     title: 'Hello',
                  *     description: 'Hello Loystore',
                  *     rating: 10,
                  *     author: 'Kim'
                  *   }
                  * }
                  */
  } catch (err) {
    console.log(err);
  }
}

async function set(documentID: string, data: Post, merge: boolean) {
  try {
    const data = await post.set(documentID, data, merge);
    return data; // { id: documentID, data: data }
  } catch (err) {
    console.log(err);
  }
}

async function add(data: Post) {
  try {
    const data = await post.add(data);
    return data; // { id: 1rcI0EZrzQ0zoWNwWbUY, data: data }
  } catch (err) {
    console.log(err);
  }
}

async function update(documentID: string, data: Post) {
  try {
    const data = await post.update(documentID, data);
    return data; // { id: documentID, data: data }
  } catch (err) {
    console.log(err);
  }
}

async function delete(documentID) {
  try {
    const data = await post.delete(documentID);
    return data; // true
  } catch (err) {
    console.log(err);
  }
}

async function getAll(limit: number) {
  try {
    // const data = await post.getAll(); // limit default 50.
    const data = await post.getAll(limit);
    return data; /**
                  * [
                  *   {
                  *     id: '1rcI0EZrzQ0zoWNwWbUY',
                  *     data: {
                  *       title: 'Hello',
                  *       description: 'Hello loystore.',
                  *       rating: 10,
                  *       author: 'Kim'
                  *     }
                  *   },
                  *   {
                  *     id: '3OlEQ0Md1fgpv2gznGg3',
                  *     data: {
                  *       title: 'Good morning',
                  *       description: 'Good morning everyone!',
                  *       rating: 0,
                  *       author: 'John'
                  *     }
                  *   },
                  *   {
                  *     id: '8qVKhEcULd6U9Dcfm0ae',
                  *     data: {
                  *       title: 'Good night',
                  *       description: 'Good night everyone!',
                  *       rating: 5,
                  *       author: 'Jack'
                  *     }
                  *   }
                  * ];
                  */
  } catch (err) {
    console.log(err);
  }
}

const query1 = post.collection.where('rating', '<=', 8).orderBy('author', 'desc');
async function getFilter(query, limit: number) {
  // const data = await post.getFilter(query); // limit default 50.
  const data = await post.getFilter(query, limit);
  return data; /**
                * [
                *   {
                *     id: '3OlEQ0Md1fgpv2gznGg3',
                *     data: {
                *       title: 'Good morning',
                *       description: 'Good morning everyone!',
                *       rating: 0,
                *       author: 'John'
                *     }
                *   },
                *   {
                *     id: '8qVKhEcULd6U9Dcfm0ae',
                *     data: {
                *       title: 'Good night',
                *       description: 'Good night everyone!',
                *       rating: 5,
                *       author: 'Jack'
                *     }
                *   }
                * ];
                */
}
// getFilter(query1, 50); // example

const query2 = post.collection.where('rating', '<=', 8).orderBy('author', 'asc');
async function getPage(query, limit: number, offset: number) { // next is lastDoc
  try {
    const data1 = await post.getPage(query, 100); 
    // Get 1 ~ 100 documents.

    const data2 = await post.getPage(query, 100, 101);
    // Get 101 ~ 200 documents.

    const next = data2.next;
    const data3 = await post.getPage(query, 10, 10, next);
    // Get 10 ~ 20 documents starting with next(Doc).

    return [...data1, ...data2, ...data3, ...data4]; // 1 ~ 200 + 210 ~ 220 documents.
  } catch (err) {
    console.log(err);
  }
}
// getPage(query2, 20); // example

// Only working on firebase-admin instance.
async function getCollections() {
  try {
    const data = await post.getCollections();
    return data; // posts collections.
  } catch (err) {
    console.log(err);
  }
}
```

## 0.2.5
 - Modify getPage parameters
 ```
  // before
  getPage(query, startAt, limit, next);

  // after
  getPage(query, limit, offset = 1, next);
 ```

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