fastify-postgresjs

1.0.0 • Public • Published

fastify-postgresjs

js-standard-style Build Status

Fastify PostgreSQL connection plugin, based on postgres.

Install

npm i postgres fastify-postgresjs --save

Usage

Add it to you project with register and you are done! This plugin will add the sql namespace in your Fastify instance.

Example:

const fastify = require("fastify")();
 
fastify.register(require("fastify-postgresjs"), {
  url: "postgres://postgres@localhost/postgres"
});
 
fastify.get("/users/:id", async (req, reply) => {
  const users = await fastify.sql`
    select * from users
    where id = ${req.params.id}
  `;
  return users;
});
 
fastify.listen(3000, err => {
  if (err) throw err;
  console.log(`server listening on ${fastify.server.address().port}`);
});

Development and Testing

First, start postgres with:

$ docker run --rm -d -p 5432:5432 --name fastify-postgresjs postgres:11-alpine
$ npm test

Package Sidebar

Install

npm i fastify-postgresjs

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

4.06 kB

Total Files

5

Last publish

Collaborators

  • herrmannplatz