April 24th, 2025

A Principled Approach to Querying Data – A Type-Safe Search DSL

The article presents a Domain-Specific Language for efficient querying in local-first web applications, emphasizing modular query processing, error handling, and performance optimizations for scalability and user-friendly search experiences.

Read original articleLink Icon
A Principled Approach to Querying Data – A Type-Safe Search DSL

The article discusses a principled approach to querying data, particularly in the context of local-first web applications that require efficient client-side data processing. It emphasizes the need for a Domain-Specific Language (DSL) tailored for searching issues in project management and bug tracking systems. The proposed DSL enhances usability by allowing users to express search intent clearly and concisely. The article outlines the structure of the dataset, error handling using the Either type from functional programming, and the use of parser combinators to build a modular and declarative query parser. The parser transforms input strings into an Abstract Syntax Tree (AST), which separates syntax from semantics, allowing for optimization and flexibility in query execution. The article also highlights the importance of performance, suggesting that while the current implementation can handle a significant number of records, indexing and other optimizations are necessary for real-world applications. The conclusion reiterates the robustness and extensibility of the system, which is built on type safety and functional programming principles, making it suitable for both local-first and server-side systems.

- The article presents a DSL for efficient querying in local-first web applications.

- It emphasizes the use of parser combinators and an AST for modular query processing.

- Error handling is managed through the Either type, enhancing reliability.

- Performance optimizations, including indexing and caching, are crucial for scalability.

- The approach is applicable to both local-first and server-side systems, promoting user-friendly search experiences.

Link Icon 8 comments
By @fire_lake - about 21 hours
> Users expect near-native responsiveness, even when offline

Do they? I think users are amazed if anything works without internet with modern applications.

By @williamcotton - about 3 hours
I've got a similar project that includes a React component for the search input. The React component is actually a Monaco text editor so you get syntax highlighting, error highlighting, tab completion and more.

Check it out here: https://github.com/williamcotton/search-input-query

There's an animated GIF of the demo so you can get a very quick idea of how it works!

By @gitroom - about 13 hours
Nice, Ive bounced around between Prisma and Kysely too. I get nervous about locking too much into one thing, you ever worry if leaning on too much codegen or magic ends up biting you down the road?
By @FrustratedMonky - about 23 hours
Seems a lot like FSharp Type Providers? Is that a good analogy?
By @tehlike - about 18 hours
LINQ or PRQL.
By @hu3 - about 23 hours
Looks good.

For a more database specific, type-safe, data querying solution, I like to use https://kysely.dev

By @mifydev - about 22 hours
The same should apply to configuration, we have prisma for sql, we should have something like this for JSONs, like https://typeconf.dev (I’m one of the founders)