Entity / Operators

Searching prefixes with Text.startsWith

To match a UPC prefix without LIKE wildcard pitfalls, use the built-in primitive Text.startsWith:

ts
import { Text } from 'foldkit-entity'

const search = Expr.input('search', Schema.String)
const ByCode = Query.from(Product).pipe(Query.where(Text.startsWith(fields.upc, search)))

// `label` lacks a field collation, so supply one at the call site.
const ByLabel = Query.from(Product).pipe(
  Query.where(Text.startsWith(fields.label, search, { collation: Collation.asciiFold })),
)

Text.startsWith requires an explicit collation (binary or asciiFold) so memory, SQLite, and Postgres agree, propagates null as unknown, matches every row for an empty prefix, and treats % and _ as literal characters.