github.com/team-ide/go-dialect@v1.9.20/dialect/mapping.shentong.go (about)

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