database

package
v1.1.17 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package database interacts with the MySQL 5.7 datastore of Defacto2.

Index

Constants

View Source
const Datetime = "2006-01-02T15:04:05Z"

Datetime MySQL 5.7 format.

View Source
const UpdateID = "b66dc282-a029-4e99-85db-2cf2892fffcc"

UpdateID is a user id to use with the updatedby column.

Variables

View Source
var (
	ErrColType  = errors.New("the value type is not usable with the mysql column")
	ErrConnect  = errors.New("could not connect to the mysql database server")
	ErrNoID     = errors.New("unique id is does not exist in the database table")
	ErrSynID    = errors.New("id is not a valid id or uuid value")
	ErrSynUUID  = errors.New("id is not a valid uuid")
	ErrNoTable  = errors.New("unknown database table")
	ErrNoMethod = errors.New("unknown database export type")
)

Functions

func Approve

func Approve(verbose bool) error

Approve automatically checks and clears file records for live.

func CheckID

func CheckID(s string) error

CheckID reports an error message for an incorrect universal unique record id or MySQL auto-generated id.

func CheckUUID

func CheckUUID(s string) error

CheckUUID reports an error message for an incorrect universal unique record id.

func ColumnTypes

func ColumnTypes(table string) error

ColumnTypes details the columns used by the table.

func Connect

func Connect() *sql.DB

Connect will connect to the database and handle any errors.

func ConnectErr

func ConnectErr() (db *sql.DB, err error)

ConnectErr will connect to the database or return any errors.

func ConnectInfo

func ConnectInfo() string

ConnectInfo will connect to the database and return any errors.

func DateTime

func DateTime(b sql.RawBytes) string

DateTime colours and formats a date and time string.

func FileUpdate

func FileUpdate(name string, database time.Time) (bool, error)

FileUpdate reports if the file is newer than the database time.

func Fix

func Fix() error

Fix any malformed section and platforms found in the database.

func IsID

func IsID(s string) bool

IsID reports whether string is a autogenerated record id.

func IsNew

func IsNew(b []sql.RawBytes) bool

IsNew reports if a file record is set to unapproved.

func IsUUID

func IsUUID(s string) bool

IsUUID reports whether string is a universal unique record id.

func LastUpdate

func LastUpdate() (t time.Time, err error)

LastUpdate reports the time when the files database was last modified.

func LookupFile

func LookupFile(s string) (name string, err error)

LookupFile returns the filename from a supplied UUID or database ID value.

func LookupID

func LookupID(s string) (id uint, err error)

LookupID returns the ID from a supplied UUID or database ID value.

func ObfuscateParam

func ObfuscateParam(param string) string

ObfuscateParam hides the param value using the method implemented in CFWheels obfuscateParam() helper.

func Rename

func Rename(replacement, group string) (count int64, err error)

Rename replaces all instances of the group name with a new group name.

func Tbls

func Tbls() string

Tbls are the available tables in the database.

func Total

func Total(s *string) (sum int, err error)

Total reports the number of records fetched by the supplied SQL query.

Types

type Connection

type Connection struct {
	// Name of the database
	Name string
	// User name access.
	User string
	// Pass is the user password.
	Pass string
	// Server is URI to connect to the database, using the protocol, address and port.
	Server string
	// Protocol to connect to the database.
	Protocol string
	// Address to connect to the database.
	Address string
	// Port to connect to the database.
	Port string
}

Connection information for a MySQL database.

func Init

func Init() Connection

Init initializes the database connection using stored settings.

func (*Connection) String

func (c *Connection) String() string

type Empty

type Empty struct{}

Empty is used as a blank value for search maps. See: https://dave.cheney.net/2014/03/25/the-empty-struct

type Flags

type Flags struct {
	Compress bool   // Compress and save the output
	CronJob  bool   //
	Parallel bool   // Run --table=all queries in parallel
	Save     bool   // Save the output uncompressed
	Table    Table  // Table of the database to use
	Method   Method // Method to export
	Tables   string // --table flag result
	Type     string // Type of export (create|update)
	Version  string // df2 app version pass-through
	Limit    uint   // Limit the number of records
}

Flags are command line arguments.

func (*Flags) ExportCronJob

func (f *Flags) ExportCronJob() error

ExportCronJob is intended for an operating system time-based job scheduler. It creates both create and update types exports for the files table.

func (*Flags) ExportDB

func (f *Flags) ExportDB() error

ExportDB saves or prints a MySQL 5.7 compatible SQL import database statement.

func (*Flags) ExportTable

func (f *Flags) ExportTable() error

ExportTable saves or prints a MySQL 5.7 compatible SQL import table statement.

type IDs

type IDs map[string]struct{}

IDs are unique UUID values used by the database and filenames.

type Method

type Method int

Method to interact with the database.

const (
	// Create uses the CREATE SQL statement to make a new record.
	Create Method = iota
	// Insert uses the UPDATE SQL statement to edit an existing record.
	Insert
)

func (Method) String

func (m Method) String() string

type Table

type Table int

Table of the database.

const (
	// Files are file items.
	Files Table = iota
	// Groups are group names.
	Groups
	// Netresources are websites.
	Netresources
	// Users contain site login details.
	Users
)

func (Table) String

func (t Table) String() string

type TableData

type TableData struct {
	VER    string
	CREATE string
	TABLE  string
	INSERT string
	SQL    string
	UPDATE string
}

TableData is a container for the tableTmpl template.

type TablesData

type TablesData struct {
	Columns string
	Rows    string
	Table   string
}

TablesData is a data container for the tablesTmpl template.

type TablesTmp

type TablesTmp struct {
	VER    string
	DB     string
	CREATE []TablesData
}

TablesTmp is a container for the tablesTmpl template.

type Update

type Update struct {
	Query string
	Args  []interface{}
}

Update row values based on conditions.

func (Update) Execute

func (u Update) Execute() (count int64, err error)

Execute Query and Args to update the database and returns the total number of changes.

Jump to

Keyboard shortcuts

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