Thanks, I'm still in the early stages of this project and any comments
are highly appreciated. What I'm trying to actually accomplish is to
build some complex queries to be executed against an Odoo [1] DB. Odoo
has it's own ORM, but it lacks some features I like the most about
SQLAlchemy:
- A clear API to define custom mappings.
- A clear low-level API to create SQL-like sentences (even coupled to
PostgreSQL) that would be a highly appreciated.
See [2] for a hard to maintain and test method.
I'd keep Odoo's models for the description of the DB layer. But I would
like more flexibility to represent the Python-side of some models.
Using the 'mock' strategy I thought I could run the SQL myself like and
funnel the SQL execution back to Odoo's cursors. Something like::
def execute(self, sql, *params, **other):
#
self.obj.cr is wrapper around pyscopg2's cursor
self.obj.cr.execute(sql, params) # How to merge params and other?
return do_something_with(self.obj.cr.fetchall())
If the 'executor' returns a ResultProxy-like, the 'mock' strategy would
work? If it should work, then the problem would be to create a
ResultProxy compliant object that bridges Odoo's world to SA's.
I'm guessing the 'executor' is only called when the real query to the DB
is required. Not at "expression-build time". Am I right?
Maybe I need another approach. So far, I was trying to use SA's
introspection of tables to avoid having the describe the tables
myself. The goals are to be able to use SA's expression language to
build complex SQL queries.
Again, this is just the first stage of this project.
Best regards,
Manuel.
[1]
https://github.com/odoo/odoo
[2]
https://github.com/odoo/odoo/blob/8.0/addons/account/account_move_line.py#L37