在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:chilts/koa-pg开源软件地址:https://github.com/chilts/koa-pg开源编程语言:JavaScript 100.0%开源软件介绍:Note: This project is in need of an owner or maintainer since I don't use it. I fear my pulling of PRs isn't making it better since it requires more of an overview by someone. Please get in touch. :) Thanks. koa-pgKoa middleware to get you a Postgres client on the way down the middlewares, and release it on the way back up the middlewares. This extends Koa by adding a Synopsisvar koa = require('koa')
var koaPg = require('koa-pg')
var app = koa()
app.use(koaPg('postgres://user:password@localhost:5432/database'))
app.use(function *(next) {
// Here we have access to this.pg.db.client which is client returned from pg.connect().
var result = yield this.pg.db.client.query_('SELECT now()')
console.log('result:', result)
this.body = result.rows[0].now.toISOString()
})
app.listen(3000) Options
This is the name you want to use for this database. The default is
This is the parameter that is passed via var config = {
name: 'master_db',
pg: {
user: 'postgres',
database: 'db',
password: 'pass',
port: 5432,
max: 10,
idleTimeoutMillis: 60
}
}
app.use(koaPg(config)) Multiple Database ConnectionsWhen using only one database connection you can use the default
AuthorWritten by Andrew Chilton - Blog - Twitter. (Ends) |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论