You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Uses SQL queries with HSTORE for the KeyValue and HashMap types.
Uses regular SQL for the List and Set types.
Sample usage
package main
import (
"log"
db "github.com/xyproto/simplehstore"
)
funcmain() {
// Check if the local db service is upiferr:=db.TestConnection(); err!=nil {
log.Fatalln("Could not connect to local database. Is the service up and running?")
}
// Create a Host, connect to the local db serverhost:=db.New()
// Connecting to a different host/port//host := db.NewHost("server:5432/db")// Connect to a different db host/port, with a username and password// host := db.NewHost("username:password@server/db")// Close the connection when the function returnsdeferhost.Close()
// Create a list named "greetings"list, err:=db.NewList(host, "greetings")
iferr!=nil {
log.Fatalln("Could not create list!")
}
// Add "hello" to the list, check if there are errorsiflist.Add("hello") !=nil {
log.Fatalln("Could not add an item to list!")
}
// Get the last item of the listifitem, err:=list.GetLast(); err!=nil {
log.Fatalln("Could not fetch the last item from the list!")
} else {
log.Println("The value of the stored item is:", item)
}
// Remove the listiflist.Remove() !=nil {
log.Fatalln("Could not remove the list!")
}
}
Testing
A PostgreSQL server must be up and running locally for go test to work, and a database named test must exist.