Documentation
¶
Index ¶
- func FormatMap(data map[string][]string) (string, int)
- func FormatSlice(data [][]string) (string, int)
- func Ping(host, database, user, password string) bool
- type DBIO
- func (d *DBIO) BackupDB(outdir string)
- func (d *DBIO) ColumnContains(table, column, value, target string) [][]string
- func (d *DBIO) Count(table, column, target, op, key string, distinct bool) int
- func (d *DBIO) CountRows(table string) int
- func (d *DBIO) DeleteRow(table, column, value string)
- func (d *DBIO) DeleteRows(table, column string, values []string)
- func (d *DBIO) EvaluateRows(table, column, op, key, target string) [][]string
- func (d *DBIO) Execute(cmd string) [][]string
- func (d *DBIO) GetColumnInt(table, column string) []int
- func (d *DBIO) GetColumnText(table, column string) []string
- func (d *DBIO) GetColumns(table string, columns []string) [][]string
- func (d *DBIO) GetMax(table, column string) int
- func (d *DBIO) GetNumOccurances(table, column string) map[string]int
- func (d *DBIO) GetRows(table, column, key, target string) [][]string
- func (d *DBIO) GetRowsMin(table, column, target string, min int) [][]string
- func (d *DBIO) GetTable(table string) [][]string
- func (d *DBIO) GetTableColumns()
- func (d *DBIO) GetTableMap(table string) map[string][]string
- func (d *DBIO) GetUpdateTimes() map[string]time.Time
- func (d *DBIO) Insert(table, command string) error
- func (d *DBIO) LastUpdate() time.Time
- func (d *DBIO) NewTables(infile string)
- func (d *DBIO) OptimizeTables()
- func (d *DBIO) ReadColumns(infile string) []string
- func (d *DBIO) TruncateTable(table string)
- func (d *DBIO) UpdateColumns(table, idcol string, values map[string]map[string]string) bool
- func (d *DBIO) UpdateDB(table, values string, l int) int
- func (d *DBIO) UpdateRow(table, target, value, column, op, key string) bool
- func (d *DBIO) UploadSlice(table string, values [][]string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatMap ¶
FormatMap converts a map of string slices to a string formatted with parentheses, commas, and appostrophe's where needed. Returns the number of rows formatted.
func FormatSlice ¶
FormatSlice converts a two-dimensional string slice to a string formatted with parentheses, commas, and appostrophe's where needed. Returns the number of rows formatted.
Types ¶
type DBIO ¶
type DBIO struct { // DB is the database connection. Any SQL query can be run directly using DB. DB *sql.DB // Host is the host IP. Host string // Database stores the name of the database. Database string // User is the MySQL user name used in this session. User string // Password stores the user's password. It is not secure, so be careful how you use it. Password string // Starttime is the time point after the password is given. Starttime time.Time // Columns stores a map with a comma-seperated string of column name for each table. Columns map[string]string // contains filtered or unexported fields }
DBIO is the central struct containing all releveant connection information.
func Connect ¶
Connect attempts to connect to the MySQL database located at host/database using the given user name and password.
func CreateDatabase ¶
CreateDatabase connects to MySQL and creates a new database.
func NewDBIO ¶ added in v1.2.1
NewDBIO returns an initialized struct. If host is left blank, it will default to localHost.
func ReplaceDatabase ¶
ReplaceDatabase deletes the given database and creates a new, empty, one (for testing).
func (*DBIO) BackupDB ¶ added in v1.3.1
BackupDB calls mysldump to back up database to local machine
func (*DBIO) ColumnContains ¶ added in v1.2.5
ColumnContains returns a 2D string slice from table if value is in column.
func (*DBIO) Count ¶
Count returns count of entries from target column(s) in table where key relates to column via op (>=/=/...; ie. column >= 7). Returns total if distinct is false; returns number of unique entries if distinct is true. Give operator, key, and target as emtpy strings to count without evaluating.
func (*DBIO) DeleteRow ¶
DeleteRow deletes a single row from the database where the value in the given column equals value.
func (*DBIO) DeleteRows ¶ added in v1.2.1
DeleteRows deletes rows from the database if the value in the given column is contained in the values slice.
func (*DBIO) EvaluateRows ¶
EvaluateRows returns rows of columns where key relates to target via op (>=/=/...) (i.e. column <= key).
func (*DBIO) GetColumnInt ¶
GetColumnInt returns a slice of all entries in column of integers.
func (*DBIO) GetColumnText ¶
GetColumnText returns a slice of all entries in column of text.
func (*DBIO) GetColumns ¶
GetColumns returns a slice of slices of all entries in given columns.
func (*DBIO) GetNumOccurances ¶
GetNumOccurances returns a map with the number of unique entries in column.
func (*DBIO) GetRowsMin ¶
GetRowsMin returns all rows of target columns where column >= key.
func (*DBIO) GetTableColumns ¶
func (d *DBIO) GetTableColumns()
GetTableColumns extracts table and column names from the database and stores them in the Columns map.
func (*DBIO) GetTableMap ¶
GetTableMap returns the given table as a map with the first column as the key.
func (*DBIO) GetUpdateTimes ¶ added in v1.2.2
GetUpdateTimes returns a map the last update date and time for each table.
func (*DBIO) LastUpdate ¶ added in v1.2.2
LastUpdate returns the time of the most recent update.
func (*DBIO) NewTables ¶
NewTables executes new table commands from infile. See README for infile formatting.
func (*DBIO) OptimizeTables ¶ added in v1.3.3
func (d *DBIO) OptimizeTables()
OptimizeTables calls optimize on all tables in the database.
func (*DBIO) ReadColumns ¶
ReadColumns builds a map of column statements with types from infile. See README for infile formatting.
func (*DBIO) TruncateTable ¶
TruncateTable clears all content from the given table.
func (*DBIO) UpdateColumns ¶ added in v1.2.1
UpdateColumns updates columns (specified as outer map key) in table where column == inner map key with map values. Returns true if successful.
func (*DBIO) UpdateDB ¶
UpdateDB adds new rows to table. Values must be formatted using FormatMap or FormatSlice.