Documentation
¶
Index ¶
- Variables
- func BeginTx(ctx context.Context) context.Context
- func CloseDB()
- func FromContext(ctx context.Context) *gorm.DB
- func GetDB() string
- func GetSQLConf() config.SQLConfig
- func GetSQLDB() string
- func GetSQLHost() string
- func GetSQLPass() string
- func GetSQLPort() int32
- func GetSQLSSLMode() string
- func GetSQLUser() string
- func InitializeDB(models ...interface{}) error
- func Middleware(next http.Handler) http.Handler
- func SetPagination(ctx context.Context, page, pageSize int) context.Context
- func WithContext(ctx context.Context) context.Context
Constants ¶
This section is empty.
Variables ¶
var ErrDBNotFound = errors.New("no db instance in context")
var ErrUnsupportedDB = errors.New("unsupported db type")
Functions ¶
func BeginTx ¶
BeginTx returns a context with a new transaction. If the context already has a db connection instance, it uses that instance. Otherwise, it uses the connection initialized in the package.
Ensure InitializeDB has been called before using this function.
func CloseDB ¶ added in v1.0.0
func CloseDB()
CloseDB close a connection to the database (if one exists). It panics if any error occurs.
func FromContext ¶
FromContext extracts the db connection instance from the given context.
The function panics, if a connection does not exist.
func GetSQLConf ¶
func GetSQLHost ¶
func GetSQLHost() string
func GetSQLPass ¶
func GetSQLPass() string
func GetSQLPort ¶
func GetSQLPort() int32
func GetSQLSSLMode ¶
func GetSQLSSLMode() string
func GetSQLUser ¶
func GetSQLUser() string
func InitializeDB ¶
func InitializeDB(models ...interface{}) error
InitializeDB initializes a connection to the database (if not already done) and ensures it has the latest schema.
func Middleware ¶
Middleware to auto-inject the db connection instance in a request's context.
Ensure InitializeDB has been called before using this middleware.
Types ¶
This section is empty.