https://github.com/romanyx/polluter
The easiest solution to seed database with Go
https://github.com/romanyx/polluter
database golang mysql postgres redis seed
Last synced: 5 months ago
JSON representation
The easiest solution to seed database with Go
- Host: GitHub
- URL: https://github.com/romanyx/polluter
- Owner: romanyx
- License: mit
- Created: 2018-06-10T07:20:23.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-07-03T13:42:17.000Z (almost 2 years ago)
- Last Synced: 2024-11-17T12:45:19.374Z (over 1 year ago)
- Topics: database, golang, mysql, postgres, redis, seed
- Language: Go
- Homepage:
- Size: 32.2 KB
- Stars: 177
- Watchers: 4
- Forks: 16
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://godoc.org/github.com/romanyx/polluter)
[](https://goreportcard.com/report/github.com/romanyx/polluter)
[](https://travis-ci.org/romanyx/polluter)
# polluter
Mainly this package was created for testing purposes, to give the ability to seed a database with records from simple .yaml files. Polluter respects the order in files, so you can handle foreign_keys just by placing them in the right order.
## Usage
```go
package main
import "github.com/romanyx/polluter"
const input = `
roles:
- name: User
users:
- name: Roman
role_id: 1
`
func TestX(t *testing.T) {
db := prepareMySQL(t)
defer db.Close()
p := polluter.New(polluter.MySQLEngine(db))
if err := p.Pollute(strings.NewReader(input)); err != nil {
t.Fatalf("failed to pollute: %s", err)
}
....
}
```
## Examples
[See](https://github.com/romanyx/polluter/blob/master/polluter_test.go#L109) examples of usage with parallel testing.
## Testing
Make shure to start docker before testing.
```bash
go test
```
## Supported databases
* MySQL
* Postgres
* Redis
## Contributing
Please feel free to submit issues, fork the repository and send pull requests!