Git Product home page Git Product logo

sequelize-autoload's Introduction

An autoloader for Sequelize, inspired by PSR-0 and PSR-4.

Installation

npm install --save sequelize-autoload

Usage

const db = require('sequelize-autoload');
db.load('/path/to/config');

To generate sequelize models files:

See sequelize-auto package.

To make a config file:

See Config File section.

To get a Sequelize table instance:

db.models.model_name

Notes:

  1. db.load() reads config, but does not load table(s) immediately.
  2. Tables are loaded when they are called.
  3. Only uninitialized table(s) will be loaded, otherwise existing table instance(s) will be returned.
  4. db.load() can be called more than once, which will reload the config and clear all existing table instance(s).

Config File

Generally, the config file is a JSON separate from your main JS script. It contains database, tables and Sequelize-specific configurations. It looks like:

{
    "server": {
        "dialect": "mysql",
        "host": "localhost",
        "database": "test",
        "username": "username",
        "password": "password",
        "define": {}
    },
    "models": {
        "root": "../models"
    }
}
Field Name Type Optional Description
server.dialect String no Sequelize ORM dialect, see here.
server.host String no Database host.
server.database String no Database name.
server.username String no Database connection username.
server.password String no Database connection password.
server.define Object yes Sequelize global define, see here.
models.root String yes Path where generated scripts (by sequelize-auto) located.

Notes:

  1. If models.root is a relative path, it describes the path related to the config JSON file.

License

MIT

sequelize-autoload's People

Contributors

boxsnake avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

anthodingo

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.