rsnext/examples/with-knex/knex/index.js
Ash Connell b8c49ae97a
Add with-knex example (#17904)
* Add with-knex example

* Fix with-knex README typo

Co-authored-by: Ash Connell <hello@ashconnell.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2020-11-10 17:45:21 -05:00

16 lines
421 B
JavaScript

import knex from 'knex'
import config from '../knexfile.js'
/**
* Global is used here to ensure the connection
* is cached across hot-reloads in development
*
* see https://github.com/vercel/next.js/discussions/12229#discussioncomment-83372
*/
let cached = global.pg
if (!cached) cached = global.pg = {}
export function getKnex() {
if (!cached.instance) cached.instance = knex(config)
return cached.instance
}