Helma Logo
main list history

HopObject Query Object

Update: the functionality described in this proposal has been implemented by HopObject.getCollection() - see Creating Collections programmatically.

I've been thinking about a query feature that allows to build HopObject collection on the fly. Under the hood, the query object would be a HopObject with a custom DbMapping. The SQL query would probably be built using a subnodeRelation built from properties of the query object's filter property. These filter conditions could cover a number of common comparison operators:

Query objects could be created by a constructor or factory function passing the arguments as object literals.

  var q = new HopQuery({
     type: Page,
     filter: {
        createtime_greater_than: t1,
        createtime_less_or_equal: t2,
        type_like: "update:%"
     },
     order: "createtime desc"
  });

Links to this page: Re(1): Helma 1.7 wishlist

Comments

#1 by maks at 2007/09/28 06:49

so does this mean a collection's properties filter could be defined "on the fly" using the above Query object, rather then having to be predefined in a type.properties line?
so you could do something like:

  Root/type.properties:
  pages= collection(Page)

and then in code:

  this.pages.filter = q;
  var somePages = this.pages.list();
#2 by hypersmil at 2007/11/15 16:00

the sql in operator is 'missing', something like:

  var q = new HopQuery({
     type: Page,
     filter: {
        creator_in: ['user','admin','guest'],
        type_like: "update:%"
     },
     order: "createtime desc"
  });

would be nice.

the not_null comparison should be named colanme_is_not_null, afaik there is no 'colname not null' comparison in sql

#3 by Lehni at 2007/11/20 17:07

I think this should be a static function in HopObject returning a HopObject collection rather than a prototype on its own, e.g. HopObject.get or HopObject.query. Does that make sense?

#4 by hannes at 2007/11/20 17:34

yes, it does. I'll update my proposal shortly.

#5 by hannes at 2008/04/09 14:33
#6 by skrat at 2008/08/08 22:17

the nice thing at appengine's implementation is that chaining of filters, that would be great to have in helma