0.11.3 ā€¢ Published 4 years ago

@cuillere/postgres-koa-middleware v0.11.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 years ago

cuillere is an extensible asynchronous execution framework based on generator functions.

šŸš§ cuillere is still in early development stage, the API may change at any time.

Why ?

The goal of cuillere is to abstract some inevitable technical complexity (such as managing database transactions) in plugins, and keep business code as simple and focused as possible.

Usage

In this example we use cuillere to manage the connection to a PostgreSQL database.

const cuillere = require('@cuillere/core')
const { poolPlugin, transactionPlugin, queryPlugin } = require('@cuillere/postgres')

const cllr = cuillere(
  poolPlugin({ /* postgres config */ }), // Manages connection pool
  transactionPlugin(), // Manages transactions
  queryPlugin() // Executes queries
)

const addUserAddress = (userId, address, setDefault) => cllr.call(function*() {
  const res = yield query({
    text: `INSERT INTO addresses (userId, street, postalcode, city)
           VALUES ($1, $2, $3, $4)
           RETURNING *`,
    values: [userId, address.street, address.postalCode, address.city]
  })
  if (setDefault) {
    const addressId = res.rows[0].id
    yield query({
      text: `UPDATE users
             SET defaultaddressid = $1
             WHERE userid = $2`,
      values: [addressId, userId]
    })
  }
})

Install

yarn add @cuillere/core

Authors

šŸ‘¤ Valentin Cocaud

šŸ‘¤ Nicolas Lepage

šŸ¤ Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page.

Show your support

Give a ā­ļø if this project helped you!

šŸ“ License

Copyright Ā© 2019 Valentin Cocaud. This project is Apache-2.0 licensed.


This README was generated with ā¤ļø by readme-md-generator