Skip to content

krishnakumar-m/array-sql-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 

Repository files navigation

array-sql-filter

Adds SQL-like query capabilities to JS Object Arrays.

Inclusion of the library adds where(), select() and orderBy() capabilities to object arrays.

  1. where() - Accepts SQL query string as parameter. Simulates SQL WHERE clause. Handles all expressions including BETWEEN and IN clauses. Scalars and Aggregate functions are not supported yet.
  2. select() - Simulates SQL SELECT.
  3. orderBy() - Simulates SQL ORDER BY.
  4. joinOn() - Simulates SQL INNER JOIN. (Experimental) Takes the join field (or the join expression) as the first parameter and the array to be joined as the next.

For testing, include sql-where.js in your project

###Example

var employee = [{
    empid: 100,
    ename: "Chuck"
}, {
    empid: 101,
    ename: "Rick"
}, {
    empid: 99,
    ename: "George"
}];

Calling

employee.where("ename like '%ck'").select("ename,empid").orderBy("empid desc")

returns [{ename:"Rick",empid:101},{ename:"Chuck",empid:100}].

Sample Fiddle

###Future Add various SQL scalar and aggregate functions

About

Use sql like where clause to filter object arrays

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published