github.com/crowdsecurity/crowdsec@v1.6.1/pkg/database/ent/meta.go (about) 1 // Code generated by ent, DO NOT EDIT. 2 3 package ent 4 5 import ( 6 "fmt" 7 "strings" 8 "time" 9 10 "entgo.io/ent" 11 "entgo.io/ent/dialect/sql" 12 "github.com/crowdsecurity/crowdsec/pkg/database/ent/alert" 13 "github.com/crowdsecurity/crowdsec/pkg/database/ent/meta" 14 ) 15 16 // Meta is the model entity for the Meta schema. 17 type Meta struct { 18 config `json:"-"` 19 // ID of the ent. 20 ID int `json:"id,omitempty"` 21 // CreatedAt holds the value of the "created_at" field. 22 CreatedAt *time.Time `json:"created_at,omitempty"` 23 // UpdatedAt holds the value of the "updated_at" field. 24 UpdatedAt *time.Time `json:"updated_at,omitempty"` 25 // Key holds the value of the "key" field. 26 Key string `json:"key,omitempty"` 27 // Value holds the value of the "value" field. 28 Value string `json:"value,omitempty"` 29 // AlertMetas holds the value of the "alert_metas" field. 30 AlertMetas int `json:"alert_metas,omitempty"` 31 // Edges holds the relations/edges for other nodes in the graph. 32 // The values are being populated by the MetaQuery when eager-loading is set. 33 Edges MetaEdges `json:"edges"` 34 selectValues sql.SelectValues 35 } 36 37 // MetaEdges holds the relations/edges for other nodes in the graph. 38 type MetaEdges struct { 39 // Owner holds the value of the owner edge. 40 Owner *Alert `json:"owner,omitempty"` 41 // loadedTypes holds the information for reporting if a 42 // type was loaded (or requested) in eager-loading or not. 43 loadedTypes [1]bool 44 } 45 46 // OwnerOrErr returns the Owner value or an error if the edge 47 // was not loaded in eager-loading, or loaded but was not found. 48 func (e MetaEdges) OwnerOrErr() (*Alert, error) { 49 if e.loadedTypes[0] { 50 if e.Owner == nil { 51 // Edge was loaded but was not found. 52 return nil, &NotFoundError{label: alert.Label} 53 } 54 return e.Owner, nil 55 } 56 return nil, &NotLoadedError{edge: "owner"} 57 } 58 59 // scanValues returns the types for scanning values from sql.Rows. 60 func (*Meta) scanValues(columns []string) ([]any, error) { 61 values := make([]any, len(columns)) 62 for i := range columns { 63 switch columns[i] { 64 case meta.FieldID, meta.FieldAlertMetas: 65 values[i] = new(sql.NullInt64) 66 case meta.FieldKey, meta.FieldValue: 67 values[i] = new(sql.NullString) 68 case meta.FieldCreatedAt, meta.FieldUpdatedAt: 69 values[i] = new(sql.NullTime) 70 default: 71 values[i] = new(sql.UnknownType) 72 } 73 } 74 return values, nil 75 } 76 77 // assignValues assigns the values that were returned from sql.Rows (after scanning) 78 // to the Meta fields. 79 func (m *Meta) assignValues(columns []string, values []any) error { 80 if m, n := len(values), len(columns); m < n { 81 return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) 82 } 83 for i := range columns { 84 switch columns[i] { 85 case meta.FieldID: 86 value, ok := values[i].(*sql.NullInt64) 87 if !ok { 88 return fmt.Errorf("unexpected type %T for field id", value) 89 } 90 m.ID = int(value.Int64) 91 case meta.FieldCreatedAt: 92 if value, ok := values[i].(*sql.NullTime); !ok { 93 return fmt.Errorf("unexpected type %T for field created_at", values[i]) 94 } else if value.Valid { 95 m.CreatedAt = new(time.Time) 96 *m.CreatedAt = value.Time 97 } 98 case meta.FieldUpdatedAt: 99 if value, ok := values[i].(*sql.NullTime); !ok { 100 return fmt.Errorf("unexpected type %T for field updated_at", values[i]) 101 } else if value.Valid { 102 m.UpdatedAt = new(time.Time) 103 *m.UpdatedAt = value.Time 104 } 105 case meta.FieldKey: 106 if value, ok := values[i].(*sql.NullString); !ok { 107 return fmt.Errorf("unexpected type %T for field key", values[i]) 108 } else if value.Valid { 109 m.Key = value.String 110 } 111 case meta.FieldValue: 112 if value, ok := values[i].(*sql.NullString); !ok { 113 return fmt.Errorf("unexpected type %T for field value", values[i]) 114 } else if value.Valid { 115 m.Value = value.String 116 } 117 case meta.FieldAlertMetas: 118 if value, ok := values[i].(*sql.NullInt64); !ok { 119 return fmt.Errorf("unexpected type %T for field alert_metas", values[i]) 120 } else if value.Valid { 121 m.AlertMetas = int(value.Int64) 122 } 123 default: 124 m.selectValues.Set(columns[i], values[i]) 125 } 126 } 127 return nil 128 } 129 130 // GetValue returns the ent.Value that was dynamically selected and assigned to the Meta. 131 // This includes values selected through modifiers, order, etc. 132 func (m *Meta) GetValue(name string) (ent.Value, error) { 133 return m.selectValues.Get(name) 134 } 135 136 // QueryOwner queries the "owner" edge of the Meta entity. 137 func (m *Meta) QueryOwner() *AlertQuery { 138 return NewMetaClient(m.config).QueryOwner(m) 139 } 140 141 // Update returns a builder for updating this Meta. 142 // Note that you need to call Meta.Unwrap() before calling this method if this Meta 143 // was returned from a transaction, and the transaction was committed or rolled back. 144 func (m *Meta) Update() *MetaUpdateOne { 145 return NewMetaClient(m.config).UpdateOne(m) 146 } 147 148 // Unwrap unwraps the Meta entity that was returned from a transaction after it was closed, 149 // so that all future queries will be executed through the driver which created the transaction. 150 func (m *Meta) Unwrap() *Meta { 151 _tx, ok := m.config.driver.(*txDriver) 152 if !ok { 153 panic("ent: Meta is not a transactional entity") 154 } 155 m.config.driver = _tx.drv 156 return m 157 } 158 159 // String implements the fmt.Stringer. 160 func (m *Meta) String() string { 161 var builder strings.Builder 162 builder.WriteString("Meta(") 163 builder.WriteString(fmt.Sprintf("id=%v, ", m.ID)) 164 if v := m.CreatedAt; v != nil { 165 builder.WriteString("created_at=") 166 builder.WriteString(v.Format(time.ANSIC)) 167 } 168 builder.WriteString(", ") 169 if v := m.UpdatedAt; v != nil { 170 builder.WriteString("updated_at=") 171 builder.WriteString(v.Format(time.ANSIC)) 172 } 173 builder.WriteString(", ") 174 builder.WriteString("key=") 175 builder.WriteString(m.Key) 176 builder.WriteString(", ") 177 builder.WriteString("value=") 178 builder.WriteString(m.Value) 179 builder.WriteString(", ") 180 builder.WriteString("alert_metas=") 181 builder.WriteString(fmt.Sprintf("%v", m.AlertMetas)) 182 builder.WriteByte(')') 183 return builder.String() 184 } 185 186 // MetaSlice is a parsable slice of Meta. 187 type MetaSlice []*Meta