View Manipulation for SQLAlchemy
================================
Adds ``CreateView`` and ``DropView`` constructs to SQLAlchemy.
Status
------
Current version is 0.3.2; 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 (1.0+ and 2.0) as of early 2023.
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 <https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/Views>`_.
Package structure is based on
`python-project-template <https://github.com/seanfisk/python-project-template>`_.
And thank you to the various
`contributors <https://github.com/jklukas/sqlalchemy-views/graphs/contributors>`_!
Raw data
{
"_id": null,
"home_page": "https://github.com/jklukas/sqlalchemy-views",
"name": "sqlalchemy-views",
"maintainer": "Jeff Klukas",
"docs_url": null,
"requires_python": "",
"maintainer_email": "jeff@klukas.net",
"keywords": "",
"author": "Jeff Klukas",
"author_email": "jeff@klukas.net",
"download_url": "https://files.pythonhosted.org/packages/cb/9b/08dbe2c33ccc2e901fd31de1e2fec79df0ba788e1d08c688f18ac1c00e5d/sqlalchemy-views-0.3.2.tar.gz",
"platform": null,
"description": "View Manipulation for SQLAlchemy\n================================\n\nAdds ``CreateView`` and ``DropView`` constructs to SQLAlchemy.\n\nStatus\n------\n\nCurrent version is 0.3.2; 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.\n\nThis package is working with latest Python and SQLAlchemy (1.0+ and 2.0) as of early 2023.\n\nUsage\n-----\n\nExamples:\n\n >>> from sqlalchemy import Table, MetaData\n >>> from sqlalchemy.sql import text\n >>> from sqlalchemy_views import CreateView, DropView\n\n >>> view = Table('my_view', MetaData())\n >>> definition = text(\"SELECT * FROM my_table\")\n >>> create_view = CreateView(view, definition)\n >>> print(str(create_view.compile()).strip())\n CREATE VIEW my_view AS SELECT * FROM my_table\n\n >>> create_view = CreateView(view, definition, or_replace=True)\n >>> print(str(create_view.compile()).strip())\n CREATE OR REPLACE VIEW my_view AS SELECT * FROM my_table\n\n >>> create_view = CreateView(view, definition, options={'check_option': 'local'})\n >>> print(str(create_view.compile()).strip())\n CREATE VIEW my_view WITH (check_option=local) AS SELECT * FROM my_table\n\n >>> drop_view = DropView(view)\n >>> print(str(drop_view.compile()).strip())\n DROP VIEW my_view\n\n >>> drop_view = DropView(view, if_exists=True, cascade=True)\n >>> print(str(drop_view.compile()).strip())\n DROP VIEW IF EXISTS my_view CASCADE\n\nNote that the SQLAlchemy ``Table`` object is used to represent\nboth tables and views. To introspect a view, create a ``Table``\nwith ``autoload=True``, and then use SQLAlchemy's\n``get_view_definition`` method to generate the second\nargument to ``CreateView``.\n\n\nInstallation\n------------\n\n``sqlalchemy-views`` is available on PyPI and can be installed via ``pip`` ::\n\n pip install sqlalchemy-views\n\n\nLimitations\n-----------\n\nVarious SQL dialects have developed custom\n``CREATE VIEW`` and ``DROP VIEW`` syntax.\nThis project aims to provide the core set of functionality\nshared by most database engines.\n\n\nAcknowledgements\n----------------\n\nSome design ideas taken from the\n`SQLAlchemy Usage Recipe for views <https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/Views>`_.\n\nPackage structure is based on\n`python-project-template <https://github.com/seanfisk/python-project-template>`_.\n\nAnd thank you to the various\n`contributors <https://github.com/jklukas/sqlalchemy-views/graphs/contributors>`_!\n",
"bugtrack_url": null,
"license": "",
"summary": "Adds CreateView and DropView constructs to SQLAlchemy",
"version": "0.3.2",
"project_urls": {
"Homepage": "https://github.com/jklukas/sqlalchemy-views"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "afab2802a1a5b4a3c5d6ef28c680cafbdca6345639778be56ce8a0862ea0d164",
"md5": "624a7d29ebee5bc1abe08aee7435d111",
"sha256": "53a376efc8badbbd6d2d360f0d03fc70f1f5ee7748cf169506ea8a6e4f20326c"
},
"downloads": -1,
"filename": "sqlalchemy_views-0.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "624a7d29ebee5bc1abe08aee7435d111",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5666,
"upload_time": "2023-02-18T21:40:43",
"upload_time_iso_8601": "2023-02-18T21:40:43.476968Z",
"url": "https://files.pythonhosted.org/packages/af/ab/2802a1a5b4a3c5d6ef28c680cafbdca6345639778be56ce8a0862ea0d164/sqlalchemy_views-0.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cb9b08dbe2c33ccc2e901fd31de1e2fec79df0ba788e1d08c688f18ac1c00e5d",
"md5": "1c77f654dfb81ec339c86556600a23f1",
"sha256": "c396416939bc4459c71f15c0279b72c9eb1f92fe022afe7fa74ed3adeef76e3b"
},
"downloads": -1,
"filename": "sqlalchemy-views-0.3.2.tar.gz",
"has_sig": false,
"md5_digest": "1c77f654dfb81ec339c86556600a23f1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 18914,
"upload_time": "2023-02-18T21:40:45",
"upload_time_iso_8601": "2023-02-18T21:40:45.770443Z",
"url": "https://files.pythonhosted.org/packages/cb/9b/08dbe2c33ccc2e901fd31de1e2fec79df0ba788e1d08c688f18ac1c00e5d/sqlalchemy-views-0.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-18 21:40:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jklukas",
"github_project": "sqlalchemy-views",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"tox": true,
"lcname": "sqlalchemy-views"
}