github.com/crowdsecurity/crowdsec@v1.6.1/pkg/database/ent/bouncer.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/bouncer" 13 ) 14 15 // Bouncer is the model entity for the Bouncer schema. 16 type Bouncer struct { 17 config `json:"-"` 18 // ID of the ent. 19 ID int `json:"id,omitempty"` 20 // CreatedAt holds the value of the "created_at" field. 21 CreatedAt *time.Time `json:"created_at"` 22 // UpdatedAt holds the value of the "updated_at" field. 23 UpdatedAt *time.Time `json:"updated_at"` 24 // Name holds the value of the "name" field. 25 Name string `json:"name"` 26 // APIKey holds the value of the "api_key" field. 27 APIKey string `json:"-"` 28 // Revoked holds the value of the "revoked" field. 29 Revoked bool `json:"revoked"` 30 // IPAddress holds the value of the "ip_address" field. 31 IPAddress string `json:"ip_address"` 32 // Type holds the value of the "type" field. 33 Type string `json:"type"` 34 // Version holds the value of the "version" field. 35 Version string `json:"version"` 36 // Until holds the value of the "until" field. 37 Until time.Time `json:"until"` 38 // LastPull holds the value of the "last_pull" field. 39 LastPull time.Time `json:"last_pull"` 40 // AuthType holds the value of the "auth_type" field. 41 AuthType string `json:"auth_type"` 42 selectValues sql.SelectValues 43 } 44 45 // scanValues returns the types for scanning values from sql.Rows. 46 func (*Bouncer) scanValues(columns []string) ([]any, error) { 47 values := make([]any, len(columns)) 48 for i := range columns { 49 switch columns[i] { 50 case bouncer.FieldRevoked: 51 values[i] = new(sql.NullBool) 52 case bouncer.FieldID: 53 values[i] = new(sql.NullInt64) 54 case bouncer.FieldName, bouncer.FieldAPIKey, bouncer.FieldIPAddress, bouncer.FieldType, bouncer.FieldVersion, bouncer.FieldAuthType: 55 values[i] = new(sql.NullString) 56 case bouncer.FieldCreatedAt, bouncer.FieldUpdatedAt, bouncer.FieldUntil, bouncer.FieldLastPull: 57 values[i] = new(sql.NullTime) 58 default: 59 values[i] = new(sql.UnknownType) 60 } 61 } 62 return values, nil 63 } 64 65 // assignValues assigns the values that were returned from sql.Rows (after scanning) 66 // to the Bouncer fields. 67 func (b *Bouncer) assignValues(columns []string, values []any) error { 68 if m, n := len(values), len(columns); m < n { 69 return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) 70 } 71 for i := range columns { 72 switch columns[i] { 73 case bouncer.FieldID: 74 value, ok := values[i].(*sql.NullInt64) 75 if !ok { 76 return fmt.Errorf("unexpected type %T for field id", value) 77 } 78 b.ID = int(value.Int64) 79 case bouncer.FieldCreatedAt: 80 if value, ok := values[i].(*sql.NullTime); !ok { 81 return fmt.Errorf("unexpected type %T for field created_at", values[i]) 82 } else if value.Valid { 83 b.CreatedAt = new(time.Time) 84 *b.CreatedAt = value.Time 85 } 86 case bouncer.FieldUpdatedAt: 87 if value, ok := values[i].(*sql.NullTime); !ok { 88 return fmt.Errorf("unexpected type %T for field updated_at", values[i]) 89 } else if value.Valid { 90 b.UpdatedAt = new(time.Time) 91 *b.UpdatedAt = value.Time 92 } 93 case bouncer.FieldName: 94 if value, ok := values[i].(*sql.NullString); !ok { 95 return fmt.Errorf("unexpected type %T for field name", values[i]) 96 } else if value.Valid { 97 b.Name = value.String 98 } 99 case bouncer.FieldAPIKey: 100 if value, ok := values[i].(*sql.NullString); !ok { 101 return fmt.Errorf("unexpected type %T for field api_key", values[i]) 102 } else if value.Valid { 103 b.APIKey = value.String 104 } 105 case bouncer.FieldRevoked: 106 if value, ok := values[i].(*sql.NullBool); !ok { 107 return fmt.Errorf("unexpected type %T for field revoked", values[i]) 108 } else if value.Valid { 109 b.Revoked = value.Bool 110 } 111 case bouncer.FieldIPAddress: 112 if value, ok := values[i].(*sql.NullString); !ok { 113 return fmt.Errorf("unexpected type %T for field ip_address", values[i]) 114 } else if value.Valid { 115 b.IPAddress = value.String 116 } 117 case bouncer.FieldType: 118 if value, ok := values[i].(*sql.NullString); !ok { 119 return fmt.Errorf("unexpected type %T for field type", values[i]) 120 } else if value.Valid { 121 b.Type = value.String 122 } 123 case bouncer.FieldVersion: 124 if value, ok := values[i].(*sql.NullString); !ok { 125 return fmt.Errorf("unexpected type %T for field version", values[i]) 126 } else if value.Valid { 127 b.Version = value.String 128 } 129 case bouncer.FieldUntil: 130 if value, ok := values[i].(*sql.NullTime); !ok { 131 return fmt.Errorf("unexpected type %T for field until", values[i]) 132 } else if value.Valid { 133 b.Until = value.Time 134 } 135 case bouncer.FieldLastPull: 136 if value, ok := values[i].(*sql.NullTime); !ok { 137 return fmt.Errorf("unexpected type %T for field last_pull", values[i]) 138 } else if value.Valid { 139 b.LastPull = value.Time 140 } 141 case bouncer.FieldAuthType: 142 if value, ok := values[i].(*sql.NullString); !ok { 143 return fmt.Errorf("unexpected type %T for field auth_type", values[i]) 144 } else if value.Valid { 145 b.AuthType = value.String 146 } 147 default: 148 b.selectValues.Set(columns[i], values[i]) 149 } 150 } 151 return nil 152 } 153 154 // Value returns the ent.Value that was dynamically selected and assigned to the Bouncer. 155 // This includes values selected through modifiers, order, etc. 156 func (b *Bouncer) Value(name string) (ent.Value, error) { 157 return b.selectValues.Get(name) 158 } 159 160 // Update returns a builder for updating this Bouncer. 161 // Note that you need to call Bouncer.Unwrap() before calling this method if this Bouncer 162 // was returned from a transaction, and the transaction was committed or rolled back. 163 func (b *Bouncer) Update() *BouncerUpdateOne { 164 return NewBouncerClient(b.config).UpdateOne(b) 165 } 166 167 // Unwrap unwraps the Bouncer entity that was returned from a transaction after it was closed, 168 // so that all future queries will be executed through the driver which created the transaction. 169 func (b *Bouncer) Unwrap() *Bouncer { 170 _tx, ok := b.config.driver.(*txDriver) 171 if !ok { 172 panic("ent: Bouncer is not a transactional entity") 173 } 174 b.config.driver = _tx.drv 175 return b 176 } 177 178 // String implements the fmt.Stringer. 179 func (b *Bouncer) String() string { 180 var builder strings.Builder 181 builder.WriteString("Bouncer(") 182 builder.WriteString(fmt.Sprintf("id=%v, ", b.ID)) 183 if v := b.CreatedAt; v != nil { 184 builder.WriteString("created_at=") 185 builder.WriteString(v.Format(time.ANSIC)) 186 } 187 builder.WriteString(", ") 188 if v := b.UpdatedAt; v != nil { 189 builder.WriteString("updated_at=") 190 builder.WriteString(v.Format(time.ANSIC)) 191 } 192 builder.WriteString(", ") 193 builder.WriteString("name=") 194 builder.WriteString(b.Name) 195 builder.WriteString(", ") 196 builder.WriteString("api_key=<sensitive>") 197 builder.WriteString(", ") 198 builder.WriteString("revoked=") 199 builder.WriteString(fmt.Sprintf("%v", b.Revoked)) 200 builder.WriteString(", ") 201 builder.WriteString("ip_address=") 202 builder.WriteString(b.IPAddress) 203 builder.WriteString(", ") 204 builder.WriteString("type=") 205 builder.WriteString(b.Type) 206 builder.WriteString(", ") 207 builder.WriteString("version=") 208 builder.WriteString(b.Version) 209 builder.WriteString(", ") 210 builder.WriteString("until=") 211 builder.WriteString(b.Until.Format(time.ANSIC)) 212 builder.WriteString(", ") 213 builder.WriteString("last_pull=") 214 builder.WriteString(b.LastPull.Format(time.ANSIC)) 215 builder.WriteString(", ") 216 builder.WriteString("auth_type=") 217 builder.WriteString(b.AuthType) 218 builder.WriteByte(')') 219 return builder.String() 220 } 221 222 // Bouncers is a parsable slice of Bouncer. 223 type Bouncers []*Bouncer