Documentation
¶
Index ¶
- func FetchLogLevel(level string) logger.LogLevel
- type CtxOrmLogger
- func (l *CtxOrmLogger) Error(ctx context.Context, msg string, opts ...interface{})
- func (l *CtxOrmLogger) Info(ctx context.Context, msg string, opts ...interface{})
- func (l *CtxOrmLogger) LogMode(level logger.LogLevel) logger.Interface
- func (l *CtxOrmLogger) ParamsFilter(ctx context.Context, sql string, params ...interface{}) (string, []interface{})
- func (l *CtxOrmLogger) Trace(ctx context.Context, begin time.Time, f func() (string, int64), err error)
- func (l *CtxOrmLogger) Warn(ctx context.Context, msg string, opts ...interface{})
- type DefaultOrmFactory
- type Driver
- type Options
- type OrmFactory
- type OrmOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchLogLevel ¶
FetchLogLevel returns a logger.LogLevel for a given value.
Types ¶
type CtxOrmLogger ¶
type CtxOrmLogger struct {
// contains filtered or unexported fields
}
CtxOrmLogger is a logger compatible with the Gorm logger.
func NewCtxOrmLogger ¶
func NewCtxOrmLogger(level logger.LogLevel, withValues bool) *CtxOrmLogger
NewCtxOrmLogger returns a new CtxOrmLogger.
func (*CtxOrmLogger) Error ¶
func (l *CtxOrmLogger) Error(ctx context.Context, msg string, opts ...interface{})
Error logs with error level.
func (*CtxOrmLogger) Info ¶
func (l *CtxOrmLogger) Info(ctx context.Context, msg string, opts ...interface{})
Info logs with info level.
func (*CtxOrmLogger) LogMode ¶
func (l *CtxOrmLogger) LogMode(level logger.LogLevel) logger.Interface
LogMode sets the logger log level.
func (*CtxOrmLogger) ParamsFilter ¶
func (l *CtxOrmLogger) ParamsFilter(ctx context.Context, sql string, params ...interface{}) (string, []interface{})
ParamsFilter is used to filter SQL queries params from logging (replace with ?).
type DefaultOrmFactory ¶
type DefaultOrmFactory struct{}
DefaultOrmFactory is the default OrmFactory implementation.
func (*DefaultOrmFactory) Create ¶
func (f *DefaultOrmFactory) Create(options ...OrmOption) (*gorm.DB, error)
Create returns a new gorm.DB, and accepts a list of OrmOption. For example with MySQL driver:
var db, _ = orm.NewDefaultOrmFactory().Create( orm.WithDriver(orm.Mysql), orm.WithDsn("user:pass@tcp(127.0.0.1:3306)/dbname?parseTime=True"), )
or with SQLite driver:
var db, _ = orm.NewDefaultOrmFactory().Create( orm.WithDriver(orm.Sqlite), orm.WithDsn("file::memory:?cache=shared"), )
type Driver ¶
type Driver int
Driver is an enum for the supported database drivers.
func FetchDriver ¶
FetchDriver returns a Driver for a given value.
type Options ¶
Options are options for the OrmFactory implementations.
func DefaultOrmOptions ¶
func DefaultOrmOptions() Options
DefaultOrmOptions are the default options used in the DefaultOrmFactory.
type OrmFactory ¶
OrmFactory is the interface for gorm.DB factories.
func NewDefaultOrmFactory ¶
func NewDefaultOrmFactory() OrmFactory
NewDefaultOrmFactory returns a DefaultOrmFactory, implementing OrmFactory.
type OrmOption ¶
type OrmOption func(o *Options)
OrmOption are functional options for the OrmFactory implementations.
func WithConfig ¶
WithConfig is used to specify the gorm.Config to use.
func WithDriver ¶
WithDriver is used to specify the database driver to use.