怎样在小程序里实现标题的更改
676
2022-10-23
Lumber: 为你的Web应用程序生成管理的microservice
Lumber: The admin microservice generator
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: You may need to use the option --ssl if your database uses a SSL connection.
Commands
$ lumber [command]
generate generate your admin microserviceuser show your current logged userlogin sign in to your accountlogout 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(
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(
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
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~