crowdsec/pkg/database/ent/decision.go
Thibault "bui" Koechlin dbb420f79e
local api (#482)
Co-authored-by: AlteredCoder
Co-authored-by: erenJag
2020-11-30 10:37:17 +01:00

237 lines
7.8 KiB
Go

// Code generated by entc, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"github.com/crowdsecurity/crowdsec/pkg/database/ent/alert"
"github.com/crowdsecurity/crowdsec/pkg/database/ent/decision"
"github.com/facebook/ent/dialect/sql"
)
// Decision is the model entity for the Decision schema.
type Decision struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
// Until holds the value of the "until" field.
Until time.Time `json:"until,omitempty"`
// Scenario holds the value of the "scenario" field.
Scenario string `json:"scenario,omitempty"`
// Type holds the value of the "type" field.
Type string `json:"type,omitempty"`
// StartIP holds the value of the "start_ip" field.
StartIP int64 `json:"start_ip,omitempty"`
// EndIP holds the value of the "end_ip" field.
EndIP int64 `json:"end_ip,omitempty"`
// Scope holds the value of the "scope" field.
Scope string `json:"scope,omitempty"`
// Value holds the value of the "value" field.
Value string `json:"value,omitempty"`
// Origin holds the value of the "origin" field.
Origin string `json:"origin,omitempty"`
// Simulated holds the value of the "simulated" field.
Simulated bool `json:"simulated,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the DecisionQuery when eager-loading is set.
Edges DecisionEdges `json:"edges"`
alert_decisions *int
}
// DecisionEdges holds the relations/edges for other nodes in the graph.
type DecisionEdges struct {
// Owner holds the value of the owner edge.
Owner *Alert
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// OwnerOrErr returns the Owner value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e DecisionEdges) OwnerOrErr() (*Alert, error) {
if e.loadedTypes[0] {
if e.Owner == nil {
// The edge owner was loaded in eager-loading,
// but was not found.
return nil, &NotFoundError{label: alert.Label}
}
return e.Owner, nil
}
return nil, &NotLoadedError{edge: "owner"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Decision) scanValues() []interface{} {
return []interface{}{
&sql.NullInt64{}, // id
&sql.NullTime{}, // created_at
&sql.NullTime{}, // updated_at
&sql.NullTime{}, // until
&sql.NullString{}, // scenario
&sql.NullString{}, // type
&sql.NullInt64{}, // start_ip
&sql.NullInt64{}, // end_ip
&sql.NullString{}, // scope
&sql.NullString{}, // value
&sql.NullString{}, // origin
&sql.NullBool{}, // simulated
}
}
// fkValues returns the types for scanning foreign-keys values from sql.Rows.
func (*Decision) fkValues() []interface{} {
return []interface{}{
&sql.NullInt64{}, // alert_decisions
}
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Decision fields.
func (d *Decision) assignValues(values ...interface{}) error {
if m, n := len(values), len(decision.Columns); m < n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
value, ok := values[0].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
d.ID = int(value.Int64)
values = values[1:]
if value, ok := values[0].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[0])
} else if value.Valid {
d.CreatedAt = value.Time
}
if value, ok := values[1].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[1])
} else if value.Valid {
d.UpdatedAt = value.Time
}
if value, ok := values[2].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field until", values[2])
} else if value.Valid {
d.Until = value.Time
}
if value, ok := values[3].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field scenario", values[3])
} else if value.Valid {
d.Scenario = value.String
}
if value, ok := values[4].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field type", values[4])
} else if value.Valid {
d.Type = value.String
}
if value, ok := values[5].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field start_ip", values[5])
} else if value.Valid {
d.StartIP = value.Int64
}
if value, ok := values[6].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field end_ip", values[6])
} else if value.Valid {
d.EndIP = value.Int64
}
if value, ok := values[7].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field scope", values[7])
} else if value.Valid {
d.Scope = value.String
}
if value, ok := values[8].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field value", values[8])
} else if value.Valid {
d.Value = value.String
}
if value, ok := values[9].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field origin", values[9])
} else if value.Valid {
d.Origin = value.String
}
if value, ok := values[10].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field simulated", values[10])
} else if value.Valid {
d.Simulated = value.Bool
}
values = values[11:]
if len(values) == len(decision.ForeignKeys) {
if value, ok := values[0].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for edge-field alert_decisions", value)
} else if value.Valid {
d.alert_decisions = new(int)
*d.alert_decisions = int(value.Int64)
}
}
return nil
}
// QueryOwner queries the owner edge of the Decision.
func (d *Decision) QueryOwner() *AlertQuery {
return (&DecisionClient{config: d.config}).QueryOwner(d)
}
// Update returns a builder for updating this Decision.
// Note that, you need to call Decision.Unwrap() before calling this method, if this Decision
// was returned from a transaction, and the transaction was committed or rolled back.
func (d *Decision) Update() *DecisionUpdateOne {
return (&DecisionClient{config: d.config}).UpdateOne(d)
}
// Unwrap unwraps the entity that was returned from a transaction after it was closed,
// so that all next queries will be executed through the driver which created the transaction.
func (d *Decision) Unwrap() *Decision {
tx, ok := d.config.driver.(*txDriver)
if !ok {
panic("ent: Decision is not a transactional entity")
}
d.config.driver = tx.drv
return d
}
// String implements the fmt.Stringer.
func (d *Decision) String() string {
var builder strings.Builder
builder.WriteString("Decision(")
builder.WriteString(fmt.Sprintf("id=%v", d.ID))
builder.WriteString(", created_at=")
builder.WriteString(d.CreatedAt.Format(time.ANSIC))
builder.WriteString(", updated_at=")
builder.WriteString(d.UpdatedAt.Format(time.ANSIC))
builder.WriteString(", until=")
builder.WriteString(d.Until.Format(time.ANSIC))
builder.WriteString(", scenario=")
builder.WriteString(d.Scenario)
builder.WriteString(", type=")
builder.WriteString(d.Type)
builder.WriteString(", start_ip=")
builder.WriteString(fmt.Sprintf("%v", d.StartIP))
builder.WriteString(", end_ip=")
builder.WriteString(fmt.Sprintf("%v", d.EndIP))
builder.WriteString(", scope=")
builder.WriteString(d.Scope)
builder.WriteString(", value=")
builder.WriteString(d.Value)
builder.WriteString(", origin=")
builder.WriteString(d.Origin)
builder.WriteString(", simulated=")
builder.WriteString(fmt.Sprintf("%v", d.Simulated))
builder.WriteByte(')')
return builder.String()
}
// Decisions is a parsable slice of Decision.
type Decisions []*Decision
func (d Decisions) config(cfg config) {
for _i := range d {
d[_i].config = cfg
}
}