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.
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.
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.
Index ¶
- Constants
- Variables
- func DiffStructArray(structA, structB interface{}) ([]interface{}, []interface{}, bool)
- func FilterDifferenceStringItems(originItems, excludeItems []string) []string
- func FilterIntersectionStringItems(originItems, newItems []string) []string
- func GbkToUtf8(s []byte) ([]byte, error)
- func GetStringSliceElementIndex(items []string, item string) int
- func IsContainString(items []string, item string) bool
- func IsEmptyString(str string) bool
- func IsNum(s string) bool
- func IsSubsetString(originItems, checkItems []string) (bool, []string)
- func PathExist(path string) error
- func ReSplit(text string, cut string) []string
- func ReplaceQuotesString(s string) string
- func ReplaceSpecifiedString(s string, oldStr, newStr string) string
- func SpecialLettersUsingMySQL(bs []byte) string
- func SpecialLettersUsingOracle(bs []byte) string
- func SplitMultipleSlice(arr []interface{}, num int64) [][]interface{}
- func SplitMultipleStringSlice(arr [][]string, num int64) [][][]string
- func StrconvFloatBitSize(s string, bitSize int) (float64, error)
- func StrconvIntBitSize(s string, bitSize int) (int64, error)
- func StrconvRune(s string) (int32, error)
- func StrconvUintBitSize(s string, bitSize int) (uint64, error)
- func StringArrayToCapitalChar(strs []string) string
- func StringJOIN(strs []string, strPrefix, strSuffix, joinS string) string
- func StringUPPER(str string) string
- func StringsBuilder(str ...string) string
- func TrimLastChar(s string) string
- func Utf8ToGbk(s []byte) ([]byte, error)
- func VersionOrdinal(version string) string
Constants ¶
const ( UpdateOperation = "UPDATE" InsertOperation = "INSERT" DeleteOperation = "DELETE" TruncateOperation = "TRUNCATE" DropOperation = "DROP" DDLOperation = "DDL" TruncateTableOperation = "TRUNCATE TABLE" DropTableOperation = "DROP TABLE" )
同步操作类型
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" )
const ( OracleSysdateDefaultValueMap = "SYSDATE" OracleSYSGUIDDefaultValueMap = "SYS_GUID()" )
ORACLE 默认值规则映射规则
const ( MysqlMaxIdleConn = 512 MysqlMaxConn = 1024 MysqlConnMaxLifeTime = 300 * time.Second MysqlConnMaxIdleTime = 200 * time.Second )
MySQL 连接配置
const (
MySQLCurrentTimestampDefaultValueMAP = "CURRENT_TIMESTAMP"
)
MySQL 默认值规则映射规则
Variables ¶
var CurrentResetFlag = 0
用于控制当程序消费追平到当前 CURRENT 重做日志, 当值 == 0 启用 filterOracleRedoGreaterOrEqualRecordByTable 大于或者等于 当值 == 1 启用 filterOracleRedoGreaterOrEqualRecordByTable 大于,避免已被消费得日志一直被重复消费
var MySQLDBCharacterSetMap = map[string]string{
"UTF8MB4": "AL32UTF8",
"UTF8": "AL32UTF8",
"GBK": "AL32UTF8",
}
MySQL 字符集映射规则
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",
}
var MySQLDefaultValueMap = map[string]string{ MySQLCurrentTimestampDefaultValueMAP: "SYSDATE", }
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 映射
var OracleDBCSVCharacterSetMap = map[string]string{
"AL32UTF8": "UTF8",
"UTF8": "UTF8",
"ZHS16GBK": "GBK",
}
ORACLE 字符集映射规则
var OracleDBCharacterSetMap = map[string]string{
"AL32UTF8": "UTF8MB4",
"UTF8": "UTF8MB4",
"ZHS16GBK": "GBK",
}
ORACLE 字符集映射规则
var OracleDefaultValueMap = map[string]string{ OracleSysdateDefaultValueMap: "NOW()", OracleSYSGUIDDefaultValueMap: "UUID()", }
var OracleIsNotSupportDataType = []string{"ENUM", "SET"}
Oracle 不支持数据类型 -> M2O
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 = ""
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 需要单引号
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 FilterIntersectionStringItems ¶
过滤两个数组相同元素(交集),返回新数组
func GetStringSliceElementIndex ¶
获取数组元素下标
func IsSubsetString ¶
两个数组对比,判断 checkItems 是否是 originItems 子集
func ReplaceSpecifiedString ¶
替换指定字符
func SpecialLettersUsingMySQL ¶
如果存在特殊字符,直接在特殊字符前添加\ * 判断是否为字母: unicode.IsLetter(v) 判断是否为十进制数字: unicode.IsDigit(v) 判断是否为数字: unicode.IsNumber(v) 判断是否为空白符号: unicode.IsSpace(v) 判断师傅是特殊符号:unicode.IsSymbol(v) 判断是否为Unicode标点字符 :unicode.IsPunct(v) 判断是否为中文:unicode.Han(v)
func SplitMultipleSlice ¶
func SplitMultipleSlice(arr []interface{}, num int64) [][]interface{}
多重数组拆分
func SplitMultipleStringSlice ¶
数组拆分
func StrconvRune ¶
func StringJOIN ¶
字符串 JOIN
Types ¶
This section is empty.