Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.
/ aiosqlite3 Public archive

sqlite3 on asyncio use loop.run_in_executor proxy

License

Notifications You must be signed in to change notification settings

zeromake/aiosqlite3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aiosqlite3

Travis Build Status codecov pypi

Basic Example

import asyncio
import aiosqlite3

async def test_example(loop):
    conn = await aiosqlite3.connect('sqlite.db', loop=loop)
    cur = await conn.cursor()
    await cur.execute("SELECT 42;")
    r = await cur.fetchall()
    print(r)
    await cur.close()
    await conn.close()

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(test_example(loop))

or async with

import asyncio
import aiosqlite3

async def test_example(loop):
    async with aiosqlite3.connect('sqlite.db', loop=loop) as conn:
        async with conn.cursor() as cur:
            await cur.execute("SELECT 42;")
            r = await cur.fetchall()
            print(r)

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(test_example(loop))