sqltemplate

package
v2.0.16 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBatchUpdateSQL

func GetBatchUpdateSQL(tableName, pkName string, pks []int64, values map[string]map[int64]interface{}) string

GetBatchUpdateSQL 根据给定的主键列表对相应的值进行批量更新 UPDATE <tableName> SET

<fieldname1> = CASE pkName
    WHEN <pk1> THEN <interface{}>
    WHEN <pk2> THEN <interface{}>
    WHEN <pk3> THEN <interface{}>
END,
<fieldname1> = CASE pkName
    WHEN <pk1> THEN <interface{}>
    WHEN <pk1> THEN <interface{}>
    WHEN <pk1> THEN <interface{}>
END

WHERE pkName IN (<pks>)

values: <fieldName1> => {
     pk1 => interface{}
     pk2 => interface{}
     pk3 => interface{}
}

func GetUnionSQL

func GetUnionSQL(subSQLs []string) string

GetUnionSQL 通过Union关键字实现多SQL批量查询

		(
		SELECT user_id, amount FROM fission_reward
		WHERE user_id=123 AND created_at BETWEEN 1575376982 and (1575376982+24*3600*7)
     )
	    UNION ALL
		(
	     	SELECT user_id, amount FROM fission_reward
			WHERE user_id=456 AND created_at BETWEEN 1575376982 and (1575376982+24*3600*7)
		)

Types

type SqlTemplate

type SqlTemplate interface {
	With(template string) SqlTemplate
	Limit(listParam *protobuf.ListParam) SqlTemplate
	Next(pkName string, nextParam *protobuf.NextParam) SqlTemplate
	OrderBy(orderBy string) SqlTemplate
	GroupBy(groupBy string) SqlTemplate
	InsertArgs(extraArgs ...any) SqlTemplate
	AppendArgs(extraArgs ...any) SqlTemplate
	JoinSubQuery(tpl SqlTemplate) SqlTemplate

	Where(condition string, args ...any)
	Generate() (string, []any, error)
	Get(v any) error
	Select(v any) error
	Count() (int64, error)
	ExportConditions() ([]string, []any) // 导出where条件
	ImportConditions([]string, []any)    // 导入where条件
}

SqlTemplate 基于模板创建, 只支持where和limit

func New

func New(dbClient intf.DbClient) SqlTemplate

func NewJoinSubQuery

func NewJoinSubQuery(dbClient intf.DbClient, template, alias, on string) SqlTemplate

Jump to

Keyboard shortcuts

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