SimpleDB is a lightweight JSON-based database for Go. It allows you to store, retrieve, and manage data with ease.
To install SimpleDB, use go get
:
go get github.com/Undefined-Developers/simple_json_db
Here is an example of how to use SimpleDB:
package main
import (
"fmt"
"github.com/Undefined-Developers/simple_json_db"
)
func main() {
// Create a new SimpleDB instance with options
options := map[string]interface{}{
"file": "mydb.json",
"debug": true,
"delay": 2000, // Set delay to 2000 milliseconds (2 seconds)
}
db := simple_json_db.NewSimpleDB(options)
// Set values
db.Set("name", "John Doe")
db.Set("age", 30)
// Get values
name := db.Get("name")
age := db.Get("age")
fmt.Printf("Name: %s, Age: %d\n", name, age)
// Get all keys
keys := db.Keys()
fmt.Println("Keys:", keys)
// Check if a key exists
exists := db.Has("name")
fmt.Printf("Does 'name' exist? %v\n", exists)
// Delete a value
db.Delete("age")
// Check deletion
age = db.Get("age")
fmt.Printf("Age after deletion: %v\n", age)
}
Creates a new SimpleDB instance. Options can include:
file
: The file path for the database (default:./db.json
)debug
: Enable debug mode (default:false
)
Sets a value in the database.
Gets a value from the database.
Deletes a value from the database.
Returns all keys in the database.
Checks if a key exists in the database. Returns true
if the key exists, otherwise false
.
This project is licensed under the GNU GENERAL PUBLIC LICENSE Version 3. See the LICENSE
file for details.