SQLike: SQL-like Querying Engine for JavaScript and ActionScript
Join the DZone community and get the full member experience.
Join For FreeA lightweight query engine that can filter arrays in JavaScript using a 'SQL-like' syntax was revealed today by creator Thomas Frank. Named "SQLike," the small (10kB) ECMAscript (JavaScript and ActionScript) query engine is used on the browser's client side to make it easier for searching, combining, and updating data when an SQL-like approach is better suited (e.g. in flat table-like structures).
Frank admits that SQLite isn't as fast as SQLite, but it's "a handy alternative for small amounts of data." He goes on to say:
Developers who are familiar with SQL should be able to easily pick up SQLike. It supports a multitude of language elements including SELECT, JOIN, EXCEPT, UPDATE, JOIN (implicit), SELECT DISTINCT, INTERSECT, and more. It also uses aggregate functions such as COUNT, SUM, and AVERAGE.
Some differences between SQL and SQLike are the way in which you write queries. In SQLike, they are written as literal objects. The where and set keywords take JavaScript and ActionScript functions as arguments. Those functions can also be included in select statements. In SQLike, you don't alter tables or create them, because they are identical to arrays and easily generated outside of SQLike. Finally, you don't index tables.
Because SQLike consists of ECMA-262 code, all of the code inside function q is identical and has been compressed by the YUI compressor. The only difference in languages is at the beginning lines defining SQLike as:
Here are some examples of SQLike's SQL-like syntax:


YQL provides the same functionality using web services, but SQLite does it in-memory.
Read more about SQLike in this blog or try a demo and short reference.
Also check out a similar solution in LINQ to JavaScript. [http://jslinq.codeplex.com/]
Frank admits that SQLite isn't as fast as SQLite, but it's "a handy alternative for small amounts of data." He goes on to say:
"Data structures in JavaScript and ActionScript are JSON:esque and sometimes deeply nested. When they are nested into XML-like structures a query language such as JSONPath (XPath for JSON) is a sound approach. But sometimes you might also use flat table-like structures. In those cases a more SQL-like approach can be more suited for searching, combining and updating data."

Some differences between SQL and SQLike are the way in which you write queries. In SQLike, they are written as literal objects. The where and set keywords take JavaScript and ActionScript functions as arguments. Those functions can also be included in select statements. In SQLike, you don't alter tables or create them, because they are identical to arrays and easily generated outside of SQLike. Finally, you don't index tables.
Because SQLike consists of ECMA-262 code, all of the code inside function q is identical and has been compressed by the YUI compressor. The only difference in languages is at the beginning lines defining SQLike as:
- JS object
- AS2 class
- AS3 class inside a package
Here are some examples of SQLike's SQL-like syntax:


YQL provides the same functionality using web services, but SQLite does it in-memory.
Read more about SQLike in this blog or try a demo and short reference.
Also check out a similar solution in LINQ to JavaScript. [http://jslinq.codeplex.com/]
JavaScript
ActionScript
Database
Engine
Opinions expressed by DZone contributors are their own.
Comments