mysql

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 License: MIT Imports: 13 Imported by: 2

Documentation

Overview

* @Author: liziwei01 * @Date: 2022-03-04 15:43:21 * @LastEditors: liziwei01 * @LastEditTime: 2023-11-01 11:22:02 * @Description: file content

* @Author: liziwei01 * @Date: 2022-03-09 19:26:42 * @LastEditors: liziwei01 * @LastEditTime: 2023-11-01 11:21:57 * @Description: file content

* @Author: liziwei01 * @Date: 2022-03-09 19:26:04 * @LastEditors: liziwei01 * @LastEditTime: 2022-04-17 15:39:35 * @Description: file content

* @Author: liziwei01 * @Date: 2022-03-04 15:42:58 * @LastEditors: liziwei01 * @LastEditTime: 2022-03-21 21:51:50 * @Description: file content

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecWithBuilder

func ExecWithBuilder(ctx context.Context, client Client, builder Builder) (sql.Result, error)

func Execraw

func Execraw(ctx context.Context, client Client, builder Builder) (sql.Result, error)

func QueryWithBuilder

func QueryWithBuilder(ctx context.Context, client Client, builder Builder, data interface{}) error

QueryWithBuilder 传入一个 SQLBuilder 并执行 QueryContext

Types

type Builder

type Builder interface {
	CompileContext(ctx context.Context, c Client) (cond string, values []interface{}, err error)
}

type Client

type Client interface {
	// Query 查询, 返回数据在data, 内有didi builder, 结构体使用tag `ddb`
	Query(ctx context.Context, tableName string, where map[string]interface{}, columns []string, data interface{}) error

	// Insert 内有didi builder, 结构体使用tag `ddb`
	Insert(ctx context.Context, tableName string, data []map[string]interface{}) (sql.Result, error)

	InsertIgnore(ctx context.Context, tableName string, data []map[string]interface{}) (sql.Result, error)

	InsertReplace(ctx context.Context, tableName string, data []map[string]interface{}) (sql.Result, error)

	InsertOnDuplicate(ctx context.Context, tableName string, data []map[string]interface{}, update map[string]interface{}) (sql.Result, error)

	Update(ctx context.Context, tableName string, where map[string]interface{}, update map[string]interface{}) (sql.Result, error)

	Delete(ctx context.Context, tableName string, where map[string]interface{}) (sql.Result, error)

	// ExecRaw 拼接的原生sql语句
	ExecRaw(ctx context.Context, sql string, args ...interface{}) (sql.Result, error)
	// contains filtered or unexported methods
}

func GetClient

func GetClient(ctx context.Context, serviceName string) (Client, error)

*

  • @description:
  • @param {context.Context} ctx
  • @param {string} serviceName
  • @return {*}

func New

func New(config *Config) Client

func NewDefault

func NewDefault() Client

type Config

type Config struct {
	// Service的名字, 必选
	Name string

	// 各种自定义的参数, 全部非必选
	// 写数据超时
	WriteTimeOut int
	// 读数据超时
	ReadTimeOut int
	// 请求失败后的重试次数: 总请求次数 = Retry + 1
	Retry int

	// 资源定位: 手动配置 - 使用IP、端口
	Resource struct {
		Manual struct {
			Host string
			Port int
		}
	}

	MySQL struct {
		Username  string
		Password  string
		DBName    string
		DBDriver  string
		Charset   string
		Collation string
		Timeout   int
		SQLLogLen int
	}
}

Config 配置

type DeleteBuilder

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

func NewDeleteBuilder

func NewDeleteBuilder(table string, where map[string]interface{}) *DeleteBuilder

func (*DeleteBuilder) CompileContext

func (b *DeleteBuilder) CompileContext(ctx context.Context, c Client) (string, []interface{}, error)

type InsertBuilder

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

InsertBuilder 默认的select sql builder

func NewInsertBuilder

func NewInsertBuilder(table string, data []map[string]interface{}, typ int, update ...map[string]interface{}) *InsertBuilder

func (*InsertBuilder) CompileContext

func (b *InsertBuilder) CompileContext(ctx context.Context, c Client) (string, []interface{}, error)

type RawBuilder

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

func NewRawBuilder

func NewRawBuilder(sql string, args []interface{}) *RawBuilder

func (*RawBuilder) CompileContext

func (b *RawBuilder) CompileContext(ctx context.Context, c Client) (string, []interface{}, error)

type SelectBuilder

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

SelectBuilder 默认的select sql builder

func NewSelectBuilder

func NewSelectBuilder(table string, where map[string]interface{}, fields []string) *SelectBuilder

func (*SelectBuilder) CompileContext

func (b *SelectBuilder) CompileContext(ctx context.Context, c Client) (string, []interface{}, error)

type UpdateBuilder

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

func NewUpdateBuilder

func NewUpdateBuilder(table string, where map[string]interface{}, update map[string]interface{}) *UpdateBuilder

func (*UpdateBuilder) CompileContext

func (b *UpdateBuilder) CompileContext(ctx context.Context, c Client) (string, []interface{}, error)

Jump to

Keyboard shortcuts

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