Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DRAFT] SA20: Add compatibility adapters for psycopg3 and asyncpg dialects#532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
amotl wants to merge2 commits intomasterfromamo/postgresql-async

Conversation

@amotl
Copy link
Member

@amotlamotl commentedMar 4, 2023
edited
Loading

About

The idea is to unlock the CrateDB dialect for SQLAlchemy with thepsycopg3 andasyncpg drivers by introducing correspondingcrate+psycopg://,crate+asyncpg://, andcrate+urllib3:// dialect identifiers.

The asynchronous variant ofpsycopg is also supported and will be automatically selected when usingcreate_async_engine() instead ofcreate_engine().

Installation

git clone https://github.com/crate/crate-python --branch=amo/postgresql-asynccd crate-pythonpython3 -m venv .venvsource .venv/bin/activatepip install --editable='.[postgresql,sqlalchemy]'

Examples

Those example programs exercise basic conversations using the specified drivers.

python examples/sync_table.py urllib3 psycopgpython examples/async_table.py psycopg asyncpgpython examples/async_streaming.py psycopg asyncpg

References

@amotl
Copy link
MemberAuthor

amotl commentedMar 4, 2023
edited
Loading

Backlog

1. Missing test cases

C'est la vie. Please use the provided example programs until we have them.

2. Still using PGDDLCompiler

There is more work to do, to make the hybrid dialect use theCrateDDLCompiler instead of thePGDDLCompiler. Otherwise, when defining a column withautoincrement=True, it will obviously croak, because it will render theSERIAL type, which CrateDB does not understand.

sa.Column("x",sa.Integer,primary_key=True,autoincrement=True)
CREATETABLEtestdrive (xSERIALNOT NULL,yINT,PRIMARY KEY (x))
sqlalchemy.exc.InternalError: (psycopg.errors.InternalError_)Cannotfinddata type:serial

3. ErrorCannot find portal: c_10479c0a0_1 withpsycopg3

This flaw has been observed with thepsycopg driver in asynchronous mode when using result streaming based on server-side cursors. It can be exercised using theasync_streaming.py example program.

python examples/async_streaming.py psycopg

The same program works fine when using theasyncpg driver.

python examples/async_streaming.py asyncpg

Introduction

About
=====
Example program to demonstrate how to connect to CrateDB using its SQLAlchemy
dialect, and exercise a few basic examples using the low-level table API, this
time in asynchronous mode.
Specific to the asynchronous mode of SQLAlchemy is the streaming of results:
> The `AsyncConnection` also features a "streaming" API via the `AsyncConnection.stream()`
> method that returns an `AsyncResult` object. This result object uses a server-side cursor
> and provides an async/await API, such as an async iterator.
>
> -- https://docs.sqlalchemy.org/en/20/orm/extensions/asyncio.html#synopsis-core

Bug

Bugs
====
When using the `psycopg` driver, the program currently croaks like::
sqlalchemy.exc.InternalError: (psycopg.errors.InternalError_) Cannot find portal: c_10479c0a0_1

References

@amotlamotl changed the title[DRAFT] SA20: Add compatibility adapter for psycopg and asyncpg dialects[DRAFT] SA20: Add compatibility adapters for psycopg3 and asyncpg dialectsMar 4, 2023
@amotl
Copy link
MemberAuthor

amotl commentedDec 23, 2023
edited
Loading

@amotlamotl closed thisDec 23, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@amotl

[8]ページ先頭

©2009-2025 Movatter.jp