polluter

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2020 License: MIT Imports: 4 Imported by: 0

README

GoDoc Go Report Card Build Status

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

package main

import "github.com/quen2404/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 examples of usage with parallel testing.

Testing

Make shure to start docker before testing.

go test

Supported databases

  • MySQL
  • Postgres
  • Redis

Contributing

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder interface {
	Build(jwalk.ObjectWalker) (Commands, error)
}

type BuilderFct

type BuilderFct func(jwalk.ObjectWalker) (Commands, error)

type Command

type Command struct {
	Q    string
	Args []interface{}
}

type Commands

type Commands []Command

type DbEngine

type DbEngine interface {
	Builder
	Execer
}

type Execer

type Execer interface {
	Exec(Commands) error
}

type Polluter

type Polluter struct {
	DbEngine
	parser.Parser
}

Polluter pollutes database with given input.

func New

func New(engine DbEngine, parser parser.Parser) *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.

Directories

Path Synopsis
database
internal

Jump to

Keyboard shortcuts

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