db

package
v0.0.0-...-19bee3a Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Example
package main

import (
	"github.com/tossp/tsgo/pkg/db"

	"go.uber.org/zap"
	"gorm.io/gorm"
)

func main() {
	logger := db.NewLogger(zap.L())
	logger.SetAsDefault() // optional: configure gorm to use this zapgorm.Logger for callbacks
	db, _ := gorm.Open(nil, &gorm.Config{Logger: logger})

	// do stuff normally
	var _ = db // avoid "unused variable" warn
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	Expr = gorm.Expr
)

Functions

func AddGormTables

func AddGormTables(t ...interface{})

AddGormTables 添加同步表

func ColumnName

func ColumnName(name string) string

TableName 计算表名

func DelAll

func DelAll() (err error)

func G

func G() *gorm.DB

G GORM实例

func IsRecordNotFoundError

func IsRecordNotFoundError(err error) bool

IsRecordNotFoundError GORM实例

func Start

func Start() (err error)

Start 启动GORM

func TableName

func TableName(name string) string

TableName 计算表名

Types

type Logger

type Logger struct {
	ZapLogger        *zap.Logger
	LogLevel         gormlogger.LogLevel
	SlowThreshold    time.Duration
	SkipCallerLookup bool
}

func NewLogger

func NewLogger(zapLogger *zap.Logger) Logger

func (Logger) Error

func (l Logger) Error(ctx context.Context, str string, args ...interface{})

func (Logger) Info

func (l Logger) Info(ctx context.Context, str string, args ...interface{})

func (Logger) LogMode

func (l Logger) LogMode(level gormlogger.LogLevel) gormlogger.Interface

func (Logger) SetAsDefault

func (l Logger) SetAsDefault()

func (Logger) Trace

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

func (Logger) Warn

func (l Logger) Warn(ctx context.Context, str string, args ...interface{})

Jump to

Keyboard shortcuts

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