github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/models/event_log__generated.go (about) 1 // This is a generated source file. DO NOT EDIT 2 // Source: models/event_log__generated.go 3 4 package models 5 6 import ( 7 "fmt" 8 "time" 9 10 "github.com/machinefi/w3bstream/pkg/depends/base/types" 11 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx" 12 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/builder" 13 ) 14 15 var EventLogTable *builder.Table 16 17 func init() { 18 EventLogTable = DB.Register(&EventLog{}) 19 } 20 21 type EventLogIterator struct { 22 } 23 24 func (*EventLogIterator) New() interface{} { 25 return &EventLog{} 26 } 27 28 func (*EventLogIterator) Resolve(v interface{}) *EventLog { 29 return v.(*EventLog) 30 } 31 32 func (*EventLog) TableName() string { 33 return "t_event_log" 34 } 35 36 func (*EventLog) TableDesc() []string { 37 return []string{ 38 "EventLog database model event", 39 } 40 } 41 42 func (*EventLog) Comments() map[string]string { 43 return map[string]string{ 44 "PublishedAt": "PublishedAt the timestamp when device publish event", 45 "ReceivedAt": "ReceivedAt the timestamp when event received by us", 46 "RespondedAt": "RespondedAt the timestamp when event handled and send response", 47 } 48 } 49 50 func (*EventLog) ColDesc() map[string][]string { 51 return map[string][]string{ 52 "PublishedAt": []string{ 53 "PublishedAt the timestamp when device publish event", 54 }, 55 "ReceivedAt": []string{ 56 "ReceivedAt the timestamp when event received by us", 57 }, 58 "RespondedAt": []string{ 59 "RespondedAt the timestamp when event handled and send response", 60 }, 61 } 62 } 63 64 func (*EventLog) ColRel() map[string][]string { 65 return map[string][]string{} 66 } 67 68 func (*EventLog) PrimaryKey() []string { 69 return []string{ 70 "ID", 71 } 72 } 73 74 func (*EventLog) Indexes() builder.Indexes { 75 return builder.Indexes{ 76 "i_created_at": []string{ 77 "CreatedAt", 78 }, 79 "i_event_id": []string{ 80 "EventID", 81 }, 82 "i_project_id": []string{ 83 "ProjectID", 84 }, 85 "i_publisher_id": []string{ 86 "PublisherID", 87 }, 88 } 89 } 90 91 func (m *EventLog) IndexFieldNames() []string { 92 return []string{ 93 "CreatedAt", 94 "EventID", 95 "ID", 96 "ProjectID", 97 "PublisherID", 98 } 99 } 100 101 func (m *EventLog) ColID() *builder.Column { 102 return EventLogTable.ColByFieldName(m.FieldID()) 103 } 104 105 func (*EventLog) FieldID() string { 106 return "ID" 107 } 108 109 func (m *EventLog) ColEventID() *builder.Column { 110 return EventLogTable.ColByFieldName(m.FieldEventID()) 111 } 112 113 func (*EventLog) FieldEventID() string { 114 return "EventID" 115 } 116 117 func (m *EventLog) ColProjectID() *builder.Column { 118 return EventLogTable.ColByFieldName(m.FieldProjectID()) 119 } 120 121 func (*EventLog) FieldProjectID() string { 122 return "ProjectID" 123 } 124 125 func (m *EventLog) ColPublisherID() *builder.Column { 126 return EventLogTable.ColByFieldName(m.FieldPublisherID()) 127 } 128 129 func (*EventLog) FieldPublisherID() string { 130 return "PublisherID" 131 } 132 133 func (m *EventLog) ColPublishedAt() *builder.Column { 134 return EventLogTable.ColByFieldName(m.FieldPublishedAt()) 135 } 136 137 func (*EventLog) FieldPublishedAt() string { 138 return "PublishedAt" 139 } 140 141 func (m *EventLog) ColReceivedAt() *builder.Column { 142 return EventLogTable.ColByFieldName(m.FieldReceivedAt()) 143 } 144 145 func (*EventLog) FieldReceivedAt() string { 146 return "ReceivedAt" 147 } 148 149 func (m *EventLog) ColRespondedAt() *builder.Column { 150 return EventLogTable.ColByFieldName(m.FieldRespondedAt()) 151 } 152 153 func (*EventLog) FieldRespondedAt() string { 154 return "RespondedAt" 155 } 156 157 func (m *EventLog) ColCreatedAt() *builder.Column { 158 return EventLogTable.ColByFieldName(m.FieldCreatedAt()) 159 } 160 161 func (*EventLog) FieldCreatedAt() string { 162 return "CreatedAt" 163 } 164 165 func (m *EventLog) ColUpdatedAt() *builder.Column { 166 return EventLogTable.ColByFieldName(m.FieldUpdatedAt()) 167 } 168 169 func (*EventLog) FieldUpdatedAt() string { 170 return "UpdatedAt" 171 } 172 173 func (m *EventLog) CondByValue(db sqlx.DBExecutor) builder.SqlCondition { 174 var ( 175 tbl = db.T(m) 176 fvs = builder.FieldValueFromStructByNoneZero(m) 177 cond = make([]builder.SqlCondition, 0) 178 ) 179 180 for _, fn := range m.IndexFieldNames() { 181 if v, ok := fvs[fn]; ok { 182 cond = append(cond, tbl.ColByFieldName(fn).Eq(v)) 183 delete(fvs, fn) 184 } 185 } 186 if len(cond) == 0 { 187 panic(fmt.Errorf("no field for indexes has value")) 188 } 189 for fn, v := range fvs { 190 cond = append(cond, tbl.ColByFieldName(fn).Eq(v)) 191 } 192 return builder.And(cond...) 193 } 194 195 func (m *EventLog) Create(db sqlx.DBExecutor) error { 196 197 if m.CreatedAt.IsZero() { 198 m.CreatedAt.Set(time.Now()) 199 } 200 201 if m.UpdatedAt.IsZero() { 202 m.UpdatedAt.Set(time.Now()) 203 } 204 205 _, err := db.Exec(sqlx.InsertToDB(db, m, nil)) 206 return err 207 } 208 209 func (m *EventLog) List(db sqlx.DBExecutor, cond builder.SqlCondition, adds ...builder.Addition) ([]EventLog, error) { 210 var ( 211 tbl = db.T(m) 212 lst = make([]EventLog, 0) 213 ) 214 adds = append([]builder.Addition{builder.Where(cond), builder.Comment("EventLog.List")}, adds...) 215 err := db.QueryAndScan(builder.Select(nil).From(tbl, adds...), &lst) 216 return lst, err 217 } 218 219 func (m *EventLog) Count(db sqlx.DBExecutor, cond builder.SqlCondition, adds ...builder.Addition) (cnt int64, err error) { 220 tbl := db.T(m) 221 adds = append([]builder.Addition{builder.Where(cond), builder.Comment("EventLog.List")}, adds...) 222 err = db.QueryAndScan(builder.Select(builder.Count()).From(tbl, adds...), &cnt) 223 return 224 } 225 226 func (m *EventLog) FetchByID(db sqlx.DBExecutor) error { 227 tbl := db.T(m) 228 err := db.QueryAndScan( 229 builder.Select(nil). 230 From( 231 tbl, 232 builder.Where( 233 builder.And( 234 tbl.ColByFieldName("ID").Eq(m.ID), 235 ), 236 ), 237 builder.Comment("EventLog.FetchByID"), 238 ), 239 m, 240 ) 241 return err 242 } 243 244 func (m *EventLog) UpdateByIDWithFVs(db sqlx.DBExecutor, fvs builder.FieldValues) error { 245 246 if _, ok := fvs["UpdatedAt"]; !ok { 247 fvs["UpdatedAt"] = types.Timestamp{Time: time.Now()} 248 } 249 tbl := db.T(m) 250 res, err := db.Exec( 251 builder.Update(tbl). 252 Where( 253 builder.And( 254 tbl.ColByFieldName("ID").Eq(m.ID), 255 ), 256 builder.Comment("EventLog.UpdateByIDWithFVs"), 257 ). 258 Set(tbl.AssignmentsByFieldValues(fvs)...), 259 ) 260 if err != nil { 261 return err 262 } 263 if affected, _ := res.RowsAffected(); affected == 0 { 264 return m.FetchByID(db) 265 } 266 return nil 267 } 268 269 func (m *EventLog) UpdateByID(db sqlx.DBExecutor, zeros ...string) error { 270 fvs := builder.FieldValueFromStructByNoneZero(m, zeros...) 271 return m.UpdateByIDWithFVs(db, fvs) 272 } 273 274 func (m *EventLog) Delete(db sqlx.DBExecutor) error { 275 _, err := db.Exec( 276 builder.Delete(). 277 From( 278 db.T(m), 279 builder.Where(m.CondByValue(db)), 280 builder.Comment("EventLog.Delete"), 281 ), 282 ) 283 return err 284 } 285 286 func (m *EventLog) DeleteByID(db sqlx.DBExecutor) error { 287 tbl := db.T(m) 288 _, err := db.Exec( 289 builder.Delete(). 290 From( 291 tbl, 292 builder.Where( 293 builder.And( 294 tbl.ColByFieldName("ID").Eq(m.ID), 295 ), 296 ), 297 builder.Comment("EventLog.DeleteByID"), 298 ), 299 ) 300 return err 301 }