New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bausmeier/tractor

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bausmeier/tractor

A simple wrapper around `pg.Pool` for managing transactions.

  • 0.3.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-90%
Maintainers
1
Weekly downloads
 
Created
Source

Transactor

A simple wrapper around pg.Pool for managing transactions.

Usage

Create a connection pool:

import {Pool} from 'pg'

const pool = new Pool({
  // Connection options go here.
})
pool.on('connect', (client) => {
  client.on('error', () => {
    // Squash the error. It will surface when the client is used.
  })
})
pool.on('error', (err) => {
  console.error('Pool error', err)
})

Create a transactor from the pool:

import createTransactor from '@bausmeier/tractor'

const db = createTransactor(pool)

Execute some queries within a transaction:

type ExampleRow = {
  name: string
}

const examples = await db.runInTransaction(
  async (client) => {
    await client.query('INSERT INTO examples (name) VALUES ($1)', ['test'])
    const {rows} = await client.query<ExampleRow>('SELECT name FROM examples')
    return rows
  },
  {
    isolationLevel: 'SERIALIZABLE',
  }
)

Publishing

rm tsconfig.tsbuildinfo
rm -r build/
yarn run build
yarn publish --access=public

FAQs

Package last updated on 06 Mar 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc