asqlite

repository·master·Indexed 40 days ago

https://github.com/rapptz/asqlite

A simple asynchronous wrapper for the standard sqlite3 library that enables SQLite operations using async/await syntax and asynchronous context managers. It features default Write-Ahead Logging (WAL), enabled foreign key constraints, disabled implicit transactions, and a built-in connection pool via asqlite.Pool.

Tokens
500
Snippets
2
Records
3
Agent score
0%

What's inside asqlite

  1. Key differences between asqlite and sqlite3

    master

    When using asqlite instead of the standard sqlite3 module, note the following default behaviors:

    1. Journal Mode: Connections are created with journal_mode set to wal (Write-Ahead Logging).
    2. Foreign Keys: Foreign key constraints are enabled by default.
    3. Transactions: Implicit transactions are turned off.
    4. Row Factory: The row_factory is set to sqlite3.Row by default.
    5. Connection Pooling: asqlite provides an asqlite.Pool for managing multiple connections.
  2. Basic usage of asqlite

    master

    asqlite is an asynchronous wrapper for sqlite3. Most operations that are synchronous in sqlite3 require the await keyword, and connections/cursors are managed using async with context managers.

    import asyncio
    import asqlite
    
    async def main():
        async with asqlite.connect('example.db') as conn:
            async with conn.cursor() as cursor:
                # Create table
                await cursor.execute('''CREATE TABLE stocks
                                        (date text, trans text, symbol text, qty real, price real)''')
    
                # Insert a row of data
                await cursor.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
    
                # Save (commit) the changes
                await conn.commit()
    
    asyncio.run(main())