- A cockroachdb plugin of eggjs.
- GitHub
egg-cockroach | egg 2.x |
---|---|
2.x | 😁 |
$ npm install egg-cockroach --save
// config/plugin.js
exports.cockroach = {
enable: true,
package: 'egg-cockroach',
};
exports.cockroach = {
client: {
user: 'root',
host: '127.0.0.1',
database: 'user',
port: 26257,
},
app: true,
agent: false,
};
// 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';
}
}