Registry / database / snack-query-builder

snack-query-builder

JSON →
library1.0.4jsnpmunverified

Snack Query Builder is a lightweight, type-safe SQL query builder for TypeScript/JavaScript that generates SQL strings programmatically without being an ORM. It provides a fluent API for building SELECT queries with projection, WHERE conditions (including comparisons like greaterOrEqualThan), GROUP BY, HAVING, subqueries, and TOP clauses. Version 1.0.4 is the latest stable release, published on npm with TypeScript type definitions included. Unlike ORMs such as TypeORM or Sequelize, it does not abstract away SQL or manage database connections; it simply constructs raw SQL strings. Ideal for developers who want full control over their SQL while benefiting from TypeScript's type checking.

npm install snack-query-builder
INSTALL
IMPORT
SIG · SNACK-QUERY-BUILDE
S
snack-query-builder
databasejavascriptv1.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SnackQueryBuilder
✓ import { SnackQueryBuilder } from 'snack-query-builder/dist';
✗ import { SnackQueryBuilder } from 'snack-query-builder';
The package exports from the 'dist' subfolder; importing from the root may not resolve.
Aggregation
✓ import { Aggregation } from 'snack-query-builder/dist';
✗ const Aggregation = require('snack-query-builder').Aggregation;
CommonJS require works but must include '/dist'; ESM import is the recommended approach for TypeScript.
Colorful
✓ import { Colorful } from 'snack-query-builder/dist';
Used for terminal-colored SQL output; optional.

Builds a SELECT query with projection, WHERE condition, and ordering, then prints the generated SQL.

import { SnackQueryBuilder, Aggregation, Colorful } from 'snack-query-builder/dist'; const query = new SnackQueryBuilder(); query .from('users') .select('id', 'name', 'email') .where() .greaterOrEqualThan(Aggregation.and, 'age', 18) .end() .orderBy('name'); console.log(query.build(Colorful.Terminal)); // Output: // select // id, // name, // email // from users // where age >= '18' // order by name
Debug
Known issues
gotchaImport must use '/dist' path
fix
Use 'import { ... } from 'snack-query-builder/dist';' instead of from 'snack-query-builder'.
affects: >=1.0.0
gotchaValues in WHERE conditions are always wrapped in quotes as strings
fix
Cast numeric values to strings before passing; consider using parameterized queries separately.
affects: >=1.0.0
gotchaNo support for JOINs, UNIONs, or subqueries beyond fromSubQuery
fix
Use raw SQL strings or another library for complex queries; snack-query-builder only covers SELECT basics.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'snack-query-builder'
Missing '/dist' in import path
fix
Ensure import path is 'snack-query-builder/dist'.
Property 'build' does not exist on type 'SnackQueryBuilder'
Chaining incomplete; forgot .end() after .where()
fix
Add .end() to close the WHERE (or HAVING) clause before calling .build().
TypeError: query.from is not a function
Misordering methods; .from() must be called first
fix
Always start with new SnackQueryBuilder() and call .from() before other methods.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
snack-query-builder — npm install snack-query-builder · libregistry