database

package
v0.0.0-...-cd4d371 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2020 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DoNothing = clause.OnConflict{DoNothing: true}

Functions

func DoUpdateColumns

func DoUpdateColumns(columns ...string) clause.OnConflict

func IfNotFound

func IfNotFound(tx *gorm.DB, repl ...error) error

IfNotFound 判断tx是否返回 gorm.ErrRecordNotFound 错误,是的话,用repl替代

Types

type Config

type Config struct {
	Connection             ConnectConfig `json:"connection" toml:"connection" yaml:"connection"`                                           //连接设置
	Table                  TableConfig   `json:"table" toml:"table" yaml:"table"`                                                          //表设置
	Logger                 LoggerConfig  `json:"log" toml:"log" yaml:"log"`                                                                //日志设置
	SkipDefaultTransaction bool          `json:"skip_default_transaction" toml:"skip_default_transaction" yaml:"skip_default_transaction"` //忽略默认事务
	PrepareStmt            bool          `json:"prepare_stmt" toml:"prepare_stmt" yaml:"prepare_stmt"`                                     //预准备Stmt
}

func (Config) DSN

func (opt Config) DSN() string

func (*Config) Default

func (opt *Config) Default()

type ConnectConfig

type ConnectConfig struct {
	Host     string `json:"host" toml:"host" yaml:"host"`             //服务器
	Port     string `json:"port" toml:"port" yaml:"port"`             //端口
	User     string `json:"user" toml:"user" yaml:"user"`             //用户
	Password string `json:"password" toml:"password" yaml:"password"` //密码
	Database string `json:"database" toml:"database" yaml:"database"` //数据库
	Args     string `json:"args" toml:"args" yaml:"args"`             //扩展参数
}

连接设置

type GDB

type GDB = gorm.DB

type LoggerConfig

type LoggerConfig struct {
	Level string `json:"level" toml:"level" yaml:"level"` //日志等级
	Std   bool   `json:"std" toml:"std" yaml:"std"`       //是否向 Os.Std 输出日志
	File  string `json:"file" toml:"file" yaml:"file"`    //是否输出文件, 不带路径,存放在全局配置的logs目录下以.log命名
}

日志设置

type Scope

type Scope = func(db *GDB) *GDB

func Page

func Page(limit, offset int) Scope

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context) (*Service, error)

func (*Service) AutoMigrate

func (db *Service) AutoMigrate(ctx context.Context, tables ...interface{}) error

AutoMigrate AutoMigrate

func (*Service) Search

func (db *Service) Search(ctx context.Context, table interface{}, result interface{}, search interface{}, orderBy string, limit, offset int, count bool) (total int64, err error)

func (*Service) Transaction

func (db *Service) Transaction(txf func(tx *Service) error) error

func (*Service) With

func (db *Service) With(ctx context.Context) *GDB

type TableConfig

type TableConfig struct {
	Prefix   string `json:"prefix" toml:"prefix" yaml:"prefix"`       //是否使用表前缀
	Singular bool   `json:"singular" toml:"singular" yaml:"singular"` //是否使用单数表名
}

表设置

Jump to

Keyboard shortcuts

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