3.0.2 • Published 5 years ago

@sharyn/db v3.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

🌹 @sharyn/db

npm

This package provides database utilities and configs.

🌹 Install

yarn add @sharyn/db

🌹 Usage

knex-config.js

A knex-config.js knexfile is provided and is used automatically unless you have your own located at src/_db/knex-config.js

knex

import { knex } from '@sharyn/db'

export const findNoteById = (userId, id) =>
  knex('Note')
    .where({ id, userId })
    .first()

createQuery

createQuery is higher-level than knex, the created query already contains the table name, and can pass a userId as a .where({ userId }) clause.

import { createQuery } from '@sharyn/db'

const query = createQuery('Note')

export const createNote = input => query().insert(input)

export const findNoteById = (userId, id) =>
  query(userId)
    .where({ id })
    .first()

createQuery with a transaction

You can pass a transaction to createQuery as the second parameter:

import { createQuery, knex } from '@sharyn/db'

const tableAQuery = createQuery('tableA')
const tableBQuery = createQuery('tableB')

export const somethingWithATransaction = userId =>
  knex.transaction(async trx => {
    await tableAQuery(userId, trx).something()
    await tableBQuery(null, trx).something()
  })
3.0.2

5 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.8.7

6 years ago

1.8.6

6 years ago

1.8.5

6 years ago

1.8.4

6 years ago

1.8.3

6 years ago

1.8.2

6 years ago

1.8.1

6 years ago

1.8.0

6 years ago

1.7.7

6 years ago

1.7.6

6 years ago

1.7.5

6 years ago

1.7.4

6 years ago

1.7.3

6 years ago

1.7.2

6 years ago

1.7.1

6 years ago

1.7.0

6 years ago

1.6.0

6 years ago

1.5.0

6 years ago

1.4.10

6 years ago

1.4.9

6 years ago

1.4.8

6 years ago

1.4.7

6 years ago

1.4.6

6 years ago

1.4.5

6 years ago

1.4.4

6 years ago

1.4.3

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago