bitbucket.org/Aishee/synsec@v0.0.0-20210414005726-236fc01a153d/pkg/database/ent/bouncer.go (about) 1 // Code generated by entc, DO NOT EDIT. 2 3 package ent 4 5 import ( 6 "fmt" 7 "strings" 8 "time" 9 10 "entgo.io/ent/dialect/sql" 11 "bitbucket.org/Aishee/synsec/pkg/database/ent/bouncer" 12 ) 13 14 // Bouncer is the model entity for the Bouncer schema. 15 type Bouncer struct { 16 config `json:"-"` 17 // ID of the ent. 18 ID int `json:"id,omitempty"` 19 // CreatedAt holds the value of the "created_at" field. 20 CreatedAt time.Time `json:"created_at,omitempty"` 21 // UpdatedAt holds the value of the "updated_at" field. 22 UpdatedAt time.Time `json:"updated_at,omitempty"` 23 // Name holds the value of the "name" field. 24 Name string `json:"name,omitempty"` 25 // APIKey holds the value of the "api_key" field. 26 APIKey string `json:"api_key,omitempty"` 27 // Revoked holds the value of the "revoked" field. 28 Revoked bool `json:"revoked,omitempty"` 29 // IPAddress holds the value of the "ip_address" field. 30 IPAddress string `json:"ip_address,omitempty"` 31 // Type holds the value of the "type" field. 32 Type string `json:"type,omitempty"` 33 // Version holds the value of the "version" field. 34 Version string `json:"version,omitempty"` 35 // Until holds the value of the "until" field. 36 Until time.Time `json:"until,omitempty"` 37 // LastPull holds the value of the "last_pull" field. 38 LastPull time.Time `json:"last_pull,omitempty"` 39 } 40 41 // scanValues returns the types for scanning values from sql.Rows. 42 func (*Bouncer) scanValues(columns []string) ([]interface{}, error) { 43 values := make([]interface{}, len(columns)) 44 for i := range columns { 45 switch columns[i] { 46 case bouncer.FieldRevoked: 47 values[i] = &sql.NullBool{} 48 case bouncer.FieldID: 49 values[i] = &sql.NullInt64{} 50 case bouncer.FieldName, bouncer.FieldAPIKey, bouncer.FieldIPAddress, bouncer.FieldType, bouncer.FieldVersion: 51 values[i] = &sql.NullString{} 52 case bouncer.FieldCreatedAt, bouncer.FieldUpdatedAt, bouncer.FieldUntil, bouncer.FieldLastPull: 53 values[i] = &sql.NullTime{} 54 default: 55 return nil, fmt.Errorf("unexpected column %q for type Bouncer", columns[i]) 56 } 57 } 58 return values, nil 59 } 60 61 // assignValues assigns the values that were returned from sql.Rows (after scanning) 62 // to the Bouncer fields. 63 func (b *Bouncer) assignValues(columns []string, values []interface{}) error { 64 if m, n := len(values), len(columns); m < n { 65 return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) 66 } 67 for i := range columns { 68 switch columns[i] { 69 case bouncer.FieldID: 70 value, ok := values[i].(*sql.NullInt64) 71 if !ok { 72 return fmt.Errorf("unexpected type %T for field id", value) 73 } 74 b.ID = int(value.Int64) 75 case bouncer.FieldCreatedAt: 76 if value, ok := values[i].(*sql.NullTime); !ok { 77 return fmt.Errorf("unexpected type %T for field created_at", values[i]) 78 } else if value.Valid { 79 b.CreatedAt = value.Time 80 } 81 case bouncer.FieldUpdatedAt: 82 if value, ok := values[i].(*sql.NullTime); !ok { 83 return fmt.Errorf("unexpected type %T for field updated_at", values[i]) 84 } else if value.Valid { 85 b.UpdatedAt = value.Time 86 } 87 case bouncer.FieldName: 88 if value, ok := values[i].(*sql.NullString); !ok { 89 return fmt.Errorf("unexpected type %T for field name", values[i]) 90 } else if value.Valid { 91 b.Name = value.String 92 } 93 case bouncer.FieldAPIKey: 94 if value, ok := values[i].(*sql.NullString); !ok { 95 return fmt.Errorf("unexpected type %T for field api_key", values[i]) 96 } else if value.Valid { 97 b.APIKey = value.String 98 } 99 case bouncer.FieldRevoked: 100 if value, ok := values[i].(*sql.NullBool); !ok { 101 return fmt.Errorf("unexpected type %T for field revoked", values[i]) 102 } else if value.Valid { 103 b.Revoked = value.Bool 104 } 105 case bouncer.FieldIPAddress: 106 if value, ok := values[i].(*sql.NullString); !ok { 107 return fmt.Errorf("unexpected type %T for field ip_address", values[i]) 108 } else if value.Valid { 109 b.IPAddress = value.String 110 } 111 case bouncer.FieldType: 112 if value, ok := values[i].(*sql.NullString); !ok { 113 return fmt.Errorf("unexpected type %T for field type", values[i]) 114 } else if value.Valid { 115 b.Type = value.String 116 } 117 case bouncer.FieldVersion: 118 if value, ok := values[i].(*sql.NullString); !ok { 119 return fmt.Errorf("unexpected type %T for field version", values[i]) 120 } else if value.Valid { 121 b.Version = value.String 122 } 123 case bouncer.FieldUntil: 124 if value, ok := values[i].(*sql.NullTime); !ok { 125 return fmt.Errorf("unexpected type %T for field until", values[i]) 126 } else if value.Valid { 127 b.Until = value.Time 128 } 129 case bouncer.FieldLastPull: 130 if value, ok := values[i].(*sql.NullTime); !ok { 131 return fmt.Errorf("unexpected type %T for field last_pull", values[i]) 132 } else if value.Valid { 133 b.LastPull = value.Time 134 } 135 } 136 } 137 return nil 138 } 139 140 // Update returns a builder for updating this Bouncer. 141 // Note that you need to call Bouncer.Unwrap() before calling this method if this Bouncer 142 // was returned from a transaction, and the transaction was committed or rolled back. 143 func (b *Bouncer) Update() *BouncerUpdateOne { 144 return (&BouncerClient{config: b.config}).UpdateOne(b) 145 } 146 147 // Unwrap unwraps the Bouncer entity that was returned from a transaction after it was closed, 148 // so that all future queries will be executed through the driver which created the transaction. 149 func (b *Bouncer) Unwrap() *Bouncer { 150 tx, ok := b.config.driver.(*txDriver) 151 if !ok { 152 panic("ent: Bouncer is not a transactional entity") 153 } 154 b.config.driver = tx.drv 155 return b 156 } 157 158 // String implements the fmt.Stringer. 159 func (b *Bouncer) String() string { 160 var builder strings.Builder 161 builder.WriteString("Bouncer(") 162 builder.WriteString(fmt.Sprintf("id=%v", b.ID)) 163 builder.WriteString(", created_at=") 164 builder.WriteString(b.CreatedAt.Format(time.ANSIC)) 165 builder.WriteString(", updated_at=") 166 builder.WriteString(b.UpdatedAt.Format(time.ANSIC)) 167 builder.WriteString(", name=") 168 builder.WriteString(b.Name) 169 builder.WriteString(", api_key=") 170 builder.WriteString(b.APIKey) 171 builder.WriteString(", revoked=") 172 builder.WriteString(fmt.Sprintf("%v", b.Revoked)) 173 builder.WriteString(", ip_address=") 174 builder.WriteString(b.IPAddress) 175 builder.WriteString(", type=") 176 builder.WriteString(b.Type) 177 builder.WriteString(", version=") 178 builder.WriteString(b.Version) 179 builder.WriteString(", until=") 180 builder.WriteString(b.Until.Format(time.ANSIC)) 181 builder.WriteString(", last_pull=") 182 builder.WriteString(b.LastPull.Format(time.ANSIC)) 183 builder.WriteByte(')') 184 return builder.String() 185 } 186 187 // Bouncers is a parsable slice of Bouncer. 188 type Bouncers []*Bouncer 189 190 func (b Bouncers) config(cfg config) { 191 for _i := range b { 192 b[_i].config = cfg 193 } 194 }