Skip to content

Instantly share code, notes, and snippets.

@koistya
Created February 26, 2016 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save koistya/f50f718e35799b1895fd to your computer and use it in GitHub Desktop.
Save koistya/f50f718e35799b1895fd to your computer and use it in GitHub Desktop.
Async node-postgres sample code
import express from 'express';
import db from './core/db';
const app = express();
const port = process.env.PORT || 3000;
app.get('/visits', (req, res, next) => {
db.connect(async ({ query } => {
await query('INSERT INTO visit (date) VALUES ($1)', new Date());
const result = await query('SELECT COUNT(date) AS count FROM visit');
res.send(`You are visitor number ${result.rows[0].count}.`);
}).catch(next);
});
app.listen(port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment