common

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Copyright © 2020 Marvin

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	UpdateOperation        = "UPDATE"
	InsertOperation        = "INSERT"
	DeleteOperation        = "DELETE"
	TruncateOperation      = "TRUNCATE"
	DropOperation          = "DROP"
	DDLOperation           = "DDL"
	TruncateTableOperation = "TRUNCATE TABLE"
	DropTableOperation     = "DROP TABLE"
)

同步操作类型

View Source
const (
	// MySQL 支持 check 约束版本 > 8.0.15
	MySQLCheckConsVersion = "8.0.15"
	// MySQL 版本分隔符号
	MySQLVersionDelimiter = "-"
	// MySQL 字符集
	MySQLCharacterSet = "UTF8MB4"

	// JSON 格式化某字段
	ColumnsJSON      = "COLUMN"
	IndexJSON        = "INDEX"
	PUConstraintJSON = "PUK"
	FKConstraintJSON = "FK"
	CKConstraintJSON = "CK"
	PartitionJSON    = "PARTITION"

	// 目标数据库类型
	TiDBTargetDBType  = "TIDB"
	MySQLTargetDBType = "MYSQL"

	// 数据全量/实时同步 Oracle 版本要求
	// 要求 oracle 11g 及以上
	OracleSYNCRequireDBVersion = "11"

	// 允许 Oracle 表、字段 Collation
	// 需要 oracle 12.2g 及以上
	OracleTableColumnCollationDBVersion = "12.2"

	// Oracle 用户、表、字段默认使用 DB 排序规则
	OracleUserTableColumnDefaultCollation = "USING_NLS_COMP"

	// CSV 字符集判断
	UTF8CharacterSetCSV = "UTF8"
	GBKCharacterSetCSV  = "GBK"

	// 模式
	ReverseO2MMode = "ReverseO2M"
	ReverseM2OMode = "ReverseM2O"
	CheckO2MMode   = "CheckO2M"
	CompareO2MMode = "CompareO2M"
	CSVO2MMode     = "CsvO2M"
	FullO2MMode    = "FullO2M"
	AllO2MMode     = "AllO2M"

	// Channel
	BufferSize = 1024

	// TiDB 数据库
	TiDBClusteredIndexIntOnlyValue = "INT_ONLY"
	TiDBClusteredIndexONValue      = "ON"
	TiDBClusteredIndexOFFValue     = "OFF"
)
View Source
const (
	OracleSysdateDefaultValueMap = "SYSDATE"
	OracleSYSGUIDDefaultValueMap = "SYS_GUID()"
)

ORACLE 默认值规则映射规则

View Source
const (
	MysqlMaxIdleConn     = 512
	MysqlMaxConn         = 1024
	MysqlConnMaxLifeTime = 300 * time.Second
	MysqlConnMaxIdleTime = 200 * time.Second
)

MySQL 连接配置

View Source
const (
	MySQLCurrentTimestampDefaultValueMAP = "CURRENT_TIMESTAMP"
)

MySQL 默认值规则映射规则

Variables

View Source
var CurrentResetFlag = 0

用于控制当程序消费追平到当前 CURRENT 重做日志, 当值 == 0 启用 filterOracleRedoGreaterOrEqualRecordByTable 大于或者等于 当值 == 1 启用 filterOracleRedoGreaterOrEqualRecordByTable 大于,避免已被消费得日志一直被重复消费

View Source
var MySQLDBCharacterSetMap = map[string]string{
	"UTF8MB4": "AL32UTF8",
	"UTF8":    "AL32UTF8",
	"GBK":     "AL32UTF8",
}

MySQL 字符集映射规则

View Source
var MySQLDBCollationMap = map[string]string{

	"utf8mb4_0900_as_ci": "BINARY_CI",

	"utf8mb4_general_ci": "BINARY_AI",

	"utf8mb4_bin": "BINARY/BINARY_CS",

	"utf8_0900_as_ci": "BINARY_CI",

	"utf8_general_ci": "BINARY_AI",

	"utf8_bin": "BINARY/BINARY_CS",
}
View Source
var MySQLDefaultValueMap = map[string]string{
	MySQLCurrentTimestampDefaultValueMAP: "SYSDATE",
}
View Source
var OracleCollationMap = map[string]string{

	"BINARY_CI": "utf8mb4_0900_as_ci",

	"BINARY_AI": "utf8mb4_general_ci",

	"BINARY_CS": "utf8mb4_bin",

	"BINARY": "utf8mb4_bin",
}

MySQL 8.0 utf8mb4_0900_as_cs 区分重音、区分大小写的排序规则 utf8mb4_0900_ai_ci 不区分重音和不区分大小写的排序规则 utf8mb4_0900_as_ci 区分重音、不区分大小写的排序规则 Oracle 字段 Collation 映射

View Source
var OracleDBCSVCharacterSetMap = map[string]string{
	"AL32UTF8": "UTF8",
	"UTF8":     "UTF8",
	"ZHS16GBK": "GBK",
}

ORACLE 字符集映射规则

View Source
var OracleDBCharacterSetMap = map[string]string{
	"AL32UTF8": "UTF8MB4",
	"UTF8":     "UTF8MB4",
	"ZHS16GBK": "GBK",
}

ORACLE 字符集映射规则

