sql

package
v0.0.1-202202251845 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2022 License: MPL-2.0 Imports: 3 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 BaseSqlBuilder

type BaseSqlBuilder struct {
	Filters map[string]string
}

func (BaseSqlBuilder) BuildWhereClause

func (b BaseSqlBuilder) BuildWhereClause(builder Builder) string

BuildWhereClause 创建where子句

type Builder

type Builder interface {
	GetConditions() []string
	GetWhereClause() string
}

Builder sql builder

Jump to

Keyboard shortcuts

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