github.com/crowdsecurity/crowdsec@v1.6.1/pkg/database/ent/event.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/event"
    14  )
    15  
    16  // Event is the model entity for the Event schema.
    17  type Event 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  	// Time holds the value of the "time" field.
    26  	Time time.Time `json:"time,omitempty"`
    27  	// Serialized holds the value of the "serialized" field.
    28  	Serialized string `json:"serialized,omitempty"`
    29  	// AlertEvents holds the value of the "alert_events" field.
    30  	AlertEvents int `json:"alert_events,omitempty"`
    31  	// Edges holds the relations/edges for other nodes in the graph.
    32  	// The values are being populated by the EventQuery when eager-loading is set.
    33  	Edges        EventEdges `json:"edges"`
    34  	selectValues sql.SelectValues
    35  }
    36  
    37  // EventEdges holds the relations/edges for other nodes in the graph.
    38  type EventEdges 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 EventEdges) 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 (*Event) scanValues(columns []string) ([]any, error) {
    61  	values := make([]any, len(columns))
    62  	for i := range columns {
    63  		switch columns[i] {
    64  		case event.FieldID, event.FieldAlertEvents:
    65  			values[i] = new(sql.NullInt64)
    66  		case event.FieldSerialized:
    67  			values[i] = new(sql.NullString)
    68  		case event.FieldCreatedAt, event.FieldUpdatedAt, event.FieldTime:
    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 Event fields.
    79  func (e *Event) 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 event.FieldID:
    86  			value, ok := values[i].(*sql.NullInt64)
    87  			if !ok {
    88  				return fmt.Errorf("unexpected type %T for field id", value)
    89  			}
    90  			e.ID = int(value.Int64)
    91  		case event.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  				e.CreatedAt = new(time.Time)
    96  				*e.CreatedAt = value.Time
    97  			}
    98  		case event.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  				e.UpdatedAt = new(time.Time)
   103  				*e.UpdatedAt = value.Time
   104  			}
   105  		case event.FieldTime:
   106  			if value, ok := values[i].(*sql.NullTime); !ok {
   107  				return fmt.Errorf("unexpected type %T for field time", values[i])
   108  			} else if value.Valid {
   109  				e.Time = value.Time
   110  			}
   111  		case event.FieldSerialized:
   112  			if value, ok := values[i].(*sql.NullString); !ok {
   113  				return fmt.Errorf("unexpected type %T for field serialized", values[i])
   114  			} else if value.Valid {
   115  				e.Serialized = value.String
   116  			}
   117  		case event.FieldAlertEvents:
   118  			if value, ok := values[i].(*sql.NullInt64); !ok {
   119  				return fmt.Errorf("unexpected type %T for field alert_events", values[i])
   120  			} else if value.Valid {
   121  				e.AlertEvents = int(value.Int64)
   122  			}
   123  		default:
   124  			e.selectValues.Set(columns[i], values[i])
   125  		}
   126  	}
   127  	return nil
   128  }
   129  
   130  // Value returns the ent.Value that was dynamically selected and assigned to the Event.
   131  // This includes values selected through modifiers, order, etc.
   132  func (e *Event) Value(name string) (ent.Value, error) {
   133  	return e.selectValues.Get(name)
   134  }
   135  
   136  // QueryOwner queries the "owner" edge of the Event entity.
   137  func (e *Event) QueryOwner() *AlertQuery {
   138  	return NewEventClient(e.config).QueryOwner(e)
   139  }
   140  
   141  // Update returns a builder for updating this Event.
   142  // Note that you need to call Event.Unwrap() before calling this method if this Event
   143  // was returned from a transaction, and the transaction was committed or rolled back.
   144  func (e *Event) Update() *EventUpdateOne {
   145  	return NewEventClient(e.config).UpdateOne(e)
   146  }
   147  
   148  // Unwrap unwraps the Event 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 (e *Event) Unwrap() *Event {
   151  	_tx, ok := e.config.driver.(*txDriver)
   152  	if !ok {
   153  		panic("ent: Event is not a transactional entity")
   154  	}
   155  	e.config.driver = _tx.drv
   156  	return e
   157  }
   158  
   159  // String implements the fmt.Stringer.
   160  func (e *Event) String() string {
   161  	var builder strings.Builder
   162  	builder.WriteString("Event(")
   163  	builder.WriteString(fmt.Sprintf("id=%v, ", e.ID))
   164  	if v := e.CreatedAt; v != nil {
   165  		builder.WriteString("created_at=")
   166  		builder.WriteString(v.Format(time.ANSIC))
   167  	}
   168  	builder.WriteString(", ")
   169  	if v := e.UpdatedAt; v != nil {
   170  		builder.WriteString("updated_at=")
   171  		builder.WriteString(v.Format(time.ANSIC))
   172  	}
   173  	builder.WriteString(", ")
   174  	builder.WriteString("time=")
   175  	builder.WriteString(e.Time.Format(time.ANSIC))
   176  	builder.WriteString(", ")
   177  	builder.WriteString("serialized=")
   178  	builder.WriteString(e.Serialized)
   179  	builder.WriteString(", ")
   180  	builder.WriteString("alert_events=")
   181  	builder.WriteString(fmt.Sprintf("%v", e.AlertEvents))
   182  	builder.WriteByte(')')
   183  	return builder.String()
   184  }
   185  
   186  // Events is a parsable slice of Event.
   187  type Events []*Event