mysql

package
v0.0.0-...-6843a2d Latest Latest
Warning

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

Go to latest
Published: May 13, 2019 License: MIT Imports: 9 Imported by: 23

Documentation

Overview

Package mysql is a MySQL changelog adapter.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrChangelogFailure occurs when the connection is not set up properly.
	ErrChangelogFailure = errors.New("error with changelog setup")
	// ErrTransactionFuncMissing occurs when the transaction function is missing.
	ErrTransactionFuncMissing = errors.New("error transaction func is missing")
)

Functions

This section is empty.

Types

type Connection

type Connection struct {
	Hostname  string `json:"Hostname" env:"DB_HOSTNAME"`
	Port      int    `json:"Port" env:"DB_PORT"`
	Username  string `json:"Username" env:"DB_USERNAME"`
	Password  string `json:"Password" env:"DB_PASSWORD"`
	Name      string `json:"Database" env:"DB_NAME"`
	Parameter string `json:"Parameter" env:"DB_PARAMETER"`
}

Connection holds the details for the MySQL connection.

func NewConnection

func NewConnection(prefix string) (*Connection, error)

NewConnection returns the info required to make a connection to a MySQL database from environment variables. The optional prefix is used when reading environment variables.

func (Connection) Connect

func (c Connection) Connect(includeDatabase bool) (*sqlx.DB, error)

Connect to the database.

func (Connection) DSN

func (c Connection) DSN(includeDatabase bool) string

DSN returns the Data Source Name.

type MySQL

type MySQL struct {
	DB              *sqlx.DB
	TableName       string
	InitializeQuery string
	TransactionFunc func(tx *sql.Tx) rove.Transaction
}

MySQL is a MySQL database changelog.

func New

func New(c *Connection) (m *MySQL, err error)

New connects to the database and returns an object that satisfies the rove.Changelog interface.

func (*MySQL) BeginTx

func (m *MySQL) BeginTx() (rove.Transaction, error)

BeginTx starts a transaction.

func (*MySQL) ChangesetApplied

func (m *MySQL) ChangesetApplied(id, author, filename string) (*changeset.Record, error)

ChangesetApplied returns the checksum from the database if it's found, an error if there was an issue, or nil with no error if it's not found.

func (*MySQL) Changesets

func (m *MySQL) Changesets(reverse bool) ([]changeset.Record, error)

Changesets returns a list of the changesets from the database in ascending order (false) or descending order (true).

func (*MySQL) Count

func (m *MySQL) Count() (count int, err error)

Count returns the number of changesets in the database.

func (*MySQL) Delete

func (m *MySQL) Delete(id, author, filename string) error

Delete will delete a changeset from the database.

func (*MySQL) Initialize

func (m *MySQL) Initialize() (err error)

Initialize will create the changelog table or return an error.

func (*MySQL) Insert

func (m *MySQL) Insert(id, author, filename string, dateexecuted time.Time,
	count int, checksum, description, version string) error

Insert will insert a new record into the database.

func (*MySQL) Rollback

func (m *MySQL) Rollback(tag string) (int, error)

Rollback return how many changesets to rollback.

func (*MySQL) Tag

func (m *MySQL) Tag(id, author, filename, tag string) error

Tag will add a tag to the record.

func (*MySQL) ToRecord

func (m *MySQL) ToRecord(cs dbchangeset) *changeset.Record

ToRecord converts a dbchangeset to a changeset.Record.

func (*MySQL) Update

func (m *MySQL) Update(id, author, filename string, dateexecuted time.Time,
	count int, checksum, description, version string) error

Update will update a record from the database.

type Tx

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

Tx is a database transaction.

func NewTx

func NewTx(tx *sql.Tx) *Tx

NewTx creates a new database transaction.

func (*Tx) Commit

func (t *Tx) Commit() error

Commit will commit changes to the database or return an error.

func (*Tx) Exec

func (t *Tx) Exec(query string) error

Exec will run a query on the database.

func (*Tx) Rollback

func (t *Tx) Rollback() error

Rollback will rollback changes to the database or return an error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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