1.2.9 • Published 1 month ago

@remotezygote/database v1.2.9

Weekly downloads
-
License
MIT
Repository
-
Last release
1 month ago

Database

import { query, withDatabaseClient, listen } from '@remotezygote/database'

const getUserData = async email => {
  const { rows } = await query('SELECT * FROM users WHERE email = $1', [email])
  return rows && row[0]
}

const updateWithTransaction = async updates => {
  const { email, data } = updates
  return await withDatabaseClient(async client => {
    const { rows } = await client.query(
      'SELECT * FROM users WHERE email = $1',
      [email]
    )
    await client.query('INSERT INTO user_log (email, item) VALUES ($1, $2)', [
      email,
      'updated'
    ])
  })
}

const processJob = async job => {
  const queue = queues[job.queue]

  if (queue) {
    await queue.add(job.name, job.data)
  }
}

export const listenForJobs = async () => {
  await listen('jobs', processJob)
}

Configuration

The only configuration needed is the connection information to Postgres, via environment variable.

Environment variables

DATABASE_URL - This library uses only the connection URL method for connection configuration. More info

1.2.9

1 month ago

1.2.8

10 months ago

1.2.7

10 months ago

1.2.6

10 months ago

1.2.5

10 months ago

1.2.4

10 months ago

1.2.3

10 months ago

1.2.2

11 months ago

1.2.1

11 months ago

1.2.0

11 months ago

1.1.3

11 months ago

1.1.2

11 months ago