2022-10-06 12:55:42 +00:00
|
|
|
// Code generated by ent, DO NOT EDIT.
|
2020-11-30 09:37:17 +00:00
|
|
|
|
|
|
|
package ent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2021-03-15 17:46:52 +00:00
|
|
|
"entgo.io/ent/dialect/sql"
|
2020-11-30 09:37:17 +00:00
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/database/ent/alert"
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/database/ent/meta"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Meta is the model entity for the Meta schema.
|
|
|
|
type Meta struct {
|
|
|
|
config `json:"-"`
|
|
|
|
// ID of the ent.
|
|
|
|
ID int `json:"id,omitempty"`
|
|
|
|
// CreatedAt holds the value of the "created_at" field.
|
2022-01-19 13:56:05 +00:00
|
|
|
CreatedAt *time.Time `json:"created_at,omitempty"`
|
2020-11-30 09:37:17 +00:00
|
|
|
// UpdatedAt holds the value of the "updated_at" field.
|
2022-01-19 13:56:05 +00:00
|
|
|
UpdatedAt *time.Time `json:"updated_at,omitempty"`
|
2020-11-30 09:37:17 +00:00
|
|
|
// Key holds the value of the "key" field.
|
|
|
|
Key string `json:"key,omitempty"`
|
|
|
|
// Value holds the value of the "value" field.
|
|
|
|
Value string `json:"value,omitempty"`
|
2023-05-11 11:49:01 +00:00
|
|
|
// AlertMetas holds the value of the "alert_metas" field.
|
|
|
|
AlertMetas int `json:"alert_metas,omitempty"`
|
2020-11-30 09:37:17 +00:00
|
|
|
// Edges holds the relations/edges for other nodes in the graph.
|
|
|
|
// The values are being populated by the MetaQuery when eager-loading is set.
|
2023-05-11 11:49:01 +00:00
|
|
|
Edges MetaEdges `json:"edges"`
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MetaEdges holds the relations/edges for other nodes in the graph.
|
|
|
|
type MetaEdges struct {
|
|
|
|
// Owner holds the value of the owner edge.
|
2021-03-15 17:46:52 +00:00
|
|
|
Owner *Alert `json:"owner,omitempty"`
|
2020-11-30 09:37:17 +00:00
|
|
|
// 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 MetaEdges) OwnerOrErr() (*Alert, error) {
|
|
|
|
if e.loadedTypes[0] {
|
|
|
|
if e.Owner == nil {
|
2022-10-06 12:55:42 +00:00
|
|
|
// Edge was loaded but was not found.
|
2020-11-30 09:37:17 +00:00
|
|
|
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.
|
2022-10-06 12:55:42 +00:00
|
|
|
func (*Meta) scanValues(columns []string) ([]any, error) {
|
|
|
|
values := make([]any, len(columns))
|
2021-01-14 15:27:45 +00:00
|
|
|
for i := range columns {
|
|
|
|
switch columns[i] {
|
2023-05-11 11:49:01 +00:00
|
|
|
case meta.FieldID, meta.FieldAlertMetas:
|
2021-10-22 14:15:57 +00:00
|
|
|
values[i] = new(sql.NullInt64)
|
2021-01-14 15:27:45 +00:00
|
|
|
case meta.FieldKey, meta.FieldValue:
|
2021-10-22 14:15:57 +00:00
|
|
|
values[i] = new(sql.NullString)
|
2021-01-14 15:27:45 +00:00
|
|
|
case meta.FieldCreatedAt, meta.FieldUpdatedAt:
|
2021-10-22 14:15:57 +00:00
|
|
|
values[i] = new(sql.NullTime)
|
2021-01-14 15:27:45 +00:00
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("unexpected column %q for type Meta", columns[i])
|
|
|
|
}
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
2021-01-14 15:27:45 +00:00
|
|
|
return values, nil
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
|
|
|
// to the Meta fields.
|
2022-10-06 12:55:42 +00:00
|
|
|
func (m *Meta) assignValues(columns []string, values []any) error {
|
2021-01-14 15:27:45 +00:00
|
|
|
if m, n := len(values), len(columns); m < n {
|
2020-11-30 09:37:17 +00:00
|
|
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
|
|
|
}
|
2021-01-14 15:27:45 +00:00
|
|
|
for i := range columns {
|
|
|
|
switch columns[i] {
|
|
|
|
case meta.FieldID:
|
|
|
|
value, ok := values[i].(*sql.NullInt64)
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field id", value)
|
|
|
|
}
|
|
|
|
m.ID = int(value.Int64)
|
|
|
|
case meta.FieldCreatedAt:
|
|
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
|
|
|
} else if value.Valid {
|
2022-01-19 13:56:05 +00:00
|
|
|
m.CreatedAt = new(time.Time)
|
|
|
|
*m.CreatedAt = value.Time
|
2021-01-14 15:27:45 +00:00
|
|
|
}
|
|
|
|
case meta.FieldUpdatedAt:
|
|
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
|
|
|
} else if value.Valid {
|
2022-01-19 13:56:05 +00:00
|
|
|
m.UpdatedAt = new(time.Time)
|
|
|
|
*m.UpdatedAt = value.Time
|
2021-01-14 15:27:45 +00:00
|
|
|
}
|
|
|
|
case meta.FieldKey:
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field key", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
m.Key = value.String
|
|
|
|
}
|
|
|
|
case meta.FieldValue:
|
|
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
|
|
return fmt.Errorf("unexpected type %T for field value", values[i])
|
|
|
|
} else if value.Valid {
|
|
|
|
m.Value = value.String
|
|
|
|
}
|
2023-05-11 11:49:01 +00:00
|
|
|
case meta.FieldAlertMetas:
|
2021-01-14 15:27:45 +00:00
|
|
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
2023-05-11 11:49:01 +00:00
|
|
|
return fmt.Errorf("unexpected type %T for field alert_metas", values[i])
|
2021-01-14 15:27:45 +00:00
|
|
|
} else if value.Valid {
|
2023-05-11 11:49:01 +00:00
|
|
|
m.AlertMetas = int(value.Int64)
|
2021-01-14 15:27:45 +00:00
|
|
|
}
|
2020-11-30 09:37:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// QueryOwner queries the "owner" edge of the Meta entity.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (m *Meta) QueryOwner() *AlertQuery {
|
|
|
|
return (&MetaClient{config: m.config}).QueryOwner(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update returns a builder for updating this Meta.
|
2021-01-14 15:27:45 +00:00
|
|
|
// Note that you need to call Meta.Unwrap() before calling this method if this Meta
|
2020-11-30 09:37:17 +00:00
|
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
|
|
func (m *Meta) Update() *MetaUpdateOne {
|
|
|
|
return (&MetaClient{config: m.config}).UpdateOne(m)
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:27:45 +00:00
|
|
|
// Unwrap unwraps the Meta entity that was returned from a transaction after it was closed,
|
|
|
|
// so that all future queries will be executed through the driver which created the transaction.
|
2020-11-30 09:37:17 +00:00
|
|
|
func (m *Meta) Unwrap() *Meta {
|
2022-10-06 12:55:42 +00:00
|
|
|
_tx, ok := m.config.driver.(*txDriver)
|
2020-11-30 09:37:17 +00:00
|
|
|
if !ok {
|
|
|
|
panic("ent: Meta is not a transactional entity")
|
|
|
|
}
|
2022-10-06 12:55:42 +00:00
|
|
|
m.config.driver = _tx.drv
|
2020-11-30 09:37:17 +00:00
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
// String implements the fmt.Stringer.
|
|
|
|
func (m *Meta) String() string {
|
|
|
|
var builder strings.Builder
|
|
|
|
builder.WriteString("Meta(")
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(fmt.Sprintf("id=%v, ", m.ID))
|
2022-01-19 13:56:05 +00:00
|
|
|
if v := m.CreatedAt; v != nil {
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString("created_at=")
|
2022-01-19 13:56:05 +00:00
|
|
|
builder.WriteString(v.Format(time.ANSIC))
|
|
|
|
}
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(", ")
|
2022-01-19 13:56:05 +00:00
|
|
|
if v := m.UpdatedAt; v != nil {
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString("updated_at=")
|
2022-01-19 13:56:05 +00:00
|
|
|
builder.WriteString(v.Format(time.ANSIC))
|
|
|
|
}
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(", ")
|
|
|
|
builder.WriteString("key=")
|
2020-11-30 09:37:17 +00:00
|
|
|
builder.WriteString(m.Key)
|
2022-10-06 12:55:42 +00:00
|
|
|
builder.WriteString(", ")
|
|
|
|
builder.WriteString("value=")
|
2020-11-30 09:37:17 +00:00
|
|
|
builder.WriteString(m.Value)
|
2023-05-11 11:49:01 +00:00
|
|
|
builder.WriteString(", ")
|
|
|
|
builder.WriteString("alert_metas=")
|
|
|
|
builder.WriteString(fmt.Sprintf("%v", m.AlertMetas))
|
2020-11-30 09:37:17 +00:00
|
|
|
builder.WriteByte(')')
|
|
|
|
return builder.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
// MetaSlice is a parsable slice of Meta.
|
|
|
|
type MetaSlice []*Meta
|
|
|
|
|
|
|
|
func (m MetaSlice) config(cfg config) {
|
|
|
|
for _i := range m {
|
|
|
|
m[_i].config = cfg
|
|
|
|
}
|
|
|
|
}
|