Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly use SQLAlchemy Strategies #45

Open
dstufft opened this issue Jan 26, 2015 · 7 comments
Open

Possibly use SQLAlchemy Strategies #45

dstufft opened this issue Jan 26, 2015 · 7 comments

Comments

@dstufft
Copy link

dstufft commented Jan 26, 2015

It looks like the aiopg.sa module relies on reimplementing some of the lower level parts of SQLAlchemy and providing alternatives which use a similar API. I wonder if this could instead be done using SQLAlchemy's support for different execution strategies?

There is an example of doing this for Twisted at https://github.com/alex/alchimia, that defers things to a thread pool, largely because it wants to work for any database not just PostgreSQL. However I wonder if it would be possible to do that instead which might deduplicate some of the code?

@asvetlov
Copy link
Member

Thank you for link to very interesting project.

I need to dig into alchimia code before making answer.

@dstufft
Copy link
Author

dstufft commented Jan 26, 2015

Of course! I could be totally wrong too and the strategy thing might not be useful at all, but figured I'd mention it in case it was useful.

@jettify
Copy link
Member

jettify commented Jan 26, 2015

@dstufft interesting point

As far as I can see: sa.Connection, sa.Transaction (nested and two phase), sa.ResultProxy and sa.Engine must be implemented in both approaches, so there are not much savings.

But I think it would be interesting to add AIOPG_STRATEGY so end user can write something like:

from sqlalchemy import engine
from aiopg import  AIOPG_STRATEGY
@asyncio.coroutine
def go()
    engine = yield from create_engine(host, port, strategy=AIOPG_STRATEGY )

in this case DefaultEngineStrategy.create method must be reimplemented:
[1] https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalchemy/engine/strategies.py#L47-L160

@eirnym
Copy link

eirnym commented Jun 26, 2015

@jettify You can't mix simple function call, generator and async def from Python3.5, so you must rewrite SQLAlchemy to use it in async mode.

@jettify
Copy link
Member

jettify commented Jun 26, 2015

@eirnym My point was not to rewrite SQLAlchemy, but use create_engine from sqlalchemy (not aiopg) in order to create instance of aiopg.Engine. This is kind of gives user common interface for engine creation.

But now I do not think this is good idea any more.

@RazerM
Copy link

RazerM commented Sep 26, 2016

I created a strategy for asyncio at https://github.com/RazerM/sqlalchemy_aio, based on alchimia.
It's currently a proof of concept (lacks tests and documentation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants