Registry / testing / sql-js

sql-js

JSON →
library0.1.0jsnpmunverified

A lightweight JavaScript library that provides an SQL-like query interface for filtering, grouping, and joining in-memory arrays of objects. Version 0.0.1 (current stable 0.1.0) offers a fluent API with methods like select(), from(), where(), groupBy(), having(), and execute(). It supports cross joins between multiple arrays and custom predicate functions. Unlike full SQL databases or query builders (e.g., alasql), SQL-js operates entirely in-memory with zero dependencies, making it ideal for trivial client-side data manipulation. Development appears slow with no recent releases.

npm install sql-js
INSTALL
IMPORT
SIG · SQL-JS
S
sql-js
testingjavascriptv0.1.0
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.

query
import { query } from 'sql-js'
import query from 'sql-js'
Only named export; default import will fail.
QueryBuilder
import { QueryBuilder } from 'sql-js'
const QueryBuilder = require('sql-js').QueryBuilder
Named export; CommonJS require may work in Node but preferred ESM.

Demonstrates basic usage: import query, filter array using where with a predicate, and execute.

import { query } from 'sql-js'; const data = [ { name: 'Han', profession: 'Smuggler', age: 30 }, { name: 'Luke', profession: 'Hero', age: 32 }, { name: 'Leia', profession: 'Princess', age: 32 }, { name: 'Anakin', profession: 'Jedi', age: 50 }, { name: 'Obi', profession: 'Jedi', age: 65 }, { name: 'Chewie', profession: 'Smuggler', age: 30 }, { name: 'Lando', profession: 'Smuggler', age: 50 } ]; const result = query() .select() .from(data) .where(p => p.profession === 'Jedi') .execute(); console.log(result); // [{ name: 'Anakin', profession: 'Jedi', age: 50 }, { name: 'Obi', profession: 'Jedi', age: 65 }]
Debug
Known issues
gotchaThe .select() method currently takes no arguments; all fields are always returned. Filtering columns is not supported.
fix
Use .select() without arguments; do not expect column projection.
affects: <=0.1.0
gotchaJoin syntax uses multiple array arguments to .from() but only performs cross joins; no INNER/LEFT JOIN semantics.
fix
Filter cross join results with .where() and custom predicates to simulate joins.
affects: <=0.1.0
gotchaThe .groupBy() method groups by a function, not a property name. For grouping by a property, use a getter function like (item) => item.age.
fix
Pass a function that extracts the grouping key instead of a string.
affects: <=0.1.0
Errors
Common errors & fixes
TypeError: (intermediate value).select is not a function
Forgetting to call query() as a function or using default import instead of named import.
fix
Use `import { query } from 'sql-js'` and invoke `query()` to start the builder chain.
SyntaxError: The requested module 'sql-js' does not provide an export named 'default'
Attempting to default import when only named export exists.
fix
Use `import { query } from 'sql-js'` instead of `import query from 'sql-js'`.
TypeError: data is not iterable
Passing a non-array to .from().
fix
Ensure .from() receives an array (or multiple arrays for cross join).
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
packagesql-js
sql-js — npm install sql-js · libregistry