Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/madflojo/hord

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/madflojo/hord

  • v0.3.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

Hord

GitHub go.mod Go version codecov Go Report Card Documentation

Package hord provides a simple and extensible interface for interacting with various database systems in a uniform way.

Hord is designed to be a database-agnostic library that provides a common interface for interacting with different database systems. It allows developers to write code that is decoupled from the underlying database technology, making it easier to switch between databases or support multiple databases in the same application.

Features

  • Driver-based: Hord follows a driver-based architecture, where each database system is implemented as a separate driver. This allows for easy extensibility to support new databases.
  • Uniform API: Hord provides a common API for database operations, including key-value operations, setup, and configuration. The API is designed to be simple and intuitive.
  • Pluggable: Developers can choose and configure the desired database driver based on their specific needs.
  • Error handling: Hord provides error types and constants for consistent error handling across drivers.
  • Testing with Mock Driver: Hord provides a mock driver in the mock package, which can be used for testing purposes. The mock driver allows users to define custom functions executed when calling the Database interface methods, making it easier to test code that relies on the Hord interface.
  • Documentation: Each driver comes with its own package documentation, providing guidance on how to use and configure the driver.

Evolving Features

  • Cache Implementations: Combine database drivers with pre-defined cache implementations.

Database Drivers:

DatabaseSupportCommentsProtocol Compatible Alternatives
BoltDB
CassandraScyllaDB, YugabyteDB, Azure Cosmos DB
HashmapOptionally allows storing to YAML or JSON file
MockMock Database interactions within unit tests
NATSExperimental
RedisDragonfly, KeyDB

Caching Implementations

Cache StrategyComments
Look AsideCache is checked before database, if not found in cache, database is checked and cache is updated

Usage

To use Hord, import it as follows:

import "github.com/madflojo/hord"

Creating a Database Client

To create a database client, you need to import and use the appropriate driver package along with the hord package.

For example, to use the Redis driver:

import (
    "github.com/madflojo/hord"
    "github.com/madflojo/hord/redis"
)

func main() {
    var db hord.Database
    db, err := redis.Dial(redis.Config{})
    if err != nil {
        // Handle connection error
    }

    // Use the db client for database operations
    // ...
}

Each driver provides its own Dial function to establish a connection to the database. Refer to the specific driver documentation for more details.

Database Operations

Once you have a database client, you can use it to perform various database operations. The API is consistent across different drivers.

// Set a value
err = db.Set("key", []byte("value"))
if err != nil {
    // Handle error
}

// Retrieve a value
value, err := db.Get("key")
if err != nil {
    // Handle error
}

Refer to the hord.Database interface documentation for a complete list of available methods.

Contributing

Thank you for your interest in helping develop Hord. The time, skills, and perspectives you contribute to this project are valued.

Please reference our Contributing Guide for details.

License

Apache License 2.0

FAQs

Package last updated on 14 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc