database

package
v0.0.0-...-ed7ff26 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TimestampFieldName is the field name used for the timestamp field.
	TimestampFieldName = zerolog.TimestampFieldName

	// DurationFieldName is the field name used for the duration field.
	DurationFieldName = "elapsed"

	// FileFieldName is the field name used for the file field.
	FileFieldName = "file"

	// SqlFieldName is the field name used for the sql field.
	SqlFieldName = "sql"

	// RowsFieldName is the field name used for the rows field.
	RowsFieldName = "rows"
)

Functions

func GenerateDSN

func GenerateDSN(options DBOptions) (string, error)

func IsValidDriver

func IsValidDriver(driver string) bool

Types

type DBOptions

type DBOptions struct {
	Driver   string
	Host     string
	Port     string
	User     string
	Password string
	Database string
	Options  string

	MaxOpenConns int
	MaxIdleConns int

	CACert string
}

type Database

type Database struct {
	DB *gorm.DB
}

func New

func New(options DBOptions) (*Database, error)

func (*Database) Migrate

func (db *Database) Migrate(entities ...interface{}) error

type GormLogger

type GormLogger struct {
	// SlowThreshold is the delay which define the query as slow
	SlowThreshold time.Duration

	// IgnoreRecordNotFoundError is to ignore when the record is not found
	IgnoreRecordNotFoundError bool

	// FieldsOrder defines the order of fields in output.
	FieldsOrder []string

	// FieldsExclude defines contextual fields to not display in output.
	FieldsExclude []string
}

func NewGormLogger

func NewGormLogger() *GormLogger

NewGormLogger creates and initializes a new GormLogger.

func (GormLogger) Error

func (l GormLogger) Error(ctx context.Context, msg string, data ...interface{})

Error print error messages

func (GormLogger) Info

func (l GormLogger) Info(ctx context.Context, msg string, data ...interface{})

Info print info

func (*GormLogger) LogMode

func (l *GormLogger) LogMode(level logger.LogLevel) logger.Interface

LogMode log mode

func (GormLogger) Trace

func (l GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)

Trace print sql message

func (GormLogger) Warn

func (l GormLogger) Warn(ctx context.Context, msg string, data ...interface{})

Warn print warn messages

Jump to

Keyboard shortcuts

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