Skip to content

Instantly share code, notes, and snippets.

@Sandesh003
Sandesh003 / buildQuery.ts
Created October 12, 2023 06:23 — forked from adrianhajdin/buildQuery.ts
How I Made My Website Load in 0.364 Seconds | Build and Deploy
export function buildQuery(params: BuildQueryParams) {
const { type, query, category, page = 1, perPage = 20 } = params;
const conditions = [`*[_type=="${type}"`];
if (query) conditions.push(`title match "*${query}*"`);
if (category && category !== "all") {
conditions.push(`category == "${category}"`);
}