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.
Supported File Types
This will install gofixtures to your $GOPATH/bin
$ go get github.com/emostafa/gofixtures $ go install github.com/emostafa/gofixtures
To start using gofixtures you need to have a configuration file for the database connection, It could be written
in YAML or JSON, here is an example for
driver: "postgres" database: "mydb" user: "foo" password: "bar" host: "localhost"
The next step is to prepare your fixtures:
- Prepare YAML file (or json file), let's call it example.yaml
- Start writing your fixture, it should have a "table" which declares that table name that we are going to insert data into, and then a list of records, as following:
table: countries records: - name: Egypt - name: Germany - name: Netherlands
- the previous yaml file inserts three records into table
- gofixtures will parse each record and insert it into the database
- in order to use gofixutres, change directory to one level above where the yaml file exists, run command
$ gofixtures --file fixtures/example.yaml --dbconf db.yaml
- by default, gofixtures expecte yaml files to exists in "fixtures/" directory, but you can override this by either:
a. specify a file to load, e.g:
$ gofixtures -file myfixture.jsonb. specify a directory and loal all the fixtures files inside it, e.g:
$ gofixtures -directory /home/foo/myfixtures
A combination of all the available flags can be used, e.g:
$ gofixtures --dbconf mydbconf.yaml --dir ./my_fixtures
Avialable Command Line Flags
- dbconf "database configuration YAML (or JSON) file"
- file "a yaml or json file to load"
- dir "a directory contains fixtures"
support JSON files
- support different sql databases like MySQL
load multiple yaml fiels, or load folders ability to load configuration from file instead of kwargs