aiosqlite icon indicating copy to clipboard operation
aiosqlite copied to clipboard

commit parity with sqlite3 doesn't exist with `conn.commit()`

Open startakovsky opened this issue 11 months ago • 3 comments

Description

I was reading this and learned that the context manager for the sqlite3 library automatically handles commits but not closes. I am referring to this line from the Python documentation: # Connection object used as context manager only commits or rollbacks transactions

Seems like the situation is not the same with aiosqlite. That you need to commit.

In other words the first example below should work, but it doesn't.

Doesn't work in an analogous fashion with sqlite3.

async with aiosqlite.connect(DB_FILEPATH) as conn:
        await conn.execute(
            '''
            UPDATE .... 
            ''', 
            (
                ...values
            )
        )
conn.close()

Current code requires an explicit conn.commit()

async with aiosqlite.connect(DB_FILEPATH) as conn:
        await conn.execute(
            '''
            UPDATE .... 
            ''', 
            (
                ...values
            )
        )
       await conn.commit()
conn.close()

startakovsky avatar Mar 18 '24 19:03 startakovsky