Adds CreateView and DropView constructs to SQLAlchemy
Project description
Adds CreateView and DropView constructs to SQLAlchemy.
Status
Current version is 0.3.0; releases are infrequent as the code here is small and based on stable pieces of the SQLAlchemy API, so there has been minimal maintenance required so far to keep compatibility with new SQLAlchemy or python versions.
This package is working with latest Python and SQLAlchemy as of early 2021.
Usage
Examples:
>>> from sqlalchemy import Table, MetaData >>> from sqlalchemy.sql import text >>> from sqlalchemy_views import CreateView, DropView>>> view = Table('my_view', MetaData()) >>> definition = text("SELECT * FROM my_table") >>> create_view = CreateView(view, definition) >>> print(str(create_view.compile()).strip()) CREATE VIEW my_view AS SELECT * FROM my_table>>> create_view = CreateView(view, definition, or_replace=True) >>> print(str(create_view.compile()).strip()) CREATE OR REPLACE VIEW my_view AS SELECT * FROM my_table>>> create_view = CreateView(view, definition, options={'check_option': 'local'}) >>> print(str(create_view.compile()).strip()) CREATE VIEW my_view WITH (check_option=local) AS SELECT * FROM my_table>>> drop_view = DropView(view) >>> print(str(drop_view.compile()).strip()) DROP VIEW my_view>>> drop_view = DropView(view, if_exists=True, cascade=True) >>> print(str(drop_view.compile()).strip()) DROP VIEW IF EXISTS my_view CASCADE
Note that the SQLAlchemy Table object is used to represent both tables and views. To introspect a view, create a Table with autoload=True, and then use SQLAlchemy’s get_view_definition method to generate the second argument to CreateView.
Installation
sqlalchemy-views is available on PyPI and can be installed via pip
pip install sqlalchemy-views
Limitations
Various SQL dialects have developed custom CREATE VIEW and DROP VIEW syntax. This project aims to provide the core set of functionality shared by most database engines.
Acknowledgements
Some design ideas taken from the SQLAlchemy Usage Recipe for views.
Package structure is based on python-project-template.
And thank you to the various [contributors](https://github.com/jklukas/sqlalchemy-views/graphs/contributors)!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sqlalchemy_views-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | caeb97cace6b60f55a9a35289388dda7d5f31c959d3cc9aa90d4f51ecdcb2522 |
|
MD5 | 63f17d555d98cd34b3f025b24a6af0b5 |
|
BLAKE2b-256 | c4a9b7992c737f39c9d600fdb4e10d9fb45f7eb6b67c95c313487849a6240f61 |