# @sowell/quasar-app-extension-rxdb

> A Quasar App Extension for RxDB

Latest version **0.1.4** (published 2021-07-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sowell/quasar-app-extension-rxdb
pnpm add @sowell/quasar-app-extension-rxdb
yarn add @sowell/quasar-app-extension-rxdb
bun add @sowell/quasar-app-extension-rxdb
```

## 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.1.4 |
| Published | 2021-07-15 |
| First published | 2021-06-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 8.9.0 |
| Dependencies | 3 |
| Unpacked size | 263.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Julien Prince |
| Maintainers | zo_sowell, donaldo |

## Links

- npm: https://www.npmjs.com/package/@sowell/quasar-app-extension-rxdb
- Homepage: http:
- npm.io page: https://npm.io/package/@sowell/quasar-app-extension-rxdb

## Dependencies (3)

- [rxdb](https://npm.io/package/rxdb.md) ^9.15.0
- [rxjs](https://npm.io/package/rxjs.md) ^7.0.1
- [subscriptions-transport-ws](https://npm.io/package/subscriptions-transport-ws.md) ^0.9.18

## Recent versions

- 0.1.4 (latest) — 2021-07-15
- 0.1.3 — 2021-07-09
- 0.1.2 — 2021-06-17
- 0.1.1 — 2021-06-14
- 0.1.0 — 2021-06-07

## README

# Quasar App Extension app-extention-rxdb

Quasar extension for GraphQl replication with [RxDB](https://rxdb.info/replication-graphql.html), based on the Composition API Vue 3

# Install:

```bash
quasar ext add @sowell/rxdb
```
# Uninstall:

```bash
quasar ext remove @sowell/rxdb
```
# Prerequisites

- Vuex 4.0: for token and database name management
- i18n: for internationalization of error messages.
  Initialize the i18n in the quasar boot, add the following variables and change the values as desired.
  More information on i18n [quasar](https://next.quasar.dev/options/app-internationalization)
```js
 rxdb: {
    initReplicationError: "Error replication verify your name of collection",
    tokenNotProvided: "Token must be provided",
    stopReplicationError: "No replication state",
    createDbError: "Database must have a name",
    getDBError: "Database doesn't exist",
    getCollectionError: "Collection doesn't exist ",
    subscribeError: "Offline mode"
  }
  ```
## Prompts:

- urlServer: URl of the GraphQl server.
- urlWebsocket: URl for GraphQl Server Subscription.
- vuex_getters_token: getters for the Authorization header
- vuex_getters_db_name: getters for the database name
**Nb:** The **namespaced**  option is set to **true**,
input format in the prompts: 

```bash
vuex_getters_token: rxdb/getToken => equivalent: getters["rxdb/getToken"]
vuex_getters_db_name: rxdb/getDbame => equivalent: getters["rxdb/getDbame"]
  ```

#### Usage:
```js
// Inside Store file
const state = {
  user: {
    token: your token,
    name: nameOfBase
  }
}
// getters
const getters = {
  getToken: (state) => state.user.token,
  getDbame: (state) => state.user.name
}
 ````
# Features
## initRxdb()

Initialization of variables for the good functioning of the extension:
For "pull-replication", we first need a pullQueryBuilder file. It is a function that gets the last replicated document as input and returns an object with a GraphQL query and its variables.
- queries : It is an array that groups the queryBuilders.
- schema: The schema define what your data looks like, the format must be respected:

```js
const schema = {
  nameOfCollection: {
    title: "Collection Name of schema",
    version: 0,
    description: "Describes your collection",
    type: "object",
    properties: {}
  }
  ```
#### Usage
Initialization of parameters in the quasar boot file.
```js
// boot.js
import rxdb from "@sowell/rxdb"
import schema from "../schemaRxdb"// import your schema file
import {
  todoPullQueryBuilder
} from "./todoQueryBuilder " // import your pullQueryBuilder file
import subscriptionTodoQuery from "./subTodoQuery" // import your subscriptionTodoQuery file

export default async () => {
  const { initRxdb } = rxdb();
  //init queryBuilders
  let queries = [];
    queries["todos"] = 
    [
      { pull: todoPullQueryBuilder },
      { push: todoPushQueryBuilder },
      { sub: subscriptionTodoQuery }
    ];
  initRxdb(queries, schema);
}
  ```
## createDb()

Asynchronous method to create the local RxDB database.
The **createDb()** method is to be called after an authentication and after the token and the variable that will be used for the database name is defined in the store.

#### Usage: 
 ```js
 //Login.vue 
import rxdb from "@sowell/rxdb"
export default defineComponent({
  name: "Login",
  setup() {
    const { createDb } = rxdb()

    const onSubmit = async () => {
      ...Your connection method
      .then( async function () {
        // creation of the database
        await createDb()
      })
    }
    return {

    }
  }
  ```

## getDB()

Method to retrieve the created database instance to manipulate it later, such as retrieving a collection or other action with the database, for more details [RxDb](https://rxdb.info/rx-database.html#functions)

#### Usage: 
 ```js
 //todo.vue
import rxdb from "@sowell/rxdb"
export default defineComponent({
  name: "todo",
  setup() {
    const { getDB } = rxdb()
    const collection = getDB.yourColectionName

    return {
      collection
    }
  }
  ```

## getCollection()

Method that returns a collection directly without going through the getDb() method, it takes as a parameter the name of the collection (in String type).
#### Usage:
```js
import rxdb from "@sowell/rxdb"
export default defineComponent({
  name: "todo",
  setup() {
    const { getCollection } = rxdb()
    const collection = getCollection("todo")

    return {
      collection
    }
  }
 ```
## initReplication()

Method to initiate GraphQl replication of RxDb.
Preferably to be used in the highest component parent after the database is created.
#### Usage:
```js
import rxdb from "@sowell/rxdb"
export default defineComponent({
  name: "todo",
  setup() {
    const { initReplication } = rxdb()
    onMounted(()=> {
      initReplication()
    })

    return {
    }
  }
 ```

## stopReplication()

Method to stop all ongoing replications.
#### Usage:
```js
import rxdb from "@sowell/rxdb"
export default defineComponent({
  name: "todo",
  setup() {
    const { stopReplication } = rxdb()

     function logout () {
       stopReplication()
     }

    return {
      logout
    }
  }
 ```
# Donate

If you like the extension, make a donation to [Sowell](https://sowellapp.com).

# License

MIT (c) Sowell

---
_Source: https://npm.io/package/@sowell/quasar-app-extension-rxdb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