View Source
var OracleDefaultValueMap = map[string]string{
	OracleSysdateDefaultValueMap: "NOW()",
	OracleSYSGUIDDefaultValueMap: "UUID()",
}
View Source
var OracleIsNotSupportDataType = []string{"ENUM", "SET"}

Oracle 不支持数据类型 -> M2O

View Source
var SpecialMySQLColumnCollationWithDataTYPE = []string{"TINYTEXT",
	"TEXT",
	"MEDIUMTEXT",
	"LONGTEXT"}

MySQL Data Type reverse Oracle CLOB or NCLOB configure collation error, need configure columnCollation = "" ORA-43912: invalid collation specified for a CLOB or NCLOB value columnCollation = ""

View Source
var SpecialMySQLDataDefaultsWithDataTYPE = []string{"TIME",
	"DATE",
	"DATETIME",
	"TIMESTAMP",
	"CHAR",
	"VARCHAR",
	"TINYTEXT",
	"TEXT", "MEDIUMTEX", "LONGTEXT", "BIT", "BINARY", "VARBINARY", "TINYBLOB", "BLOB", "MEDIUMBLOB", "LONGBLOB"}

MySQL Reverse M2O mysql 默认值未区分,字符数据、数值数据,用于匹配 mysql 字符串默认值,判断是否需单引号 默认值 uuid() 匹配到 xxx() 括号结尾,不需要单引号 默认值 CURRENT_TIMESTAMP 不需要括号,内置转换成 ORACLE SYSDATE 默认值 skp 或者 1 需要单引号

View Source
var TiDBIntegerPrimaryKeyList = []string{"TINYINT", "SMALLINT", "INT", "BIGINT", "DECIMAL"}

alter-primary-key = fase 主键整型数据类型列表

Functions

func DiffStructArray

func DiffStructArray(structA, structB interface{}) ([]interface{}, []interface{}, bool)

用于对比 struct 是否相等

func FilterDifferenceStringItems

func FilterDifferenceStringItems(originItems, excludeItems []string) []string

过滤排除元素,返回新数组

func FilterIntersectionStringItems

func FilterIntersectionStringItems(originItems, newItems []string) []string

过滤两个数组相同元素(交集),返回新数组

func GbkToUtf8

func GbkToUtf8(s []byte) ([]byte, error)

GBK 转 UTF-8

func GetStringSliceElementIndex

func GetStringSliceElementIndex(items []string, item string) int

获取数组元素下标

func IsContainString

func IsContainString(items []string, item string) bool

数组中是否包含某元素

func IsEmptyString

func IsEmptyString(str string) bool

是否空字符串

func IsNum

func IsNum(s string) bool

判断字符是否是数字

func IsSubsetString

func IsSubsetString(originItems, checkItems []string) (bool, []string)

两个数组对比,判断 checkItems 是否是 originItems 子集

func PathExist

func PathExist(path string) error

判断文件夹是否存在,不存在则创建

func ReSplit

func ReSplit(text string, cut string) []string

忽略大小写切分字符串

func ReplaceQuotesString

func ReplaceQuotesString(s string) string

替换字符串引号字符

func ReplaceSpecifiedString

func ReplaceSpecifiedString(s string, oldStr, newStr string) string

替换指定字符

func SpecialLettersUsingMySQL

func SpecialLettersUsingMySQL(bs []byte) string

如果存在特殊字符,直接在特殊字符前添加\ * 判断是否为字母: unicode.IsLetter(v) 判断是否为十进制数字: unicode.IsDigit(v) 判断是否为数字: unicode.IsNumber(v) 判断是否为空白符号: unicode.IsSpace(v) 判断师傅是特殊符号:unicode.IsSymbol(v) 判断是否为Unicode标点字符 :unicode.IsPunct(v) 判断是否为中文:unicode.Han(v)

func SpecialLettersUsingOracle

func SpecialLettersUsingOracle(bs []byte) string

func SplitMultipleSlice

func SplitMultipleSlice(arr []interface{}, num int64) [][]interface{}

多重数组拆分

func SplitMultipleStringSlice

func SplitMultipleStringSlice(arr [][]string, num int64) [][][]string

数组拆分

func StrconvFloatBitSize

func StrconvFloatBitSize(s string, bitSize int) (float64, error)

func StrconvIntBitSize

func StrconvIntBitSize(s string, bitSize int) (int64, error)

字符转换

func StrconvRune

func StrconvRune(s string) (int32, error)

func StrconvUintBitSize

func StrconvUintBitSize(s string, bitSize int) (uint64, error)

func StringArrayToCapitalChar

func StringArrayToCapitalChar(strs []string) string

字符数组转字符

func StringJOIN

func StringJOIN(strs []string, strPrefix, strSuffix, joinS string) string

字符串 JOIN

func StringUPPER

func StringUPPER(str string) string

字符串大写

func StringsBuilder

func StringsBuilder(str ...string) string

字符串拼接

func TrimLastChar

func TrimLastChar(s string) string

删除字符中最后一个字母

func Utf8ToGbk

func Utf8ToGbk(s []byte) ([]byte, error)

UTF-8 转 GBK

func VersionOrdinal

func VersionOrdinal(version string) string

用于版本号比较

Types

This section is empty.

Jump to

Keyboard shortcuts

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