This project follows an interface-based architecture to ensure testability and maintainability:
- IOdbcConnection: Interface for database connections
- IOdbcStatement: Interface for SQL statements with different types:
- TransientStatement: For one-off query execution
- PreparedStatement: For parameterized, reusable statements
- TvpStatement: For table-valued parameters
ODBC statements follow this lifecycle:
- Creation: Statement is created by OdbcStatementFactory based on statement type
- Preparation (for PreparedStatement): Statement is prepared for execution
- Execution: Statement is executed with parameters
- Result Processing: Result metadata is collected and returned
- Fetching: Rows are fetched in batches
- Next Result Set: Move to next result set if available
- Cleanup: Statement is freed
The project includes mock implementations for testing:
- MockIOdbcStatement: Implements the IOdbcStatement interface for testing
- MockOdbcApi: Implements the IOdbcApi interface for testing
- MockOdbcErrorHandler: Implements error handling for testing
Example usage:
// Create a mock statement
auto mockStatement = std::make_shared<MockIOdbcStatement>();
// Configure the mock
EXPECT_CALL(*mockStatement, GetType())
.WillRepeatedly(Return(StatementType::Prepared));
EXPECT_CALL(*mockStatement, Execute(_, _))
.WillOnce(/* Define behavior */);Recent changes include:
- Implementation of FetchRows for retrieving results
- Interface-based refactoring to improve testability
- Added missing implementations for Promise-based APIs in TypeScript
- Implemented PreparedStatement and TvpStatement classes
The project includes both C++ and TypeScript tests:
- C++ tests use Google Test and Google Mock
- TypeScript tests use Mocha
Testing focuses on:
- Unit tests for individual components
- Integration tests for interaction between components
- Mock tests to verify behavior with controlled dependencies
All ODBC calls should be routed through the IOdbcApi interface rather than being called directly. This allows for proper mocking in tests and ensures consistent error handling and logging across the codebase.
Example of correct usage:
// Instead of directly calling ODBC functions:
// auto ret = SQLGetData(statement, column, SQL_C_WCHAR, buffer, bufferSize, &resultSize);
// Use the interface:
auto ret = odbcApi_->SQLGetData(statement, column, SQL_C_WCHAR, buffer, bufferSize, &resultSize);Benefits of using the interface:
- Consistent logging of all ODBC calls
- Centralized error handling
- Support for mocking in tests
- Better cross-platform compatibility
- Easier maintenance when ODBC API changes
-
Install required dependencies:
sudo apt-get install -y unixodbc-dev g++ make
-
Build the module:
npm install --build-from-source
-
Install Visual Studio 2019 or later with C++ development tools.
-
Build the module:
npm install --build-from-source