Registry / database / sql-select

sql-select

JSON →
library3.0.1jsnpmunverified

A JavaScript library for performing SQL-like queries (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, JOIN) directly on arrays of objects, without requiring a database or schema. Current stable version is 3.0.1. Release cadence is irregular. Key differentiators: uses functions instead of strings/objects for queries, dependency-free (<8KB gzipped), works in browser, supports custom scalar functions and user-defined predicates. Not suitable for big data, complex queries (subqueries, set operations), or complex data types (only number and string).

npm install sql-select
INSTALL
IMPORT
SIG · SQL-SELECT
S
sql-select
databasejavascriptv3.0.1
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.

SELECT
import { SELECT } from 'sql-select'
const { SELECT } = require('sql-select')
CommonJS require is not supported; the library is ESM-only.
FROM
import { FROM } from 'sql-select'
import { from } from 'sql-select'
Case-sensitive: function names are uppercase. Lowercase 'from' will not be found.
WHERE
import { WHERE } from 'sql-select'
import { where } from 'sql-select'
Uppercase only. Also note that WHERE takes a predicate function, not a string condition.

Demonstrates basic SELECT with aggregate functions (SUM, AVG), WHERE filter, GROUP BY, and ORDER BY on an array of objects.

import { SELECT, FROM, SUM, AVG, WHERE, GROUP_BY, ORDER_BY, DESC, AS } from 'sql-select' import { drawTable } from 'sql-select-utils' const input = [ { name: 'John', salary: 20 }, { name: 'James', salary: 30 }, { name: 'Joe', salary: 50 }, { name: 'John', salary: 100 }, { name: 'James', salary: 130 }, { name: 'Joe', salary: 150 }, { name: 'John', salary: 10 } ] const query = () => SELECT('name', SUM('salary', AS('sum')), AVG('salary', AS('avg')), FROM(input), WHERE(row => row.salary > 15), GROUP_BY('name'), ORDER_BY('sum', DESC)) console.log(drawTable(query()))
Debug
Known issues
breakingIn v2, SELECT required an array of column names. In v3, SELECT takes variadic arguments (string or aggregate functions).
fix
Change SELECT(['col1', 'col2'], ...) to SELECT('col1', 'col2', ...).
affects: >=3.0.0
breakingIn v2, FROM returned a query object. In v3, FROM is a function that must be called inside SELECT.
fix
Ensure FROM(input) is placed inside the SELECT() call, not used separately.
affects: >=3.0.0
deprecatedThe 'AS' function is used to alias columns, but its syntax may change in future versions.
fix
Use AS('alias') as shown in docs; watch for updates.
affects: >=3.0.0
gotchaAll SQL function names are uppercase (SELECT, FROM, WHERE, etc.). Using lowercase will throw a ReferenceError.
fix
Use uppercase function names: SELECT, FROM, WHERE, GROUP_BY, ORDER_BY, etc.
affects: >=1.0.0
gotchaThe library is ESM-only; CommonJS require will not work. This may cause issues in Node.js CJS projects.
fix
Use import syntax or configure your project for ESM. If using Node.js, set 'type': 'module' in package.json.
affects: >=3.0.0
gotchaThe WHERE clause predicate function must return a boolean. If it returns undefined/null, the row is filtered out.
fix
Ensure the predicate explicitly returns true/false.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: SELECT is not defined
Using lowercase or forgetting to import SELECT
fix
Import SELECT as { SELECT } from 'sql-select' and use uppercase.
SyntaxError: Unexpected identifier
Calling FROM or WHERE outside of a SELECT call
fix
Place FROM, WHERE, etc. inside the SELECT() function call.
TypeError: input is not iterable
Passing a non-array to FROM()
fix
Ensure FROM() receives an array of objects.
Error: Cannot find module 'sql-select'
Missing installation or using CommonJS require in ESM-only package
fix
Run 'npm install sql-select' and use import { SELECT } from 'sql-select'.
TypeError: fn is not a function
Using a string as a condition in WHERE or HAVING instead of a function
fix
Pass a predicate function like row => row.age > 18.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies
sql-select-utilsoptionalProvides drawTable and other utility functions for formatting query results
Agent activity
11 hits · last 30 days
node
8
Meta
1
OpenAI (training)
1
Resources
sql-select — npm install sql-select · libregistry