SpahQL - A query language for Javascript objects(angryamoeba.co.uk) |
SpahQL - A query language for Javascript objects(angryamoeba.co.uk) |
SQlike is another effort in the same direction. It provides a wide range of SQL features including joins. JavaScript tables are used as query language.
See http://www.thomasfrank.se/sqlike.html for an overview and http://www.thomasfrank.se/SQLike/ for examples.
dataArray = [
{firstName: "Paul", lastName: "Stele", age:35, salary:35000},
...
]
dataArray2 = [
{firstName: "Paul", lastName: "Stele", favColor:"green"},
...
]
SQLike.q(
{
Select: ['*'],
From: dataArray,
Where: function(){return this.salary>50000},
OrderBy: ['salary','|desc|']
}
)
SQLike.q(
{
Select: ['*'],
From: {t1:dataArray},
NaturalJoin: {t2:dataArray2},
Where:function(){return this.t1.firstName!='Vicki'}
}
)SpahQL is definitely much lighter than that - the API is intended to be more jquery-like with a specific selector language, each selection returning a resultset object which then provides methods for subselections and modifications.
Features
--------------------------------------
implement all .NET 4.0 methods and many extra methods
(inspiration from Rx, Achiral, Haskell, Ruby, etc...)
complete lazy evaluation
full IntelliSense support for VisualStudio
two versions - linq.js and jquery.linq.js (jQuery plugin)
support Windows Script Host
binding for Reactive Extensions for JavaScript(RxJS) and
IntelliSense Generator -> see documentation
NuGet install support(linq.js, linq.js-jQuery, linq.js-Bindings)
90 Methods
----------------------------------------
Aggregate, All, Alternate, Any, Average, BufferWithCount,
CascadeBreadthFirst, CascadeDepthFirst, Catch, Choice,
Concat,Contains, Count, Cycle, DefaultIfEmpty, Distinct, Do,
ElementAt, ElementAtOrDefault, Empty, Except, Finally, First,
FirstOrDefault, Flatten, ForEach, Force, From, Generate,
GetEnumerator, GroupBy, GroupJoin, IndexOf, Insert, Intersect,
Join, Last, LastIndexOf,
LastOrDefault, Let, Matches, Max, MaxBy, MemoizeAll, Min,
MinBy, OfType, OrderBy, OrderByDescending, Pairwise,
PartitionBy, Range, RangeDown, RangeTo, Repeat,
RepeatWithFinalize, Return, Reverse, Scan, Select, SelectMany,
SequenceEqual, Share, Shuffle,
Single, SingleOrDefault, Skip, SkipWhile, Sum, Take,
TakeExceptLast, TakeFromLast, TakeWhile, ThenBy,
ThenByDescending, ToArray,
ToDictionary, ToInfinity,ToJSON, ToLookup, ToNegativeInfinity,
ToObject, ToString, Trace, Unfold, Union, Where, Write,
WriteLine, Zip* Declarative syntax for selections, such that selection queries may be handed between implementations in other languages
* Imperative syntax for updates, such that updates may be idiomatic to the language in which the spahql library has been ported (linq meets this criteria)
In essence all SpahQL is, is a shorthand syntax for generating traversal and descent functions, which output a proxy object for reading to and writing from the selected nodes.
it would be more javascripty and would be another implementation (or a superset) of jsonpath
http://goessner.net/articles/JsonPath/ http://code.google.com/p/jsonpath/ https://github.com/joshbuddy/jsonpath https://github.com/marianoguerra/jsonpath-scala
It's most certainly not perfect, but I had fun experimenting with it.
but sometimes I think jsonpath should be more visible and it's not, that's why I was trying to avoid fragmentation for the same solution. But as you said, it tries a different approach so it makes sense to use a different syntax.
This really doesn't look much like SQL to me - much more like an interesting variation on XPath...
Why do you think it is a copy of SQL?
Edit: I also want to add Datalog http://en.wikipedia.org/wiki/Datalog
and list comprehensions http://en.wikipedia.org/wiki/List_comprehensions
Along these lines, by the way, is my Javascript port of Apple's "key-value coding":
http://quile.github.com/keyvaluecoding-js
which allows you to traverse object graphs without all the null-check nonsense. Admittedly the purpose is slightly different, but they seem related.
I hope I don't cause too much confusion!
www.example.com/data.json,
one could append SparQL to select a subset www.example.com/data.json/user
www.example.com/data.json/categories/*
www.example.com/data.json/categories/0/products
www.example.com/data.json//avatarIt's a shame that QUEL lost to SQL. Betamax vs. VHS, all over again.
Perhaps something like:
www.example.com/data.json?query=/user www.example.com/foo
and it can arbitary sub-resources e.g. www.example.com/foo/bar/raz
then how do I know whether bar is a different resource or part of the JSON returned describing www.example.com/fooThis would mean you'd have to restrict your resource names to ensure they don't clash with JSON names - which seems a pain (e.g. say the resource names are uploaded files and directories, so you won't have much control over what they are called)