mysql

package
v0.0.0-...-bf85ca1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ConfigSource string `yaml:"config_source"`
	Host         string `yaml:"host"`
	Port         string `yaml:"port"`
	Username     string `yaml:"username"`
	Password     string `yaml:"password"`
	DBName       string `yaml:"dbname"`
	TableName    string
}

type Impl

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

func (*Impl) Delete

func (mt *Impl) Delete(toDeleteTarget UserDefinedModel) error

Delete 一个参数:toDeleteTarget 传入一个UserDefinedModel类型,如果此对象的userId = 1,则删除掉数据库中userId= 1的字段

func (*Impl) First

func (mt *Impl) First(queryStr string, findTarget UserDefinedModel, args ...interface{}) error

First 两个参数: queryStr、findTarget queryStr为筛选用的query,例如`userId = ?`, args = "1", findTarget为 UserDefinedModel 类型指针,为第一个找到的数据。

func (*Impl) GetDB

func (i *Impl) GetDB() *gorm.DB

func (*Impl) Insert

func (mt *Impl) Insert(toInsertLines UserDefinedModel) error

Insert 一个参数 toInsertLines 调用次函数,相当于针对当前table,插入toInsertLines 对应的数据 toInsertLines类型为 UserDefinedModel

func (*Impl) SelectWhere

func (mt *Impl) SelectWhere(queryStr string, result interface{}, args ...interface{}) error

SelectWhere 两个参数: queryStr result 调用次函数,相当于针对当前table执行 select * from table where `queryStr`,例如`userId = ?`, args = "1" 将结果写入result, result类型只能是注册好的model数组,类型为 &[]UserDefinedModel{}

func (*Impl) Update

func (mt *Impl) Update(queryStr, field string, target interface{}, args ...interface{}) error

Update 三个参数:queryStr、 field、target 调用此函数,相当于针对queryStr 筛选出的数据条目(例如queryStr = 'userId = ?', args = "1") ,将筛选出的数据条目的field字段替换为target内容

type Mysql

type Mysql interface {
	GetDB() *gorm.DB
	SelectWhere(queryStr string, result interface{}, args ...interface{}) error
	Insert(toInsertLines UserDefinedModel) error
	Delete(toDeleteTarget UserDefinedModel) error
	First(queryStr string, findTarget UserDefinedModel, args ...interface{}) error
	Update(queryStr, field string, target interface{}, args ...interface{}) error
}

type UserDefinedModel

type UserDefinedModel interface {
	TableName() string
}

Jump to

Keyboard shortcuts

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