Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@tailored-apps/rethinkable

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tailored-apps/rethinkable

Util collection for APIs using RethinkDB (Model, CRUD Router, CRUD Pluralized Router).

latest
npmnpm
Version
1.1.1
Version published
Maintainers
2
Created
Source

rethinkable

js-standard-style

rethinkable is a model and CRUD helper library for rethinkdb and Koa, using Koa-Router].

Installation and Updating

npm install @tailored-apps/rethinkable

Usage

Configuration

Once you should set the connection and if you want your custom logger instance to the library. Therefor the library provides you 2 functions setConnection(__connectioon__) and setLogger(__logger__).

Without the connection the library will not be able to conenct to your database.

Model

I would prefer you to create your own abstract model which extends from the Model provided by the library. At this place you could setup your configuration and some more optional custom changes.

import { Model, setLogger, setConnection } from 'rethinkable'

import { getLogger } from './logger'
import { getConnection ] from './database'

setLogger(getLogger())
setConnection(getConnection())

export default class Abstract extends Model {
    // general custom changes could be implemented hiere
}

Per default your models should be named (uppercase first character) like your tables. The id property will be handled from the library's model class.

import Abstract from './Abstract'

export default class TableName extends Abstract {
  constructor ({ name1, name2, name3, ...other }) {
    super(other)

    this.name1 = name1
    this.name2 = name2
    this.name3 = name3
  }
}

Router and RouterPluralized

In general each router is an instance of the koa-router. Like for models I would prefer you to create your own abstract router, at least to set the require path for your models.

import Router from 'rethinkable/RouterPluralized'

export default class Abstract extends Router {
  get modelsRequirePath () {
    return '../models'
  }
}

Like models, the router should be named (uppercase first character) like your tables, to work out of the box with your previously generated models.

import Abstract from './Abstract'

esport default class TableName extends Abstract {}

After all classes are created, you have to enable router's route to your koa-router.

import Router from 'koa-router'
import TableNameRouter from './routers/TableName'

const router = new TableNameRouter({ prefix: '/tableName', listFields: 'id,name1' }).enableRoutes()

export default new Router()
    .use(router.routes(), router.allowedMethods())

Router Configuration

The router class could initialized with some configuration options:

OptionDescription
middlewarea list of middleware which should be executed before the router calls
routesa list of all routes which should be enables
modifiersa modifier function, which prepare each returned entry
offsetthe default offset value for the list call (default: 0)
limitthe default limit value for the list call (default: 10)
listFieldsa comma separated list of values, which should be returned on the list call

Routes

RouteHTTP MethodPath
loadGET/
loadAllGET/:id
createPOST/
replacePUT/
updatePATCH/:id
removeDELETE/:id

Keywords

rethink

FAQs

Package last updated on 06 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts