database

package
v0.0.0-...-6684bfc Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertConfigDatabaseExists

func AssertConfigDatabaseExists()

Check if the snap config database exists. if it doesn't, create it.

func AssertDatabaseExists

func AssertDatabaseExists(name string)

Assert the a database exists. If not throw a fatal error.

func AssertUseConfigDatabase

func AssertUseConfigDatabase()

Switch to using the config database.

func Close

func Close()

Close the datbase connection.

func Commit

func Commit()

Commit a transaction.

func CopyDatabase

func CopyDatabase(source string, destination string, revision uint64)

Copy a full source database (sans data) to a new destination at a particular source revision.

func CreateConfigDatabase

func CreateConfigDatabase()

Create the snap config database and all associated tables.

func CreateNewRevision

func CreateNewRevision(database string, file string, comment string)

Create a new revision for a managed database. This function applies the file and creates the new revision in the database.

func DatabaseExists

func DatabaseExists(name string) bool

Check if a database exists.

func Exec

func Exec(sql string, params ...interface{}) (err error)

Execute a prepared statement not expecting results.

func ExecMulti

func ExecMulti(sql string) (err error)

Execute a multi-statement query expecting no results. This is especially useful for executing many SQL statements in one go, such as applying DDL's to an existing schema.

func ExecUnsafe

func ExecUnsafe(sql string, params ...interface{}) (err error)

Execute an unsafe statement not expecting results. This function is used very similarly to the fmt.Sprintf function and all format specifiers are supported. Escaping of parameters is handled in the wrapped library.

func GenerateSchema

func GenerateSchema(databaseName string) string

Generate the full schema of the named database (not including data) in SQL format as a string. The format of the generated SQL is that which would be generated from the mysqldump tool.

func GetCurrentSchemaRevision

func GetCurrentSchemaRevision(database string) uint64

Get the current schema revision of the passed database. The value returned will be different to the latest revision if the database has been rolled back using the update command.

func GetDatabaseEncoding

func GetDatabaseEncoding(databaseName string) (charSet string, collation string)

Get the character encoding and collation of the passed database.

func GetDownSql

func GetDownSql(database string, revision uint64) (downSql string)

Return the down SQL for the database and revision passed.

func GetHeadRevision

func GetHeadRevision(database string) uint64

Get the maximum revision of the passed database.

func GetLogEntries

func GetLogEntries(database string) (log logEntries)

Get log entries for the passed database.

func GetManagedDatabaseList

func GetManagedDatabaseList() (list databaseList)

List all managed databases.

func GetSchema

func GetSchema(database string, revision uint64) (sql string)

Return the full SQL for the database and revision passed.

func GetUpdateSql

func GetUpdateSql(database string, revision uint64) (upSql string)

Return the update SQL for the database and revision passed. This function defaults to the full SQL if the update SQL doesn't exist. This is because when initialising a database (revision 1) only the full SQL is available.

func InitialiseDatabase

func InitialiseDatabase(database string)

Add a database to be managed.

func InsertRow

func InsertRow(sql string, params ...interface{}) (insertId uint64, err error)

Execute a prepared statement to insert a single row. The insert id is returned.

func Open

func Open(config config.Config)

Establishes a connection to the database.

func Query

func Query(sql string, params ...interface{}) (rows []mysql.Row, err error)

Execute a prepared statement expecting multiple results.

func QueryRow

func QueryRow(sql string, params ...interface{}) (row mysql.Row, err error)

Execute a prepared statement expecting a single row result.

func QueryRowUnsafe

func QueryRowUnsafe(sql string, params ...interface{}) (row mysql.Row, err error)

Execute an unsafe statement expecting a single row result. This function is used very similarly to the fmt.Sprintf function and all format specifiers are supported. Escaping of parameters is handled in the wrapped library.

func QueryUnsafe

func QueryUnsafe(sql string, params ...interface{}) (rows []mysql.Row, err error)

Execute an unsafe statement expecting multiple results. This function is used very similarly to the fmt.Sprintf function and all format specifiers are supported. Escaping of parameters is handled in the wrapped library.

func Rollback

func Rollback()

Rollback a transaction.

func SetConnectionEncoding

func SetConnectionEncoding(charSet string, collation string)

Set the connection encoding.

func StartTransaction

func StartTransaction()

Start a transaction.

func UpdateSchemaToRevision

func UpdateSchemaToRevision(database string, target uint64)

Update the schema of a managed database to a previously committed revision.

func ValidateSchemaUpdate

func ValidateSchemaUpdate(database string, file string)

Validate that the schema file updates then correctly reverses any changes made.

Types

This section is empty.

Jump to

Keyboard shortcuts

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