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