zmdbzero-maintenance data layer
Docs Benchmarks Anti-patterns OpenAPI
Docs / Schema and ORM

Full-Text SearchSupported

PostgreSQL full-text search is expressible directly in the query builder, and a typed SearchDTO layers ranking + paging on top.

Match a term#

import { postgres } from '@zmdb/postgres';
import { createQueryCompiler, trustedTable } from '@zmdb/sql';

createQueryCompiler(postgres).selectFrom(trustedTable('products')).whereMatch('description', 'wireless headphones').compile();
SELECT * FROM "products"
WHERE to_tsvector("description") @@ to_tsquery($1)

Through the repository#

await products.findByFullText('description', 'wireless headphones');

Ranked search with SearchDTO#

import { buildSearchResult, type SearchDTO } from '@zmdb/schema/dto';

const search: SearchDTO<Product> = {
  query: 'wireless',
  columns: ['description'],
  rank: true,
};
const result = buildSearchResult(hits, { limit: 20 }); // items carry an optional _score
❗ Important

FTS is dialect-specific. On SQLite (no arbitrary-column FTS without FTS5), findByFullText throws an explicit UnsupportedFeatureError rather than silently running a wrong query. This is one of the routes exercised against real Postgres in the benchmarks.