🌳
pt0/serverF/dbF/dbCtxF.mts
1import type { Knex } from 'knex'
2import { genContext } from "../genContextF.mts";
4import type { DbHandles } from './dbTypesF.mts'
6export const dbCtx = genContext<DbHandles>('dbCtx')
8/**
9 * Per-request AsyncLocalStorage for DataLoaders. Entered alongside dbCtx in
10 * withDb so all resolvers within a GraphQL request share loader instances.
11 * Populated lazily by getVideoSourceLoader/getImmutablesLoader/getSvesLoader
12 * in stor2core.
13 */
14export const loadersCtx = genContext<Record<string, unknown>>('loadersCtx')
16export const getDb = (): DbHandles => {
17 const ret = dbCtx.getStore()
19 return ret
22export const getReqKnex = (): Knex => {
23 const {db} = getDb()
25 return db as Knex