@sharyn/db
[![npm](https://img.shields.io/npm/v/@sharyn/db.svg)](https://www.npmjs.com/package/@sharyn/db)
Last updated 5 months ago by sharyn .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install @sharyn/db 
SYNC missed versions from official npm registry.

???? @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()
  })

Current Tags

  • 3.0.2                                ...           latest (5 months ago)

49 Versions

  • 3.0.2                                ...           5 months ago
  • 3.0.1                                ...           a year ago
  • 3.0.0                                ...           a year ago
  • 2.0.7                                ...           a year ago
  • 2.0.6                                ...           a year ago
  • 2.0.5                                ...           a year ago
  • 2.0.4                                ...           a year ago
  • 2.0.3                                ...           a year ago
  • 2.0.2                                ...           a year ago
  • 2.0.1                                ...           a year ago
  • 2.0.0                                ...           a year ago
  • 1.8.7                                ...           a year ago
  • 1.8.6                                ...           a year ago
  • 1.8.5                                ...           a year ago
  • 1.8.4                                ...           a year ago
  • 1.8.3                                ...           a year ago
  • 1.8.2                                ...           a year ago
  • 1.8.1                                ...           a year ago
  • 1.8.0                                ...           a year ago
  • 1.7.7                                ...           a year ago
  • 1.7.6                                ...           a year ago
  • 1.7.5                                ...           a year ago
  • 1.7.4                                ...           a year ago
  • 1.7.3                                ...           a year ago
  • 1.7.2                                ...           a year ago
  • 1.7.1                                ...           a year ago
  • 1.7.0                                ...           a year ago
  • 1.6.0                                ...           a year ago
  • 1.5.0                                ...           a year ago
  • 1.4.10                                ...           a year ago
  • 1.4.9                                ...           a year ago
  • 1.4.8                                ...           a year ago
  • 1.4.7                                ...           a year ago
  • 1.4.6                                ...           a year ago
  • 1.4.5                                ...           a year ago
  • 1.4.4                                ...           a year ago
  • 1.4.3                                ...           a year ago
  • 1.4.2                                ...           a year ago
  • 1.4.1                                ...           a year ago
  • 1.4.0                                ...           a year ago
  • 1.3.2                                ...           a year ago
  • 1.3.1                                ...           a year ago
  • 1.3.0                                ...           a year ago
  • 1.2.0                                ...           a year ago
  • 1.1.1                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.0                                ...           a year ago
  • 0.2.1                                ...           a year ago
  • 0.2.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |