Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gompact/gofixtures
Golang lib/command line tool to load fixtures to databases, useful for testing
https://github.com/gompact/gofixtures
csv database fixture-loading fixtures go golang json postgresql test-automation test-data yaml
Last synced: 2 months ago
JSON representation
Golang lib/command line tool to load fixtures to databases, useful for testing
- Host: GitHub
- URL: https://github.com/gompact/gofixtures
- Owner: gompact
- Created: 2016-11-10T01:04:34.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-25T20:38:18.000Z (over 5 years ago)
- Last Synced: 2023-07-12T10:09:44.568Z (over 1 year ago)
- Topics: csv, database, fixture-loading, fixtures, go, golang, json, postgresql, test-automation, test-data, yaml
- Language: Go
- Homepage:
- Size: 221 KB
- Stars: 9
- Watchers: 3
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gofixtures
version: 3.0.0
[![Build Status](https://travis-ci.org/schehata/gofixtures.svg)](https://travis-ci.org/schehata/gofixtures)
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
- [X] JSON
- [X] YAML
- [X] CSV#### Supported Databases
- [x] PostgreSQL
- [ ] MySQL
- [ ] SQLServer
- [ ] MongoDB
- [ ] Redis
- [ ] Cassandra
- [ ] Firebase#### Install
This will install gofixtures to your $GOPATH/bin
```bash
$ go get github.com/schehata/gofixtures/v3
```#### Usage
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:```go
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`:
```yaml
table: countries
records:
- name: Egypt
- capital: Cairo
- name: Germany
capital: Berlin
- name: Netherlands
capital: Amsterdam
```3. the previous yaml file inserts three records into table `countries`
4. gofixtures will parse each record and insert it into the database#### Notes on CSV Support
- 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## Usage from Command Line
You can use the gofixtures CLI tool to quickly load data into datastores from the command line, check the CLI docs.