plc.directory mirror
1// Code generated by ent, DO NOT EDIT.
2
3package ent
4
5import (
6 "encoding/json"
7 "fmt"
8 "strings"
9 "time"
10
11 "entgo.io/ent"
12 "entgo.io/ent/dialect/sql"
13 "tangled.sh/seiso.moe/aletheia.directory/ent/operation"
14 "tangled.sh/seiso.moe/aletheia.directory/pkg/plc"
15)
16
17// Operation is the model entity for the Operation schema.
18type Operation struct {
19 config `json:"-"`
20 // ID of the ent.
21 ID int `json:"id,omitempty"`
22 // Decentralized identifier
23 Did string `json:"did,omitempty"`
24 // PLC operation data with proper typing
25 Operation plc.PLCOperation `json:"operation,omitempty"`
26 // Content identifier
27 Cid string `json:"cid,omitempty"`
28 // Whether the operation is nullified
29 Nullified bool `json:"nullified,omitempty"`
30 // Operation creation timestamp
31 CreatedAt time.Time `json:"created_at,omitempty"`
32 selectValues sql.SelectValues
33}
34
35// scanValues returns the types for scanning values from sql.Rows.
36func (*Operation) scanValues(columns []string) ([]any, error) {
37 values := make([]any, len(columns))
38 for i := range columns {
39 switch columns[i] {
40 case operation.FieldOperation:
41 values[i] = new([]byte)
42 case operation.FieldNullified:
43 values[i] = new(sql.NullBool)
44 case operation.FieldID:
45 values[i] = new(sql.NullInt64)
46 case operation.FieldDid, operation.FieldCid:
47 values[i] = new(sql.NullString)
48 case operation.FieldCreatedAt:
49 values[i] = new(sql.NullTime)
50 default:
51 values[i] = new(sql.UnknownType)
52 }
53 }
54 return values, nil
55}
56
57// assignValues assigns the values that were returned from sql.Rows (after scanning)
58// to the Operation fields.
59func (o *Operation) assignValues(columns []string, values []any) error {
60 if m, n := len(values), len(columns); m < n {
61 return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
62 }
63 for i := range columns {
64 switch columns[i] {
65 case operation.FieldID:
66 value, ok := values[i].(*sql.NullInt64)
67 if !ok {
68 return fmt.Errorf("unexpected type %T for field id", value)
69 }
70 o.ID = int(value.Int64)
71 case operation.FieldDid:
72 if value, ok := values[i].(*sql.NullString); !ok {
73 return fmt.Errorf("unexpected type %T for field did", values[i])
74 } else if value.Valid {
75 o.Did = value.String
76 }
77 case operation.FieldOperation:
78 if value, ok := values[i].(*[]byte); !ok {
79 return fmt.Errorf("unexpected type %T for field operation", values[i])
80 } else if value != nil && len(*value) > 0 {
81 if err := json.Unmarshal(*value, &o.Operation); err != nil {
82 return fmt.Errorf("unmarshal field operation: %w", err)
83 }
84 }
85 case operation.FieldCid:
86 if value, ok := values[i].(*sql.NullString); !ok {
87 return fmt.Errorf("unexpected type %T for field cid", values[i])
88 } else if value.Valid {
89 o.Cid = value.String
90 }
91 case operation.FieldNullified:
92 if value, ok := values[i].(*sql.NullBool); !ok {
93 return fmt.Errorf("unexpected type %T for field nullified", values[i])
94 } else if value.Valid {
95 o.Nullified = value.Bool
96 }
97 case operation.FieldCreatedAt:
98 if value, ok := values[i].(*sql.NullTime); !ok {
99 return fmt.Errorf("unexpected type %T for field created_at", values[i])
100 } else if value.Valid {
101 o.CreatedAt = value.Time
102 }
103 default:
104 o.selectValues.Set(columns[i], values[i])
105 }
106 }
107 return nil
108}
109
110// Value returns the ent.Value that was dynamically selected and assigned to the Operation.
111// This includes values selected through modifiers, order, etc.
112func (o *Operation) Value(name string) (ent.Value, error) {
113 return o.selectValues.Get(name)
114}
115
116// Update returns a builder for updating this Operation.
117// Note that you need to call Operation.Unwrap() before calling this method if this Operation
118// was returned from a transaction, and the transaction was committed or rolled back.
119func (o *Operation) Update() *OperationUpdateOne {
120 return NewOperationClient(o.config).UpdateOne(o)
121}
122
123// Unwrap unwraps the Operation entity that was returned from a transaction after it was closed,
124// so that all future queries will be executed through the driver which created the transaction.
125func (o *Operation) Unwrap() *Operation {
126 _tx, ok := o.config.driver.(*txDriver)
127 if !ok {
128 panic("ent: Operation is not a transactional entity")
129 }
130 o.config.driver = _tx.drv
131 return o
132}
133
134// String implements the fmt.Stringer.
135func (o *Operation) String() string {
136 var builder strings.Builder
137 builder.WriteString("Operation(")
138 builder.WriteString(fmt.Sprintf("id=%v, ", o.ID))
139 builder.WriteString("did=")
140 builder.WriteString(o.Did)
141 builder.WriteString(", ")
142 builder.WriteString("operation=")
143 builder.WriteString(fmt.Sprintf("%v", o.Operation))
144 builder.WriteString(", ")
145 builder.WriteString("cid=")
146 builder.WriteString(o.Cid)
147 builder.WriteString(", ")
148 builder.WriteString("nullified=")
149 builder.WriteString(fmt.Sprintf("%v", o.Nullified))
150 builder.WriteString(", ")
151 builder.WriteString("created_at=")
152 builder.WriteString(o.CreatedAt.Format(time.ANSIC))
153 builder.WriteByte(')')
154 return builder.String()
155}
156
157// Operations is a parsable slice of Operation.
158type Operations []*Operation