Socket
Book a DemoInstallSign in
Socket

sails-hook-thinky-multi-db

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sails-hook-thinky-multi-db

A hook to enable the Thinky ORM for RethinkDB in Sails, with multi database support. Can be configured alongside or as a replacement for Waterline.js.

latest
Source
npmnpm
Version
0.0.7
Version published
Maintainers
1
Created
Source

sails-hook-thinky

A hook to enable the Thinky ORM for RethinkDB in Sails, with multi database support.

Using this in Production would be unwise. It has been lightly tested. Develop at your own risk.

Usage

The hook configures the thinky orm and expsoses the connection instance to the global connection. All model files in the /api/thinky directory will be loaded automatically and exposed in the sails.thinkymodels propery and optionally to the global namespace.

Make model calls from any service, controller, policy, etc. just as you would normally. No need to require thinky or any model files.

Post.getJoin().then(function(posts) {
     console.log(posts);
 });

Model file configuration

var type = connection_one.type;

module.exports = {

    tableName: "Car", // optional, will use name of file if not present
    connection: "connection_one", // can be any name
    schema: {
        id: type.string(),
        type: type.string(),
        year: type.string(),
        idOwner: type.string()
    },
    options: {},

    // set up any relationships, indexes or function definitions here
    init: function(model) {
        model.belongsTo(Person, "owner", "idOwner", "id");

        model.ensureIndex("type");

        model.define("isDomestic", function() {
            return this.type === 'Ford' || this.type === 'GM';
        });
    }

};

*Also see examples directory for sample model files.

Configuration

Create a new directory /api/thinky. This will be where your thinky models files will be auto-loaded by the hook.

Create a new configuration file thinky.js in the config directory.

/**
 * Thinky config
 * (sails.config.thinky)
 *
 */

module.exports.thinky = {

  connection_one: {
      host: "localhost",
      port: 28015,
      authKey: "",
      db: "test"
  },

  connection_two: {
      host: "localhost",
      port: 28015,
      authKey: "",
      db: "other_db"
  },

};

Optional: edit the .sailsrc file to disable Waterline to prevent any conflicts. (pubsub and blueprints will also need to be disabled due to dependencies on Waterline)

{
  "generators": {
    "modules": {}
  },
  "hooks": {
    "orm": false,
    "pubsub": false,
    "blueprints": false
  }
}

Keywords

rethinkdb

FAQs

Package last updated on 11 Nov 2015

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