libsql-experimental-python icon indicating copy to clipboard operation
libsql-experimental-python copied to clipboard

Support iterating a cursor for query results

Open CodingDoug opened this issue 10 months ago • 0 comments

In sqlite3, this is the idiomatic way to iterate rows from a query:

con = sqlite3.connect(":memory:")
cur = con.cursor()
for row in cur.execute("SELECT * FROM users"):
    print(row)

execute just returns the same Cursor object, so this is equivalent:

con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.execute("SELECT * FROM users")
for row in cur:
    print(row)

However, in libsql, this yields the error:

TypeError: 'builtins.Cursor' object is not iterable

CodingDoug avatar Aug 28 '23 13:08 CodingDoug