package module
v1.2.2 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2019 License: MIT Imports: 11 Imported by: 13


GoDoc Go Report Card Build Status


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.


package main

import "github.com/romanyx/polluter"

const input = `
- name: User
- 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)



See examples of usage with parallel testing.


Make shure to start docker before testing.

go test

Supported databases

  • MySQL
  • Postgres
  • Redis


Please feel free to submit issues, fork the repository and send pull requests!




This section is empty.


View Source
var (
	// ErrEngineNotSpecified causes if no engine option was used
	// with the factory method.
	ErrEngineNotSpecified = errors.New("specify database engine with the factory method option")


func JSONParser

func JSONParser(p *Polluter)

JSONParser option enambles JSON parsing engine for seeding.

func YAMLParser

func YAMLParser(p *Polluter)

YAMLParser option enambles YAML parsing engine for seeding.


type Option

type Option func(*Polluter)

Option defines options for Polluter.

func MySQLEngine

func MySQLEngine(db *sql.DB) Option

MySQLEngine option enables MySQL engine for poluter.

func PostgresEngine

func PostgresEngine(db *sql.DB) Option

PostgresEngine option enables Postgres engine for Polluter.

func RedisEngine

func RedisEngine(cli *redis.Client) Option

RedisEngine option enables Redis engine for Polluter.

type Polluter

type Polluter struct {
	// contains filtered or unexported fields

Polluter pollutes database with given input.

func New

func New(options ...Option) *Polluter

New factory method returns initialized Polluter. For example to seed MySQL database with JSON input use:

p := New(MySQLEngine(db))

To seed Postgres database with YAML input use:

p := New(PostgresEngine(db), YAMLParser)

func (*Polluter) Pollute

func (p *Polluter) Pollute(r io.Reader) error

Pollute parses input from the reader and tries to exec generated commands on a database. Use New factory function to generate.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL