7.4.0 • Published 4 years ago

@lanetix/as-user-transaction v7.4.0

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
4 years ago

CircleCI codecov js-standard-style

node-as-user-transaction

Usage

Setup (v7.0.0+)

import { transaction } from '@lanetix/as-user-transaction'

const aUT = transaction({
  schema: `records,public`      // which schema(s) to query
  dbConfig: 'something'         // how to get to a DB; defaults to null in most cases
  timeout: '42s'                // optional parameter to set the statement timeout
  shouldRetry: (err) => false   // optional function which takes an error and indicates if the transaction should be retried
})

const asUserTransaction = (user, fn) => aUT({ user, writable: false }, fn)  // makes it a read only transaction
asUserTransaction.writable = (user, fn) => aUT({ user, writable: true }, fn)     // this is a write friendly transaction

export default asUserTransaction

Execution (v7.0.0+)

import asUserTransaction from './curried-as-user-transaction'

const user = {} // JWT in JSON form
const myResult = await asUserTransaction(user, (query, settings) => query('SELECT 1'))

console.log(myResult) // { rows: [] } # the PG JSON object

Installation

npm i -S @lanetix/as-user-transaction

Logging

This package uses debug, so you can log debugging things by setting DEBUG=lx-sql or DEBUG=lx-pg-pool to enable logs for the sql being executed and logs for the connection pool, respectively.

7.4.0

8 years ago

7.3.2

8 years ago

7.3.1

9 years ago

7.3.0

9 years ago

7.2.0

9 years ago

7.1.1

9 years ago

7.1.0

9 years ago

7.0.1

9 years ago

7.0.0

9 years ago

6.0.0

9 years ago

5.1.0

9 years ago

5.0.0

9 years ago

4.1.0-test0

9 years ago

4.0.0

9 years ago

4.0.0-test1

9 years ago

3.0.0

10 years ago

2.0.2

10 years ago

2.0.1

10 years ago

2.0.0

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago