Giter VIP home page Giter VIP logo

lumber's Introduction

Lumber: The admin microservice generator

Lumber logo

Lumber is an opensource tool to generate an admin microservice. It serves a REST API hooked directly into your database (MySQL and Postgres for now).

DISCLAIMER: Lumber is a project from Forest. Your Lumber-generated app gives you a free pass to all the powerful features of Forest, as per our Hacker plan.

Install

$ npm install -g lumber-cli

NOTICE:

  • You may need to use sudo depending on your platform.

Usage

Quickstart

$ lumber generate

NOTICE:

  • Your database credentials are safe. They are only stored in the Lumber generated microservice.
  • You may need to use the option --ssl if your database uses a SSL connection.

Example

Commands

$ lumber [command]

  • generate generate your admin microservice
  • user show your current logged user
  • login sign in to your account
  • logout sign out of your account

Advanced

Relationships

As Lumber generates an admin microservice from the database schema, it only creates belongsTo relationships, based on all your foreign keys. Please note that some ORMs do not create foreign key constraints. This means that in some cases, you will have to add belongsTo relationships manually. Lastly, as databases don't have the notion of inverse relationships, you will need to add hasMany or hasOne relationships manually.

The generated admin microservice uses the ORM Sequelize. Check out their documentation for advanced model customization.

Adding belongsTo relationships

Open the model file you want in the models directory and declare the belongsTo relationship in the associate function.

Syntax:

Model.belongsTo(<targetModel>, {
  foreignKey: '<foreignKey>',
  // ...
));

Available options can be found in the Sequelize documentation.

Example:

module.exports = (sequelize, DataTypes) => {
  let models = sequelize.models;

  var Model = sequelize.define('users', {
    // ...
  }, {
    classMethods: {
      associate: () => {
        // BelongsTo relationships
        Model.belongsTo(models.addresses);
      }
    },
    // ...
  });

  return Model;
};

Adding inverse of relationships (hasOne, hasMany, …)

Open the model file you want in the models directory and declare the hasMany (hasOne is very similar) relationship in the associate function.

Syntax:

Model.hasMany(<targetModel>, {
  // [options]
  // ...
));

Available options can be found in the Sequelize documentation.

module.exports = (sequelize, DataTypes) => {
  let models = sequelize.models;

  var Model = sequelize.define('users', {
    // ...
  }, {
    classMethods: {
      associate: () => {
        // hasMany relationships
        Model.hasMany(models.books);

        // hasOne relationships
        Model.hasOne(models.car);
      }
    },
    // ...
  });

  return Model;
};

Actions

Common actions such as CRUD, sort or search are implemented by default. You will probably want to provide your admin with actions to perform operations that are specific to your application. Moderating comments, logging into a customer’s account (a.k.a impersonate) or banning a user are typical examples of specific actions.

The following command will automatically generate an approve action on the comments collection.

$ lumber action comments approve

Declaration: /forest/comments.js

'use strict';
var liana = require('forest-express-sequelize');

liana.collection('comments', {
  actions: [
    { name: 'approve' },
  ]
});

Implementation: /routes/comments.js (customize the business logic here).

'use strict';
var express = require('express');
var router = express.Router();
var liana = require('forest-express-sequelize');

router.post('/actions/approve', liana.ensureAuthenticated,
  (req, res) => {
    // Your business logic here.

    res.send({
      success: 'Comments successfully approved!'
    });
  });

module.exports = router;

License

GPL

lumber's People

Contributors

seyz avatar alanrsoares avatar moflo avatar

Watchers

Subhash Ramesh 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.