Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

k7

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

k7

Connect your database with Hapijs made easy

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by20%
Maintainers
1
Weekly downloads
 
Created
Source

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.;

Keywords

FAQs

Package last updated on 24 Mar 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc