JSPM

fastify-postgresjs

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q17999F
  • License MIT

Fastify postgres.js plugin

Package Exports

  • fastify-postgresjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fastify-postgresjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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')()

const url = 'postgres://postgres@localhost/postgres'

const options = { /* postgres.js options */ }

fastify.register(require('fastify-postgresjs'), {
  url, ...options
})

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

Run the tests.

$ npm test