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:
- columnname - add equal to clause for the column
- columnname_not_equal - add not equal to clause for the column
- columnname_less_than - add less than clause for the column
- columnname_greater_than - add greater than clause for the column
- columnname_less_or_equal - add a less than or equal to clause for the column
- columnname_greater_or_equal - add a greater than or equal for the column
- columnname_like - add like clause for the column
- columnname_not_like - add not like clause for the column
- columnname_is_null - add is null clause for the column
- columnname_not_null - add is not null clause for the column
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"
});
Comments
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:
and then in code:
the sql in operator is 'missing', something like:
would be nice.
the not_null comparison should be named colanme_is_not_null, afaik there is no 'colname not null' comparison in sql
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?
yes, it does. I'll update my proposal shortly.
Ok, forget those endless object literal arguments. This is the way to do it:
http://code.google.com/appengine/docs/datastore/queryclass.html
http://bret.appspot.com/entry/experimenting-google-app-engine
the nice thing at appengine's implementation is that chaining of filters, that would be great to have in helma