db

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const TokenHeader string = "X-Lbry-Auth-Token"

TokenHeader is the name of HTTP header which is supplied by client and should contain internal-api auth_token

Variables

This section is empty.

Functions

func Cleanup

func Cleanup(c ConnData)

func CreateDB

func CreateDB(dbName string) (err error)

CreateDB creates the requested database.

func DropDB

func DropDB(dbName string) (err error)

DropDB drops the requested database.

func GetAccountIDFromRequest

func GetAccountIDFromRequest(req *http.Request) (string, error)

GetAccountIDFromRequest retrieves SDK account_id of a user making a http request by a header provided by the http client

func GetDSN

func GetDSN(params ConnParams) string

GetDSN generates DSN string from config parameters, which can be overridden in params.

func GetDefaultDSN

func GetDefaultDSN() string

GetDefaultDSN is a wrapper for GetDSN without params.

func GetUserByToken

func GetUserByToken(token string) (*models.User, error)

GetUserByToken retrieves user by internal-api auth_token

Types

type ConnData

type ConnData struct {
	DB *sqlx.DB

	Logger monitor.ModuleLogger
	// contains filtered or unexported fields
}

ConnData holds connection data.

var Conn *ConnData

Conn is a module-level connection-holding variable

func Init

func Init() *ConnData

Init initializes a module-level connection object

func NewConnection

func NewConnection(dsn string) *ConnData

NewConnection sets up a database object, panics if unable to connect.

func (ConnData) MigrateDown

func (c ConnData) MigrateDown()

MigrateDown undoes the previous migration.

func (ConnData) MigrateUp

func (c ConnData) MigrateUp()

MigrateUp executes forward migrations.

type ConnParams

type ConnParams struct {
	DatabaseConnection string
	DatabaseName       string
	DatabaseOptions    string
}

ConnParams holds database server parameters.

type Connection

type Connection interface {
	MigrateUp()
	MigrateDown()
}

Connection implements the app database handler.

Jump to

Keyboard shortcuts

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