Dict to Query conversion

39 views
Skip to first unread message

Alan Etkin

unread,
Jan 27, 2013, 6:52:38 PM1/27/13
to
I wrote this snippet that accepts a database query represented as Python dictionary and builds a Query instance. I think this could be used by the DAL class for accepting this syntax:

>>> db({"op": "GT", "first": {"tablename": "auth_user", "fieldname": "id"}, "second": 0})
<Set (auth_user.id > 0)>

http://www.web2pyslices.com/slice/show/1593/class-for-building-db-queries-from-python-dictionaries

I think that Set could also support Set.as_dict() for mapping Query objects with the above syntax

I know there's also Query.__dict__ and Set.__dict__, but those attributes return non json-serializable objects and much of the data cannot be easily converted to protocols like JSON or XML.

Massimo DiPierro

unread,
Jan 27, 2013, 5:17:34 PM1/27/13
to web2py-d...@googlegroups.com
It would be really be nice to have a way to do

  def dalservice(): db.expose_service()

and in a different application


i think your code may enable it.

On Jan 27, 2013, at 2:45 PM, Alan Etkin wrote:

I wrote this snippet that accepts a represented as Python dictionary and builds a Query instance. I think this could be used by the DAL class for accepting this syntax:
--
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
 
 

Alan Etkin

unread,
Jan 28, 2013, 6:06:06 AM1/28/13
to web2py-d...@googlegroups.com
It would be really be nice to have a way to do ...
 
I'm not sure I understood  expose_service, but with the experimental db.as_dict, we could return the model as xml/json.
The missing feature would be the serialization of the actions (different service resources). Perhaps it would be possible to register action definitions (args, output) in a service object so they can be consumed by expose_service in a similar way as pysimplesoap does.

About the dal(url), I belive this is more explicit and consistent with the other types of engines

remotedb = DAL("service://<url>")


Reply all
Reply to author
Forward
0 new messages