Connection Module¶
This module provides connection management for SQLite databases.
Transaction¶
AsyncTransaction¶
Connection Functions¶
- wsqlite.core.connection.get_connection(db_path: str) _SQLiteConnection[source]¶
Get a connection from global pool (sync).
- Usage:
- with get_connection(“database.db”) as conn:
conn.execute(…)
- async wsqlite.core.connection.get_async_connection(db_path: str) Any[source]¶
Get a configured async connection.
- Usage:
- async with get_async_connection(“database.db”) as conn:
await conn.execute(…)
- wsqlite.core.connection.get_transaction(db_path: str) Iterator[Transaction][source]¶
Get a transaction context manager (sync).
- wsqlite.core.connection.get_async_transaction(db_path: str) AsyncTransaction[source]¶
Get an async transaction context manager.
Exception Handling¶
Connection-related exceptions are defined in wsqlite.exceptions:
Example Usage¶
from wsqlite.core.connection import get_connection, Transaction
# Using connection context manager
with get_connection("database.db") as conn:
cursor = conn.execute("SELECT COUNT(*) FROM users")
count = cursor.fetchone()[0]
print(f"Total users: {count}")
# Using transaction
with Transaction("database.db") as txn:
txn.execute("INSERT INTO users (name) VALUES (?)", ("Alice",))
txn.commit()