subscription.go
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/google/uuid" 13 "github.com/mrusme/journalist/ent/feed" 14 "github.com/mrusme/journalist/ent/subscription" 15 "github.com/mrusme/journalist/ent/user" 16 ) 17 18 // Subscription is the model entity for the Subscription schema. 19 type Subscription struct { 20 config `json:"-"` 21 // ID of the ent. 22 ID uuid.UUID `json:"id,omitempty"` 23 // UserID holds the value of the "user_id" field. 24 UserID uuid.UUID `json:"user_id,omitempty"` 25 // FeedID holds the value of the "feed_id" field. 26 FeedID uuid.UUID `json:"feed_id,omitempty"` 27 // Name holds the value of the "name" field. 28 Name string `json:"name,omitempty"` 29 // Group holds the value of the "group" field. 30 Group string `json:"group,omitempty"` 31 // CreatedAt holds the value of the "created_at" field. 32 CreatedAt time.Time `json:"created_at,omitempty"` 33 // Edges holds the relations/edges for other nodes in the graph. 34 // The values are being populated by the SubscriptionQuery when eager-loading is set. 35 Edges SubscriptionEdges `json:"edges"` 36 selectValues sql.SelectValues 37 } 38 39 // SubscriptionEdges holds the relations/edges for other nodes in the graph. 40 type SubscriptionEdges struct { 41 // User holds the value of the user edge. 42 User *User `json:"user,omitempty"` 43 // Feed holds the value of the feed edge. 44 Feed *Feed `json:"feed,omitempty"` 45 // loadedTypes holds the information for reporting if a 46 // type was loaded (or requested) in eager-loading or not. 47 loadedTypes [2]bool 48 } 49 50 // UserOrErr returns the User value or an error if the edge 51 // was not loaded in eager-loading, or loaded but was not found. 52 func (e SubscriptionEdges) UserOrErr() (*User, error) { 53 if e.User != nil { 54 return e.User, nil 55 } else if e.loadedTypes[0] { 56 return nil, &NotFoundError{label: user.Label} 57 } 58 return nil, &NotLoadedError{edge: "user"} 59 } 60 61 // FeedOrErr returns the Feed value or an error if the edge 62 // was not loaded in eager-loading, or loaded but was not found. 63 func (e SubscriptionEdges) FeedOrErr() (*Feed, error) { 64 if e.Feed != nil { 65 return e.Feed, nil 66 } else if e.loadedTypes[1] { 67 return nil, &NotFoundError{label: feed.Label} 68 } 69 return nil, &NotLoadedError{edge: "feed"} 70 } 71 72 // scanValues returns the types for scanning values from sql.Rows. 73 func (*Subscription) scanValues(columns []string) ([]any, error) { 74 values := make([]any, len(columns)) 75 for i := range columns { 76 switch columns[i] { 77 case subscription.FieldName, subscription.FieldGroup: 78 values[i] = new(sql.NullString) 79 case subscription.FieldCreatedAt: 80 values[i] = new(sql.NullTime) 81 case subscription.FieldID, subscription.FieldUserID, subscription.FieldFeedID: 82 values[i] = new(uuid.UUID) 83 default: 84 values[i] = new(sql.UnknownType) 85 } 86 } 87 return values, nil 88 } 89 90 // assignValues assigns the values that were returned from sql.Rows (after scanning) 91 // to the Subscription fields. 92 func (s *Subscription) assignValues(columns []string, values []any) error { 93 if m, n := len(values), len(columns); m < n { 94 return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) 95 } 96 for i := range columns { 97 switch columns[i] { 98 case subscription.FieldID: 99 if value, ok := values[i].(*uuid.UUID); !ok { 100 return fmt.Errorf("unexpected type %T for field id", values[i]) 101 } else if value != nil { 102 s.ID = *value 103 } 104 case subscription.FieldUserID: 105 if value, ok := values[i].(*uuid.UUID); !ok { 106 return fmt.Errorf("unexpected type %T for field user_id", values[i]) 107 } else if value != nil { 108 s.UserID = *value 109 } 110 case subscription.FieldFeedID: 111 if value, ok := values[i].(*uuid.UUID); !ok { 112 return fmt.Errorf("unexpected type %T for field feed_id", values[i]) 113 } else if value != nil { 114 s.FeedID = *value 115 } 116 case subscription.FieldName: 117 if value, ok := values[i].(*sql.NullString); !ok { 118 return fmt.Errorf("unexpected type %T for field name", values[i]) 119 } else if value.Valid { 120 s.Name = value.String 121 } 122 case subscription.FieldGroup: 123 if value, ok := values[i].(*sql.NullString); !ok { 124 return fmt.Errorf("unexpected type %T for field group", values[i]) 125 } else if value.Valid { 126 s.Group = value.String 127 } 128 case subscription.FieldCreatedAt: 129 if value, ok := values[i].(*sql.NullTime); !ok { 130 return fmt.Errorf("unexpected type %T for field created_at", values[i]) 131 } else if value.Valid { 132 s.CreatedAt = value.Time 133 } 134 default: 135 s.selectValues.Set(columns[i], values[i]) 136 } 137 } 138 return nil 139 } 140 141 // Value returns the ent.Value that was dynamically selected and assigned to the Subscription. 142 // This includes values selected through modifiers, order, etc. 143 func (s *Subscription) Value(name string) (ent.Value, error) { 144 return s.selectValues.Get(name) 145 } 146 147 // QueryUser queries the "user" edge of the Subscription entity. 148 func (s *Subscription) QueryUser() *UserQuery { 149 return NewSubscriptionClient(s.config).QueryUser(s) 150 } 151 152 // QueryFeed queries the "feed" edge of the Subscription entity. 153 func (s *Subscription) QueryFeed() *FeedQuery { 154 return NewSubscriptionClient(s.config).QueryFeed(s) 155 } 156 157 // Update returns a builder for updating this Subscription. 158 // Note that you need to call Subscription.Unwrap() before calling this method if this Subscription 159 // was returned from a transaction, and the transaction was committed or rolled back. 160 func (s *Subscription) Update() *SubscriptionUpdateOne { 161 return NewSubscriptionClient(s.config).UpdateOne(s) 162 } 163 164 // Unwrap unwraps the Subscription entity that was returned from a transaction after it was closed, 165 // so that all future queries will be executed through the driver which created the transaction. 166 func (s *Subscription) Unwrap() *Subscription { 167 _tx, ok := s.config.driver.(*txDriver) 168 if !ok { 169 panic("ent: Subscription is not a transactional entity") 170 } 171 s.config.driver = _tx.drv 172 return s 173 } 174 175 // String implements the fmt.Stringer. 176 func (s *Subscription) String() string { 177 var builder strings.Builder 178 builder.WriteString("Subscription(") 179 builder.WriteString(fmt.Sprintf("id=%v, ", s.ID)) 180 builder.WriteString("user_id=") 181 builder.WriteString(fmt.Sprintf("%v", s.UserID)) 182 builder.WriteString(", ") 183 builder.WriteString("feed_id=") 184 builder.WriteString(fmt.Sprintf("%v", s.FeedID)) 185 builder.WriteString(", ") 186 builder.WriteString("name=") 187 builder.WriteString(s.Name) 188 builder.WriteString(", ") 189 builder.WriteString("group=") 190 builder.WriteString(s.Group) 191 builder.WriteString(", ") 192 builder.WriteString("created_at=") 193 builder.WriteString(s.CreatedAt.Format(time.ANSIC)) 194 builder.WriteByte(')') 195 return builder.String() 196 } 197 198 // Subscriptions is a parsable slice of Subscription. 199 type Subscriptions []*Subscription