https://github.com/miguelpragier/kebabdb
GoLang Database Helper for MySQL
https://github.com/miguelpragier/kebabdb
Last synced: about 1 month ago
JSON representation
GoLang Database Helper for MySQL
- Host: GitHub
- URL: https://github.com/miguelpragier/kebabdb
- Owner: miguelpragier
- License: unlicense
- Created: 2018-06-14T21:50:58.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-14T21:51:27.000Z (almost 7 years ago)
- Last Synced: 2025-01-27T23:37:33.458Z (3 months ago)
- Language: Go
- Size: 2.93 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# KebabDB
Database helper for goFor now, only **MySql** helper is written.
## Dependencies:
KebabDB depends on this nice work: [github.com/go-sql-driver/mysql]("github.com/go-sql-driver/mysql")## API or How to Use
I bet it's simpler than you expectedFirst, you need to download kebabdb.go and put it in a directory called kebabdb.
Now you can call methods qualifying like this: kebabdb.GetCount("tablecustomers")## Connection String
**Set an environment variable named KebabDBConnectionString**### Examples
```go
/*
* All methods can be called with query + separated ( variadic ) params or with a ready query only.
*/// Execute() sends a sql query to database. tipically update, delete and insert, and return the number of affected rows
affectedRows,err := kebabdb.Execute("UPDATE tablecustomers SET age=? WHERE id=?", age, id)// Insert() executes "insert" sql queries against database an try to return lastInsertedID
newID, err := kebabdb.Insert("INSERT INTO tablecustomers (name,age) VALUES (?,?)")// GetString returns the text of the first row and column, or nil.
customerName := kebabdb.GetString("SELECT name FROM tablecustomers WHERE id=?", 15)// GetInt executes the query, and get the first rol/col data, and - if necessary - converts to int.
customerAge := kebabdb.GetInt("SELECT age FROM tablecustomers WHERE name='adelle' LIMIT 1")// GetCount() returns the rows count of the given table
howManyRows := kebabdb.GetCount("tablecustomers")// GetOne returns query result as a map[string]string
// If something goes wrong, it returns an empty map[string]string or nil, depending on the case
row, err := kebabdb.GetOne("SELECT id, name, age FROM tablecustomers WHERE id=8")fmt.Printf("Customer's id: %s\n", row["id"])
fmt.Printf("Customer's name: %s\n", row["name"])
fmt.Printf("Customer's age: %s\n", row["age"])// GetMany returns query result as a []map[string]string
// If something goes wrong, it returns an empty []map[string]string or nil, depending on the case
resultset, err := kebabdb.GetMany("SELECT id, name, age FROM tablecustomers ORDER BY name")for _,row := range resultset {
fmt.Printf("Customer's id: %s\n", row["id"])
fmt.Printf("Customer's name: %s\n", row["name"])
fmt.Printf("Customer's age: %s\n", row["age"])
}```