https://github.com/ulbora/go-crud-mysql
A curd library that wraps database access to MySQL , MariaDB, Percona Server, Google CloudSQL or Sphinx
https://github.com/ulbora/go-crud-mysql
Last synced: about 1 month ago
JSON representation
A curd library that wraps database access to MySQL , MariaDB, Percona Server, Google CloudSQL or Sphinx
- Host: GitHub
- URL: https://github.com/ulbora/go-crud-mysql
- Owner: Ulbora
- License: mit
- Created: 2017-07-16T14:53:20.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-06-09T17:33:41.000Z (almost 7 years ago)
- Last Synced: 2025-01-26T13:22:31.302Z (3 months ago)
- Language: Go
- Size: 11.7 KB
- Stars: 1
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
go-crud-mysql
==============Go Crud library for MySql
# Installation
```
$ go get github.com/Ulbora/go-crud-mysql```
# Usage
## InitializeMysql
```
res = InitializeMysql("localhost:3306", "admin", "admin", "some_database")
if res != true {
// do something
}```
## GetDb
### Gets a pointer to the DB for creating transactions```
db = GetDb()
tx, err := db.Begin()```
## Insert
```
var noTx *sql.Tx
var q = "INSERT INTO table (title, created_date, text, client_id) VALUES (?, ?, ?, ?)"
var a []interface{}
a = append(a, "test insert 2", time.Now(), "some content text", 125)
success, insID := Insert(noTx, q, a...)```
## Update
```
var noTx *sql.Tx
var q = "UPDATE table set title = ?, modified_date = ?, text = ? where id = ? and client_id = ? "
a := []interface{}{"test insert update", time.Now(), "some content new text updated", insertID, 125}
success := Update(noTx, q, a...)```
## Get
```
a := []interface{}{insertID, 125}
var q = "select * from table WHERE id = ? and client_id = ?"
rowPtr := Get(q, a...)
if rowPtr != nil {
foundRow := rowPtr.row
}```
## GetList
```
a := []interface{}{125}
var q = "select * from table WHERE client_id = ? order by id"
rowsPtr := GetList(q, a...)
if rowsPtr != nil {
foundRows := rowsPtr.rows
}```
## Delete
```
var noTx *sql.Tx
var q = "DELETE FROM table WHERE id = ? "
success := Delete(noTx, q, insertID)```
## Close Database
```
success := Close()```