Skip to content

Use SQL syntax to filter and select from arrays of objects

Notifications You must be signed in to change notification settings

andrewf414/jsql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jSQL

This is a small utility to enable using SQL style queries on JavaScript arrays of objects. Essentially it boils down to doing a reduce and a sort, but it means you don't have to set them up each time and think about it.

Install

$ npm i @fitzy/jsql

Usage

import  *  as  jsql  from  '@fitzy/jsql';

jsql.select('SELECT * FROM myData', { myData: [{a: 1, b: 'foo'}, {a: 4, b: 'bar'}, ...], relatedData: [] });

The data is passed in as an array to: a) allow putting the key in the select statement, and b) allow me to expand this to have joins later

Supported Syntax

  • SELECT
  • FROM
  • WHERE (=, <=, >=, <, >, <>, like, in, between)
  • ORDER BY
  • Aliasing (i.e. select field AS othername)

Working on

  • Dates

Yet to Implement

  • GROUP BY
  • HAVING
  • Aggregate functions (avg, count, etc)
  • JOINs

About

Use SQL syntax to filter and select from arrays of objects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published