0.1.7 • Published 6 months ago

egg-radishpit v0.1.7

Weekly downloads
11
License
-
Repository
github
Last release
6 months ago

egg radishpit plugin

Install

$ npm i egg-radishpit --save

Configuration

Enable egg-radishpit

{app_root}/config/plugin.js:

exports.radishpit = {
  enable: true,
  package: 'egg-radishpit',
};

Schema

Schemas need to be put in {app_root}/app/schema/.

{app_root}/app/schema/user.js:

const types = require('./types'); // this is for custom radishpit type defination
const schema = {
  id: 'int',
  password: 'string',
  name: {
    type: 'string',
    max: 20,
  },
  avatar: {
    type: 'string?',
    max: 255,
  },
  mobile: 'mobile',
  email: {
    type: 'email?',
    max: 50,
  },
  createdAt: {
    type: 'date',
    get default() { return new Date(); },
  },
};

const columnMap = {
  $full: ['id', 'name', 'avatar', 'mobile', 'email', 'createdAt'],
  $default: ['id', 'name', 'avatar'],
  $mini: ['id', 'name'],
};

module.exports = {
  types,
  schema,
  columnMap,
};

{app_root}/app/controller/user.js:

...
const data = {
  name: 'Echo Chen',
  mobile: '18888888888',
  email: 'qdechochen@gmail.com',
};
this.ctx.validate(this.app.schema.user(Object.keys(data)), data);
// An error with the results and 422 staus will be thrown if valiation fails. You need to resolve the result in your middlware.
0.1.7

6 months ago

0.1.6

6 months ago

0.1.5

7 months ago

0.1.4

10 months ago

0.1.3

5 years ago

0.1.2

6 years ago

0.1.1

6 years ago