fileDB

command module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2024 License: MIT Imports: 8 Imported by: 0

README ΒΆ

fileDB πŸ“πŸ”‘

fileDB is a lightweight, file-based key-value storage system implemented in Go. It provides a simple interface for storing and retrieving string data using a persistent file storage mechanism. πŸ’Ύ

refer: https://github.com/avinassh/go-caskdb

✨ Features

  • πŸ“‚ File-based persistent storage
  • πŸ”‘ Simple key-value operations (Get and Set)
  • πŸš€ Efficient data encoding and decoding
  • ⏱️ Automatic timestamp recording for each entry

πŸ› οΈ Installation

To use fileDB in your Go project, you can clone this repository or import it in your Go module:

go get github.com/DanielZhui/fileDB

πŸš€ Usage

Here's a quick example of how to use fileDB:

package main

import (
    "fmt"
    "github.com/DanielZhui/fileDB"
)

func main() {
    // Initialize the disk store
    ds, err := fileDB.InitDiskStore("./test.db")
    if err != nil {
        panic(err)
    }

    // Set some key-value pairs
    ds.Set("hello", "world")
    ds.Set("foo", "bar")

    // Retrieve a value
    value := ds.Get("foo")
    fmt.Println(value) // Output: bar
}

πŸ“š API

InitDiskStore(fileName string) (*DiskStore, error)

Initializes a new DiskStore or loads an existing one from the specified file.

(d *DiskStore) Set(key string, value string)

Stores a key-value pair in the database.

(d *DiskStore) Get(key string) string

Retrieves the value associated with the given key. Returns an empty string if the key is not found.

πŸ—οΈ Data Structure

Each entry in the file is stored in the following format:

  • Header (12 bytes):
    • ⏱️ Timestamp (4 bytes)
    • πŸ“ Key Size (4 bytes)
    • πŸ“ Value Size (4 bytes)
  • πŸ”‘ Key (variable length)
  • πŸ“„ Value (variable length)

⚠️ Limitations and Future Improvements

  • πŸ”’ Currently not thread-safe
  • πŸ—‘οΈ No delete or update operations
  • πŸ’Ύ All key information is stored in memory, which may not be suitable for large datasets
  • πŸ” No data compression or integrity checks

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. πŸ‘¨β€πŸ’»πŸ‘©β€πŸ’»

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL