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.3.1; 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 late 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!

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

sqlalchemy-views-0.3.1.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

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

sqlalchemy_views-0.3.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy-views-0.3.1.tar.gz.

File metadata

  • Download URL: sqlalchemy-views-0.3.1.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.7

File hashes

Hashes for sqlalchemy-views-0.3.1.tar.gz
Algorithm Hash digest
SHA256 5aeaaa3be005ead283e4fe189dd65d2c9ccfdf0212e19d6647b8589332d7e31e
MD5 a7f20cb39c4f5dc80fe81be00b244bea
BLAKE2b-256 478052783c6bc672129db4d396bcd524864c355b7c3a1f94318dcdebfdd1c84f

See more details on using hashes here.

File details

Details for the file sqlalchemy_views-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: sqlalchemy_views-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.7

File hashes

Hashes for sqlalchemy_views-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 de2b714274b3f32da8a496571848ff75ae3c9cb5145195e402fa1bb896dd400f
MD5 7c672623c81bf0d968a97effe1f21ffe
BLAKE2b-256 87c07cd3dfef586e54481bd747c939545440b81dd30ac2fd40655b3a10c768af

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