Closed ghost closed 7 years ago
Yes, simple like this:
$ npm install --save pg pg-hstore
$ npm install --save koa-orm
const join = require('path').join;
const config = {
modelPath: join(__dirname, 'models'),
database: 'orm_test',
username: 'root',
password: 'pass',
dialect: 'postgres',
host: '127.0.0.1',
port: 5432,
pool: {
maxConnections: 10,
minConnections: 0,
maxIdleTime: 30000
}
};
const orm = require('koa-orm')(config);
app.use(orm.middleware);
app.use(async function (ctx) {
const { User } = ctx.orm();
const { userId } = ctx.params;
ctx.body = await User.findById(userId);
});
Great thanks!
@helloyou2012 What is pg-hstore used for?
@alexdrans sequelize
use it for serializing and deserializing JSON data: http://docs.sequelizejs.com/en/v3/docs/getting-started/
Can this ORM be used to talk to Postgresql using async/await?