@molecule/api-search-sqlite
Provider bond · search · API (Node) · v1.0.1 · Apache-2.0
SQLite FTS5 full-text search provider for molecule.dev
npm install @molecule/api-search-sqlitenpm · Source on GitHub · Implements @molecule/api-search
How it works
@molecule/api-search-sqlite is a provider bond on the API (Node) side: it implements the search core interface (@molecule/api-search) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
import { createIndex, index, search, setProvider } from '@molecule/api-search'
import { provider } from '@molecule/api-search-sqlite'
// After bonding a SQLite database pool:
setProvider(provider)
await createIndex('articles', { fields: { title: 'text' }, searchableFields: ['title'] })
await index('articles', 'intro', { title: 'Getting started', published: true })
const results = await search('articles', { text: 'start', filters: { published: true } })Works with: @molecule/api-database, @molecule/api-search
Reference
SQLite FTS5 full-text search through the bonded SQLite database pool.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
import { createIndex, index, search, setProvider } from '@molecule/api-search'
import { provider } from '@molecule/api-search-sqlite'
// After bonding a SQLite database pool:
setProvider(provider)
await createIndex('articles', { fields: { title: 'text' }, searchableFields: ['title'] })
await index('articles', 'intro', { title: 'Getting started', published: true })
const results = await search('articles', { text: 'start', filters: { published: true } })
Type
provider
Installation
npm install @molecule/api-search-sqlite @molecule/api-analytics @molecule/api-database @molecule/api-search
API
Interfaces
SqliteSearchProvider
SQLite search provider with atomic deletion of multiple document IDs.
interface SqliteSearchProvider extends SearchProvider {
/**
* Deletes the requested documents in one statement. Unknown IDs are ignored.
*
* @param indexName - Index containing the documents.
* @param ids - Document IDs to delete.
* @returns A promise that resolves after deletion.
*/
bulkDelete(indexName: string, ids: readonly string[]): Promise<void>
}
Functions
createProvider()
Creates a SQLite FTS5 search provider that uses the currently bonded database pool.
function createProvider(): SqliteSearchProvider
Returns: A search provider with an additional atomic bulkDelete method.
Constants
provider
Default SQLite search provider. Database access begins on the first operation.
const provider: SqliteSearchProvider
Core Interface
Implements @molecule/api-search interface.
Bond Wiring
Setup function to register this provider with the core interface:
import { setProvider } from '@molecule/api-search'
import { provider } from '@molecule/api-search-sqlite'
export function setupSearchSqlite(): void {
setProvider(provider)
}
Injection Notes
Requirements
Peer dependencies:
@molecule/api-database^1.2.2@molecule/api-search^1.0.4
Runtime Dependencies
@molecule/api-analytics@molecule/api-database@molecule/api-search
Each index stores the original JSON document and an FTS5 index in the same database.
At creation, searchableFields selects which top-level strings and string array elements
to index. Omitting it includes every top-level text field. Recreating an existing index
preserves its documents and configuration. createIndex() is memoized per active database
pool instance (automatically invalidating on deleteIndex(), closeDefaultPool(), or
setPool()), so callers can invoke await createIndex(...) directly without keeping
module-global indexReady flags or reset helpers.
Search matches every word as a literal prefix. Blank input browses the index.
BM25 scores increase with relevance, and equal scores sort by document ID.
Highlighted snippets use the combined _content field and escape HTML from documents.
Filters compare top-level fields by JSON value. Sorting uses SQLite's native JSON scalar
types, and facets count non-null values across all matches before pagination.
Suggestions use prefix search and return a text field from each ranked document.
The optional field list selects labels in priority order. Fuzzy matching is unavailable.
Use provider.bulkDelete(indexName, ids) to delete multiple documents atomically.
E2E Tests
Integration checklist — drive the real UI (live preview, no mocks), adapt each item to this app's actual screens/flows, and check every box off one by one. A box you can't check is an integration bug to fix — not a skip:
- Searching a term that exists in seeded data returns the matching records in the results UI.
- An empty search box shows the browse-everything view (empty
textmatches ALL documents by contract) — not zero results and not an error. - A term with no matches shows a clear "no results" state.
- Index-on-write is wired: create a new record through the UI, then search for it — it must be findable without a manual reindex.
- If autocomplete/suggestions are surfaced, typing a prefix of a known record shows relevant suggestions.
- Search is scoped to the caller: one user's search never returns another user's private records.