Svelte query builder
MIT · Svelte 5 · runes · TypeScript
@qnot/svelte, default builder, live on this page. Edit a rule and watch the exports.
pnpm add @qnot/core @qnot/svelteA Svelte query builder in two files.
For more control, put a store in context with setQueryStore and read it with getQueryStore. The create* helpers (createRule, createGroup, createQuery, createHistory) each subscribe only to the node they read, so editing one rule updates one rule.
The default builder takes components, labels and class. See the Svelte guide.
What you get.
- Typed schemadefineFields · QueryOf
Declare fields once. Rule values narrow by field and operator, and validated queries come back typed.
- Export anywhereSQL · Mongo · JsonLogic
Parameterized SQL in five dialects, MongoDB, JsonLogic, Elasticsearch, SpEL and plain English.
- Validationissues
Per-rule issues from the schema: required, min/max, patterns, options and your own checks.
- Undo and redohistory
Every edit is a step, typing merges into one. The demo above has the buttons wired up.
- Drag and dropdnd
Move rules and groups anywhere. The Svelte binding ships the drag handle and drop target helpers.
- Any languagelabels · messages
Every UI string and validation message is an override away. No i18n library required.
- Same query on the servervalidate · compile
Share fields.ts with your API. Validate the query, then run it as bound SQL or filter rows in memory.
- Fast at 1,000 rulesper-node subscriptions
Editing one rule updates one rule. A keystroke costs the same at ten rules or a thousand.
How it compares.
Questions people ask
- Is it free?
- Yes. @qnot/svelte and @qnot/core are MIT licensed, with no license key, no trial banner and no paid tier.
- Which Svelte versions are supported?
- Svelte 5. The components use runes, and the reactive helpers subscribe once per node, so an edit only wakes the rows it changes.
- Does it work with SvelteKit?
- Yes. The package ships .svelte source through the svelte export condition, which SvelteKit's Vite plugin compiles. The default builder renders on the server (we checked it with svelte/server's render), and your +server.ts or form actions can import the same fields.ts to validate the query and turn it into SQL.Server usage
- Does it support bind:value?
- Yes. QueryBuilder takes value as a bindable prop, plus onchange. You can also pass a store you created and share it with setQueryStore.
- Can I write my own components?
- Yes. createRule, createGroup, createQuery, createHistory and the drag helpers return objects whose getters subscribe only to what they read. They work in components and in .svelte.ts modules. The default Group, Rule and ValueEditor are exported for reuse.Svelte guide
- Can the same query run on the server?
- Yes. The query is plain JSON typed by your schema. On the server, validate it with validateQuery, then encode it to parameterized SQL, a MongoDB filter or JsonLogic, or filter rows in memory with compile.Formats