v.io: v.io/x/ref/services/internal/dbutil Index | Files

package dbutil

import "v.io/x/ref/services/internal/dbutil"

Package dbutil implements utilities for opening and configuring connections to MySQL-like databases, with optional TLS support.

Functions in this file are not thread-safe. However, the returned *sql.DB is. Sane defaults are assumed: utf8mb4 encoding, UTC timezone, parsing date/time into time.Time.

Index

Package Files

mysql.go

Constants

const SQLConfigFileDescription = "" /* 821 byte string literal not displayed */

Description of the SQL configuration file format.

const SQLCreateTableSuffix = "CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci"

SQL statement suffix to be appended when creating tables.

func NewSQLDBConnFromFile Uses

func NewSQLDBConnFromFile(sqlConfigFile, txIsolation string) (*sql.DB, error)

Convenience function to parse and activate the configuration file and open a connection to the SQL database. If multiple connections with the same configuration are needed, a single ActivateSQLConfigFromFile() and multiple NewSQLDbConn() calls are recommended instead.

type ActiveSQLConfig Uses

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

ActiveSQLConfig represents a SQL configuration that has been activated by registering the TLS configuration (if applicable). It can be used for opening SQL database connections.

func ActivateSQLConfigFromFile Uses

func ActivateSQLConfigFromFile(sqlConfigFile string) (*ActiveSQLConfig, error)

Convenience function to parse and activate the SQL configuration file. Certificate paths that aren't absolute are interpreted relative to the directory containing sqlConfigFile.

func (*ActiveSQLConfig) NewSQLDBConn Uses

func (sqlConfig *ActiveSQLConfig) NewSQLDBConn(txIsolation string) (*sql.DB, error)

Opens a connection to the SQL database using the provided configuration. Sets the specified transaction isolation (see link below). https://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_tx_isolation

type SQLConfig Uses

type SQLConfig struct {
    // DataSourceName is the connection string as required by go-sql-driver:
    // "[username[:password]@][protocol[(address)]]/dbname";
    // database name must be specified, query parameters are not supported.
    DataSourceName string `json:"dataSourceName"`
    // TLSDisable, if set to true, uses an unencrypted connection;
    // otherwise, the following fields are mandatory.
    TLSDisable bool `json:"tlsDisable"`
    // TLSServerName is the domain name of the SQL server for TLS.
    TLSServerName string `json:"tlsServerName"`
    // RootCertPath is the root certificate of the SQL server for TLS.
    RootCertPath string `json:"rootCertPath"`
    // ClientCertPath is the client certificate for TLS.
    ClientCertPath string `json:"clientCertPath"`
    // ClientKeyPath is the client private key for TLS.
    ClientKeyPath string `json:"clientKeyPath"`
}

SQLConfig holds the fields needed to connect to a SQL instance and to configure TLS encryption of the information sent over the wire. It must be activated via Activate() before use.

func ParseSQLConfigFromFile Uses

func ParseSQLConfigFromFile(sqlConfigFile string) (*SQLConfig, error)

Parses the SQL configuration file pointed to by sqlConfigFile (format described in SqlConfigFileDescription; also see links below). https://github.com/go-sql-driver/mysql/#dsn-data-source-name https://github.com/go-sql-driver/mysql/#tls

func (*SQLConfig) Activate Uses

func (sc *SQLConfig) Activate(certBaseDir string) (*ActiveSQLConfig, error)

Activates the SQL configuration by registering the TLS configuration with go-mysql-driver (if TLSDisable is not set). Certificate paths from SqlConfig that aren't absolute are interpreted relative to certBaseDir. For more information see https://github.com/go-sql-driver/mysql/#tls

Package dbutil imports 12 packages (graph) and is imported by 4 packages. Updated 2020-10-22. Refresh now. Tools for package owners.