-
Notifications
You must be signed in to change notification settings - Fork 314
Open
Description
I've been trying to use this library as an express middleware, for dependency injection convenience.
But I ran into a roadblock; queries get stuck seemingly forever when I do this. I am not sure why this happens? I've tested the code over and over and the issue persists. I moved off my production project to try reproducing it and was able to do it.
Here's some sample code, running on Node LTS with Postgres.js 3.4.4 and Express 4.20.0.
import express from 'express';
import postgres from 'postgres';
function createExpressApp() {
const app = express();
app.use(databaseMiddleware());
app.get('/', testHandler);
return app;
}
const databaseMiddleware = () => {
const sql = postgres(
'postgresql://postgres:postgres@localhost:8080/postgres',
);
return (req, res, next) => {
req.sql = sql;
next();
};
};
const testHandler = async (req, res, next) => {
try {
const response = await req.sql`SELECT version()`;
res.status(200).json(response);
} catch (err) {
next(err);
}
};
createExpressApp().listen(8080, () => console.log("listenin'"));
I hope this gets fixed if it really is a bug; feels like a shame to not be able to use such a nice library because of such an obnoxious issue.
Metadata
Metadata
Assignees
Labels
No labels