2024-01-12 00:01:44 +01:00
|
|
|
import knex from "knex";
|
|
|
|
import config from "../knexfile.js";
|
2020-11-10 23:45:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2024-01-12 00:01:44 +01:00
|
|
|
let cached = global.pg;
|
|
|
|
if (!cached) cached = global.pg = {};
|
2020-11-10 23:45:21 +01:00
|
|
|
|
|
|
|
export function getKnex() {
|
2024-01-12 00:01:44 +01:00
|
|
|
if (!cached.instance) cached.instance = knex(config);
|
|
|
|
return cached.instance;
|
2020-11-10 23:45:21 +01:00
|
|
|
}
|