mdq

package module
v0.0.0-...-6b5d807 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2017 License: MIT Imports: 9 Imported by: 0

README

mdq

Build Status

mdq queries multiple databases in parallel and output the results in JSON.

Example

$ mysql -u root --database example -e "select * from hello";

+------+---------+
| id   | message |
+------+---------+
|    1 | hello   |
|    2 | world   |
+------+---------+


$ cat ~/.config/mdq/config.yaml
dbs:
  - name: "example_db"
    driver: "mysql"
    dsn: "root@/example"
    tags: ["example_tag"]


$ mdq --tag example_tag "select * from hello" | jq .
[
  {
    "Database": "example_db",
    "Columns": [
      "id",
      "message"
    ],
    "Rows": [
      {
        "id": "1",
        "message": "hello"
      },
      {
        "id": "2",
        "message": "world"
      }
    ]
  }
]

Supported Databases and DSN

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultReporter = NewReporter(os.Stderr)
	SilentReporter  = NewReporter(ioutil.Discard)
)
View Source
var (
	DefaultConfigParser = ConfigParser{NewDB}
)

Functions

This section is empty.

Types

type AnyValue

type AnyValue struct {
	Value interface{}
}

func (*AnyValue) Scan

func (v *AnyValue) Scan(src interface{}) error

type Cluster

type Cluster interface {
	Query(qeury string) []Result
}

func NewCluster

func NewCluster(dbs []DB, reporter Reporter) Cluster

type Config

type Config struct {
	DBs []DBConfig `yaml:"dbs"`
}

func ParseConfig

func ParseConfig(r io.Reader) (Config, error)

type ConfigParser

type ConfigParser struct {
	NewDB func(name, driver, dsn string) (DB, error)
}

func (ConfigParser) CreateDBsFromConfig

func (cp ConfigParser) CreateDBsFromConfig(r io.Reader, tag string) ([]DB, error)

type DB

type DB interface {
	Query(query string) (Result, error)
}

func CreateDBsFromConfig

func CreateDBsFromConfig(r io.Reader, tag string) ([]DB, error)

func NewDB

func NewDB(name, driver, dsn string) (DB, error)

type DBConfig

type DBConfig struct {
	Name   string   `yaml:"name"`
	Driver string   `yaml:"driver"`
	DSN    string   `yaml:"dsn"`
	Tags   []string `yaml:"tags,flow"`
}

type Executor

type Executor interface {
	Query(query string, args ...interface{}) (*sql.Rows, error)
}

type Printer

type Printer interface {
	Print(results []Result) error
}

func NewJsonPrinter

func NewJsonPrinter(w io.Writer) Printer

func NewTemplatePrinter

func NewTemplatePrinter(w io.Writer, format string) (Printer, error)

type Reporter

type Reporter interface {
	Report(err error)
}

func NewReporter

func NewReporter(w io.Writer) Reporter

type Result

type Result struct {
	Database string
	Columns  []string
	Rows     []map[string]interface{}
}

Directories

Path Synopsis
cmd
mdq

Jump to

Keyboard shortcuts

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