Documentation ¶
Index ¶
- Variables
- func AddPostCommitAction(ctx context.Context, f func()) error
- func Begin(ctx context.Context) error
- func CreateMigrationFromActions(id string, actions ...MigrationAction) *gormigrate.Migration
- func FromContext(ctx context.Context) (*sql.Tx, error)
- func MarkForRollback(ctx context.Context, err error)
- func Resolve(ctx context.Context) error
- func TransactionMiddleware(db *ConnectionFactory) func(next http.Handler) http.Handler
- type ConnectionFactory
- type DatabaseConfig
- type Migration
- type MigrationAction
- func AddTableColumnAction(table interface{}, columnName string) MigrationAction
- func AddTableColumnsAction(table interface{}) MigrationAction
- func CreateTableAction(table interface{}) MigrationAction
- func DropTableAction(table interface{}) MigrationAction
- func DropTableColumnAction(table interface{}, columnName string) MigrationAction
- func DropTableColumnsAction(table interface{}, tableName ...string) MigrationAction
- func ExecAction(applySql string, unapplySql string) MigrationAction
- func FuncAction(applyFunc func(*gorm.DB) error, unapplyFunc func(*gorm.DB) error) MigrationAction
- func RenameTableColumnAction(table interface{}, oldFieldName string, newFieldName string) MigrationAction
- type Model
Constants ¶
This section is empty.
Variables ¶
var KafkaAdditionalLeasesExpireTime = time.Now().Add(1 * time.Minute)
Set new additional leases expire time to a minute later from now so that the old "kafka" leases finishes its execution before the new jobs kicks in.
Functions ¶
func AddPostCommitAction ¶
func CreateMigrationFromActions ¶
func CreateMigrationFromActions(id string, actions ...MigrationAction) *gormigrate.Migration
func FromContext ¶
FromContext Retrieves the transaction from the context.
func MarkForRollback ¶
MarkForRollback flags the transaction stored in the context for rollback and logs whatever error caused the rollback
func TransactionMiddleware ¶
func TransactionMiddleware(db *ConnectionFactory) func(next http.Handler) http.Handler
TransactionMiddleware creates a new HTTP middleware that begins a database transaction and stores it in the request context.
Types ¶
type ConnectionFactory ¶
type ConnectionFactory struct { Config *DatabaseConfig DB *gorm.DB }
func NewConnectionFactory ¶
func NewConnectionFactory(config *DatabaseConfig) (*ConnectionFactory, func())
NewConnectionFactory will initialize a singleton ConnectionFactory as needed and return the same instance. Go includes database connection pooling in the platform. Gorm uses the same and provides a method to clone a connection via New(), which is safe for use by concurrent Goroutines.
func NewMockConnectionFactory ¶
func NewMockConnectionFactory(dbConfig *DatabaseConfig) *ConnectionFactory
NewMockConnectionFactory should only be used for defining mock database drivers This uses mocket under the hood, use the global mocket.Catcher to change how the database should respond to SQL queries
func (*ConnectionFactory) CheckConnection ¶
func (f *ConnectionFactory) CheckConnection() error
Checks to ensure a connection is present
func (*ConnectionFactory) New ¶
func (f *ConnectionFactory) New() *gorm.DB
New returns a new database connection
func (*ConnectionFactory) NewContext ¶
NewContext returns a new context with transaction stored in it. Upon error, the original context is still returned along with an error
type DatabaseConfig ¶
type DatabaseConfig struct { Dialect string `json:"dialect"` SSLMode string `json:"sslmode"` Debug bool `json:"debug"` MaxOpenConnections int `json:"max_connections"` Host string `json:"host"` Port int `json:"port"` Name string `json:"name"` Username string `json:"username"` Password string `json:"password"` DatabaseCaCertFile string `json:"db_ca_cert_file"` HostFile string `json:"host_file"` PortFile string `json:"port_file"` NameFile string `json:"name_file"` UsernameFile string `json:"username_file"` PasswordFile string `json:"password_file"` }
func NewDatabaseConfig ¶
func NewDatabaseConfig() *DatabaseConfig
func (*DatabaseConfig) AddFlags ¶
func (c *DatabaseConfig) AddFlags(fs *pflag.FlagSet)
func (*DatabaseConfig) ConnectionString ¶
func (c *DatabaseConfig) ConnectionString() string
func (*DatabaseConfig) LogSafeConnectionString ¶
func (c *DatabaseConfig) LogSafeConnectionString() string
func (*DatabaseConfig) ReadFiles ¶
func (c *DatabaseConfig) ReadFiles() error
type Migration ¶
type Migration struct { DbFactory *ConnectionFactory Gormigrate *gormigrate.Gormigrate GormOptions *gormigrate.Options }
func NewMigration ¶
func NewMigration(dbConfig *DatabaseConfig, gormOptions *gormigrate.Options, migrations []*gormigrate.Migration) (*Migration, func(), error)
func (*Migration) CountMigrationsApplied ¶
func (*Migration) MigrateTo ¶
Migrating to a specific migration will not seed the database, seeds are up to date with the latest schema based on the most recent migration This should be for testing purposes mainly
func (*Migration) RollbackLast ¶
func (m *Migration) RollbackLast()
func (*Migration) RollbackTo ¶
type MigrationAction ¶
func AddTableColumnAction ¶
func AddTableColumnAction(table interface{}, columnName string) MigrationAction
func AddTableColumnsAction ¶
func AddTableColumnsAction(table interface{}) MigrationAction
func CreateTableAction ¶
func CreateTableAction(table interface{}) MigrationAction
func DropTableAction ¶
func DropTableAction(table interface{}) MigrationAction
func DropTableColumnAction ¶
func DropTableColumnAction(table interface{}, columnName string) MigrationAction
func DropTableColumnsAction ¶
func DropTableColumnsAction(table interface{}, tableName ...string) MigrationAction
func ExecAction ¶
func ExecAction(applySql string, unapplySql string) MigrationAction
func FuncAction ¶
func RenameTableColumnAction ¶
func RenameTableColumnAction(table interface{}, oldFieldName string, newFieldName string) MigrationAction