fastify-typeorm-query-runner-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

fastify-typeorm-query-runner-plugin

CI NPM version js-standard-style NPM size Coverage Status

A plugin for Fastify that adds support for typrorm QueryRunner and Transaction.

Supports Fastify versions 4.x.

Support TypeScript

Install

# npm
npm i fastify-typeorm-query-runner-plugin

# pnpm
pnpm add fastify-typeorm-query-runner-plugin

# yarn
yarn add fastify-typeorm-query-runner-plugin

Usage

const fastify = require('fastify')()

fastify.register(require('fastify-typeorm-query-runner-plugin'), {
  // put your options here
})

fastify.get('/', async (req, reply) => {
  console.log(req.queryRunner)
  console.log(req.queryRunner.manager)

  await  req.queryRunner.manager.insert();
  
  reply.send({ hello: 'world' })
})

fastify.listen(3000)

Options

  • dataSource(Required): TypeORM dataSource

  • transaction(Optional): Whether to bind the life cycle of a thing to a request.

    • Receiving requests: opening transaction
    • Return response: close transaction
    • Requesting an error: rolling back transaction
  • match(Optional): Only matching requests will enable the plugin.

match: request => {
  return request.routerPath.startsWith('/v2')
}
  • respIsError(Optional): When the response matches the condition, it is considered an error
respIsError: (respStr) => {
  return respStr === '{"status":false}'
}

License

Licensed under MIT.

Package Sidebar

Install

npm i fastify-typeorm-query-runner-plugin

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

7.86 kB

Total Files

5

Last publish

Collaborators

  • black_hole