On Wed, Nov 8, 2017 at 1:57 PM,  <char...@konversion.ca> wrote:
> So I'm trying to add support for Views, following a few recipes like this,
> and this.
>
> Beyond the DDL element, I'd like greater integration with higher level
> SQLAlchemy abstractions.
>
> For example, using the first recipe, the view isn't registered with the
> metadata.
> So while there is a table-like construct associated with the view, it isn't
> really integrated with SQLAlchemy table-management facilities.
> Tables on which the view depends can't be dropped through the `Table.drop`
> or `Metadata.drop_all` methods, since they don't cascade.
> So the `Metadata.drop_all` method is now broken.

I don't understand.  The wiki example runs MetaData.drop_all() as the
last step.   The view is dropped because it *is* associated with the
MetaData via the "before-drop" hook.   I can offer general guidance on
the other requests here but I would need specific runnable code
illustrating how "drop_all" is broken to understand fully what you are
trying to do.

If you'd like the view to be associated as a drop with all the
individual Table objects as well, then add a before-drop linking to
each of those table objects.  This could be automated by looking for
all those Table objects in the given selectable when the view is first
made.

>
> Basically, I'd like to be able to implement the `Table ` "interface" for
> views(i.e. methods like `drop` and `create`). Is it possible? Any pointers
> for that?

The recipe makes use of TableClause, you can subclass it and add a
create() and drop() method to it which calls upon CreateView()  /
DropView(), if you want the "checkfirst" part you can also use
inspect(engine).get_views() (probably didn't exist whe this recipe was
made) to see if the view exists first.

>
> Also, the first recipe uses the "_make_proxy" private method to create a
> TableClause from the selectable. That method is undocumented(and obviously
> private),
> so I don't really like having that in production code. Is there an
> alternative pattern suitable here?

Not at the moment, _make_proxy can be made public across the board if
folks want to work on writing good test suites and documentation for
it.

>
> Is there any chance of seeing views officially supported by SQLAlchemy at
> some point?

Absolutely, with proper contributions it would be great to have a full
featured view object but I would expect that contributors would be
willing to provide tests, draft documentation, as well as some level
of support in triaging and solving bugs discovered once released.
Since views right now work pretty much fully (sans the examples of
"not working" you'll show me) it's been less burdensome on the project
to have views be just an application of existing event and compiler
hooks, since it's easier to maintain those hooks rather than the full
set of features a "View" object would.


>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to