🚨 Latest Research:Tanstack npm Packages Compromised in Ongoing Mini Shai-Hulud Supply-Chain Attack.Learn More →
Socket
Book a DemoSign in
Socket

@fastify-userland/typeorm-query-runner

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify-userland/typeorm-query-runner

Fastify typeorm QueryRunner

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

@fastify-userland/typeorm-query-runner

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-userland/typeorm-query-runner

# pnpm
pnpm add @fastify-userland/typeorm-query-runner

# yarn
yarn add @fastify-userland/typeorm-query-runner

Usage

const fastify = require('fastify')()

fastify.register(require('@fastify-userland/typeorm-query-runner'), {
  dataSource: dataSource,
  transaction: true,
  match: request => request.routerPath.startsWith('/v2'),
  respIsError: (respStr) => respStr === '{"status":false}'
})

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. - default: false

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

    • Receiving requests: opening transaction
    • Return response: close transaction
    • Requesting an error: rolling back transaction
match: request => {
  return request.routerPath.startsWith('/v2')
}
  • respIsError(Optional): When the response matches the condition, it is considered an error - default: () => false
respIsError: (respStr) => {
  return respStr === '{"status":false}'
}

License

Licensed under MIT.

Keywords

fastify

FAQs

Package last updated on 11 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts