-
-
Save amyreese/de20d95f5d6697e427a5e8b7a035b298 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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