storage

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2020 License: MIT Imports: 13 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
}

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 deferredly called by function caller for properly getting 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.

type Handler added in v0.6.4

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

Handler implements the app database handler.

Jump to

Keyboard shortcuts

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