github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/internal/pkg/model/index.go (about) 1 package model 2 3 import ( 4 consts "github.com/easysoft/zendata/internal/pkg/const" 5 ) 6 7 var ( 8 CommonPrefix = "zd_" 9 Models = []interface{}{ 10 &ZdExcel{}, 11 &ZdDef{}, &ZdField{}, &ZdSection{}, &ZdRefer{}, 12 &ZdRanges{}, &ZdRangesItem{}, &ZdText{}, &ZdConfig{}, &ZdInstances{}, &ZdInstancesItem{}, 13 &ZdMock{}, &ZdMockSampleSrc{}, 14 } 15 ) 16 17 type ZdDef struct { 18 Model 19 Title string `gorm:"column:title" json:"title"` 20 Type string `gorm:"column:type" json:"type"` 21 Desc string `gorm:"column:desc" json:"desc"` 22 23 Yaml string `gorm:"yaml" json:"yaml"` 24 Path string `gorm:"column:path" json:"path" yaml:"-"` 25 Folder string `gorm:"column:folder" json:"folder" yaml:"-"` 26 FileName string `gorm:"column:fileName" json:"fileName" yaml:"-"` 27 IsMock bool `gorm:"column:isMock" json:"isMock"` 28 29 ReferName string `gorm:"column:referName" json:"referName" yaml:"-"` 30 From string `gorm:"-" json:"from"` 31 Fields []ZdField `gorm:"-" json:"fields"` 32 } 33 34 func (*ZdDef) TableName() string { 35 return consts.TablePrefix + "def" 36 } 37 38 type ZdField struct { 39 Model 40 Field string `gorm:"column:field" json:"field"` 41 Note string `gorm:"column:note" json:"note"` 42 43 Range string `gorm:"column:range" json:"range"` 44 Prefix string `gorm:"column:prefix" json:"prefix"` 45 Postfix string `gorm:"column:postfix" json:"postfix"` 46 Divider string `gorm:"column:divider" json:"divider"` 47 Loop string `gorm:"column:loop" json:"loop"` 48 Loopfix string `gorm:"column:loopfix" json:"loopfix"` 49 Format string `gorm:"column:format" json:"format"` 50 Type string `gorm:"column:type" json:"type"` 51 Mode string `gorm:"column:mode" json:"mode"` 52 Items int `gorm:"column:records" json:"records"` 53 Length int `gorm:"column:length" json:"length"` 54 LeftPad string `gorm:"column:leftPad" json:"leftPad"` 55 RightPad string `gorm:"column:rightPad" json:"rightPad"` 56 Rand bool `gorm:"column:rand" json:"rand"` 57 Config string `gorm:"column:config" json:"config"` 58 Use string `gorm:"column:use" json:"use"` 59 From string `gorm:"column:fromCol" json:"fromCol"` 60 Select string `gorm:"column:selectCol" json:"selectCol"` 61 Where string `gorm:"column:whereCol" json:"whereCol"` 62 Limit int `gorm:"column:limitCol" json:"limitCol"` 63 64 // refer to yaml or text by using range prop 65 Step string `gorm:"column:step" json:"step"` 66 Repeat string `gorm:"column:repeat" json:"repeat"` 67 68 Exp string `gorm:"column:exp" json:"exp"` 69 DefID uint `gorm:"column:defID" json:"defID"` 70 ParentID uint `gorm:"column:parentID" json:"parentID"` 71 UseID uint `gorm:"column:useID" json:"useID"` 72 ConfigID uint `gorm:"column:configID" json:"configID"` 73 74 Ord int `gorm:"column:ord;default:1" json:"ord"` 75 Join bool `gorm:"join" json:"join"` 76 77 Fields []*ZdField `gorm:"-" json:"fields"` 78 Froms []*ZdField `gorm:"-" json:"froms"` 79 80 // for range edit 81 IsRange bool `gorm:"column:isRange;default:true" json:"isRange"` 82 Sections []ZdSection `gorm:"ForeignKey:ownerID" json:"sections"` 83 84 // for refer edit 85 Refer ZdRefer `gorm:"ForeignKey:ownerID" json:"refer"` 86 87 // generated by range or refer 88 GeneratedBy consts.GeneratedBy `gorm:"column:generatedBy;default:range" json:"generatedBy"` 89 } 90 91 func (*ZdField) TableName() string { 92 return consts.TablePrefix + "field" 93 } 94 95 type ZdSection struct { 96 Model 97 OwnerType string `gorm:"column:ownerType" json:"ownerType"` // field or instances 98 OwnerID uint `gorm:"column:ownerID" json:"ownerID"` 99 Type string `gorm:"column:type;default:interval" json:"type"` 100 Value string `gorm:"column:value" json:"value"` 101 Ord int `gorm:"column:ord;default:1" json:"ord"` 102 103 // for range 104 Start string `gorm:"column:start" json:"start"` 105 End string `gorm:"column:end" json:"end"` 106 Step int `gorm:"column:step;default:1" json:"step"` 107 Repeat string `gorm:"column:repeat;default:1" json:"repeat"` 108 RepeatTag string `gorm:"column:repeatTag" json:"repeatTag"` 109 Rand bool `gorm:"column:rand;default:false" json:"rand"` 110 111 // for arr and const 112 Text string `gorm:"-" json:"-"` 113 } 114 115 func (*ZdSection) TableName() string { 116 return consts.TablePrefix + "section" 117 } 118 119 type ZdRefer struct { 120 Model 121 OwnerType string `gorm:"column:ownerType" json:"ownerType"` // field or instances 122 OwnerID uint `gorm:"column:ownerID" json:"ownerID"` 123 Type string `gorm:"column:type" json:"type"` 124 125 Value string `gorm:"column:value" json:"value"` 126 File string `gorm:"column:file" json:"file"` 127 Sheet string `gorm:"column:sheet" json:"sheet"` 128 129 ColName string `gorm:"column:colName" json:"colName"` 130 ColIndex int `gorm:"column:colIndex" json:"colIndex"` 131 Condition string `gorm:"column:condition" json:"condition"` 132 Count int `gorm:"column:count" json:"count"` 133 CountTag string `gorm:"column:countTag" json:"countTag"` 134 Step int `gorm:"column:step" json:"step"` 135 Rand bool `gorm:"column:rand" json:"rand"` 136 HasTitle bool `gorm:"column:hasTitle" json:"hasTitle"` 137 } 138 139 func (*ZdRefer) TableName() string { 140 return consts.TablePrefix + "refer" 141 } 142 143 type ZdRanges struct { 144 Model 145 Title string `gorm:"column:title" json:"title"` 146 Desc string `gorm:"column:desc" json:"desc"` 147 Prefix string `gorm:"column:prefix" json:"prefix"` 148 Postfix string `gorm:"column:postfix" json:"postfix"` 149 Format string `gorm:"column:format" json:"format"` 150 151 Yaml string `gorm:"yaml" json:"yaml"` 152 Path string `gorm:"column:path" json:"path" yaml:"-"` 153 Folder string `gorm:"folder" json:"folder" yaml:"-"` 154 FileName string `gorm:"column:fileName" json:"fileName" yaml:"-"` 155 ReferName string `gorm:"column:referName" json:"referName" yaml:"-"` 156 157 Ranges []ZdRangesItem `gorm:"ForeignKey:rangesID" json:"ranges" yaml:"-"` 158 RangeMap map[string]string `gorm:"-" yaml:"ranges"` 159 } 160 161 func (*ZdRanges) TableName() string { 162 return consts.TablePrefix + "ranges" 163 } 164 165 type ZdRangesItem struct { 166 Model 167 RangesID uint `gorm:"column:rangesID" json:"rangesID"` 168 Field string `gorm:"column:name" json:"field"` 169 Ord int `gorm:"column:ord" json:"ord"` 170 171 Value string `gorm:"column:value" json:"value"` 172 Sections []ZdSection `gorm:"ForeignKey:ownerID" json:"sections"` 173 174 // for tree node 175 ParentID uint `gorm:"-" json:"parentID"` 176 Fields []*ZdRangesItem `gorm:"-" json:"fields"` 177 } 178 179 func (*ZdRangesItem) TableName() string { 180 return consts.TablePrefix + "ranges_item" 181 } 182 183 type ZdInstances struct { 184 Model `yaml:"-"` 185 Title string `gorm:"column:title" json:"title" yaml:"title,omitempty"` 186 Desc string `gorm:"column:desc" json:"desc" yaml:"desc,omitempty"` 187 188 Yaml string `gorm:"yaml" json:"yaml" yaml:"-"` 189 Path string `gorm:"column:path" json:"path" yaml:"-"` 190 Folder string `gorm:"folder" json:"folder" yaml:"-"` 191 192 FileName string `gorm:"column:fileName" json:"fileName" yaml:"-"` 193 ReferName string `gorm:"column:referName" json:"referName" yaml:"-"` 194 195 From string `gorm:"-" json:"from"` 196 Instances []ZdInstancesItem `gorm:"ForeignKey:instancesID" json:"instances" yaml:"instances"` 197 } 198 199 func (*ZdInstances) TableName() string { 200 return consts.TablePrefix + "instances" 201 } 202 203 type ZdInstancesItem struct { 204 Model `yaml:"-"` 205 206 Instance string `gorm:"column:instance" json:"instance" yaml:"instance,omitempty"` 207 Note string `gorm:"column:note" json:"note" yaml:"note,omitempty"` 208 209 Field string `gorm:"column:field" json:"field" yaml:"field,omitempty"` 210 Range string `gorm:"column:range" json:"range" yaml:"range,omitempty"` 211 Prefix string `gorm:"column:prefix" json:"prefix" yaml:"prefix,omitempty"` 212 Postfix string `gorm:"column:postfix" json:"postfix" yaml:"postfix,omitempty"` 213 Loop string `gorm:"column:loop" json:"loop" yaml:"loop,omitempty"` 214 Loopfix string `gorm:"column:loopfix" json:"loopfix" yaml:"loopfix,omitempty"` 215 Format string `gorm:"column:format" json:"format" yaml:"format,omitempty"` 216 Type string `gorm:"column:type" json:"type" yaml:"type,omitempty"` 217 Mode string `gorm:"column:mode" json:"mode" yaml:"mode,omitempty"` 218 Items int `gorm:"column:records" json:"records,omitempty" yaml:"records,omitempty"` 219 Length int `gorm:"column:length" json:"length" yaml:"length,omitempty"` 220 LeftPad string `gorm:"column:leftPad" json:"leftPad" yaml:"leftPad,omitempty"` 221 RightPad string `gorm:"column:rightPad" json:"rightPad" yaml:"rightPad,omitempty"` 222 Rand bool `gorm:"column:rand" json:"rand" yaml:"rand,omitempty"` 223 224 Config string `gorm:"column:config" json:"config" yaml:"config,omitempty"` 225 Use string `gorm:"column:use" json:"use" yaml:"use,omitempty"` 226 From string `gorm:"column:fromCol" json:"fromCol" yaml:"from,omitempty"` 227 Select string `gorm:"column:selectCol" json:"selectCol" yaml:"select,omitempty"` 228 Where string `gorm:"column:whereCol" json:"whereCol" yaml:"where,omitempty"` 229 Limit int `gorm:"column:limitCol" json:"limitCol" yaml:"limit,omitempty"` 230 231 Exp string `gorm:"column:exp" json:"exp" yaml:"exp,omitempty"` 232 InstancesID uint `gorm:"column:instancesID" json:"instancesID" yaml:"-"` 233 ParentID uint `gorm:"column:parentID" json:"parentID" yaml:"-"` 234 ConfigID uint `gorm:"column:configID" json:"configID" yaml:"-"` 235 UseID uint `gorm:"column:useID" json:"useID" yaml:"-"` 236 237 Ord int `gorm:"column:ord;default:1" json:"ord" yaml:"-"` 238 Fields []*ZdInstancesItem `gorm:"-" json:"fields" yaml:"fields,omitempty"` 239 Froms []*ZdInstancesItem `gorm:"-" json:"froms" yaml:"froms,omitempty"` 240 241 // for range edit 242 IsRange bool `gorm:"column:isRange;default:true" json:"isRange" yaml:"-"` 243 Sections []ZdSection `gorm:"ForeignKey:ownerID" json:"sections" yaml:"-"` 244 245 // for refer edit 246 Refer ZdRefer `gorm:"ForeignKey:ownerID" json:"refer" yaml:"-"` 247 } 248 249 func (*ZdInstancesItem) TableName() string { 250 return consts.TablePrefix + "instances_item" 251 } 252 253 type ZdConfig struct { 254 Model 255 Title string `gorm:"column:title" json:"title"` 256 Desc string `gorm:"column:desc" json:"desc"` 257 258 Range string `gorm:"column:range" json:"range"` 259 Prefix string `gorm:"column:prefix" json:"prefix"` 260 Postfix string `gorm:"column:postfix" json:"postfix"` 261 Loop string `gorm:"column:loop" json:"loop"` 262 Loopfix string `gorm:"column:loopfix" json:"loopfix"` 263 Format string `gorm:"column:format" json:"format"` 264 265 Yaml string `gorm:"yaml" json:"yaml"` 266 Path string `gorm:"column:path" json:"path" yaml:"-"` 267 Folder string `gorm:"folder" json:"folder" yaml:"-"` 268 FileName string `gorm:"column:fileName" json:"fileName" yaml:"-"` 269 ReferName string `gorm:"column:referName" json:"referName" yaml:"-"` 270 271 // for range edit 272 IsRange bool `gorm:"column:isRange;default:true" json:"isRange" yaml:"-"` 273 Sections []ZdSection `gorm:"ForeignKey:ownerID" json:"sections" yaml:"-"` 274 } 275 276 func (*ZdConfig) TableName() string { 277 return consts.TablePrefix + "config" 278 } 279 280 type ZdText struct { 281 Model 282 Title string `gorm:"column:title" json:"title"` 283 284 Content string `gorm:"column:content" json:"content"` 285 Path string `gorm:"column:path" json:"path" yaml:"-"` 286 Folder string `gorm:"folder" json:"folder" yaml:"-"` 287 FileName string `gorm:"column:fileName" json:"fileName" yaml:"-"` 288 ReferName string `gorm:"column:referName" json:"referName" yaml:"-"` 289 } 290 291 func (*ZdText) TableName() string { 292 return consts.TablePrefix + "text" 293 } 294 295 type ZdExcel struct { 296 Model 297 Title string `gorm:"column:title" json:"title"` 298 Sheet string `gorm:"column:sheet" json:"sheet"` 299 300 ChangeTime string `gorm:"column:changeTime" json:"changeTime"` 301 Yaml string `gorm:"yaml" json:"yaml"` 302 Path string `gorm:"column:path" json:"path" yaml:"-"` 303 Folder string `gorm:"folder" json:"folder" yaml:"-"` 304 FileName string `gorm:"column:fileName" json:"fileName" yaml:"-"` 305 ReferName string `gorm:"column:referName" json:"referName" yaml:"-"` 306 } 307 308 func (*ZdExcel) TableName() string { 309 return consts.TablePrefix + "excel" 310 }