https://github.com/shogo82148/go-mysql-pool
create MySQL database for testing
https://github.com/shogo82148/go-mysql-pool
go golang mysql
Last synced: 3 months ago
JSON representation
create MySQL database for testing
- Host: GitHub
- URL: https://github.com/shogo82148/go-mysql-pool
- Owner: shogo82148
- License: mit
- Created: 2024-03-17T14:19:45.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-09T12:42:38.000Z (3 months ago)
- Last Synced: 2025-04-11T12:44:51.491Z (3 months ago)
- Topics: go, golang, mysql
- Language: Go
- Homepage: https://pkg.go.dev/github.com/shogo82148/go-mysql-pool
- Size: 46.9 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/shogo82148/go-mysql-pool)
[](https://github.com/shogo82148/go-mysql-pool/actions/workflows/test.yaml)# go-mysql-pool
Go-MySQL-Pool is a package that simplifies the creation and management of MySQL database pools for testing and development purposes.
## Synopsis
```go
package example_testimport (
"context"
"testing""github.com/go-sql-driver/mysql"
"github.com/shogo82148/go-mysql-pool"
)var pool *mysqlpool.Pool
func TestMain(m *testing.M) {
// setup the pool
cfg := mysql.NewConfig()
cfg.User = "username"
cfg.Passwd = "password"
cfg.Net = "tcp"
cfg.Addr = "127.0.0.1:3306"
pool = &mysqlpool.Pool{
MySQLConfig: cfg,
DDL: "CREATE TABLE foo (id INT PRIMARY KEY)",
}
defer pool.Close() // cleanup all databasesm.Run()
}func TestFooBar(t *testing.T) {
// get *sql.DB from the pool.
db, err := pool.Get(context.Background())
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
pool.Put(db)
})// use db for testing.
}
```## Reference
- [Go で MySQL を使ったテストを書くときにつかうユーティリティーライブラリを作った](https://shogo82148.github.io/blog/2024/03/20/2024-03-20-go-mysql-pool/)