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.