sqlalchemy-views icon indicating copy to clipboard operation
sqlalchemy-views copied to clipboard

ORM Support?

Open fgblomqvist opened this issue 7 years ago • 3 comments

I'm confused as to if this adds view support to the SQLAlchemy ORM? As in, how would I go about defining a view model with this (that would be created/dropped automatically when the create_all/drop_all commands are used)?

Ideally one would be able to do something like:

class MyView(ModelView):
    definition = 'SELECT * FROM mytable'
    # column declaration that reflects the SQL

But I'm not sure if this addon allows for anything remotely like that.

fgblomqvist avatar Apr 13 '18 23:04 fgblomqvist

Was looking at an old recipe (https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/Views) but it's using the deprecated execute_at. Tried replicating it using the new DDL events, which went alright I think, however, it still (obviously) emits the normal create and drop statements. Which means it's creating a table, then tries to create a view. Maybe we're supposed to override the create and drop functions instead?

fgblomqvist avatar Apr 14 '18 02:04 fgblomqvist

I haven't personally used the ORM much, so the use cases there aren't immediately obvious to me. I'll try to take more of a look at your suggestions later this week.

jklukas avatar Apr 16 '18 14:04 jklukas

No worries. After a ton of researching and experimenting, I successfully came up with a solution that works (so far): https://stackoverflow.com/a/49894177/998919.

fgblomqvist avatar Apr 18 '18 07:04 fgblomqvist