bitbucket.org/Aishee/synsec@v0.0.0-20210414005726-236fc01a153d/pkg/database/ent/meta.go (about)

     1  // Code generated by entc, DO NOT EDIT.
     2  
     3  package ent
     4  
     5  import (
     6  	"fmt"
     7  	"strings"
     8  	"time"
     9  
    10  	"entgo.io/ent/dialect/sql"
    11  	"bitbucket.org/Aishee/synsec/pkg/database/ent/alert"
    12  	"bitbucket.org/Aishee/synsec/pkg/database/ent/meta"
    13  )
    14  
    15  // Meta is the model entity for the Meta schema.
    16  type Meta 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,omitempty"`
    22  	// UpdatedAt holds the value of the "updated_at" field.
    23  	UpdatedAt time.Time `json:"updated_at,omitempty"`
    24  	// Key holds the value of the "key" field.
    25  	Key string `json:"key,omitempty"`
    26  	// Value holds the value of the "value" field.
    27  	Value string `json:"value,omitempty"`
    28  	// Edges holds the relations/edges for other nodes in the graph.
    29  	// The values are being populated by the MetaQuery when eager-loading is set.
    30  	Edges       MetaEdges `json:"edges"`
    31  	alert_metas *int
    32  }
    33  
    34  // MetaEdges holds the relations/edges for other nodes in the graph.
    35  type MetaEdges struct {
    36  	// Owner holds the value of the owner edge.
    37  	Owner *Alert `json:"owner,omitempty"`
    38  	// loadedTypes holds the information for reporting if a
    39  	// type was loaded (or requested) in eager-loading or not.
    40  	loadedTypes [1]bool
    41  }
    42  
    43  // OwnerOrErr returns the Owner value or an error if the edge
    44  // was not loaded in eager-loading, or loaded but was not found.
    45  func (e MetaEdges) OwnerOrErr() (*Alert, error) {
    46  	if e.loadedTypes[0] {
    47  		if e.Owner == nil {
    48  			// The edge owner was loaded in eager-loading,
    49  			// but was not found.
    50  			return nil, &NotFoundError{label: alert.Label}
    51  		}
    52  		return e.Owner, nil
    53  	}
    54  	return nil, &NotLoadedError{edge: "owner"}
    55  }
    56  
    57  // scanValues returns the types for scanning values from sql.Rows.
    58  func (*Meta) scanValues(columns []string) ([]interface{}, error) {
    59  	values := make([]interface{}, len(columns))
    60  	for i := range columns {
    61  		switch columns[i] {
    62  		case meta.FieldID:
    63  			values[i] = &sql.NullInt64{}
    64  		case meta.FieldKey, meta.FieldValue:
    65  			values[i] = &sql.NullString{}
    66  		case meta.FieldCreatedAt, meta.FieldUpdatedAt:
    67  			values[i] = &sql.NullTime{}
    68  		case meta.ForeignKeys[0]: // alert_metas
    69  			values[i] = &sql.NullInt64{}
    70  		default:
    71  			return nil, fmt.Errorf("unexpected column %q for type Meta", columns[i])
    72  		}
    73  	}
    74  	return values, nil
    75  }
    76  
    77  // assignValues assigns the values that were returned from sql.Rows (after scanning)
    78  // to the Meta fields.
    79  func (m *Meta) assignValues(columns []string, values []interface{}) 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 meta.FieldID:
    86  			value, ok := values[i].(*sql.NullInt64)
    87  			if !ok {
    88  				return fmt.Errorf("unexpected type %T for field id", value)
    89  			}
    90  			m.ID = int(value.Int64)
    91  		case meta.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  				m.CreatedAt = value.Time
    96  			}
    97  		case meta.FieldUpdatedAt:
    98  			if value, ok := values[i].(*sql.NullTime); !ok {
    99  				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
   100  			} else if value.Valid {
   101  				m.UpdatedAt = value.Time
   102  			}
   103  		case meta.FieldKey:
   104  			if value, ok := values[i].(*sql.NullString); !ok {
   105  				return fmt.Errorf("unexpected type %T for field key", values[i])
   106  			} else if value.Valid {
   107  				m.Key = value.String
   108  			}
   109  		case meta.FieldValue:
   110  			if value, ok := values[i].(*sql.NullString); !ok {
   111  				return fmt.Errorf("unexpected type %T for field value", values[i])
   112  			} else if value.Valid {
   113  				m.Value = value.String
   114  			}
   115  		case meta.ForeignKeys[0]:
   116  			if value, ok := values[i].(*sql.NullInt64); !ok {
   117  				return fmt.Errorf("unexpected type %T for edge-field alert_metas", value)
   118  			} else if value.Valid {
   119  				m.alert_metas = new(int)
   120  				*m.alert_metas = int(value.Int64)
   121  			}
   122  		}
   123  	}
   124  	return nil
   125  }
   126  
   127  // QueryOwner queries the "owner" edge of the Meta entity.
   128  func (m *Meta) QueryOwner() *AlertQuery {
   129  	return (&MetaClient{config: m.config}).QueryOwner(m)
   130  }
   131  
   132  // Update returns a builder for updating this Meta.
   133  // Note that you need to call Meta.Unwrap() before calling this method if this Meta
   134  // was returned from a transaction, and the transaction was committed or rolled back.
   135  func (m *Meta) Update() *MetaUpdateOne {
   136  	return (&MetaClient{config: m.config}).UpdateOne(m)
   137  }
   138  
   139  // Unwrap unwraps the Meta entity that was returned from a transaction after it was closed,
   140  // so that all future queries will be executed through the driver which created the transaction.
   141  func (m *Meta) Unwrap() *Meta {
   142  	tx, ok := m.config.driver.(*txDriver)
   143  	if !ok {
   144  		panic("ent: Meta is not a transactional entity")
   145  	}
   146  	m.config.driver = tx.drv
   147  	return m
   148  }
   149  
   150  // String implements the fmt.Stringer.
   151  func (m *Meta) String() string {
   152  	var builder strings.Builder
   153  	builder.WriteString("Meta(")
   154  	builder.WriteString(fmt.Sprintf("id=%v", m.ID))
   155  	builder.WriteString(", created_at=")
   156  	builder.WriteString(m.CreatedAt.Format(time.ANSIC))
   157  	builder.WriteString(", updated_at=")
   158  	builder.WriteString(m.UpdatedAt.Format(time.ANSIC))
   159  	builder.WriteString(", key=")
   160  	builder.WriteString(m.Key)
   161  	builder.WriteString(", value=")
   162  	builder.WriteString(m.Value)
   163  	builder.WriteByte(')')
   164  	return builder.String()
   165  }
   166  
   167  // MetaSlice is a parsable slice of Meta.
   168  type MetaSlice []*Meta
   169  
   170  func (m MetaSlice) config(cfg config) {
   171  	for _i := range m {
   172  		m[_i].config = cfg
   173  	}
   174  }