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

     1  package dialect
     2  
     3  type ParamModel struct {
     4  	OwnerNamePack      *bool   `json:"ownerNamePack"`
     5  	OwnerNamePackChar  *string `json:"ownerNamePackChar"`
     6  	TableNamePack      *bool   `json:"tableNamePack"`
     7  	TableNamePackChar  *string `json:"tableNamePackChar"`
     8  	ColumnNamePack     *bool   `json:"columnNamePack"`
     9  	ColumnNamePackChar *string `json:"columnNamePackChar"`
    10  	SqlValuePackChar   *string `json:"sqlValuePackChar"`
    11  	SqlValueEscapeChar *string `json:"sqlValueEscapeChar"`
    12  
    13  	AppendSqlValue *bool `json:"appendSqlValue"`
    14  
    15  	CustomData map[string]interface{} `json:"customData"`
    16  }
    17  
    18  type OwnerModel struct {
    19  	OwnerName             string                 `json:"ownerName"`
    20  	OwnerComment          string                 `json:"ownerComment"`
    21  	OwnerUsername         string                 `json:"ownerUsername"`
    22  	OwnerPassword         string                 `json:"ownerPassword"`
    23  	OwnerCharacterSetName string                 `json:"ownerCharacterSetName"`
    24  	OwnerCollationName    string                 `json:"ownerCollationName"`
    25  	Extend                map[string]interface{} `json:"extend,omitempty"`
    26  
    27  	Error string `json:"error,omitempty"`
    28  }
    29  
    30  type TableModel struct {
    31  	TableName    string `json:"tableName"`
    32  	TableComment string `json:"tableComment"`
    33  
    34  	ColumnList            []*ColumnModel         `json:"columnList"`
    35  	IndexList             []*IndexModel          `json:"indexList"`
    36  	PrimaryKeys           []string               `json:"primaryKeys"`
    37  	TableCharacterSetName string                 `json:"tableCharacterSetName"`
    38  	TableCollationName    string                 `json:"tableCollationName"`
    39  	Extend                map[string]interface{} `json:"extend,omitempty"`
    40  
    41  	OwnerName string `json:"ownerName"`
    42  
    43  	Sql   string `json:"sql,omitempty"`
    44  	Error string `json:"error,omitempty"`
    45  }
    46  
    47  func (this_ *TableModel) AddColumn(column *ColumnModel) *ColumnModel {
    48  	this_.ColumnList = append(this_.ColumnList, column)
    49  	return nil
    50  }
    51  func (this_ *TableModel) FindColumnByName(name string) *ColumnModel {
    52  	if len(this_.ColumnList) > 0 {
    53  		for _, one := range this_.ColumnList {
    54  			if one.ColumnName == name {
    55  				return one
    56  			}
    57  		}
    58  	}
    59  	return nil
    60  }
    61  
    62  func (this_ *TableModel) FindIndexByName(name string) *IndexModel {
    63  	if len(this_.IndexList) > 0 {
    64  		for _, one := range this_.IndexList {
    65  			if one.IndexName == name {
    66  				return one
    67  			}
    68  		}
    69  	}
    70  	return nil
    71  }
    72  
    73  func (this_ *TableModel) AddPrimaryKey(models ...*PrimaryKeyModel) {
    74  
    75  	for _, model := range models {
    76  		if StringsIndex(this_.PrimaryKeys, model.ColumnName) >= 0 {
    77  			continue
    78  		}
    79  		this_.PrimaryKeys = append(this_.PrimaryKeys, model.ColumnName)
    80  		find := this_.FindColumnByName(model.ColumnName)
    81  		if find != nil {
    82  			find.PrimaryKey = true
    83  		}
    84  	}
    85  }
    86  func (this_ *TableModel) AddIndex(models ...*IndexModel) {
    87  
    88  	for _, model := range models {
    89  		var find *IndexModel
    90  		if model.IndexName != "" {
    91  			find = this_.FindIndexByName(model.IndexName)
    92  		}
    93  		columnNames := model.ColumnNames
    94  		if model.ColumnName != "" && StringsIndex(columnNames, model.ColumnName) < 0 {
    95  			columnNames = append(columnNames, model.ColumnName)
    96  		}
    97  		if find != nil {
    98  			for _, columnName := range columnNames {
    99  				if StringsIndex(find.ColumnNames, columnName) < 0 {
   100  					find.ColumnNames = append(find.ColumnNames, columnName)
   101  				}
   102  			}
   103  		} else {
   104  			model.ColumnNames = columnNames
   105  			this_.IndexList = append(this_.IndexList, model)
   106  		}
   107  	}
   108  }
   109  
   110  type ColumnModel struct {
   111  	ColumnName     string `json:"columnName"`
   112  	ColumnComment  string `json:"columnComment"`
   113  	ColumnDataType string `json:"columnDataType"`
   114  	//ColumnType             string `json:"columnType"`
   115  	ColumnLength           int    `json:"columnLength"`
   116  	ColumnPrecision        int    `json:"columnPrecision"`
   117  	ColumnScale            int    `json:"columnScale"`
   118  	ColumnNotNull          bool   `json:"columnNotNull"`
   119  	ColumnDefault          string `json:"columnDefault"`
   120  	ColumnAfterColumn      string `json:"columnAfterColumn"`
   121  	ColumnCharacterSetName string `json:"columnCharacterSetName"`
   122  
   123  	PrimaryKey bool `json:"primaryKey"`
   124  
   125  	ColumnEnums []string               `json:"columnEnums"`
   126  	ColumnExtra string                 `json:"columnExtra"`
   127  	OwnerName   string                 `json:"ownerName"`
   128  	TableName   string                 `json:"tableName"`
   129  	Extend      map[string]interface{} `json:"extend,omitempty"`
   130  
   131  	Error string `json:"error,omitempty"`
   132  }
   133  
   134  type ColumnTypeInfo struct {
   135  	Name         string `json:"name,omitempty"`
   136  	Comment      string `json:"comment,omitempty"`
   137  	Format       string `json:"format,omitempty"`
   138  	MinLength    *int   `json:"minLength"`
   139  	MaxLength    *int   `json:"maxLength"`
   140  	MinPrecision *int   `json:"minPrecision"`
   141  	MaxPrecision *int   `json:"maxPrecision"`
   142  	MinScale     *int   `json:"minScale"`
   143  	MaxScale     *int   `json:"maxScale"`
   144  
   145  	// IsNumber 如果 是 数字 数据存储 设置该属性
   146  	IsNumber  bool `json:"isNumber,omitempty"`
   147  	IsInteger bool `json:"isInteger,omitempty"`
   148  	IsFloat   bool `json:"isFloat,omitempty"`
   149  
   150  	// IsString 如果 是 字符串 数据存储 设置该属性
   151  	IsString bool `json:"isString,omitempty"`
   152  
   153  	// IsDateTime 如果 是 日期时间 数据存储 设置该属性
   154  	IsDateTime bool `json:"isDateTime,omitempty"`
   155  
   156  	// IsBytes 如果 是 流 数据存储 设置该属性
   157  	IsBytes bool `json:"isBytes,omitempty"`
   158  
   159  	IsBoolean bool `json:"isBoolean,omitempty"`
   160  
   161  	// IsEnum 如果 是 枚举 数据存储 设置该属性
   162  	IsEnum bool `json:"isEnum,omitempty"`
   163  
   164  	// IsExtend 如果 非 当前 数据库能支持的类型 设置该属性
   165  	IsExtend bool     `json:"isExtend,omitempty"`
   166  	Matches  []string `json:"matches"`
   167  
   168  	IfNotFound             bool                                                                               `json:"ifNotFound,omitempty"`
   169  	ColumnDefaultPack      func(param *ParamModel, column *ColumnModel) (columnDefaultPack string, err error) `json:"-"`
   170  	ColumnTypePack         func(column *ColumnModel) (columnTypePack string, err error)                       `json:"-"`
   171  	SqlValuePack           func(value string) (sqlValue string)                                               `json:"-"`
   172  	FullColumnByColumnType func(columnType string, column *ColumnModel) (err error)                           `json:"-"`
   173  }
   174  
   175  type IndexTypeInfo struct {
   176  	Name   string `json:"name,omitempty"`
   177  	Format string `json:"format,omitempty"`
   178  
   179  	// IsExtend 如果 非 当前 数据库能支持的类型 设置该属性
   180  	IsExtend bool `json:"isExtend,omitempty"`
   181  
   182  	OnlySupportDataTypes []string `json:"onlySupportDataTypes"`
   183  	NotSupportDataTypes  []string `json:"notSupportDataTypes"`
   184  
   185  	IndexTypeFormat func(index *IndexModel) (indexTypeFormat string, err error)                                                        `json:"-"`
   186  	IndexNameFormat func(param *ParamModel, ownerName string, tableName string, index *IndexModel) (indexNameFormat string, err error) `json:"-"`
   187  }
   188  
   189  type PrimaryKeyModel struct {
   190  	ColumnName string `json:"columnName"`
   191  
   192  	OwnerName string `json:"ownerName"`
   193  	TableName string `json:"tableName"`
   194  	Error     string `json:"error,omitempty"`
   195  }
   196  
   197  type IndexModel struct {
   198  	IndexName    string   `json:"indexName"`
   199  	IndexType    string   `json:"indexType"`
   200  	ColumnName   string   `json:"columnName"`
   201  	ColumnNames  []string `json:"columnNames"`
   202  	IndexComment string   `json:"indexComment"`
   203  
   204  	OwnerName string `json:"ownerName"`
   205  	TableName string `json:"tableName"`
   206  	Error     string `json:"error,omitempty"`
   207  }