Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zdb package for Database Management #10

Merged
merged 6 commits into from
Aug 30, 2023
Merged

Add zdb package for Database Management #10

merged 6 commits into from
Aug 30, 2023

Conversation

lucaslopezf
Copy link
Contributor

@lucaslopezf lucaslopezf commented Aug 30, 2023

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

  1. Features
  2. How To Test
  3. Dependencies

Features

  1. ZDatabase Interface: Defines methods for common database operations such as Find, Create, Delete, Raw, etc.

  2. Connector Mechanism: Added a zdbconnector package to manage different database connectors. Initially, we are supporting ClickHouse.

  3. Database Configuration: Extracted database configuration logic to a separate package called zdbconfig. It also handles log configuration.

  4. Error Handling and Logging: Incorporated the Zap logging library for better debugging and traceability.

  5. Retry Mechanism: If the database connection fails, the system will attempt to reconnect based on the settings in zdbconfig.

  6. 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

  1. Unit Tests: Run go test inside the zdatabase package.

    go test ./...
    

Dependencies

  • GORM: Database operations are delegated to the GORM library.
  • Zap: Used for logging.

@lucaslopezf lucaslopezf changed the title Add zdatabase pkg Add zdb package for Database Management Aug 30, 2023
@lucaslopezf lucaslopezf marked this pull request as ready for review August 30, 2023 10:41
Copy link
Member

@lawRathod lawRathod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks cool, would love to try out testing through mocks. Support for postgres coming soon? 😆

Copy link
Member

@emmanuelm41 emmanuelm41 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really love it too! If we can bring postgres here too, we could use it on zevm backend, and other projects where we still use postgres.

@lucaslopezf lucaslopezf merged commit 9e79ccd into main Aug 30, 2023
1 check passed
@lucaslopezf lucaslopezf deleted the feat/db branch August 30, 2023 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants