mylogindriver

package module
v0.0.0-...-29be9a2 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

mylogin-driver - Go database/sql driver for MySQL loading credentials from ~/.mylogin.cnf

GoDoc Travis-CI Go Report Card

mylogin-driver provides a MySQL driver for database/sql. This is just a wrapper around github.com/go-sql-driver/mysql with a different connection string syntax that allows to read server address and credentials from ~/.mylogin.cnf.

About mylogin.cnf:

See also package github.com/dolmen-go/mylogin that provides low-level access to ~/.mylogin.cnf reading and writing.

Usage

import (
    "database/sql"
    _ "github.com/dolmen-go/mylogin-driver/register"
)

db, err := sql.Open("mylogin", "[filepath//]<section>/[<database>]")

Example

Here is an example with the public MySQL server provided by ensembl.org.

Create MySQL credentials in a section named client_ensembl in ~/.mylogin.cnf:

$ mysql_config_editor set -G client_ensembl -h ensembldb.ensembl.org -P 5306 -u anonymous -p
$ cat >main.go <<EOF
package main

import (
    "database/sql"
    "fmt"
    _ "github.com/dolmen-go/mylogin-driver/register"
)

func main() {
    db, _ := sql.Open("mylogin", "client_ensembl/")
    var s string
    _ = db.QueryRow("SELECT NOW()").Scan(&s)
    fmt.Println(s)
}
EOF
$ go run main.go

License

Copyright 2018 Olivier Mengué

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Overview

Package mylogindriver provides a database/sql driver for MySQL using credentials stored in ~/.mylogin.cnf.

Connection string syntax:

[<filepath>//]<section>/[<database>]

Default filepath is $HOME/.mylogin.cnf or $MYSQL_TEST_LOGIN_FILE. See https://pkg.golang.ir/github.com/dolmen-go/mylogin/#DefaultFile.

About mylogin.cnf:

https://dev.mysql.com/doc/refman/8.0/en/mysql-config-editor.html
https://dev.mysql.com/doc/mysql-utilities/1.5/en/mysql-utils-intro-connspec-mylogin.cnf.html

A package that auto-registers the driver is provided in https://pkg.golang.ir/github.com/dolmen-go/mylogin-driver/register/.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver is a database/sql driver.

It implements interfaces database/sql/driver.Driver and database/sql/driver.DriverContext.

func (Driver) Open

func (drv Driver) Open(name string) (driver.Conn, error)

Open implements interface database/sql/driver.Driver.

func (Driver) OpenConnector

func (drv Driver) OpenConnector(name string) (driver.Connector, error)

OpenConnector implements interface database/sql/driver.DriverContext.

Directories

Path Synopsis
cmd
mylogin-query Module
Package register provides auto-registration into database/sql for mylogin-driver.Driver with name "mylogin".
Package register provides auto-registration into database/sql for mylogin-driver.Driver with name "mylogin".

Jump to

Keyboard shortcuts

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