diff --git a/src/db/fetching.ts b/src/db/fetching.ts index 49ed6748..3e22375d 100644 --- a/src/db/fetching.ts +++ b/src/db/fetching.ts @@ -24,7 +24,7 @@ type InstanceOf = T extends Model * database, otherwise an error will be thrown */ export const findAndOrganizeObjectsByUniqueProperty = < - Table extends Database[keyof Database], + Table extends Database[keyof Omit], P extends keyof InstanceOf >( table: Table, @@ -47,7 +47,7 @@ export const findAndOrganizeObjectsByUniqueProperty = < * and organize them into an AnnotatedMap by a unique value. */ export const findAndOrganizeObjectsByUniqueValue = async < - Table extends Database[keyof Database], + Table extends Database[keyof Omit], V >( table: Table, diff --git a/src/db/index.ts b/src/db/index.ts index 4b7fe392..ca1b5d0a 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -95,8 +95,20 @@ import unitType from './models/unitType'; import usageYear from './models/usageYear'; import workflowStatusOption from './models/workflowStatusOption'; import workflowStatusOptionStep from './models/workflowStatusOptionStep'; +import { Op, Cond } from './util/conditions'; export default (conn: Knex) => ({ + util: { + /** + * Define `_internals` so that it is present on every object in the Database + * to make iterating over tables easier + */ + _internals: { + type: 'util', + } as const, + Op, + Cond, + } as const, attachment: attachment(conn), attachmentPrototype: attachmentPrototype(conn), attachmentVersion: attachmentVersion(conn), diff --git a/src/db/util/conditions.ts b/src/db/util/conditions.ts index bfe5373a..72e4864f 100644 --- a/src/db/util/conditions.ts +++ b/src/db/util/conditions.ts @@ -6,7 +6,7 @@ import Knex = require('knex'); /** * Symbols to use for where condition construction */ -namespace ConditionSymbols { +export namespace ConditionSymbols { export const BUILDER = Symbol('builder'); export const AND = Symbol('and'); export const OR = Symbol('or'); @@ -26,7 +26,7 @@ export const Cond = ConditionSymbols.Cond; /** * Symbols to use when constructing conditions for a single property */ -namespace PropertySymbols { +export namespace PropertySymbols { export const IN = Symbol('in'); export const NOT_IN = Symbol('not in');