Skip to main content

Adds CreateView and DropView constructs to SQLAlchemy

Project description

Adds CreateView and DropView constructs to SQLAlchemy.

Status

Current version is 0.2.2; releases are infrequent as the code here is small and based on stable pieces of the SQLAlchemy API, so there has been no maintenance required so far to keep compatibility with new SQLAlchemy or python versions.

As of late 2018, this package is still working with latest Python and SQLAlchemy.

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
>>> 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlalchemy_views-0.2.2-py2.py3-none-any.whl (4.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sqlalchemy_views-0.2.2-py2.py3-none-any.whl.

File metadata

  • Download URL: sqlalchemy_views-0.2.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.10

File hashes

Hashes for sqlalchemy_views-0.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 82e6df12a71c9db30247bdb88c190170adde4acd1ccf2d997656a52e7da94c5a
MD5 a88cd5fd9d93233684edd25e302d05cc
BLAKE2b-256 debb2bdd883ac43f78ccbbb7a23df0bbbfe435f8fd8ef179cffdde6785af61d8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page