Skip to content

Add thread-safe connection handling and transaction support#29

Draft
ncoop57 wants to merge 4 commits intomainfrom
concurrent
Draft

Add thread-safe connection handling and transaction support#29
ncoop57 wants to merge 4 commits intomainfrom
concurrent

Conversation

@ncoop57
Copy link
Contributor

@ncoop57 ncoop57 commented Feb 3, 2026

Refactors fastsql to be safe for concurrent use (sync web frameworks, threaded workers):

  • Connection management: Remove persistent db.conn; use connection pool with per-operation checkout. Database.conn(write=) context manager handles connection lifecycle.
  • Transaction support: Add db.tx() for explicit transaction scopes with automatic commit/rollback. Nested calls use SAVEPOINTs.
  • Thread-safe state: DBTable.xtra_id and result now use contextvars so each thread/task gets isolated state.
  • Thread-safe table cache: Database._tables protected by lock.
  • Simplified execute: db.execute() now buffers and returns results directly (list of mappings or rowcount).
  • Pass engine_kws through database() for pool configuration (pool_size, max_overflow, etc.)

@ncoop57 ncoop57 added the enhancement New feature or request label Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments