Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ensure ¶
func Ensure(logger logrus.FieldLogger, conn DB, v DatabaseEntity) error
Ensure makes sure that a given DatabaseEntity has its schema in the database.
func MaybeRollback ¶
MaybeRollback tries to roll back a transaction.
If the current connection is not a transaction, or if the transaction is already done then nothing will happen.
Types ¶
type DB ¶
type DB interface { Exec(query string, args ...interface{}) (sql.Result, error) Query(query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...interface{}) *sql.Row }
DB represents a database connection.
func NewLoggerDB ¶
func NewLoggerDB(logger logrus.FieldLogger, db DB) DB
NewLoggerDB wraps a database connection with a logger.
type DatabaseEntity ¶
type DatabaseEntity interface {
SchemaSQL() string
}
DatabaseEntity represents an entity that has schema in the database.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware stores a database connection in the request context.
func NewMiddleware ¶
func NewMiddleware(conn DB) *Middleware
func (*Middleware) ServeHTTP ¶
func (m *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
type Transaction ¶
Transaction represents a database connection with an active transaction.
func GetTx ¶
func GetTx(r *http.Request) Transaction
GetTx returns the transaction from the request context.
type TransactionFactory ¶
type TransactionFactory interface {
Begin() (Transaction, error)
}
TransactionFactory can initiate a transaction.
type TxMiddleware ¶
type TxMiddleware struct {
// contains filtered or unexported fields
}
TxMiddleware stores a database transaction in the request context.
func NewTxMiddleware ¶
func NewTxMiddleware(auto bool) *TxMiddleware
NewTxMiddleware creates a TxMiddleware.
The auto parameter tells the middleware to automatically commit or roll back the transaction based on the response code (roll back over 400, commit below).
func (*TxMiddleware) ServeHTTP ¶
func (m *TxMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)