Ticket #5873 (closed enhancement: fixed)

Opened 2 years ago

Last modified 23 months ago

[patch][cla] AndOrReadStore, AndOrWriteStore: New stores supporting complex queries

Reported by: frankf Owned by: jaredj
Priority: normal Milestone: 1.2
Component: Data Version: 1.0
Severity: normal Keywords: AndOrReadStore,AndOrWriteStore,complex query
Cc: frank.fortson@…

Description

The attached AndOrReadStore?.js and AndOrWriteStore?.js are identical to ItemFileReadStore? and ItemFileWriteStore?, except the read store's _fetchItems, filter function supports complex queries against the store.

Example queries supported:

  Programmatic:
    query[:|=]"NOT id:23* AND (type:'test*' OR dept:'bob') && !filed:true"

  Widget (where json object may be required for query):
    query[:|=]{complexQuery:"NOT id:23* AND (type:'test*' OR dept:'bob') && !filed:true"}

Available logical operators (case insensitive):

  , NOT AND OR ( ) ! && ||  Note: "," included for legacy queries (translated to AND).

Also, simple queries, as typically used with the other stores, are supported.

The stores are intended for dojox/data.

The attached AndOrXXXXStore.js unit test files are intended for dojox/data/tests/stores. The test file names are temporarily pre-fixed with "t" to prevent overwriting.

The attached patch file adds the two stores to the modules.js file in dojox/data/tests.

Attachments

AndOrReadStore.js (31.2 kB) - added by frankf 2 years ago.
AndOrReadStore?.js, complex query capability
AndOrWriteStore.js (28.2 kB) - added by frankf 2 years ago.
AndOrWriteStore?.js, complex query capability
tAndOrReadStore.js (93.9 kB) - added by frankf 2 years ago.
to be renamed to AndOrReadStore?.js and placed in dojox/data/tests/stores
tAndOrWriteStore.js (144.7 kB) - added by frankf 2 years ago.
to be renamed to AndOrWriteStore?.js and placed in dojox/data/tests/stores
module.js.patch (0.8 kB) - added by frankf 2 years ago.
patch to dojox/data/tests/module.js to add the two stores
dojox.data.AndOrStore_20080508.patch.zip (41.1 kB) - added by jaredj 23 months ago.
Zipped version of the patch. Otherwise too big.

Change History

Changed 2 years ago by frankf

AndOrReadStore?.js, complex query capability

Changed 2 years ago by frankf

AndOrWriteStore?.js, complex query capability

Changed 2 years ago by frankf

to be renamed to AndOrReadStore?.js and placed in dojox/data/tests/stores

Changed 2 years ago by frankf

to be renamed to AndOrWriteStore?.js and placed in dojox/data/tests/stores

Changed 2 years ago by frankf

patch to dojox/data/tests/module.js to add the two stores

Changed 2 years ago by frankf

  • summary changed from AndOrReadStore, AndOrWriteStore: New stores supporting complex queries to AndOrReadStore, AndOrWriteStore: [cla]New stores supporting complex queries

Changed 2 years ago by dylan

  • summary changed from AndOrReadStore, AndOrWriteStore: [cla]New stores supporting complex queries to [patch][cla] AndOrReadStore, AndOrWriteStore: New stores supporting complex queries
  • milestone set to 1.1

Changed 2 years ago by wolfram

Is the read store doing the filtering on the client side? So its first loading the data from the server and later filtering it in the browser?

Changed 2 years ago by frankf

Yes. The two stores are copies of ItemFileXXXXStore, with the only change being the query (_fetchItem) modified to accept a more complex query.

So, to do filtering for a Grid, you just do grid.model.query="...." and then grid.model.refresh(), and the Grid will reflect the results of the complexQuery.

Changed 2 years ago by wolfram

Aha, so you could also extend the ItemFileXXXXStore and add a method such as _filterResponse() just like it was added to QueryReadStore? and supply a mixin or alike that supplies the filtering stuff you are suggesting? see http://trac.dojotoolkit.org/browser/dojox/trunk/data/QueryReadStore.js?rev=11711#L363 What do you think?

Changed 2 years ago by frankf

I didn't study that closely, but it seems possible, maybe for any of the stores? Are you suggesting that approach (1) to replace what I submitted or (2) using the complex query part from it for other stores? Both sound interesting...

Changed 2 years ago by wolfram

I think it would also prove extensibility of the existing stores quite well if you could provide AndOrReadStore? as an extension, so I think it would be 1) of your options.

I have to possible ways in mind A) A new store extending ItemFileReadStore?

dojo.declare("dojox.data.AndOrReadStore", "dojo.data.ItemFileReadStore", {
    _filterResponse:function(data) {
    }
});

Which has the big disadvantage of working ONLY with ItemFileReadStore? ...

B) Write a mixin that can be used for any store

dojo.declare("dojox.data._AndOrReadMixin", null, {
    _filterResponse:function(data) {
    }
});

Which then can be used by the anyone to extend any store, i.e.

var s = new dojox.data.QueryReadStore(params);
dojo.mixin(s, dojox.data._AndOrReadMixin);

And now "s" would also have the capabilities you suggested! Disadvantage is that one would always have to mix-in the _AndOrReadMixin. or is there something like

<div dojoType="dojox.data.QueryReadStore" mixin="dojox.data._AndOrReadMixin" />

I hope others have opinions too to know which makes most sense. Actually I like the second one best. But it might also very much be possible that I make things too complicated again :-)

Changed 2 years ago by frankf

Thanks. I like your suggestion of having a bite-sized piece of code to maintain and just being able to mixin it, with possibly having a pre-mixedin store, also, for the newer dojo users who don't yet grasp it, just want to grab a store and go.

I'll look at it some at the end of the week, unless you get there first :).

Changed 2 years ago by dante

I vote generic mixin (b) so it can be reused in any store, in generic ways (if it's really that easy)

But this discussion should be continued on dojo-interest/contributors or more ideally the dojox dev forums.

Changed 2 years ago by jaredj

  • milestone changed from 1.1 to 1.2

A mixin helper (much like the stuff in dojo.data.util), would be nice for those who want to extend their query support beyond the recommended basic queries that all stores should support.

I'm going to move this to 1.2 so we can settle on how to put it in.

Changed 23 months ago by jaredj

Zipped version of the patch. Otherwise too big.

Changed 23 months ago by jaredj

  • status changed from new to closed
  • resolution set to fixed

(In [13644]) Adding in the AndOr?*Store from Frank F. Had to do a lot of work to get JSLint to like the code. fixes #5873 \!strict

Note: See TracTickets for help on using tickets.