egg-arango

Simple Api template for ArangoDB.

Usage no npm install needed!

<script type="module">
  import eggArango from 'https://cdn.skypack.dev/egg-arango';
</script>

README

egg-arango

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-arango --save

Usage

// {app_root}/config/plugin.js
exports.arango = {
  enable: true,
  package: 'egg-arango',
};

Configuration

// {app_root}/config/config.default.js

exports.arango = {
  client: {
    url: [
      'http://127.0.0.1:8529',
    ],
    username: 'dba',
    password: 'psd',
    database: 'dbName',
  },
};

see config/config.default.js for more detail.

Example

  • Controller
const { BaseController } = require('egg-arango');
const Joi = require('joi');

class DemoController extends BaseController {
  async demo() {
    const { ctx, callService } = this;
    const result = await callService(
      'demo',
      ctx.request.body,
      Joi.object({
        name: Joi.string().required(),
      }).required()
    );
    ctx.body = this.success(result);
  }

}

module.exports = DemoController;
  • Service
const { BaseService } = require('egg-arango');

class DemoService extends BaseService {
  /**
    * description
    * @param {object} params params
    * @return {object} obj
    */
  async demo(params) {
    const { demo } = await this.get(params._id);
    if (demo && Object.keys(demo).length === 0) {
      throw this.BizError(`[${params._id}] is not existed!`);
    }
    return { demo };
  }

}

module.exports = DemoService;
  • Dao
const { BaseDao } = require('egg-arango');

class DemoDao extends BaseDao {
}

module.exports = DemoDao;

Questions & Suggestions

Please open an issue here.

License

MIT