version: 3.0.0
A small command line tool written in Go lang, that loads fixtures and insert it's records to a database. Currently supports YAML and JSON files through CLI, and supports PostgreSQL only.
- JSON
- YAML
- CSV
- PostgreSQL
- MySQL
- SQLServer
- MongoDB
- Redis
- Cassandra
- Firebase
This will install gofixtures to your $GOPATH/bin
$ go get github.com/schehata/gofixtures/v3
To start using gofixtures you need to have a configuration file, that includes information
on which db driver should it use, and what are the credentials
It could be written
in YAML or JSON, here is an example for .gofixtures.yaml
which will be automatically loaded
by gofixtures:
import (
"github.com/schehata/gofixutres/v3"
"github.com/schehata/gofixutres/v3/entity"
)
func main() {
config := entity.Config {
entity.DBConfig{
Driver: "postgres"
}
}
gf, err := gofixutres.New(config)
if err != nil {
log.Fatal(err)
}
err = gf.LoadFromFiles(string[]{"./fixtures/countries.yml"})
if err != nil {
log.Fatal(err)
}
}
example of ./fixtures/countries.yml
:
table: countries
records:
- name: Egypt
- capital: Cairo
- name: Germany
capital: Berlin
- name: Netherlands
capital: Amsterdam
- the previous yaml file inserts three records into table
countries
- gofixtures will parse each record and insert it into the database
- Column names are read from the first row
- Filename will be used as a tablename
- For now only comma ',' is allowed as a separator, will work on providing CLI flags to change that as needed
You can use the gofixtures CLI tool to quickly load data into datastores from the command line, check the CLI docs.