[storm] Mixing explicit and implicit joins
James Henstridge
james.henstridge at canonical.com
Tue Mar 17 02:56:51 GMT 2009
On Tue, Mar 17, 2009 at 1:39 AM, Shaun McCance <shaunm at gnome.org> wrote:
> Thanks for the response. This sounds like exactly what I'm
> looking for. I did see AutoTables when looking through the
> Storm source, but I couldn't quite figure out how to use it.
> I think I don't really understand the compilation process.
Here is an example that assumes the presence of User and Bug Storm classes
>>> from storm.expr import State
>>> state = State()
>>> store._connection.compile(User.id == Bug.submitter, state)
'user.id = bug.submitter'
>>> state.auto_tables
[<class 'User'>, <class 'Bug'>]
We can use AutoTables to augment the automatic list of tables:
>>> from storm.expr import AutoTables
>>> state = State()
>>> store._connection.compile(AutoTables(User.id == Bug.submitter,
[Foo]), state)
u'(user.id = bug.submitter)'
>>> state.auto_tables
[<class 'User'>, <class 'Bug'>, <class 'Foo'>]
> I don't know what other people would find useful, but for me,
> a simple utility function like get_tables_for_args would be
> great. It could just return a tuple of every referenced table.
> I can take care of filtering out the ones I know I'm explicitly
> joining.
You can introduce joins using AutoTables as above. The compilation
function for Select expressions takes care of filtering out duplicate
table references, prefering joins over bare table references by
default. So the code to do what you want already exists in Storm.
> For the time being, I've just required callers of my selection
> function to pass a tuple of extra tables if they need them.
> Not the most elegant solution, but it gets the job done and
> lets me get on to other tasks.
Thank you for sending the email. Hopefully we can improve the
situation either through better documentation of what is currently
available and/or improving the API to be more discoverable.
James.
More information about the storm
mailing list