Skip to content

Dare-DB is a lightweight in-memory database written in Go, featuring Redis-inspired hashtables and HTTP/HTTPS endpoints for seamless data storage and retrieval, with Docker support for easy deployment

License

Notifications You must be signed in to change notification settings

dmarro89/dare-db

Repository files navigation

Dare-DB

Here's the official documentation.

Dare-DB is a project that provides an in-memory database utilizing Redis-inspired hashtables implemented in Go here. It offers a lightweight and efficient solution for storing data in memory and accessing it through simple HTTP operations.

Project Purpose

The primary goal of this project is to offer an in-memory database that leverages hashtables for efficient data storage and retrieval. The Go implementation allows using this database as a component in other Go services or integrating it into applications that require rapid access to in-memory data.

Running the Database

Using Docker

To run the database as a Docker image, ensure you have Docker installed on your system. First, navigate to the root directory of your project and execute the following command to build the Docker image:

docker build -t dare-db:latest .

Once the image is built, you can run the database as a Docker container with the following command (note: a configuration option -e DARE_HOST="0.0.0.0" is explicitly set to enable connections from the host machine to the database running within the Docker container):

docker run -d -p "127.0.0.1:2605:2605" -e DARE_HOST="0.0.0.0" dare-db 

This command will start the database as a Docker container in detached mode, exposing port 2605 of the container to port 2605 on your localhost.

Using TLS Version in Docker

Build special Docker image, which will generate certificates

docker build -t dare-db-tls:latest -f Dockerfile.tls.yml .

Once the image is built, you can run the database as a Docker container with the following command:

docker run -d -p "127.0.0.1:2605:2605" -e DARE_HOST="0.0.0.0" -e DARE_PORT=2605 -e DARE_TLS_ENABLED="True" -e DARE_CERT_PRIVATE="/app/settings/cert_private.pem" -e DARE_CERT_PUBLIC="/app/settings/cert_public.pem" dare-db-tls

Access API over HTTPS on https://localhost:2605

How to Use

The in-memory database provides three simple HTTP endpoints to interact with stored data:

GET /get/{key}

This endpoint retrieves an item from the hashtable using a specific key.

Example usage with cURL:

curl -X GET http://localhost:2605/get/myKey

SET /set

This endpoint inserts a new item into the hashtable. The request body should contain the key and value of the new item.

Example usage with cURL:

curl -X POST -d '{"myKey":"myValue"}' http://localhost:2605/set

DELETE /delete/{key}

This endpoint deletes an item from the hashtable using a specific key.

Example usage with cURL:

curl -X DELETE http://localhost:2605/delete/myKey

Example Usage

Below is a simple example of how to use this database in a Go application:

package main

import (
    "fmt"
    "net/http"
    "bytes"
)

func main() {
    // Example of inserting a new item
    _, err := http.Post("http://localhost:2605/set", "application/json", bytes.NewBuffer([]byte(`{"myKey":"myValue"}`)))
    if err != nil {
        fmt.Println("Error while inserting item:", err)
        return
    }

    // Example of retrieving an item
    resp, err := http.Get("http://localhost:2605/get/myKey")
    if err != nil {
        fmt.Println("Error while retrieving item:", err)
        return
    }
    defer resp.Body.Close()

    // Example of deleting an item
    req, err := http.NewRequest("DELETE", "http://localhost:2605/delete/myKey", nil)
    if err != nil {
        fmt.Println("Error while deleting item:", err)
        return
    }
    _, err = http.DefaultClient.Do(req)
    if err != nil {
        fmt.Println("Error while deleting item:", err)
        return
    }
}

How to Contribute

All sorts of contributions to this project! Here's how you can get involved:

  • Found a bug? Let us know! Open an issue and briefly describe the problem.
  • Have a great idea for a new feature? Open an issue to discuss it. If you'd like to implementing it yourself, you can assign this issue to yourself and create a pull request once the code/improvement/fix is ready.
  • Want to talk about something related to the project? Discussion threads are the perfect place to brainstorm ideas

Here is how you could add your new code/improvement/fix with a pull request:

  1. Fork the repository (e.g., latest changes must be in develop branch)
    git clone -b develop https://github.com/dmarro89/dare-db
    
  2. Create a new branch for your feature. Use number of a newly created issue and keywords (e.g., 10-implement-feature-ABC)
    git checkout -b 10-implement-feature-ABC
    
  3. Add changes to the branch
    git add .
    
  4. Commit your changes
    git commit -am 'add new feature ABC'
    
  5. Push to the branch
    git push origin 10-implement-feature-ABC
    
  6. Open a pull request based on a new branch
  7. Provide a short notice in the pull request according to the following template:
    • Added: ...
    • Changed: ...
    • Fixed: ...
    • Dependencies: ...
How to Contribute: Dependencies

How to Contribute: Dependencies

About

Dare-DB is a lightweight in-memory database written in Go, featuring Redis-inspired hashtables and HTTP/HTTPS endpoints for seamless data storage and retrieval, with Docker support for easy deployment

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published