Dean,
I'm looking for a declarative language like jsonpath or jsonquery in
order to bind javascript objects (it's a bit more complicated, since
it's restfull resources in fact) to ui widgets.
I'm using kris zyp implementation of jsonquery, having modified it in
order to get values *and* absolutes paths when i execute a query.
By absolutes paths, i mean :
JSONQuery("store.book[?price<10].title").paths -->
["store.book[0].title", "store.book[1].title", "store.book[3].title"]
I need absolutes paths to make read/write bindinds. Of course queries
like "store.book[0][=title + " : " + author] are readonly.
What i'm doing is a bit like what Microsoft is doing with jQuery
(
http://forum.jquery.com/topic/proposal-for-adding-data-linking-to-
jquery) and a bit like what Kris Zyp seems to have done with
persevere.
I do stuff like :
var q = createAQuery("/store/store.book[?price<10].title"); //
createAQuery is not the real function name
q.onChange(function(newVal, oldVal) {
//Do Stuff
});
q.onError(function(errors) {
//Do Stuff with errors
});
---
var q = createAQuery("/store/store.book[?price<10").attr("title", "my
new title");
---
var title = createAQuery("/store/store.book[?price<10").attr("title");
var title = createAQuery("/store/store.book[?price<10").value().title;
---
var q = createAQuery("/store/store.book[?price<10]");
q.each(function(value, itemQuery, index) {
if (value.price > 5) {
itemQuery.attr("buyit", true);
}
});
---
As IQueryable in Linq, q variables are *lazy* with datas.
So i'm really interested with resource-queries, do you have more
documentation on it ?
On 6 mai, 01:19, Dean Landolt <
d...@deanlandolt.com> wrote:
> On Wed, May 5, 2010 at 6:19 PM, Marak Squires <
marak.squi...@gmail.com>wrote:
>
> > Dean -
>
> > Thank you for the detailed response.
>
> No problem -- awesome job on this BTW! I just wanted to point out lighter
> weight (syntax-wise) alternative...or complement, depending on how you look
> at it.
>
> I'm still experimenting with JSON based query languages, always good to know
>
> > there are options available. I haven't had the chance to really dive into
> > doing a lot of complicated JSON queries, so far most of it has been fairly
> > simple stuff.
>
> > *a couple of quick questions if you don't mind:*
>
> > does resource-query work browser-side and cross-browser?
>
> It should be able to be adapted -- it's completely dep-free. I haven't tried
> it in the browser but only thing that jumps out at me from a cross-browser
> standpoint would be arrays expected to have a forEach -- but that's
> obviously easy to work around.
>
>
>
> > does / will resource-query support most of these methods?
> >
http://maraksquires.com/JSLINQ/api.html(more specifically,
> > im particularly interested in JOIN and GroupBy)
>
> I see you don't have these yet either :)
>
> Grouping is also of particular interest to me as well -- I'd love to find a
> syntax for grouping that works (and can be optimized for, for instance, sql
> and mongo query compilation). Sacrifices would have to be made but I'm
> confident there are some primitives that would give us what we need.
>
> As I see it there are three levels to efficient query handling -- what can
> be compiled and pushed down to datastore to handle natively (e.g.
> comparisons), what can be handled reasonably efficiently in the streamed
> response (e.g. filters) and what requires full buffering (e.g. reverse). And
> of course this will depend on your store's query support. I'd like to go
> deeper into what I mean by this but it's a bit OT and irrelevant when
> comparing apples-to-apples with JSLINQ except to say it one of the reasons I
> think these two techniques are complementary is that resource-query
> *could* server
> as an excellent *source* for arrays to LINQ over (e.g. database result sets)
> -- you may not *always *want to keep your whole db in memory.
>
> > it seems you also have a whole packaged solution, is it possible to just
> > one some of these pieces?
>
> Yes, it should be possible to just use *resource-query* itself, or any part
> thereof (just the parseQuery function, for instance, to get a parsed query
> object that you can do what you want with -- like compile alternate queries
> with). Does JSLINQ offer anything like an AST? That'd be really cool.
>
> > are there any pages where i play around with the syntax in an interactive
> > console? something likehttp://
maraksquires.com/JSLINQ/
>
> No but that's a damn fine idea. I'll push your example data set to somewhere
> public so that you can play around with it like God intended -- right in the
> url :)
>
>
>
> > *and a few comments : *
>
> > i do like the idea of having the queries be URL safe, but in the context of
> > what i'm doing thats a bit irrelevant.
>
> Sure enough -- just a bonus.
>
>
>
> > i do kinda like the syntax that Linq uses, but more importantly Linq is
> > pretty well known in the .net community.
>
> You *like* LINQ's syntax? I'd always considered it a necessary evil. The
> chaining is great but its still so imperative. It's just not something I'd
> trust to be built on the fly based on some client side form, for example.
> That's where something like resource-query shines. If you're lazy and you're
> down with Dojo you can use the JsonRestStore to build resource-query for
> you.
>
> > pretty much anyone who does .net work with data should know about Linq.
>
> But what does that have to do with javascript?! As far as I can tell I'm one
> of the *few* people around these parts that *do* use LINQ regularly (I work
> for a .NET shop and try to abuse LINQ every time I'm forced to crack open
> Visual Studio). Still, after quite a bit of usage I *still* don't fully grep
> it -- and that's my real gripe with it -- it's very much like magic (though
> not as pretty).
>
> > it seems kris is inventing his own syntax? this isn't nessarlity a bad
> > thing, but there is something to be said on language design.
>
> Ah, but to me that's the fundamental difference between the two approaches
> -- LINQ *is* like a full on language -- resource-query is a reasonably
> lightweight extension to standard querystring syntax.
>
> Thanks for the comments. I'll get something for you to poke around at.
> Looking at your api docs and code make me think a lot of the LINQ stuff
> could be supported in one way or another. And for that which can't, the
> ability to throw some JSLINQ on top of a resource-query result is pretty
> awesome!
>
>
>
>
>
> > -Marak
>
> > On Wed, May 5, 2010 at 5:39 PM, Dean Landolt <
d...@deanlandolt.com> wrote:
>
> >> On Tue, May 4, 2010 at 9:49 PM, Marak Squires <
marak.squi...@gmail.com>wrote:
>
> >>> Hello dear internet friends!
>
> >>> i have freed some code from codeplex and got Microsoft's LINQ working
> >>> nicely in the browser and in node.
>
> >>> LINQ (
http://en.wikipedia.org/wiki/Language_Integrated_Query) is pretty
> >>> well known in .NET land, but I think it could really help out in JavaScript
> >>> land as its power lays in the ability to perform queries against JSON. i've
> >>> tried json-path and json-query in the past and did not like.
>
> >> I'm also not a huge fan of json-query's syntax but there's definitely
> >> value in the declarative approach. Kris Zyp's successor to json-query is
> >> resource-query [1] -- I think you'll find it a little more palatable. It's
> >> much more compact and familiar than both json-query and LINQ and almost as
> >> expressive. Here are the examples you've got on github compared
> >> to equivalent resource queries:
>
> >> *simple Select*:
>
> >> var sample = JSLINQ(sampleData).
> >> Select(function (item) {return item.FirstName;});
>
> >> *resource-query:* "select(FirstName)"
>
> >> *simple Select with OrderBy*
>
> >> var sample = JSLINQ(sampleData).
> >> Select(function (item) {return item.FirstName;}).
> >> OrderBy(function (item) {return item;});
>
> >> *resource-query:* "sort(FirstName)&select(FirstName)"
>
> >> *more complex select/sorts, just for good measure:*
>
> >> *sort descending:* "sort(-FirstName)&select(FirstName)"
>
> >> *multisort, multiselect*:
> >> "sort(FirstName,-LastName)&select(FirstName,LastName)"
>
> >> *simple Where*
>
> >> var sample = JSLINQ(sampleData).Where(function (item) {return
> >> item.FirstName == "Chris";});
>
> >> *resource-query:* "FirstName=Chris"
>
> >> Other types of *calls* are supported: for instance "in" and "slice" --
> >> and for comparisons you can use other comparators (<, >=, != ... ). And
> >> these two things -- calls and comparisons -- are really the only primitives
> >> you'll typically need.
>
> >> Right now the resource-query module is bundled in the perstore [2] package
> >> it could be put somewhere (perhaps the commonjs-utils [3] package). But if
> >> you choose to use it *with* perstore you'll get some added benefits --
> >> for starters you can use the persistent-memory store and get a
> >> node-dirty-like experience plus resource-query. And, of course, you could
> >> always run JSLINQ operations on top of the result set -- the best of both
> >> worlds. Oh yeah -- perstore "stores" support resource-query (or some
> >> reasonable subset) which allows you to use the same syntax to efficiently
> >> query mongo and sql and your raw memory store all the same. It's relatively
> >> easy to compile resource-query down into your query language of choice to
> >> push to your data store of choice -- that's a pretty big win.
>
> >> If you choose to use it with pintura [4] (meaning, over HTTP) the resource
> >> queries are simply the query component of your urls (notice how the syntax
> >> is url-safe: try that with LINQ :) so your queries would look like this:
>
> >>
http://localhost:8080/book/?sort(FirstName,-LastName)&select(FirstNam...)
> >>
nodejs+un...@googlegroups.com<
nodejs%2Bunsu...@googlegroups.com>
> >> .
> >
nodejs+un...@googlegroups.com<
nodejs%2Bunsu...@googlegroups.com>
> > .
> To unsubscribe from this group, send email ...
>
> plus de détails »