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