Add zdb package for Database Management #10
Merged
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.
Summary
This PR introduces a database abstraction layer called
zdb
. It's designed to simplify database interactions within Golang applications. It's built on top of the GORM library but provides a more straightforward and extensible API.Table of Contents
Features
ZDatabase
Interface: Defines methods for common database operations such asFind
,Create
,Delete
,Raw
, etc.Connector Mechanism: Added a
zdbconnector
package to manage different database connectors. Initially, we are supporting ClickHouse.Database Configuration: Extracted database configuration logic to a separate package called
zdbconfig
. It also handles log configuration.Error Handling and Logging: Incorporated the Zap logging library for better debugging and traceability.
Retry Mechanism: If the database connection fails, the system will attempt to reconnect based on the settings in
zdbconfig
.Mocks for Easy Testing: Provides mock implementations for DBConnector and ZDatabase interfaces, making it straightforward to unit test the package components without setting up actual database connections.
How To Test
Unit Tests: Run
go test
inside thezdatabase
package.Dependencies