Mapping views as Table/ORM

1,225 views
Skip to first unread message

temp...@gmail.com

unread,
Aug 9, 2013, 4:55:01 AM8/9/13
to sqlal...@googlegroups.com
It seems that SQLAlchemy has no support for creating views by a "View" construct or something like that but you can map them as a "Table" or even an ORM class when applicable, and query from them, the problem is that SQLAlchemy will than try to create them as a new table when you issue metadata.create_all(), is there a convenient way around this, without having to pass a list of tables to create_all?
 

Werner

unread,
Aug 9, 2013, 6:11:59 AM8/9/13
to sqlal...@googlegroups.com
Maybe this recipe will help.

http://www.sqlalchemy.org/trac/wiki/UsageRecipes/Views

Werner

temp...@gmail.com

unread,
Aug 13, 2013, 2:45:56 PM8/13/13
to sqlal...@googlegroups.com
Seems like a reasonable way to do this until maybe one day proper support is added to sqlalchemy.
 
I'm still missing one thing though, it seems like there is a feature that allows you to reflect views, but it reflects them as a "Table" and as such when you later on try to create_all(), it will recreate the view as a table in the database, is there any way to use reflection while avoiding this side effect?
בתאריך יום שישי, 9 באוגוסט 2013 13:11:59 UTC+3, מאת werner:

Michael Bayer

unread,
Aug 13, 2013, 2:50:42 PM8/13/13
to sqlal...@googlegroups.com
maybe use a separate MetaData collection when reflecting your views, so that create_all() isn't impacted.  The View recipe could also be enhanced to support reflection, you can use the inspector to get at lists of columns individually: http://docs.sqlalchemy.org/en/rel_0_8/core/schema.html?highlight=inspector.get_columns#sqlalchemy.engine.reflection.Inspector.get_columns


--
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+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

signature.asc
Reply all
Reply to author
Forward
0 new messages