github.com/crowdsecurity/crowdsec@v1.6.1/pkg/database/ent/configitem.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/configitem"
    13  )
    14  
    15  // ConfigItem is the model entity for the ConfigItem schema.
    16  type ConfigItem 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  	// Value holds the value of the "value" field.
    27  	Value        string `json:"value"`
    28  	selectValues sql.SelectValues
    29  }
    30  
    31  // scanValues returns the types for scanning values from sql.Rows.
    32  func (*ConfigItem) scanValues(columns []string) ([]any, error) {
    33  	values := make([]any, len(columns))
    34  	for i := range columns {
    35  		switch columns[i] {
    36  		case configitem.FieldID:
    37  			values[i] = new(sql.NullInt64)
    38  		case configitem.FieldName, configitem.FieldValue:
    39  			values[i] = new(sql.NullString)
    40  		case configitem.FieldCreatedAt, configitem.FieldUpdatedAt:
    41  			values[i] = new(sql.NullTime)
    42  		default:
    43  			values[i] = new(sql.UnknownType)
    44  		}
    45  	}
    46  	return values, nil
    47  }
    48  
    49  // assignValues assigns the values that were returned from sql.Rows (after scanning)
    50  // to the ConfigItem fields.
    51  func (ci *ConfigItem) assignValues(columns []string, values []any) error {
    52  	if m, n := len(values), len(columns); m < n {
    53  		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
    54  	}
    55  	for i := range columns {
    56  		switch columns[i] {
    57  		case configitem.FieldID:
    58  			value, ok := values[i].(*sql.NullInt64)
    59  			if !ok {
    60  				return fmt.Errorf("unexpected type %T for field id", value)
    61  			}
    62  			ci.ID = int(value.Int64)
    63  		case configitem.FieldCreatedAt:
    64  			if value, ok := values[i].(*sql.NullTime); !ok {
    65  				return fmt.Errorf("unexpected type %T for field created_at", values[i])
    66  			} else if value.Valid {
    67  				ci.CreatedAt = new(time.Time)
    68  				*ci.CreatedAt = value.Time
    69  			}
    70  		case configitem.FieldUpdatedAt:
    71  			if value, ok := values[i].(*sql.NullTime); !ok {
    72  				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
    73  			} else if value.Valid {
    74  				ci.UpdatedAt = new(time.Time)
    75  				*ci.UpdatedAt = value.Time
    76  			}
    77  		case configitem.FieldName:
    78  			if value, ok := values[i].(*sql.NullString); !ok {
    79  				return fmt.Errorf("unexpected type %T for field name", values[i])
    80  			} else if value.Valid {
    81  				ci.Name = value.String
    82  			}
    83  		case configitem.FieldValue:
    84  			if value, ok := values[i].(*sql.NullString); !ok {
    85  				return fmt.Errorf("unexpected type %T for field value", values[i])
    86  			} else if value.Valid {
    87  				ci.Value = value.String
    88  			}
    89  		default:
    90  			ci.selectValues.Set(columns[i], values[i])
    91  		}
    92  	}
    93  	return nil
    94  }
    95  
    96  // GetValue returns the ent.Value that was dynamically selected and assigned to the ConfigItem.
    97  // This includes values selected through modifiers, order, etc.
    98  func (ci *ConfigItem) GetValue(name string) (ent.Value, error) {
    99  	return ci.selectValues.Get(name)
   100  }
   101  
   102  // Update returns a builder for updating this ConfigItem.
   103  // Note that you need to call ConfigItem.Unwrap() before calling this method if this ConfigItem
   104  // was returned from a transaction, and the transaction was committed or rolled back.
   105  func (ci *ConfigItem) Update() *ConfigItemUpdateOne {
   106  	return NewConfigItemClient(ci.config).UpdateOne(ci)
   107  }
   108  
   109  // Unwrap unwraps the ConfigItem entity that was returned from a transaction after it was closed,
   110  // so that all future queries will be executed through the driver which created the transaction.
   111  func (ci *ConfigItem) Unwrap() *ConfigItem {
   112  	_tx, ok := ci.config.driver.(*txDriver)
   113  	if !ok {
   114  		panic("ent: ConfigItem is not a transactional entity")
   115  	}
   116  	ci.config.driver = _tx.drv
   117  	return ci
   118  }
   119  
   120  // String implements the fmt.Stringer.
   121  func (ci *ConfigItem) String() string {
   122  	var builder strings.Builder
   123  	builder.WriteString("ConfigItem(")
   124  	builder.WriteString(fmt.Sprintf("id=%v, ", ci.ID))
   125  	if v := ci.CreatedAt; v != nil {
   126  		builder.WriteString("created_at=")
   127  		builder.WriteString(v.Format(time.ANSIC))
   128  	}
   129  	builder.WriteString(", ")
   130  	if v := ci.UpdatedAt; v != nil {
   131  		builder.WriteString("updated_at=")
   132  		builder.WriteString(v.Format(time.ANSIC))
   133  	}
   134  	builder.WriteString(", ")
   135  	builder.WriteString("name=")
   136  	builder.WriteString(ci.Name)
   137  	builder.WriteString(", ")
   138  	builder.WriteString("value=")
   139  	builder.WriteString(ci.Value)
   140  	builder.WriteByte(')')
   141  	return builder.String()
   142  }
   143  
   144  // ConfigItems is a parsable slice of ConfigItem.
   145  type ConfigItems []*ConfigItem