Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shogo82148/go-mysql-pool
create MySQL database for testing
https://github.com/shogo82148/go-mysql-pool
go golang mysql
Last synced: about 1 month 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 (8 months ago)
- Default Branch: main
- Last Pushed: 2024-03-27T12:04:05.000Z (8 months ago)
- Last Synced: 2024-06-21T14:06:02.098Z (5 months ago)
- Topics: go, golang, mysql
- Language: Go
- Homepage: https://pkg.go.dev/github.com/shogo82148/go-mysql-pool
- Size: 38.1 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Go Reference](https://pkg.go.dev/badge/github.com/shogo82148/go-mysql-pool.svg)](https://pkg.go.dev/github.com/shogo82148/go-mysql-pool)
[![test](https://github.com/shogo82148/go-mysql-pool/actions/workflows/test.yaml/badge.svg)](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/)