Easy way to use a PostgreSQL database (and the HSTORE feature) from Go.
package main import ( "log" db "github.com/xyproto/simplehstore" ) func main() { // Check if the local db service is up if err := 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 server host := 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 returns defer host.Close() // Create a list named "greetings" list, err := db.NewList(host, "greetings") if err != nil { log.Fatalln("Could not create list!") } // Add "hello" to the list, check if there are errors if list.Add("hello") != nil { log.Fatalln("Could not add an item to list!") } // Get the last item of the list if item, 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 list if list.Remove() != nil { log.Fatalln("Could not remove the list!") } }
go test
to work, and a database named test
must exist.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4