feat: Enhanced transaction handling with savepoints and isolation levels#126
Open
Mrunal112 wants to merge 1 commit into
Open
feat: Enhanced transaction handling with savepoints and isolation levels#126Mrunal112 wants to merge 1 commit into
Mrunal112 wants to merge 1 commit into
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enhanced Transaction Handling for PostgreSQL Wire Protocol Mock
Changes Proposed
This PR enhances the transaction handling capabilities of the PostgreSQL wire protocol mock server to better simulate real PostgreSQL transaction behavior. The implementation includes comprehensive support for transaction control, savepoints, isolation levels, and proper error handling.
Key Features Added
1. Advanced Transaction Control
BEGIN/START TRANSACTIONwith full option supportREAD UNCOMMITTED,READ COMMITTED,REPEATABLE READ,SERIALIZABLEREAD ONLY,READ WRITE,DEFERRABLECOMMITandROLLBACKhandlingSET TRANSACTIONcommand support2. Savepoint Management
SAVEPOINT <name>- Create named savepoints within transactionsROLLBACK TO SAVEPOINT <name>- Rollback to a specific savepointRELEASE SAVEPOINT <name>- Release a savepoint3. Enhanced Error Handling
25001- ACTIVE_SQL_TRANSACTION (already in transaction)25P01- NO_ACTIVE_SQL_TRANSACTION (no transaction active)25P02- IN_FAILED_SQL_TRANSACTION (transaction aborted)3B001- UNDEFINED_SAVEPOINT (savepoint not found)4. Transaction State Management
postgres=#vspostgres=*>vspostgres=!>)5. Comprehensive Testing
6. Documentation
docs/TRANSACTION_SUPPORT.md)TRANSACTION_CLI_TESTING.md)Related Issues
Fixes #57
Files Changed
Core Implementation
src/connection/connectionState.js- Enhanced connection state managementbeginTransaction(),createSavepoint(),rollbackToSavepoint(),releaseSavepoint()src/handlers/queryHandlers.js- Transaction query handlershandleTransactionQuery()- Main transaction command routerhandleBeginTransaction()- BEGIN with options parserhandleCommitTransaction()- COMMIT handlerhandleRollbackTransaction()- ROLLBACK and ROLLBACK TO SAVEPOINT handlerhandleSavepoint()- SAVEPOINT creationhandleReleaseSavepoint()- SAVEPOINT releaseparseTransactionOptions()- Transaction option parserhandleSetTransaction()- SET TRANSACTION handlersrc/protocol/constants.js- AddedUNDEFINED_SAVEPOINTerror codeTests
__tests__/handlers/transactionHandlers.test.js- Comprehensive test suite (69 tests)Documentation
docs/TRANSACTION_SUPPORT.md- Complete feature documentationTRANSACTION_CLI_TESTING.md- CLI testing guideREADME.md- Updated with transaction featuresCHANGELOG.md- Added detailed change log entryTesting Results
✅ All 69 tests passing
npm test -- transactionHandlers.test.js✅ CLI Testing Verified (via psql client)
postgres=*>prompt)Example Usage
Basic Transaction
Transaction with Isolation Level
Savepoint Recovery
Multiple Savepoints
Checklist
Screenshots