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

Support SQLite

Open wadetregaskis-linkedin opened this issue 5 years ago • 3 comments

SQLite doesn't have … OR REPLACE … syntax for view creation - instead you have to do DROP VIEW IF EXISTS foo as a separate statement.

I intended to try adding this myself, but ran into #9 before I even really got started. The actual changes in views.py are pretty trivial, but having to first deal with the existing test failures is a bit discouraging.

wadetregaskis-linkedin avatar Jun 23 '20 22:06 wadetregaskis-linkedin

#9 should hopefully be resolved now.

Are you proposing that we support CreateView(..., or_replace=True) for SQLite by rewriting to "DROP VIEW IF EXISTS" and "CREATE"?

jklukas avatar Jun 24 '20 13:06 jklukas

I assume this module generally works with SQLite, but throws an error if you set or_replace=True. Is that correct?

jklukas avatar Jun 24 '20 13:06 jklukas

Precisely. As a workaround, I'm right now 'manually' adding a DropView(…, if_exists=True) first, and specifying or_replace=False, when I'm using SQLite - but otherwise, when not using SQLite, just using CreateView(…, or_replace=True). Not a big deal, but it'd be nice to just integrate that into this library directly so that application code doesn't have to worry about the distinction (and doesn't have to explicitly do the drop).

In my use, SQLite is sometimes used in test environments instead of a real DB, which is why this comes up & has to be handled dynamically; I can't just hard-code for one specific DB dialect.

wadetregaskis-linkedin avatar Jun 24 '20 14:06 wadetregaskis-linkedin