egg-cockroach
v1.1.0
Published
A CockroachDB plugin for eggjs.
Downloads
4
Readme
egg-cockroach
- 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';
}
}