long2ice / asyncmy

A fast asyncio MySQL/MariaDB driver with replication protocol support
https://github.com/long2ice/asyncmy
Apache License 2.0
250 stars 29 forks source link

Using SSCursor as default cursor when setting connect_args from SQLAlchemy #58

Closed cnicodeme closed 1 year ago

cnicodeme commented 1 year ago

Hi,

I'm transposing this answer: https://stackoverflow.com/a/31413200/330867

from sqlalchemy import create_engine, MetaData
import MySQLdb.cursors
engine = create_engine('mysql://your:details@go/here', connect_args={'cursorclass': MySQLdb.cursors.SSCursor})

to AsyncMy, which I'm using, but I can't make it work:

from sqlalchemy.ext.asyncio import create_async_engine
from asyncmy.cursors import SSCursor
engine = create_async_engine('mysql+asyncmy://user:pass@127.0.0.1/db', connect_args={'cursorclass': SSCursor})

I get the following error:

TypeError: connect() got an unexpected keyword argument 'cursorclass'

I tried changing it to cursor, and got the same error:

TypeError: connect() got an unexpected keyword argument 'cursor'

Is there a way to define which cursor to use?

cnicodeme commented 1 year ago

... And just like that, I found the solution!

It's cursor_cls !

from sqlalchemy.ext.asyncio import create_async_engine
from asyncmy.cursors import SSCursor
engine = create_async_engine('mysql+asyncmy://user:pass@127.0.0.1/db', connect_args={'cursor_cls': SSCursor})
long2ice commented 1 year ago

Thanks for share that!