github.com/wfusion/gofusion@v1.1.14/test/db/cases/types.go (about) 1 package cases 2 3 import ( 4 "gorm.io/gorm" 5 6 "github.com/wfusion/gofusion/db" 7 ) 8 9 const ( 10 nameMysqlWrite = "write" 11 nameMysqlRead = "read" 12 namePostgres = "postgres" 13 nameOpenGauss = "opengauss" 14 nameSqlserver = "sqlserver" 15 nameSqlite = "sqlite" 16 ) 17 18 type modelWithData struct { 19 db.Data 20 Name string `gorm:"column:name"` 21 } 22 23 func (*modelWithData) TableName() string { 24 return "model_with_data" 25 } 26 27 func modelWithDataDAL(read, write, appName string) db.DalInterface[modelWithData, []*modelWithData] { 28 return db.NewDAL[modelWithData, []*modelWithData](read, write, db.AppName(appName)) 29 } 30 31 type modelWithDataExtend struct { 32 db.Data 33 ModelID uint64 `gorm:"column:model_id"` 34 OtherName string `gorm:"column:other_name"` 35 } 36 37 func (*modelWithDataExtend) TableName() string { 38 return "model_with_data_extend" 39 } 40 41 type modelWithBusiness struct { 42 db.Business 43 Name string `gorm:"column:name"` 44 } 45 46 func (*modelWithBusiness) TableName() string { 47 return "model_with_business" 48 } 49 50 type modelWithSoftDeleted struct { 51 db.DataSoftDeleted 52 DeletedAt gorm.DeletedAt `gorm:"column:deleted_at"` 53 Name string `gorm:"column:name"` 54 } 55 56 func (*modelWithSoftDeleted) TableName() string { 57 return "model_with_soft_deleted" 58 } 59 60 type modelBizWithSoftDeleted struct { 61 db.BusinessSoftDeleted 62 Name string `gorm:"column:name"` 63 } 64 65 func (*modelBizWithSoftDeleted) TableName() string { 66 return "model_biz_with_soft_deleted" 67 } 68 69 type modelWithBusinessAndUser struct { 70 db.Business 71 UserBase 72 Name string `gorm:"column:name"` 73 } 74 75 func (*modelWithBusinessAndUser) TableName() string { 76 return "model_with_business_and_user" 77 } 78 79 type modelWithSharding struct { 80 db.Business 81 AZBase 82 gorm.DeletedAt 83 84 Name string `gorm:"column:name"` 85 86 EmbedList []*modelWithShardingEmbed `gorm:"foreignKey:ModelID;AssociationForeignKey:ID"` 87 } 88 89 func (modelWithSharding) TableName() string { 90 return "model_with_sharding" 91 } 92 93 type modelWithShardingPtr struct { 94 db.Business 95 AZBase 96 Name string `gorm:"column:name"` 97 Age int `gorm:"column:age"` 98 } 99 100 func (*modelWithShardingPtr) TableName() string { 101 return "model_with_sharding_ptr" 102 } 103 104 type modelWithShardingExtend struct { 105 db.Data 106 AZBase 107 108 ModelID uint64 `gorm:"column:model_id"` 109 OtherName string `gorm:"column:other_name"` 110 } 111 112 func (*modelWithShardingExtend) TableName() string { 113 return "model_with_sharding_extend" 114 } 115 116 type modelWithShardingEmbed struct { 117 db.Data 118 AZBase 119 120 ModelID uint64 `gorm:"column:model_id"` 121 OtherName string `gorm:"column:other_name"` 122 } 123 124 func (*modelWithShardingEmbed) TableName() string { 125 return "model_with_sharding_embed" 126 } 127 128 type modelWithShardingByRawValue struct { 129 db.Business 130 AZBase 131 Name string `gorm:"column:name"` 132 Age int `gorm:"column:age"` 133 } 134 135 func (*modelWithShardingByRawValue) TableName() string { 136 return "model_with_sharding_by_raw_value" 137 } 138 139 type RegionBase struct { 140 RegionID string `gorm:"column:region_id;type:varchar(64);index:,composite:base" json:"regionID"` 141 } 142 143 func (r *RegionBase) Clone() *RegionBase { 144 if r == nil { 145 return nil 146 } 147 return &RegionBase{ 148 RegionID: r.RegionID, 149 } 150 } 151 func (r *RegionBase) Equals(o *RegionBase) bool { 152 if r == nil && o == nil { 153 return true 154 } 155 if r == nil || o == nil { 156 return false 157 } 158 return r.RegionID == o.RegionID 159 } 160 161 type AZBase struct { 162 RegionBase 163 AZName string `gorm:"column:az_name;type:varchar(64);index:,composite:base" json:"azName"` 164 } 165 166 func (a *AZBase) Clone() *AZBase { 167 if a == nil { 168 return nil 169 } 170 return &AZBase{ 171 RegionBase: *a.RegionBase.Clone(), 172 AZName: a.AZName, 173 } 174 } 175 func (a *AZBase) Equals(o *AZBase) bool { 176 if a == nil && o == nil { 177 return true 178 } 179 if a == nil || o == nil { 180 return false 181 } 182 return a.RegionBase.Equals(&o.RegionBase) && 183 a.AZName == o.AZName 184 } 185 186 type UserBase struct { 187 AZBase 188 UserID string `gorm:"column:user_id;type:varchar(64);index:,composite:base" json:"userID"` 189 } 190 191 func (u *UserBase) Clone() *UserBase { 192 if u == nil { 193 return nil 194 } 195 return &UserBase{ 196 AZBase: *u.AZBase.Clone(), 197 UserID: u.UserID, 198 } 199 } 200 func (u *UserBase) Equals(o *UserBase) bool { 201 if u == nil && o == nil { 202 return true 203 } 204 if u == nil || o == nil { 205 return false 206 } 207 return u.AZBase.Equals(&o.AZBase) && 208 u.UserID == o.UserID 209 }