egg-cockroach

1.1.0 • Public • Published

egg-cockroach

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

  • A cockroachdb plugin of eggjs.
  • GitHub

Direction

egg version

egg-cockroach egg 2.x
2.x 😁

Get

$ npm install egg-cockroach --save

Open Plugin

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

Config

exports.cockroach = {
  client: {
    user: 'root',
    host: '127.0.0.1',
    database: 'user',
    port: 26257,
  },
  app: true,
  agent: false,
};

Using

// controller/home.js
// it is can only execute SQL  Statements now.
class HomeController extends Controller {
  async index() {
    const [err, conn, done] = await this.app.cockroach;
    if(err) {
      console.log(err);
    } else {
      const time = await conn.query('select now() as currentTime;');
      console.log(time.rows[0].currenttime);
      const res = await conn.query('SELECT * FROM accounts;');
      console.log(res);
      await done();
    }
    this.ctx.body = 'hi, egg';
  }
}

Q & A

egg-cockroach issues

License

MIT

Package Sidebar

Install

npm i egg-cockroach

Weekly Downloads

5

Version

1.1.0

License

MIT

Unpacked Size

10.2 kB

Total Files

8

Last publish

Collaborators

  • txiaozhe