mysqldriver

package
v2.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assemble

func Assemble(config DBConfig) (dbinfo *structs.DBInfo, err error)

Assemble is more useful for calling into the library so you don't have to instantiate an empty type.

func ColumnsFromList

func ColumnsFromList(list []string, tablename string) []string

ColumnsFromList takes a whitelist or blacklist and returns the columns for a given table.

func MySQLBuildQueryString

func MySQLBuildQueryString(user, pass, dbname, host string, port int, sslmode string) string

MySQLBuildQueryString builds a query string for MySQL.

func TablesFromList

func TablesFromList(list []string) []string

TablesFromList takes a whitelist or blacklist and returns the table names.

Types

type Config

type Config map[string]any

Config define config value needed

func (Config) DefaultInt

func (c Config) DefaultInt(key string, def int) int

DefaultInt retrieves a non-zero int or the default value provided.

func (Config) DefaultString

func (c Config) DefaultString(key, def string) string

DefaultString retrieves a non-empty string or the default value provided.

func (Config) Int

func (c Config) Int(key string) (int, bool)

Int retrieves an int, the bool says if it exists, is of the appropriate type, and is non-zero. Coerces float64 to int because JSON and Javascript kinda suck.

func (Config) MustString

func (c Config) MustString(key string) string

MustString retrieves a string that must exist and must be a string, it must also not be the empty string

func (Config) String

func (c Config) String(key string) (string, bool)

String retrieves a non-empty string, the bool says if it exists, is of appropriate type, and has a non-zero length or not.

func (Config) StringSlice

func (c Config) StringSlice(key string) ([]string, bool)

StringSlice retrieves an string slice, the bool says if it exists, is of the appropriate type, is non-nil and non-zero length

type DBConfig

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

DBConfig define db config value needed

func NewDBConfig

func NewDBConfig(config Config) DBConfig

NewDBConfig convert Config obj(read via viper) to DBConfig

type MySQLDriver

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

MySQLDriver holds the database connection string and a handle to the database connection.

func (*MySQLDriver) Assemble

func (m *MySQLDriver) Assemble(c DBConfig) (dbinfo *structs.DBInfo, err error)

Assemble all the information we need to provide back to the driver

func (*MySQLDriver) Columns

func (m *MySQLDriver) Columns(schema string, table *structs.Table, tableName string, whitelist, blacklist []string) ([]structs.Column, error)

Columns takes a table name and attempts to retrieve the table information from the database information_schema.columns. It retrieves the column names and column types and returns those as a []Column after TranslateColumnType() converts the SQL types to Go types, for example: "varchar" to "string"

func (*MySQLDriver) ForeignKeyInfo

func (m *MySQLDriver) ForeignKeyInfo(schema, tableName string) ([]structs.ForeignKey, error)

ForeignKeyInfo retrieves the foreign keys for a given table name.

func (*MySQLDriver) PrimaryKeyInfo

func (m *MySQLDriver) PrimaryKeyInfo(schema, tableName string) (*structs.PrimaryKey, error)

PrimaryKeyInfo looks up the primary key for a table.

func (*MySQLDriver) SetIndexAndKey

func (m *MySQLDriver) SetIndexAndKey(tables []*structs.Table) (err error)

SetIndexAndKey sets indexes & key information to given tables

func (*MySQLDriver) TableNames

func (m *MySQLDriver) TableNames(schema string, whitelist, blacklist []string) ([]string, error)

TableNames connects to the mysql database and retrieves all table names from the information_schema where the table schema is public.

func (*MySQLDriver) TranslateColumnType

func (m *MySQLDriver) TranslateColumnType(c structs.Column) structs.Column

TranslateColumnType converts mysql database types to Go types, for example "varchar" to "string" and "bigint" to "int64". It returns this parsed data as a Column object.

Jump to

Keyboard shortcuts

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