storage

package
v0.14.4 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeDSN added in v0.6.4

func MakeDSN(params ConnParams) string

MakeDSN generates DSN string from ConnParams.

func UnsetDefaultConnection added in v0.6.4

func UnsetDefaultConnection()

Types

type ConnParams

type ConnParams struct {
	Connection     string
	DBName         string
	Options        string
	MigrationsPath string
}

ConnParams are accepted by InitConn, containing database server parameters.

type Connection

type Connection struct {
	DB *sqlx.DB
	// contains filtered or unexported fields
}

Connection holds connection data.

var Conn *Connection

Conn holds a global database connection.

func CreateTestConn added in v0.6.4

func CreateTestConn(params ConnParams) (*Connection, func())

CreateTestConn creates a temporary test database and returns a connection object for accessing it plus a cleanup callback that should be called by function caller to properly get rid of this temporary database.

func InitConn added in v0.6.4

func InitConn(params ConnParams) *Connection

InitConn initializes a module-level connection object.

func (*Connection) Close added in v0.6.4

func (c *Connection) Close() error

Close terminates the database server connection.

func (*Connection) Connect added in v0.6.4

func (c *Connection) Connect() error

Connect initiates a connection to the database server defined in c.params.

func (*Connection) CreateDB added in v0.6.4

func (c *Connection) CreateDB(dbName string) error

CreateDB creates the requested database.

func (*Connection) DropDB added in v0.6.4

func (c *Connection) DropDB(dbName string) error

DropDB drops the requested database.

func (*Connection) MigrateDown

func (c *Connection) MigrateDown()

MigrateDown undoes the previous migration.

func (*Connection) MigrateUp

func (c *Connection) MigrateUp()

MigrateUp executes forward migrations.

func (*Connection) SetDefaultConnection added in v0.6.4

func (c *Connection) SetDefaultConnection()

SetDefaultConnection sets global database connection object that other packages can import and utilize. You want to call that once in your main.go (or another entrypoint) after the physical DB connection has been established.

func (*Connection) SpawnConn added in v0.6.4

func (c *Connection) SpawnConn(dbName string) (*Connection, error)

SpawnConn creates a connection to another database on the same server.

func (*Connection) Truncate added in v0.6.4

func (c *Connection) Truncate(tables []string)

Truncate purges records from the requested tables.

func (*Connection) WatchMetrics added in v0.14.1

func (c *Connection) WatchMetrics(interval time.Duration)

type Handler added in v0.6.4

type Handler interface {
	MigrateUp()
	MigrateDown()
	Connect()
}

Handler implements the app database handler.

type Migrator added in v0.14.4

type Migrator struct {
	Path string
	// contains filtered or unexported fields
}

func NewMigrator added in v0.14.4

func NewMigrator(path string) Migrator

func (*Migrator) MigrateDown added in v0.14.4

func (m *Migrator) MigrateDown(conn *Connection, max int)

MigrateDown undoes a specified number of migrations.

func (*Migrator) MigrateUp added in v0.14.4

func (m *Migrator) MigrateUp(conn *Connection)

MigrateUp executes forward migrations.

Jump to

Keyboard shortcuts

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