db

package module
v0.0.0-...-443cbc5 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2019 License: MIT Imports: 7 Imported by: 0

README

garsaud/go-mysql-ssh 🔐

Package garsaud/go-mysql-ssh implements a thin layer above database/sql to run MySQL queries through ssh and make it easier to retrieve rows.

Install

go get github.com/garsaud/go-mysql-ssh

Examples

package main

import (
    db "github.com/garsaud/go-mysql-ssh"
    "database/sql"
)

type User struct {
    id uint
    email string
}

func main() {
    // Optional. Default value is "ssh.pem"
    db.PrivateKeyFilename = "private-key.pem"

    users := make([]*User, 0)

    db.FetchSSH(
        "sshlogin@example.com:22",
        "mysqllogin:mysqlpassword@mysql+tcp(127.0.0.1:3306)/databasename",
        "select id, email from users",
        func(row *sql.Rows) {
            user := new(User)
            row.Scan(&user.id, &user.email)
            users = append(users, user)
        },
    )

    // Direct MySQL connection without SSH is also possible:

    db.Fetch(
        "mysqllogin:mysqlpassword@tcp(example.com:3306)/databasename",
        "select id, email from users",
        func(row *sql.Rows) {
            user := new(User)
            row.Scan(&user.id, &user.email)
            users = append(users, user)
        },
    )
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PrivateKeyFilename string = "ssh.pem"
)

Functions

func Fetch

func Fetch(uri string, query string, callback func(row *sql.Rows)) error

func FetchSSH

func FetchSSH(sshUri string, uri string, query string, callback func(row *sql.Rows)) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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