Database Helper methods for GoLang Based on DBBasic in Java, PHP
Methods for Simplifying development in Go Lang.
Update Statement
sql : Standard SQL statement thats meant to be Executed by the server - eg Insert, Update or Delete
func updateStatement(db *sql.DB, sql string) error
err = updateStatement(db, "insert into pix(id, title) values(103, 'One Hundred One')")
Select Statement
sql : Standard SQL statement thats meant to be Queried by the server - Usually Select
Returns an Array of Map of the result set. []map[string]string
func selectStatement(db *sql.DB, sql string) ([]map[string]string, error)
clist := []map[string]string{}
clist, _ = selectStatement(db, "SELECT customername FROM customers limit 2")
for i, x := range clist {
fmt.Println(i, x["customername"])
}
Select Single Statement
sql : Standard SQL statement for 1 record thats meant to be Queried by the server - Usually Select
Returns a Map of the result set. map[string]string
func selectSingleStatement(db *sql.DB, sql string) (map[string]string, error)
cdata := map[string]string{}
cdata, _ = selectSingleStatement(db, "SELECT customername FROM customers limit 1")
fmt.Println(cdata["customername"])
Select Data
sql : Standard SQL statement for 1 record and 1 data thats meant to be Queried by the server - Usually Select x from A limit 1
Returns a string of the data returned
func selectData(db *sql.DB, sql string) (string, error)
data := ""
data, _ = selectData(db, "SELECT customername FROM customers limit 1")
fmt.Println(data)
Note
Data are returned as string at the moment.
Aims to keep the Query session open to a minimum, so the results are coppied to the App memory.
The SQL statement needs to be safe, the code does not do that.