modulepackage
0.0.0-20200727072720-ac7794c26bf3
Repository: https://github.com/takashabe/go-fixture.git
Documentation: pkg.go.dev
# README
go-fixture
Management the fixtures of the database for testing.
features
- Load database fixture from .yaml or .sql file
- Before cleanup table(.yaml only)
- Support databases
- MySQL
- and more drivers are todo...
usage
- Import
go-fixture
and drirvergo-fixture/mysql
as likedatabase/sql
driver
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
"github.com/takashabe/go-fixture"
_ "github.com/takashabe/go-fixture/mysql"
)
func main() {
// omit error handling
db, _ := sql.Open("mysql", "fixture@/db_fixture")
f, _ := fixture.NewFixture(db, "mysql")
f.Load("fixture/setup.yml")
f.Load("fixture/setup.sql")
}
fixture file format
.yml .yaml
table: foo
record:
- id: 1
first_name: foo
last_name: bar
- id: 2
first_name: piyo
last_name: fuga
.sql
- Need to add a semicolon at the end of the line
- If table cleanup is required it will need to be in the fixture file
DELETE FROM person;
INSERT INTO person(id, name) VALUES (1, 'foo');
# Variables
error variables.
error variables.
error variables.
error variables.
error variables.
# Structs
Fixture supply fixture methods sample: import _ "github.com/takashabe/go-fixture/mysql" ..
QueryModelWithYaml represent fixture yaml file mapper.
# Interfaces
Driver is database adapter.