From bbd7df362bb736266e645c93c1f5a9f108de4494 Mon Sep 17 00:00:00 2001 From: matkuliak Date: Thu, 30 Mar 2023 19:19:48 +0200 Subject: [PATCH 1/5] Edit the robots to stop the readthedocs page from being indexed --- docs/_extra/robots.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/_extra/robots.txt b/docs/_extra/robots.txt index baa43f3c..412dae65 100644 --- a/docs/_extra/robots.txt +++ b/docs/_extra/robots.txt @@ -1,2 +1,4 @@ -Sitemap: https://crate.io/docs/python/en/latest/site.xml User-agent: * +Disallow: / + +Sitemap: https://crate.io/docs/python/en/latest/site.xml From f5e10722e23f7f0e1acde559ab5506b488393d09 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Apr 2023 15:04:14 +0000 Subject: [PATCH 2/5] Update zope-testrunner requirement from <6,>=5 to >=5,<7 Updates the requirements on [zope-testrunner](https://github.com/zopefoundation/zope.testrunner) to permit the latest version. - [Release notes](https://github.com/zopefoundation/zope.testrunner/releases) - [Changelog](https://github.com/zopefoundation/zope.testrunner/blob/master/CHANGES.rst) - [Commits](https://github.com/zopefoundation/zope.testrunner/compare/5.0...6.0) --- updated-dependencies: - dependency-name: zope-testrunner dependency-type: direct:development ... Signed-off-by: dependabot[bot] --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a11c4e0f..be1b8a5c 100644 --- a/setup.py +++ b/setup.py @@ -65,7 +65,7 @@ def read(path): 'backports.zoneinfo<1; python_version<"3.9"'], test=['tox>=3,<5', 'zope.testing>=4,<6', - 'zope.testrunner>=5,<6', + 'zope.testrunner>=5,<7', 'zc.customdoctests>=1.0.1,<2', 'createcoverage>=1,<2', 'stopit>=1.1.2,<2', From f1a338fb30ce81a3f01ed0ae48888f88b76f822a Mon Sep 17 00:00:00 2001 From: Fabian Reisegger Date: Mon, 17 Apr 2023 11:05:15 +0200 Subject: [PATCH 3/5] Enable ``RETURNING`` clause for sqlalchemy 2.0 --- .../sqlalchemy/advanced-querying.rst | 69 +++++++++++++++++++ src/crate/client/sqlalchemy/dialect.py | 2 + 2 files changed, 71 insertions(+) diff --git a/docs/by-example/sqlalchemy/advanced-querying.rst b/docs/by-example/sqlalchemy/advanced-querying.rst index 863373e4..a6ce97db 100644 --- a/docs/by-example/sqlalchemy/advanced-querying.rst +++ b/docs/by-example/sqlalchemy/advanced-querying.rst @@ -257,6 +257,73 @@ Now, verify that the data is present in the database: ["('Write Tests',)"] +``INSERT...RETURNING`` +====================== + +The ``RETURNING`` clause can be used to retrieve the result rows of an ``INSERT`` +operation. It may be specified using the ``Insert.returning()`` method. + +The first step is to define the table: + + >>> from sqlalchemy import insert + + >>> class User(Base): + ... __tablename__ = 'user' + ... __table_args__ = { + ... 'crate_number_of_replicas': '0' + ... } + ... id = sa.Column(sa.String, primary_key=True, default=gen_key) + ... username = sa.Column(sa.String) + ... email = sa.Column(sa.String) + + >>> Base.metadata.create_all(bind=engine) + +Now, let's use the returning clause on our insert to retrieve the values inserted: + + >>> ins = insert(User).values(username='Crate', email='crate@crate.io').returning(User.username, User.email) + >>> result = session.execute(ins) + >>> session.commit() + >>> print([str(r) for r in result]) + ["('Crate', 'crate@crate.io')"] + +The following ``INSERT...RETURNING`` statement was issued to the database: + + INSERT INTO user (id, username, email) + VALUES (:id, :username, :email) + RETURNING user.id, user.username, user.email + +``UPDATE...RETURNING`` + +The ``RETURNING`` clause can also be used with an ``UPDATE`` operation to return +specified rows to be returned on execution. It can be specified using the +``Update.returning()`` method. + + +We can reuse the user table previously created in the ``INSERT...RETURNING`` section. + +Insert a user and get the user id: + + >>> from sqlalchemy import insert, update + + >>> ins = insert(User).values(username='Arthur Dent', email='arthur_dent@crate.io').returning(User.id, User.username, User.email) + >>> result = session.execute(ins) + >>> session.commit() + >>> uid = [r[0] for r in result][0] + +Now let's update the user: + + >>> updt = update(User).where(User.id == uid).values(username='Tricia McMillan', email='tricia_mcmillan@crate.io').returning(User.username, User.email) + >>> res = session.execute(updt) + >>> session.commit() + >>> print([str(r) for r in res]) + ["('Tricia McMillan', 'tricia_mcmillan@crate.io')"] + +The following ``UPDATE...RETURNING`` statement was issued to the database: + + UPDATE user SET username=:username, email=:email + WHERE user.id = :id_1 + RETURNING user.username, user.email + .. hidden: Disconnect from database >>> session.close() @@ -265,3 +332,5 @@ Now, verify that the data is present in the database: .. _count result rows: https://docs.sqlalchemy.org/en/14/orm/tutorial.html#counting + +UPDATE stuff SET content=:content WHERE stuff.id = :id_1 RETURNING stuff.content, stuff.status \ No newline at end of file diff --git a/src/crate/client/sqlalchemy/dialect.py b/src/crate/client/sqlalchemy/dialect.py index f615e5f6..5737f994 100644 --- a/src/crate/client/sqlalchemy/dialect.py +++ b/src/crate/client/sqlalchemy/dialect.py @@ -180,6 +180,8 @@ class CrateDialect(default.DefaultDialect): supports_statement_cache = True colspecs = colspecs implicit_returning = True + insert_returning = True + update_returning = True def __init__(self, *args, **kwargs): super(CrateDialect, self).__init__(*args, **kwargs) From 68c689f934c48924e34b0ca7e1a060227a02e46b Mon Sep 17 00:00:00 2001 From: Fabian Reisegger Date: Tue, 18 Apr 2023 11:33:12 +0200 Subject: [PATCH 4/5] fixup! Enable ``RETURNING`` clause for sqlalchemy 2.0 --- CHANGES.txt | 3 +++ .../sqlalchemy/advanced-querying.rst | 18 ++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 81e81543..fb969a87 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,6 +5,9 @@ Changes for crate Unreleased ========== +- SQLAlchemy Core: Re-enable support for ``INSERT/UPDATE...RETURNING`` in + SQLAlchemy 2.0 by adding the new ``insert_returning`` and ``update_returning`` flags + in the CrateDB dialect. 2023/03/30 0.31.0 ================= diff --git a/docs/by-example/sqlalchemy/advanced-querying.rst b/docs/by-example/sqlalchemy/advanced-querying.rst index a6ce97db..9108bb49 100644 --- a/docs/by-example/sqlalchemy/advanced-querying.rst +++ b/docs/by-example/sqlalchemy/advanced-querying.rst @@ -280,13 +280,13 @@ The first step is to define the table: Now, let's use the returning clause on our insert to retrieve the values inserted: - >>> ins = insert(User).values(username='Crate', email='crate@crate.io').returning(User.username, User.email) - >>> result = session.execute(ins) + >>> stmt = insert(User).values(username='Crate', email='crate@crate.io').returning(User.username, User.email) + >>> result = session.execute(stmt) >>> session.commit() >>> print([str(r) for r in result]) ["('Crate', 'crate@crate.io')"] -The following ``INSERT...RETURNING`` statement was issued to the database: +The following ``INSERT...RETURNING`` statement was issued to the database:: INSERT INTO user (id, username, email) VALUES (:id, :username, :email) @@ -305,20 +305,20 @@ Insert a user and get the user id: >>> from sqlalchemy import insert, update - >>> ins = insert(User).values(username='Arthur Dent', email='arthur_dent@crate.io').returning(User.id, User.username, User.email) - >>> result = session.execute(ins) + >>> stmt = insert(User).values(username='Arthur Dent', email='arthur_dent@crate.io').returning(User.id, User.username, User.email) + >>> result = session.execute(stmt) >>> session.commit() >>> uid = [r[0] for r in result][0] Now let's update the user: - >>> updt = update(User).where(User.id == uid).values(username='Tricia McMillan', email='tricia_mcmillan@crate.io').returning(User.username, User.email) - >>> res = session.execute(updt) + >>> stmt = update(User).where(User.id == uid).values(username='Tricia McMillan', email='tricia_mcmillan@crate.io').returning(User.username, User.email) + >>> res = session.execute(stmt) >>> session.commit() >>> print([str(r) for r in res]) ["('Tricia McMillan', 'tricia_mcmillan@crate.io')"] -The following ``UPDATE...RETURNING`` statement was issued to the database: +The following ``UPDATE...RETURNING`` statement was issued to the database:: UPDATE user SET username=:username, email=:email WHERE user.id = :id_1 @@ -332,5 +332,3 @@ The following ``UPDATE...RETURNING`` statement was issued to the database: .. _count result rows: https://docs.sqlalchemy.org/en/14/orm/tutorial.html#counting - -UPDATE stuff SET content=:content WHERE stuff.id = :id_1 RETURNING stuff.content, stuff.status \ No newline at end of file From 9032a3ff00a108c6f9d7c0d3010ac7d78a908a1a Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Tue, 18 Apr 2023 15:09:10 +0200 Subject: [PATCH 5/5] Release 0.31.1 --- CHANGES.txt | 5 +++++ src/crate/client/__init__.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index fb969a87..141b0667 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,10 +5,15 @@ Changes for crate Unreleased ========== + +2023/04/18 0.31.1 +================= + - SQLAlchemy Core: Re-enable support for ``INSERT/UPDATE...RETURNING`` in SQLAlchemy 2.0 by adding the new ``insert_returning`` and ``update_returning`` flags in the CrateDB dialect. + 2023/03/30 0.31.0 ================= diff --git a/src/crate/client/__init__.py b/src/crate/client/__init__.py index e47ffb51..59cbb6e0 100644 --- a/src/crate/client/__init__.py +++ b/src/crate/client/__init__.py @@ -29,7 +29,7 @@ # version string read from setup.py using a regex. Take care not to break the # regex! -__version__ = "0.31.0" +__version__ = "0.31.1" apilevel = "2.0" threadsafety = 2