https://github.com/koepkeca/mysqlmgr
Mysql Database Statement Manager
https://github.com/koepkeca/mysqlmgr
database mysql-database
Last synced: 5 months ago
JSON representation
Mysql Database Statement Manager
- Host: GitHub
- URL: https://github.com/koepkeca/mysqlmgr
- Owner: koepkeca
- License: mit
- Created: 2017-06-12T20:50:21.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-03-17T01:22:00.000Z (over 8 years ago)
- Last Synced: 2024-03-20T08:00:36.885Z (over 2 years ago)
- Topics: database, mysql-database
- Language: Go
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://goreportcard.com/report/github.com/koepkeca/mysqlMgr)
[](https://godoc.org/github.com/koepkeca/mysqlMgr)
# Overview
mysqlMgr is a library which wraps database connections and prepared statments in a single data structure which is safe for concurrent use.
# Installation
To install the library use go get:
```
go get github.com/koepkeca/mysqlMgr
```
# Configuration
Each instance of the library is designed to manage one database connection. The New method takes an [io.Reader](https://godoc.org/io#Reader) which contains json configuration data. An example of the file is here:
```
{
"database" : "mysqlMgr_Demo",
"server" : "localhost",
"port" : "3306",
"driver" : "mysql",
"user" : "changeme",
"pw" : "changeme"
}
```
# Usage
To use the library you can create a new instance with an io.Reader that contains the json configuration. A **very basic** example is here, please note, this example skips error checking and a more complete example is available in the example folder.
```
confRdr, _ := ioutil.ReadFile("config.conf")
confByte := bytes.NewBuffer(confRdr)
s, _ := mysqlMgr.New(confByte)
_ = s.AddStmt("statement","INSERT INTO table (value1, value2) VALUES (?,?)")
//then get the statement
stmt, _ := s.GetStmt("statement")
s.Close()
```
# Example program
There is an example program that demonstrates the library. It is fully functional but requires a few steps to set it up.
## Prereqs
The example program requires a few items.
* A words file (linux dictionary) located in /usr/share/dict/words used to populate the random data pool. You can use any list of strings seperated by new lines.
* A mysql database with the test database created. The schema is located in test_database.sql in the example directory.
* A **properly configured** configuration file. There is an example configuration file which needs to be modified with your specific configuration values in order to function properly.
This example program creates a random data pool and the sequentially load 8192 random records into the example database. You can adjust this number by changing the maxElements in example.go