Strategy utils
Every custom step (strategy.ids, strategy.rows, strategy.facets, strategy.query) receives utils: helpers built from the resource's field paths and your Drizzle setup.
utils.buildWhereClause({ filters, search })
Compiles the normalized filters and search into a Drizzle where condition you can pass directly to .where(...).
const strategy = {
ids: async ({ request, utils }: any) => {
const where = utils.buildWhereClause({
filters: request.filters,
search: request.search,
});
return { where, rows: [] };
},
};
The compiled condition already includes all filters from the request, including scope-merged filters (the scope is merged into request.filters before your strategy runs). Handles all operators, nested groups, ILIKE for search, and relation-path resolution.
utils.compileOrderBy(sorting)
Compiles the normalized sorting array into a Drizzle orderBy array.
const orderBy = utils.compileOrderBy(request.sorting);
utils.executeIdsQuery(options)
Runs the engine's automatic ids query. Use this inside a strategy.ids override when you only need to customize part of the logic and want the default SQL for the rest:
const strategy = {
ids: async ({ request, context, utils }: any) => {
console.time("ids");
const result = await utils.executeIdsQuery({ request, context });
console.timeEnd("ids");
return result;
},
};
Returns: { ids: unknown[], pageInfo: QueryPageInfo }
utils.executeRowsQuery({ ids, relations })
Hydrates a set of ordered ids using the resolved hydration profile and db.query.root.findMany(...). Handles deduplication and restores the original id order.
const strategy = {
rows: async ({ ids, relations, utils }: any) => utils.executeRowsQuery({ ids, relations }),
};
Returns: { rows: TRow[] }
utils.resolveFacets({ request, facets })
Runs the engine's default facet aggregation for each requested facet.
const strategy = {
facets: async ({ request, facets, utils }: any) => utils.resolveFacets({ request, facets }),
};
Returns: { facets: QueryFacetResult[] }
utils.resolveField(path)
Resolves a field path string to its Drizzle column reference. Useful when writing custom SQL that needs to reference a field by its path name:
const col = utils.resolveField("customer.name");
Combining utils with custom SQL
The most common pattern is to use buildWhereClause and compileOrderBy for filter/sort compilation (avoiding duplication of that logic) while writing the join shape yourself:
const strategy = {
ids: async ({ request, context, utils }: any) => {
const where = utils.buildWhereClause({
filters: request.filters,
search: request.search,
});
const orderBy = utils.compileOrderBy(request.sorting);
const { pageSize } = request.pagination;
return { ids: [], pageInfo: offsetPageInfo };
},
};