Git Product home page Git Product logo

dogwater's Introduction

dogwater

A hapi plugin integrating Waterline ORM

Build Status Coverage Status

v1.0.0 release notes

Usage

var Hapi = require('hapi');
var Dogwater = require('dogwater');
var Memory = require('sails-memory');

var server = new Hapi.Server();
server.connection({ port: 3000 });

server.route({
    method: 'GET',
    path: '/dogs/{id}',
    handler: function (request, reply) {

        var Dogs = request.collections.dogs;

        // reply with promise
        reply(Dogs.findOne(request.params.id));
    }
});

server.register({
    register: Dogwater,
    options: {
        adapters: {
            memory: Memory
        },
        connections: {
            simple: { adapter: 'memory' },
        },
        models: [
            {
                identity: 'dogs',
                connection: 'simple',
                attributes: { name: 'string' }
            }
        ],
        fixtures: [
            {
                model: 'dogs',
                items: [
                    { name: 'Guinness' },
                    { name: 'Sully' },
                    { name: 'Ren' }
                ]
            }
        ],
    }
}, function (err) {

    if (err) {
        throw err;
    }

    server.start(function () {

       console.log('Server running at:', server.info.uri);
    });
});

Interface

Server

  • server.waterline - the raw Waterline ORM object.

Request

  • request.collections - an object containing all Waterline collections indexed by identity.

Exposed

  • server.plugins.dogwater.collections - an object containing all Waterline collections indexed by identity.
  • server.plugins.dogwater.connections - an object containing all Waterline connections indexed by name.
  • server.plugins.dogwater.schema - an object containing the normalized Waterline schema.
  • server.plugins.dogwater.teardown(cb) - a method to teardown all Waterline-managed connections, cb taking a single error argument.

Options

  • adapters - An object whose keys are adapter names (to be referenced in the connections option), and whose values are Waterline adapter modules or string names of adapter modules to be required.
  • connections - A object containing a Waterline connections configuration. Each key should be a connection name, and each value should be an object specifying the relevant adapter's name plus any adapter connection configurations.
  • models - Either a relative (to the current working directory) or absolute path to be required that will return an array of unextended Waterline collections, or an array of unextended Waterline collections. If a function is an element of this array, it will be called with the raw Waterline ORM object as an argument. It is expected to return an unextended Waterline collection. This allows one to easily reference Waterline in lifecycle callbacks.
  • fixtures - An optional object containing the configuration used by waterline-fixtures to load data fixtures, with the exception of its collections option, which is automatically set by dogwater. Alternately, this option may specify an array of fixture data in the format prescribed by waterline-fixtures (which can be seen in the usage example above).

Dogwater's options aim to be friendly with rejoice manifests.

Extras

dogwater's People

Contributors

devinivy avatar g-div avatar moklick avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.