Description
The problem is that mysql doesn't have cursors, so why would you want to fake them?
In an async world you don't need to expose cursors to the user anyway. You want to simply call
async with trio_mysql.connect("localhost") as db:
async with db.query("select a,b,c …") as result
async for a,b,c in result:
await process_record(a,b,c)
instead. SO, none of that fetch_one
, fetch_many
or fetch_dict
stuff – let the record be a named tuple instead, and/or add some options that describe how the result should look like.
If process
needs to run a query (like an update), well, you need to save the not-yet-read results in memory – which you should not do when that is not necessary.
Also, cancelling a query requires sending a "kill" command to the server if not all results have been read (if any). The mysql command line client can do that: if you interrupt a query before it returns any result it asks you whether you want to.
Also, mysql now supports nested transactions. This adapter should support them. It should also refuse to accept queries on the connection (or outer transactions) when a(n inner) transaction is active, i.e.
async with trio_mysql.connect("localhost") as db:
await db.query("insert into test values(1)") # works, auto-commits
async with db.transaction() as tr:
await tr.query("insert into test values(2)") # works
await db.query("insert into test values(3)") # raises an error