sql_util

package
v0.0.0-...-73f8a9c Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Semicolon   = `;`
	Space       = ` `
	DoubleSpace = `  `
	Table       = `	`
	NewLine     = `
`
)
View Source
const KeyJoinChar = "+"

Variables

View Source
var Parser *parser.Parser = parser.New()

Functions

func BuildDelRollBackSql

func BuildDelRollBackSql(column []Column, dataItems [][]string, tableName string) (string, error)

func DeleteSpecifyCharAtHead

func DeleteSpecifyCharAtHead(str string) string

func GetCondition

func GetCondition(sqlAfterWhere string) []string

获取sql的条件,字符串处理 方式: 小写化,and前后有空格,空格分割,再依次进一步判断。

func GetSelectColumn

func GetSelectColumn(sql string, db *sql.DB) ([]string, error)

func GetSqlAfterWhere

func GetSqlAfterWhere(sql string) string

返回值为where后面的部分,不包括where

func GetSqlColumn

func GetSqlColumn(sql string) ([]string, error)

注意这个返回的列是乱序的

func GetTableColumn

func GetTableColumn(tableName string, db *sql.DB) (*[]Column, error)

func GetTableName

func GetTableName(sql string) (string, error)

仅dml用

func GetTablePrimaryInfo

func GetTablePrimaryInfo(columnInfos []Column) (primaryCol []string, index []int)

func HandelKeyWorldForCondition

func HandelKeyWorldForCondition(originWhere string) string

add “ to key words todo 有瑕疵,同时有关键字和value内包含关键字内容的情况(eg: xxxx where `index` = 'index hello'; ),会出问题。待更换更好的方式。

func IsKeyWord

func IsKeyWord(name string) bool

func IsSubKey

func IsSubKey(keyA, keyB string) bool

func NewReadSql

func NewReadSql(sql string) *readSql

func ReplaceSpecifyChar

func ReplaceSpecifyChar(str string) string

func ScanMap

func ScanMap(rows Rows) ([]map[string]interface{}, error)

func SinglePrimaryKeyIsInt

func SinglePrimaryKeyIsInt(nodes []ast.StmtNode) bool

func SortColOnOriginSeq

func SortColOnOriginSeq(columnInfos []Column, column []string) []string

columnInfos:所有的顺序的列信息, column: 待排序列信息 注意这个返回值里有空值,为了对应其原来的顺序和位置 eg : {"id","","age"}

func SplitMultiSql

func SplitMultiSql(sql string) (resp []string, err error)

func VarcharLengthTooLong

func VarcharLengthTooLong(nodes []ast.StmtNode) bool

Types

type ColsSeq

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

type Column

type Column struct {
	Field   string
	Type    string
	Null    string
	Key     string
	Default *string
	Extra   string
}

取出数据的顺序同建表语句的顺序

type Rows

type Rows interface {
	Close() error

	Columns() ([]string, error)

	Next() bool

	Scan(dest ...interface{}) error
}

Rows defines methods that scanner needs, which database/sql.Rows already implements

type WriterBuffer

type WriterBuffer struct {
	Condition strings.Builder
}

func (*WriterBuffer) Write

func (v *WriterBuffer) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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