Git Product home page Git Product logo

k7's Introduction

k7 Logo

hapi database connector

Build Status Dependencies Status DevDependencies Status Known Vulnerabilities js-semistandard-style

K7 is the simplest way to connect Hapi.js with your favorite Database Mapper, you can use any of ours available connectors for the most populars Databases.

Example Usage

For example:

const Hapi = require('hapi');
const Server = new Hapi.Server();

Server.connection({host: 'localhost'});

let options = {
    adapter: require('k7-mongoose'),
    connectionString: 'mongodb://localhost:27017/K7Mongoose'
};

Server.register({
    register: require('k7'),
    options: options
}, (err) => {
    if (err) {
        throw err;
    }
    
    Server.start((err) => {
        if (err) {
            throw err;
        }
        
        Server.log('info', 'Server running at: ' + Server.info.uri);
    });
});

This example does:

  1. Setting the k7-mongoose adapter
  2. Setting the connectionString for mongoose connect
  3. Register the k7 to Hapi.js

Options

k7 have minimal options, and the major options are specified in ours Adapters.

  • connectionString: Is a common option, specified a connectionString to connecto in your database.
  • connectionOptions: Is a common option, where you will specify the options passed for the connector.
  • models: Is a common option, where you will specify how we can find your models. Default: models/*.js In this option you can pass a String or an Array of files or glob patterns like: **/model.js

Where my Models?

Your models will be available in server.database all of your databases will be there. In server.database have the instance of the Database Mapper used too.

If your model are in a file called models/user.js, the model will be avaiblable as server.database.User.

Adapters

Write your own adapter

The K7 API is very simple, your adapter just need be a Class and export a function load and return an Object with all models and the Database Mapper instance for k7 decorate the database in Hapi.js. For more examples, please see the source code in the k7-sequelize plugin.

Testing

For testing you just need clone this repo and run npm install && npm test inside root folder of this project.;

k7's People

Contributors

thebergamo avatar fernandocagale avatar a0viedo avatar misterdai avatar

Watchers

James Cloos avatar  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.