github.com/team-ide/go-dialect@v1.9.20/dialect/mapping.kingbase.go (about) 1 package dialect 2 3 import ( 4 "fmt" 5 "strconv" 6 "strings" 7 ) 8 9 func NewMappingKingBase() (mapping *SqlMapping) { 10 11 // http://www.yaotu.net/biancheng/21946.html 12 // https://www.modb.pro/db/442114 13 // https://help.kingbase.com.cn/v8/index.html 14 mapping = &SqlMapping{ 15 dialectType: TypeKingBase, 16 17 OwnerNamePackChar: "\"", 18 TableNamePackChar: "\"", 19 ColumnNamePackChar: "\"", 20 SqlValuePackChar: "'", 21 SqlValueEscapeChar: "'", 22 } 23 24 appendKingBaseSql(mapping) 25 26 mapping.PackPageSql = func(selectSql string, pageSize int, pageNo int) (pageSql string) { 27 pageSql = selectSql + fmt.Sprintf(" LIMIT %d OFFSET %d", pageSize, pageSize*(pageNo-1)) 28 return 29 } 30 31 mapping.ReplaceSqlVariable = func(sqlInfo string, args []interface{}) (variableSql string) { 32 strList := strings.Split(sqlInfo, "?") 33 if len(strList) < 1 { 34 variableSql = sqlInfo 35 return 36 } 37 variableSql = strList[0] 38 for i := 1; i < len(strList); i++ { 39 variableSql += "$" + strconv.Itoa(i) 40 variableSql += strList[i] 41 } 42 return 43 } 44 45 for _, one := range kingBaseColumnTypeList { 46 mapping.AddColumnTypeInfo(one) 47 } 48 49 for _, one := range kingBaseIndexTypeList { 50 mapping.AddIndexTypeInfo(one) 51 } 52 53 return 54 } 55 56 var ( 57 kingBaseIndexTypeList []*IndexTypeInfo 58 ) 59 60 func appendKingBaseIndexType(indexType *IndexTypeInfo) { 61 kingBaseIndexTypeList = append(kingBaseIndexTypeList, indexType) 62 } 63 64 func init() { 65 appendKingBaseIndexType(&IndexTypeInfo{Name: "", Format: "INDEX", 66 NotSupportDataTypes: []string{"CLOB", "BLOB"}, 67 }) 68 appendKingBaseIndexType(&IndexTypeInfo{Name: "INDEX", Format: "INDEX", 69 NotSupportDataTypes: []string{"CLOB", "BLOB"}, 70 }) 71 appendKingBaseIndexType(&IndexTypeInfo{Name: "NORMAL", Format: "INDEX", 72 NotSupportDataTypes: []string{"CLOB", "BLOB"}, 73 }) 74 appendKingBaseIndexType(&IndexTypeInfo{Name: "UNIQUE", Format: "UNIQUE", 75 NotSupportDataTypes: []string{"CLOB", "BLOB"}, 76 IndexTypeFormat: func(index *IndexModel) (indexTypeFormat string, err error) { 77 indexTypeFormat = "UNIQUE INDEX" 78 return 79 }, 80 }) 81 appendKingBaseIndexType(&IndexTypeInfo{Name: "FULLTEXT", Format: "FULLTEXT", IsExtend: true, 82 IndexTypeFormat: func(index *IndexModel) (indexTypeFormat string, err error) { 83 return 84 }, 85 }) 86 appendKingBaseIndexType(&IndexTypeInfo{Name: "SPATIAL", Format: "SPATIAL", IsExtend: true, 87 IndexTypeFormat: func(index *IndexModel) (indexTypeFormat string, err error) { 88 return 89 }, 90 }) 91 }