Entity
    Preparing search index...

    Type Alias EntityLoaderSearchFieldSQLFragmentFnSpecification<TFields, TSelectedFields>

    Specification for a search field that is a manually constructed SQLFragment. Useful for complex search fields that require transformations to make nullable fields non-null or to make combinations of multiple fields.

    type EntityLoaderSearchFieldSQLFragmentFnSpecification<
        TFields extends Record<string, any>,
        TSelectedFields extends keyof TFields = keyof TFields,
    > = {
        fieldConstructor: (
            getFragmentForFieldName: EntityLoaderFieldNameConstructorFn<
                TFields,
                TSelectedFields,
            >,
        ) => SQLFragment<Pick<TFields, TSelectedFields>>;
    }

    Type Parameters

    • TFields extends Record<string, any>
    • TSelectedFields extends keyof TFields = keyof TFields
    Index

    Properties

    Properties

    fieldConstructor: (
        getFragmentForFieldName: EntityLoaderFieldNameConstructorFn<
            TFields,
            TSelectedFields,
        >,
    ) => SQLFragment<Pick<TFields, TSelectedFields>>

    Function that constructs the SQLFragment for the search field.

    Type Declaration

    For example, to construct a search field that searches by display name (nullable column) with fallback to full name, the fieldConstructor function could be implemented as follows:

    fieldConstructor: (getFragmentForFieldName) => {
    const displayNameFragment = getFragmentForFieldName('display_name');
    const fullNameFragment = getFragmentForFieldName('full_name');
    return sql`COALESCE(NULLIF(${displayNameFragment}, ''), split_part(${fullNameFragment}, '/', 2))`;
    }