Documentation ¶
Index ¶
- func MakeDSN(params ConnParams) string
- func UnsetDefaultConnection()
- type ConnParams
- type Connection
- func (c *Connection) Close() error
- func (c *Connection) Connect() error
- func (c *Connection) CreateDB(dbName string) error
- func (c *Connection) DropDB(dbName string) error
- func (c *Connection) MigrateDown()
- func (c *Connection) MigrateUp()
- func (c *Connection) SetDefaultConnection()
- func (c *Connection) SpawnConn(dbName string) (*Connection, error)
- func (c *Connection) Truncate(tables []string)
- type Handler
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 ¶
ConnParams are accepted by InitConn, containing database server parameters.
type Connection ¶
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.