Skip to content

SQL Wrapper for MySQL over SSH in Golang πŸ”

License

Notifications You must be signed in to change notification settings

garsaud/go-mysql-ssh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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(
        "[email protected]: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)
        },
    )
}

About

SQL Wrapper for MySQL over SSH in Golang πŸ”

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages