Skip to content

Instantly share code, notes, and snippets.

@amyreese

amyreese/foo.py Secret

Last active January 18, 2024 05:39
Show Gist options
  • Save amyreese/de20d95f5d6697e427a5e8b7a035b298 to your computer and use it in GitHub Desktop.
Save amyreese/de20d95f5d6697e427a5e8b7a035b298 to your computer and use it in GitHub Desktop.
import asyncio
import aiosqlite
from pathlib import Path
DBNAME = Path("foo.sql")
async def foo():
print("create")
async with aiosqlite.connect(DBNAME) as db:
cursor = await db.execute("CREATE TABLE test (str TEXT)")
await db.commit()
print("insert")
async with aiosqlite.connect(DBNAME) as db:
cursor = await db.execute("INSERT INTO test VALUES ('hello world')")
await db.commit()
print("select")
async with aiosqlite.connect(DBNAME) as db:
cursor = await db.execute("SELECT * FROM test")
rows = await cursor.fetchall()
print(f"{rows = }")
print("done")
if __name__ == "__main__":
DBNAME.unlink(missing_ok=True)
asyncio.run(foo())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment