mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-25 10:05:43 +00:00
refactor schema edges
This commit is contained in:
parent
ccd40ffcac
commit
883468e04c
12 changed files with 499 additions and 460 deletions
|
@ -2147,22 +2147,6 @@ func (c *NotifierClient) GetX(ctx context.Context, id uuid.UUID) *Notifier {
|
|||
return obj
|
||||
}
|
||||
|
||||
// QueryUser queries the user edge of a Notifier.
|
||||
func (c *NotifierClient) QueryUser(n *Notifier) *UserQuery {
|
||||
query := (&UserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := n.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(notifier.Table, notifier.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, notifier.UserTable, notifier.UserColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(n.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryGroup queries the group edge of a Notifier.
|
||||
func (c *NotifierClient) QueryGroup(n *Notifier) *GroupQuery {
|
||||
query := (&GroupClient{config: c.config}).Query()
|
||||
|
@ -2179,6 +2163,22 @@ func (c *NotifierClient) QueryGroup(n *Notifier) *GroupQuery {
|
|||
return query
|
||||
}
|
||||
|
||||
// QueryUser queries the user edge of a Notifier.
|
||||
func (c *NotifierClient) QueryUser(n *Notifier) *UserQuery {
|
||||
query := (&UserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := n.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(notifier.Table, notifier.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, notifier.UserTable, notifier.UserColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(n.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *NotifierClient) Hooks() []Hook {
|
||||
return c.hooks.Notifier
|
||||
|
|
|
@ -9871,10 +9871,10 @@ type NotifierMutation struct {
|
|||
url *string
|
||||
is_active *bool
|
||||
clearedFields map[string]struct{}
|
||||
user *uuid.UUID
|
||||
cleareduser bool
|
||||
group *uuid.UUID
|
||||
clearedgroup bool
|
||||
user *uuid.UUID
|
||||
cleareduser bool
|
||||
done bool
|
||||
oldValue func(context.Context) (*Notifier, error)
|
||||
predicates []predicate.Notifier
|
||||
|
@ -10056,42 +10056,6 @@ func (m *NotifierMutation) ResetUpdatedAt() {
|
|||
m.updated_at = nil
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (m *NotifierMutation) SetUserID(u uuid.UUID) {
|
||||
m.user = &u
|
||||
}
|
||||
|
||||
// UserID returns the value of the "user_id" field in the mutation.
|
||||
func (m *NotifierMutation) UserID() (r uuid.UUID, exists bool) {
|
||||
v := m.user
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldUserID returns the old "user_id" field's value of the Notifier entity.
|
||||
// If the Notifier object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *NotifierMutation) OldUserID(ctx context.Context) (v uuid.UUID, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldUserID requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
|
||||
}
|
||||
return oldValue.UserID, nil
|
||||
}
|
||||
|
||||
// ResetUserID resets all changes to the "user_id" field.
|
||||
func (m *NotifierMutation) ResetUserID() {
|
||||
m.user = nil
|
||||
}
|
||||
|
||||
// SetGroupID sets the "group_id" field.
|
||||
func (m *NotifierMutation) SetGroupID(u uuid.UUID) {
|
||||
m.group = &u
|
||||
|
@ -10128,6 +10092,42 @@ func (m *NotifierMutation) ResetGroupID() {
|
|||
m.group = nil
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (m *NotifierMutation) SetUserID(u uuid.UUID) {
|
||||
m.user = &u
|
||||
}
|
||||
|
||||
// UserID returns the value of the "user_id" field in the mutation.
|
||||
func (m *NotifierMutation) UserID() (r uuid.UUID, exists bool) {
|
||||
v := m.user
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldUserID returns the old "user_id" field's value of the Notifier entity.
|
||||
// If the Notifier object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *NotifierMutation) OldUserID(ctx context.Context) (v uuid.UUID, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldUserID is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldUserID requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldUserID: %w", err)
|
||||
}
|
||||
return oldValue.UserID, nil
|
||||
}
|
||||
|
||||
// ResetUserID resets all changes to the "user_id" field.
|
||||
func (m *NotifierMutation) ResetUserID() {
|
||||
m.user = nil
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (m *NotifierMutation) SetName(s string) {
|
||||
m.name = &s
|
||||
|
@ -10236,32 +10236,6 @@ func (m *NotifierMutation) ResetIsActive() {
|
|||
m.is_active = nil
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (m *NotifierMutation) ClearUser() {
|
||||
m.cleareduser = true
|
||||
}
|
||||
|
||||
// UserCleared reports if the "user" edge to the User entity was cleared.
|
||||
func (m *NotifierMutation) UserCleared() bool {
|
||||
return m.cleareduser
|
||||
}
|
||||
|
||||
// UserIDs returns the "user" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// UserID instead. It exists only for internal usage by the builders.
|
||||
func (m *NotifierMutation) UserIDs() (ids []uuid.UUID) {
|
||||
if id := m.user; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetUser resets all changes to the "user" edge.
|
||||
func (m *NotifierMutation) ResetUser() {
|
||||
m.user = nil
|
||||
m.cleareduser = false
|
||||
}
|
||||
|
||||
// ClearGroup clears the "group" edge to the Group entity.
|
||||
func (m *NotifierMutation) ClearGroup() {
|
||||
m.clearedgroup = true
|
||||
|
@ -10288,6 +10262,32 @@ func (m *NotifierMutation) ResetGroup() {
|
|||
m.clearedgroup = false
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (m *NotifierMutation) ClearUser() {
|
||||
m.cleareduser = true
|
||||
}
|
||||
|
||||
// UserCleared reports if the "user" edge to the User entity was cleared.
|
||||
func (m *NotifierMutation) UserCleared() bool {
|
||||
return m.cleareduser
|
||||
}
|
||||
|
||||
// UserIDs returns the "user" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// UserID instead. It exists only for internal usage by the builders.
|
||||
func (m *NotifierMutation) UserIDs() (ids []uuid.UUID) {
|
||||
if id := m.user; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetUser resets all changes to the "user" edge.
|
||||
func (m *NotifierMutation) ResetUser() {
|
||||
m.user = nil
|
||||
m.cleareduser = false
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NotifierMutation builder.
|
||||
func (m *NotifierMutation) Where(ps ...predicate.Notifier) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
|
@ -10329,12 +10329,12 @@ func (m *NotifierMutation) Fields() []string {
|
|||
if m.updated_at != nil {
|
||||
fields = append(fields, notifier.FieldUpdatedAt)
|
||||
}
|
||||
if m.user != nil {
|
||||
fields = append(fields, notifier.FieldUserID)
|
||||
}
|
||||
if m.group != nil {
|
||||
fields = append(fields, notifier.FieldGroupID)
|
||||
}
|
||||
if m.user != nil {
|
||||
fields = append(fields, notifier.FieldUserID)
|
||||
}
|
||||
if m.name != nil {
|
||||
fields = append(fields, notifier.FieldName)
|
||||
}
|
||||
|
@ -10356,10 +10356,10 @@ func (m *NotifierMutation) Field(name string) (ent.Value, bool) {
|
|||
return m.CreatedAt()
|
||||
case notifier.FieldUpdatedAt:
|
||||
return m.UpdatedAt()
|
||||
case notifier.FieldUserID:
|
||||
return m.UserID()
|
||||
case notifier.FieldGroupID:
|
||||
return m.GroupID()
|
||||
case notifier.FieldUserID:
|
||||
return m.UserID()
|
||||
case notifier.FieldName:
|
||||
return m.Name()
|
||||
case notifier.FieldURL:
|
||||
|
@ -10379,10 +10379,10 @@ func (m *NotifierMutation) OldField(ctx context.Context, name string) (ent.Value
|
|||
return m.OldCreatedAt(ctx)
|
||||
case notifier.FieldUpdatedAt:
|
||||
return m.OldUpdatedAt(ctx)
|
||||
case notifier.FieldUserID:
|
||||
return m.OldUserID(ctx)
|
||||
case notifier.FieldGroupID:
|
||||
return m.OldGroupID(ctx)
|
||||
case notifier.FieldUserID:
|
||||
return m.OldUserID(ctx)
|
||||
case notifier.FieldName:
|
||||
return m.OldName(ctx)
|
||||
case notifier.FieldURL:
|
||||
|
@ -10412,13 +10412,6 @@ func (m *NotifierMutation) SetField(name string, value ent.Value) error {
|
|||
}
|
||||
m.SetUpdatedAt(v)
|
||||
return nil
|
||||
case notifier.FieldUserID:
|
||||
v, ok := value.(uuid.UUID)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUserID(v)
|
||||
return nil
|
||||
case notifier.FieldGroupID:
|
||||
v, ok := value.(uuid.UUID)
|
||||
if !ok {
|
||||
|
@ -10426,6 +10419,13 @@ func (m *NotifierMutation) SetField(name string, value ent.Value) error {
|
|||
}
|
||||
m.SetGroupID(v)
|
||||
return nil
|
||||
case notifier.FieldUserID:
|
||||
v, ok := value.(uuid.UUID)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUserID(v)
|
||||
return nil
|
||||
case notifier.FieldName:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
|
@ -10502,12 +10502,12 @@ func (m *NotifierMutation) ResetField(name string) error {
|
|||
case notifier.FieldUpdatedAt:
|
||||
m.ResetUpdatedAt()
|
||||
return nil
|
||||
case notifier.FieldUserID:
|
||||
m.ResetUserID()
|
||||
return nil
|
||||
case notifier.FieldGroupID:
|
||||
m.ResetGroupID()
|
||||
return nil
|
||||
case notifier.FieldUserID:
|
||||
m.ResetUserID()
|
||||
return nil
|
||||
case notifier.FieldName:
|
||||
m.ResetName()
|
||||
return nil
|
||||
|
@ -10524,12 +10524,12 @@ func (m *NotifierMutation) ResetField(name string) error {
|
|||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *NotifierMutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 2)
|
||||
if m.user != nil {
|
||||
edges = append(edges, notifier.EdgeUser)
|
||||
}
|
||||
if m.group != nil {
|
||||
edges = append(edges, notifier.EdgeGroup)
|
||||
}
|
||||
if m.user != nil {
|
||||
edges = append(edges, notifier.EdgeUser)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
|
@ -10537,14 +10537,14 @@ func (m *NotifierMutation) AddedEdges() []string {
|
|||
// name in this mutation.
|
||||
func (m *NotifierMutation) AddedIDs(name string) []ent.Value {
|
||||
switch name {
|
||||
case notifier.EdgeUser:
|
||||
if id := m.user; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
case notifier.EdgeGroup:
|
||||
if id := m.group; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
case notifier.EdgeUser:
|
||||
if id := m.user; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -10564,12 +10564,12 @@ func (m *NotifierMutation) RemovedIDs(name string) []ent.Value {
|
|||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *NotifierMutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 2)
|
||||
if m.cleareduser {
|
||||
edges = append(edges, notifier.EdgeUser)
|
||||
}
|
||||
if m.clearedgroup {
|
||||
edges = append(edges, notifier.EdgeGroup)
|
||||
}
|
||||
if m.cleareduser {
|
||||
edges = append(edges, notifier.EdgeUser)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
|
@ -10577,10 +10577,10 @@ func (m *NotifierMutation) ClearedEdges() []string {
|
|||
// was cleared in this mutation.
|
||||
func (m *NotifierMutation) EdgeCleared(name string) bool {
|
||||
switch name {
|
||||
case notifier.EdgeUser:
|
||||
return m.cleareduser
|
||||
case notifier.EdgeGroup:
|
||||
return m.clearedgroup
|
||||
case notifier.EdgeUser:
|
||||
return m.cleareduser
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -10589,12 +10589,12 @@ func (m *NotifierMutation) EdgeCleared(name string) bool {
|
|||
// if that edge is not defined in the schema.
|
||||
func (m *NotifierMutation) ClearEdge(name string) error {
|
||||
switch name {
|
||||
case notifier.EdgeUser:
|
||||
m.ClearUser()
|
||||
return nil
|
||||
case notifier.EdgeGroup:
|
||||
m.ClearGroup()
|
||||
return nil
|
||||
case notifier.EdgeUser:
|
||||
m.ClearUser()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Notifier unique edge %s", name)
|
||||
}
|
||||
|
@ -10603,12 +10603,12 @@ func (m *NotifierMutation) ClearEdge(name string) error {
|
|||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *NotifierMutation) ResetEdge(name string) error {
|
||||
switch name {
|
||||
case notifier.EdgeUser:
|
||||
m.ResetUser()
|
||||
return nil
|
||||
case notifier.EdgeGroup:
|
||||
m.ResetGroup()
|
||||
return nil
|
||||
case notifier.EdgeUser:
|
||||
m.ResetUser()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Notifier edge %s", name)
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@ type Notifier struct {
|
|||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// UserID holds the value of the "user_id" field.
|
||||
UserID uuid.UUID `json:"user_id,omitempty"`
|
||||
// GroupID holds the value of the "group_id" field.
|
||||
GroupID uuid.UUID `json:"group_id,omitempty"`
|
||||
// UserID holds the value of the "user_id" field.
|
||||
UserID uuid.UUID `json:"user_id,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// URL holds the value of the "url" field.
|
||||
|
@ -40,32 +40,19 @@ type Notifier struct {
|
|||
|
||||
// NotifierEdges holds the relations/edges for other nodes in the graph.
|
||||
type NotifierEdges struct {
|
||||
// User holds the value of the user edge.
|
||||
User *User `json:"user,omitempty"`
|
||||
// Group holds the value of the group edge.
|
||||
Group *Group `json:"group,omitempty"`
|
||||
// User holds the value of the user edge.
|
||||
User *User `json:"user,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [2]bool
|
||||
}
|
||||
|
||||
// UserOrErr returns the User value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e NotifierEdges) UserOrErr() (*User, error) {
|
||||
if e.loadedTypes[0] {
|
||||
if e.User == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return e.User, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// GroupOrErr returns the Group value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e NotifierEdges) GroupOrErr() (*Group, error) {
|
||||
if e.loadedTypes[1] {
|
||||
if e.loadedTypes[0] {
|
||||
if e.Group == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: group.Label}
|
||||
|
@ -75,6 +62,19 @@ func (e NotifierEdges) GroupOrErr() (*Group, error) {
|
|||
return nil, &NotLoadedError{edge: "group"}
|
||||
}
|
||||
|
||||
// UserOrErr returns the User value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e NotifierEdges) UserOrErr() (*User, error) {
|
||||
if e.loadedTypes[1] {
|
||||
if e.User == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return e.User, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Notifier) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
|
@ -86,7 +86,7 @@ func (*Notifier) scanValues(columns []string) ([]any, error) {
|
|||
values[i] = new(sql.NullString)
|
||||
case notifier.FieldCreatedAt, notifier.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
case notifier.FieldID, notifier.FieldUserID, notifier.FieldGroupID:
|
||||
case notifier.FieldID, notifier.FieldGroupID, notifier.FieldUserID:
|
||||
values[i] = new(uuid.UUID)
|
||||
default:
|
||||
return nil, fmt.Errorf("unexpected column %q for type Notifier", columns[i])
|
||||
|
@ -121,18 +121,18 @@ func (n *Notifier) assignValues(columns []string, values []any) error {
|
|||
} else if value.Valid {
|
||||
n.UpdatedAt = value.Time
|
||||
}
|
||||
case notifier.FieldUserID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
||||
} else if value != nil {
|
||||
n.UserID = *value
|
||||
}
|
||||
case notifier.FieldGroupID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field group_id", values[i])
|
||||
} else if value != nil {
|
||||
n.GroupID = *value
|
||||
}
|
||||
case notifier.FieldUserID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
||||
} else if value != nil {
|
||||
n.UserID = *value
|
||||
}
|
||||
case notifier.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
|
@ -156,16 +156,16 @@ func (n *Notifier) assignValues(columns []string, values []any) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// QueryUser queries the "user" edge of the Notifier entity.
|
||||
func (n *Notifier) QueryUser() *UserQuery {
|
||||
return NewNotifierClient(n.config).QueryUser(n)
|
||||
}
|
||||
|
||||
// QueryGroup queries the "group" edge of the Notifier entity.
|
||||
func (n *Notifier) QueryGroup() *GroupQuery {
|
||||
return NewNotifierClient(n.config).QueryGroup(n)
|
||||
}
|
||||
|
||||
// QueryUser queries the "user" edge of the Notifier entity.
|
||||
func (n *Notifier) QueryUser() *UserQuery {
|
||||
return NewNotifierClient(n.config).QueryUser(n)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Notifier.
|
||||
// Note that you need to call Notifier.Unwrap() before calling this method if this Notifier
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
|
@ -195,12 +195,12 @@ func (n *Notifier) String() string {
|
|||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(n.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("user_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", n.UserID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("group_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", n.GroupID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("user_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", n.UserID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(n.Name)
|
||||
builder.WriteString(", ")
|
||||
|
|
|
@ -17,29 +17,22 @@ const (
|
|||
FieldCreatedAt = "created_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// FieldUserID holds the string denoting the user_id field in the database.
|
||||
FieldUserID = "user_id"
|
||||
// FieldGroupID holds the string denoting the group_id field in the database.
|
||||
FieldGroupID = "group_id"
|
||||
// FieldUserID holds the string denoting the user_id field in the database.
|
||||
FieldUserID = "user_id"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// FieldURL holds the string denoting the url field in the database.
|
||||
FieldURL = "url"
|
||||
// FieldIsActive holds the string denoting the is_active field in the database.
|
||||
FieldIsActive = "is_active"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// EdgeGroup holds the string denoting the group edge name in mutations.
|
||||
EdgeGroup = "group"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// Table holds the table name of the notifier in the database.
|
||||
Table = "notifiers"
|
||||
// UserTable is the table that holds the user relation/edge.
|
||||
UserTable = "notifiers"
|
||||
// UserInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
UserInverseTable = "users"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "user_id"
|
||||
// GroupTable is the table that holds the group relation/edge.
|
||||
GroupTable = "notifiers"
|
||||
// GroupInverseTable is the table name for the Group entity.
|
||||
|
@ -47,6 +40,13 @@ const (
|
|||
GroupInverseTable = "groups"
|
||||
// GroupColumn is the table column denoting the group relation/edge.
|
||||
GroupColumn = "group_id"
|
||||
// UserTable is the table that holds the user relation/edge.
|
||||
UserTable = "notifiers"
|
||||
// UserInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
UserInverseTable = "users"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "user_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for notifier fields.
|
||||
|
@ -54,8 +54,8 @@ var Columns = []string{
|
|||
FieldID,
|
||||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldUserID,
|
||||
FieldGroupID,
|
||||
FieldUserID,
|
||||
FieldName,
|
||||
FieldURL,
|
||||
FieldIsActive,
|
||||
|
|
|
@ -66,16 +66,16 @@ func UpdatedAt(v time.Time) predicate.Notifier {
|
|||
return predicate.Notifier(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||
func UserID(v uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// GroupID applies equality check predicate on the "group_id" field. It's identical to GroupIDEQ.
|
||||
func GroupID(v uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldEQ(FieldGroupID, v))
|
||||
}
|
||||
|
||||
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||
func UserID(v uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldEQ(FieldName, v))
|
||||
|
@ -171,26 +171,6 @@ func UpdatedAtLTE(v time.Time) predicate.Notifier {
|
|||
return predicate.Notifier(sql.FieldLTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||
func UserIDEQ(v uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||
func UserIDNEQ(v uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldNEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDIn applies the In predicate on the "user_id" field.
|
||||
func UserIDIn(vs ...uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||
func UserIDNotIn(vs ...uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldNotIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// GroupIDEQ applies the EQ predicate on the "group_id" field.
|
||||
func GroupIDEQ(v uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldEQ(FieldGroupID, v))
|
||||
|
@ -211,6 +191,26 @@ func GroupIDNotIn(vs ...uuid.UUID) predicate.Notifier {
|
|||
return predicate.Notifier(sql.FieldNotIn(FieldGroupID, vs...))
|
||||
}
|
||||
|
||||
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||
func UserIDEQ(v uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||
func UserIDNEQ(v uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldNEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDIn applies the In predicate on the "user_id" field.
|
||||
func UserIDIn(vs ...uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||
func UserIDNotIn(vs ...uuid.UUID) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldNotIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Notifier {
|
||||
return predicate.Notifier(sql.FieldEQ(FieldName, v))
|
||||
|
@ -351,33 +351,6 @@ func IsActiveNEQ(v bool) predicate.Notifier {
|
|||
return predicate.Notifier(sql.FieldNEQ(FieldIsActive, v))
|
||||
}
|
||||
|
||||
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||
func HasUser() predicate.Notifier {
|
||||
return predicate.Notifier(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||
func HasUserWith(preds ...predicate.User) predicate.Notifier {
|
||||
return predicate.Notifier(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasGroup applies the HasEdge predicate on the "group" edge.
|
||||
func HasGroup() predicate.Notifier {
|
||||
return predicate.Notifier(func(s *sql.Selector) {
|
||||
|
@ -405,6 +378,33 @@ func HasGroupWith(preds ...predicate.Group) predicate.Notifier {
|
|||
})
|
||||
}
|
||||
|
||||
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||
func HasUser() predicate.Notifier {
|
||||
return predicate.Notifier(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||
func HasUserWith(preds ...predicate.User) predicate.Notifier {
|
||||
return predicate.Notifier(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Notifier) predicate.Notifier {
|
||||
return predicate.Notifier(func(s *sql.Selector) {
|
||||
|
|
|
@ -51,18 +51,18 @@ func (nc *NotifierCreate) SetNillableUpdatedAt(t *time.Time) *NotifierCreate {
|
|||
return nc
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (nc *NotifierCreate) SetUserID(u uuid.UUID) *NotifierCreate {
|
||||
nc.mutation.SetUserID(u)
|
||||
return nc
|
||||
}
|
||||
|
||||
// SetGroupID sets the "group_id" field.
|
||||
func (nc *NotifierCreate) SetGroupID(u uuid.UUID) *NotifierCreate {
|
||||
nc.mutation.SetGroupID(u)
|
||||
return nc
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (nc *NotifierCreate) SetUserID(u uuid.UUID) *NotifierCreate {
|
||||
nc.mutation.SetUserID(u)
|
||||
return nc
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (nc *NotifierCreate) SetName(s string) *NotifierCreate {
|
||||
nc.mutation.SetName(s)
|
||||
|
@ -103,16 +103,16 @@ func (nc *NotifierCreate) SetNillableID(u *uuid.UUID) *NotifierCreate {
|
|||
return nc
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (nc *NotifierCreate) SetUser(u *User) *NotifierCreate {
|
||||
return nc.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// SetGroup sets the "group" edge to the Group entity.
|
||||
func (nc *NotifierCreate) SetGroup(g *Group) *NotifierCreate {
|
||||
return nc.SetGroupID(g.ID)
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (nc *NotifierCreate) SetUser(u *User) *NotifierCreate {
|
||||
return nc.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the NotifierMutation object of the builder.
|
||||
func (nc *NotifierCreate) Mutation() *NotifierMutation {
|
||||
return nc.mutation
|
||||
|
@ -174,12 +174,12 @@ func (nc *NotifierCreate) check() error {
|
|||
if _, ok := nc.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Notifier.updated_at"`)}
|
||||
}
|
||||
if _, ok := nc.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "Notifier.user_id"`)}
|
||||
}
|
||||
if _, ok := nc.mutation.GroupID(); !ok {
|
||||
return &ValidationError{Name: "group_id", err: errors.New(`ent: missing required field "Notifier.group_id"`)}
|
||||
}
|
||||
if _, ok := nc.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "Notifier.user_id"`)}
|
||||
}
|
||||
if _, ok := nc.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Notifier.name"`)}
|
||||
}
|
||||
|
@ -199,12 +199,12 @@ func (nc *NotifierCreate) check() error {
|
|||
if _, ok := nc.mutation.IsActive(); !ok {
|
||||
return &ValidationError{Name: "is_active", err: errors.New(`ent: missing required field "Notifier.is_active"`)}
|
||||
}
|
||||
if _, ok := nc.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "Notifier.user"`)}
|
||||
}
|
||||
if _, ok := nc.mutation.GroupID(); !ok {
|
||||
return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "Notifier.group"`)}
|
||||
}
|
||||
if _, ok := nc.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "Notifier.user"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -260,26 +260,6 @@ func (nc *NotifierCreate) createSpec() (*Notifier, *sqlgraph.CreateSpec) {
|
|||
_spec.SetField(notifier.FieldIsActive, field.TypeBool, value)
|
||||
_node.IsActive = value
|
||||
}
|
||||
if nodes := nc.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.UserTable,
|
||||
Columns: []string{notifier.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.UserID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := nc.mutation.GroupIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
|
@ -300,6 +280,26 @@ func (nc *NotifierCreate) createSpec() (*Notifier, *sqlgraph.CreateSpec) {
|
|||
_node.GroupID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := nc.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.UserTable,
|
||||
Columns: []string{notifier.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.UserID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ type NotifierQuery struct {
|
|||
order []OrderFunc
|
||||
inters []Interceptor
|
||||
predicates []predicate.Notifier
|
||||
withUser *UserQuery
|
||||
withGroup *GroupQuery
|
||||
withUser *UserQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
|
@ -62,28 +62,6 @@ func (nq *NotifierQuery) Order(o ...OrderFunc) *NotifierQuery {
|
|||
return nq
|
||||
}
|
||||
|
||||
// QueryUser chains the current query on the "user" edge.
|
||||
func (nq *NotifierQuery) QueryUser() *UserQuery {
|
||||
query := (&UserClient{config: nq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := nq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := nq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(notifier.Table, notifier.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, notifier.UserTable, notifier.UserColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(nq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryGroup chains the current query on the "group" edge.
|
||||
func (nq *NotifierQuery) QueryGroup() *GroupQuery {
|
||||
query := (&GroupClient{config: nq.config}).Query()
|
||||
|
@ -106,6 +84,28 @@ func (nq *NotifierQuery) QueryGroup() *GroupQuery {
|
|||
return query
|
||||
}
|
||||
|
||||
// QueryUser chains the current query on the "user" edge.
|
||||
func (nq *NotifierQuery) QueryUser() *UserQuery {
|
||||
query := (&UserClient{config: nq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := nq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := nq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(notifier.Table, notifier.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, notifier.UserTable, notifier.UserColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(nq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Notifier entity from the query.
|
||||
// Returns a *NotFoundError when no Notifier was found.
|
||||
func (nq *NotifierQuery) First(ctx context.Context) (*Notifier, error) {
|
||||
|
@ -298,25 +298,14 @@ func (nq *NotifierQuery) Clone() *NotifierQuery {
|
|||
order: append([]OrderFunc{}, nq.order...),
|
||||
inters: append([]Interceptor{}, nq.inters...),
|
||||
predicates: append([]predicate.Notifier{}, nq.predicates...),
|
||||
withUser: nq.withUser.Clone(),
|
||||
withGroup: nq.withGroup.Clone(),
|
||||
withUser: nq.withUser.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: nq.sql.Clone(),
|
||||
path: nq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (nq *NotifierQuery) WithUser(opts ...func(*UserQuery)) *NotifierQuery {
|
||||
query := (&UserClient{config: nq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
nq.withUser = query
|
||||
return nq
|
||||
}
|
||||
|
||||
// WithGroup tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "group" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (nq *NotifierQuery) WithGroup(opts ...func(*GroupQuery)) *NotifierQuery {
|
||||
|
@ -328,6 +317,17 @@ func (nq *NotifierQuery) WithGroup(opts ...func(*GroupQuery)) *NotifierQuery {
|
|||
return nq
|
||||
}
|
||||
|
||||
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (nq *NotifierQuery) WithUser(opts ...func(*UserQuery)) *NotifierQuery {
|
||||
query := (&UserClient{config: nq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
nq.withUser = query
|
||||
return nq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
|
@ -407,8 +407,8 @@ func (nq *NotifierQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Not
|
|||
nodes = []*Notifier{}
|
||||
_spec = nq.querySpec()
|
||||
loadedTypes = [2]bool{
|
||||
nq.withUser != nil,
|
||||
nq.withGroup != nil,
|
||||
nq.withUser != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
|
@ -429,50 +429,21 @@ func (nq *NotifierQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Not
|
|||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := nq.withUser; query != nil {
|
||||
if err := nq.loadUser(ctx, query, nodes, nil,
|
||||
func(n *Notifier, e *User) { n.Edges.User = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := nq.withGroup; query != nil {
|
||||
if err := nq.loadGroup(ctx, query, nodes, nil,
|
||||
func(n *Notifier, e *Group) { n.Edges.Group = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := nq.withUser; query != nil {
|
||||
if err := nq.loadUser(ctx, query, nodes, nil,
|
||||
func(n *Notifier, e *User) { n.Edges.User = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (nq *NotifierQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*Notifier, init func(*Notifier), assign func(*Notifier, *User)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*Notifier)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].UserID
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "user_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (nq *NotifierQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*Notifier, init func(*Notifier), assign func(*Notifier, *Group)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*Notifier)
|
||||
|
@ -502,6 +473,35 @@ func (nq *NotifierQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes
|
|||
}
|
||||
return nil
|
||||
}
|
||||
func (nq *NotifierQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*Notifier, init func(*Notifier), assign func(*Notifier, *User)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*Notifier)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].UserID
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "user_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nq *NotifierQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := nq.querySpec()
|
||||
|
|
|
@ -37,18 +37,18 @@ func (nu *NotifierUpdate) SetUpdatedAt(t time.Time) *NotifierUpdate {
|
|||
return nu
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (nu *NotifierUpdate) SetUserID(u uuid.UUID) *NotifierUpdate {
|
||||
nu.mutation.SetUserID(u)
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetGroupID sets the "group_id" field.
|
||||
func (nu *NotifierUpdate) SetGroupID(u uuid.UUID) *NotifierUpdate {
|
||||
nu.mutation.SetGroupID(u)
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (nu *NotifierUpdate) SetUserID(u uuid.UUID) *NotifierUpdate {
|
||||
nu.mutation.SetUserID(u)
|
||||
return nu
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (nu *NotifierUpdate) SetName(s string) *NotifierUpdate {
|
||||
nu.mutation.SetName(s)
|
||||
|
@ -75,33 +75,33 @@ func (nu *NotifierUpdate) SetNillableIsActive(b *bool) *NotifierUpdate {
|
|||
return nu
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (nu *NotifierUpdate) SetUser(u *User) *NotifierUpdate {
|
||||
return nu.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// SetGroup sets the "group" edge to the Group entity.
|
||||
func (nu *NotifierUpdate) SetGroup(g *Group) *NotifierUpdate {
|
||||
return nu.SetGroupID(g.ID)
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (nu *NotifierUpdate) SetUser(u *User) *NotifierUpdate {
|
||||
return nu.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the NotifierMutation object of the builder.
|
||||
func (nu *NotifierUpdate) Mutation() *NotifierMutation {
|
||||
return nu.mutation
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (nu *NotifierUpdate) ClearUser() *NotifierUpdate {
|
||||
nu.mutation.ClearUser()
|
||||
return nu
|
||||
}
|
||||
|
||||
// ClearGroup clears the "group" edge to the Group entity.
|
||||
func (nu *NotifierUpdate) ClearGroup() *NotifierUpdate {
|
||||
nu.mutation.ClearGroup()
|
||||
return nu
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (nu *NotifierUpdate) ClearUser() *NotifierUpdate {
|
||||
nu.mutation.ClearUser()
|
||||
return nu
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (nu *NotifierUpdate) Save(ctx context.Context) (int, error) {
|
||||
nu.defaults()
|
||||
|
@ -150,12 +150,12 @@ func (nu *NotifierUpdate) check() error {
|
|||
return &ValidationError{Name: "url", err: fmt.Errorf(`ent: validator failed for field "Notifier.url": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := nu.mutation.UserID(); nu.mutation.UserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Notifier.user"`)
|
||||
}
|
||||
if _, ok := nu.mutation.GroupID(); nu.mutation.GroupCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Notifier.group"`)
|
||||
}
|
||||
if _, ok := nu.mutation.UserID(); nu.mutation.UserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Notifier.user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -183,41 +183,6 @@ func (nu *NotifierUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
if value, ok := nu.mutation.IsActive(); ok {
|
||||
_spec.SetField(notifier.FieldIsActive, field.TypeBool, value)
|
||||
}
|
||||
if nu.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.UserTable,
|
||||
Columns: []string{notifier.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nu.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.UserTable,
|
||||
Columns: []string{notifier.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if nu.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
|
@ -253,6 +218,41 @@ func (nu *NotifierUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if nu.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.UserTable,
|
||||
Columns: []string{notifier.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nu.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.UserTable,
|
||||
Columns: []string{notifier.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, nu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{notifier.Label}
|
||||
|
@ -279,18 +279,18 @@ func (nuo *NotifierUpdateOne) SetUpdatedAt(t time.Time) *NotifierUpdateOne {
|
|||
return nuo
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (nuo *NotifierUpdateOne) SetUserID(u uuid.UUID) *NotifierUpdateOne {
|
||||
nuo.mutation.SetUserID(u)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetGroupID sets the "group_id" field.
|
||||
func (nuo *NotifierUpdateOne) SetGroupID(u uuid.UUID) *NotifierUpdateOne {
|
||||
nuo.mutation.SetGroupID(u)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (nuo *NotifierUpdateOne) SetUserID(u uuid.UUID) *NotifierUpdateOne {
|
||||
nuo.mutation.SetUserID(u)
|
||||
return nuo
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (nuo *NotifierUpdateOne) SetName(s string) *NotifierUpdateOne {
|
||||
nuo.mutation.SetName(s)
|
||||
|
@ -317,33 +317,33 @@ func (nuo *NotifierUpdateOne) SetNillableIsActive(b *bool) *NotifierUpdateOne {
|
|||
return nuo
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (nuo *NotifierUpdateOne) SetUser(u *User) *NotifierUpdateOne {
|
||||
return nuo.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// SetGroup sets the "group" edge to the Group entity.
|
||||
func (nuo *NotifierUpdateOne) SetGroup(g *Group) *NotifierUpdateOne {
|
||||
return nuo.SetGroupID(g.ID)
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (nuo *NotifierUpdateOne) SetUser(u *User) *NotifierUpdateOne {
|
||||
return nuo.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the NotifierMutation object of the builder.
|
||||
func (nuo *NotifierUpdateOne) Mutation() *NotifierMutation {
|
||||
return nuo.mutation
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (nuo *NotifierUpdateOne) ClearUser() *NotifierUpdateOne {
|
||||
nuo.mutation.ClearUser()
|
||||
return nuo
|
||||
}
|
||||
|
||||
// ClearGroup clears the "group" edge to the Group entity.
|
||||
func (nuo *NotifierUpdateOne) ClearGroup() *NotifierUpdateOne {
|
||||
nuo.mutation.ClearGroup()
|
||||
return nuo
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (nuo *NotifierUpdateOne) ClearUser() *NotifierUpdateOne {
|
||||
nuo.mutation.ClearUser()
|
||||
return nuo
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NotifierUpdate builder.
|
||||
func (nuo *NotifierUpdateOne) Where(ps ...predicate.Notifier) *NotifierUpdateOne {
|
||||
nuo.mutation.Where(ps...)
|
||||
|
@ -405,12 +405,12 @@ func (nuo *NotifierUpdateOne) check() error {
|
|||
return &ValidationError{Name: "url", err: fmt.Errorf(`ent: validator failed for field "Notifier.url": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := nuo.mutation.UserID(); nuo.mutation.UserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Notifier.user"`)
|
||||
}
|
||||
if _, ok := nuo.mutation.GroupID(); nuo.mutation.GroupCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Notifier.group"`)
|
||||
}
|
||||
if _, ok := nuo.mutation.UserID(); nuo.mutation.UserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Notifier.user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -455,41 +455,6 @@ func (nuo *NotifierUpdateOne) sqlSave(ctx context.Context) (_node *Notifier, err
|
|||
if value, ok := nuo.mutation.IsActive(); ok {
|
||||
_spec.SetField(notifier.FieldIsActive, field.TypeBool, value)
|
||||
}
|
||||
if nuo.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.UserTable,
|
||||
Columns: []string{notifier.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nuo.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.UserTable,
|
||||
Columns: []string{notifier.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if nuo.mutation.GroupCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
|
@ -525,6 +490,41 @@ func (nuo *NotifierUpdateOne) sqlSave(ctx context.Context) (_node *Notifier, err
|
|||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if nuo.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.UserTable,
|
||||
Columns: []string{notifier.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := nuo.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: notifier.UserTable,
|
||||
Columns: []string{notifier.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeUUID,
|
||||
Column: user.FieldID,
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Notifier{config: nuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
|
|
@ -493,7 +493,7 @@ func init() {
|
|||
// notifier.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
notifier.UpdateDefaultUpdatedAt = notifierDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||
// notifierDescName is the schema descriptor for name field.
|
||||
notifierDescName := notifierFields[2].Descriptor()
|
||||
notifierDescName := notifierFields[0].Descriptor()
|
||||
// notifier.NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||
notifier.NameValidator = func() func(string) error {
|
||||
validators := notifierDescName.Validators
|
||||
|
@ -511,7 +511,7 @@ func init() {
|
|||
}
|
||||
}()
|
||||
// notifierDescURL is the schema descriptor for url field.
|
||||
notifierDescURL := notifierFields[3].Descriptor()
|
||||
notifierDescURL := notifierFields[1].Descriptor()
|
||||
// notifier.URLValidator is a validator for the "url" field. It is called by the builders before save.
|
||||
notifier.URLValidator = func() func(string) error {
|
||||
validators := notifierDescURL.Validators
|
||||
|
@ -529,7 +529,7 @@ func init() {
|
|||
}
|
||||
}()
|
||||
// notifierDescIsActive is the schema descriptor for is_active field.
|
||||
notifierDescIsActive := notifierFields[4].Descriptor()
|
||||
notifierDescIsActive := notifierFields[2].Descriptor()
|
||||
// notifier.DefaultIsActive holds the default value on creation for the is_active field.
|
||||
notifier.DefaultIsActive = notifierDescIsActive.Default.(bool)
|
||||
// notifierDescID is the schema descriptor for id field.
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/schema/mixins"
|
||||
)
|
||||
|
||||
|
@ -56,15 +57,31 @@ func (Group) Edges() []ent.Edge {
|
|||
// GroupMixin when embedded in an ent.Schema, adds a reference to
|
||||
// the Group entity.
|
||||
type GroupMixin struct {
|
||||
ref string
|
||||
ref string
|
||||
field string
|
||||
mixin.Schema
|
||||
}
|
||||
|
||||
func (g GroupMixin) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("group", Group.Type).
|
||||
Ref(g.ref).
|
||||
Unique().
|
||||
Required(),
|
||||
func (g GroupMixin) Fields() []ent.Field {
|
||||
if g.field != "" {
|
||||
return []ent.Field{
|
||||
field.UUID(g.field, uuid.UUID{}),
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (g GroupMixin) Edges() []ent.Edge {
|
||||
edge := edge.From("group", Group.Type).
|
||||
Ref(g.ref).
|
||||
Unique().
|
||||
Required()
|
||||
|
||||
if g.field != "" {
|
||||
edge = edge.Field(g.field)
|
||||
}
|
||||
|
||||
return []ent.Edge{edge}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,9 @@ package schema
|
|||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/schema/mixins"
|
||||
)
|
||||
|
||||
|
@ -17,14 +15,20 @@ type Notifier struct {
|
|||
func (Notifier) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
mixins.BaseMixin{},
|
||||
GroupMixin{
|
||||
ref: "notifiers",
|
||||
field: "group_id",
|
||||
},
|
||||
UserMixin{
|
||||
ref: "notifiers",
|
||||
field: "user_id",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the Notifier.
|
||||
func (Notifier) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("user_id", uuid.UUID{}),
|
||||
field.UUID("group_id", uuid.UUID{}),
|
||||
field.String("name").
|
||||
MaxLen(255).
|
||||
NotEmpty(),
|
||||
|
@ -37,22 +41,6 @@ func (Notifier) Fields() []ent.Field {
|
|||
}
|
||||
}
|
||||
|
||||
// Edges of the Notifier.
|
||||
func (Notifier) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("user", User.Type).
|
||||
Field("user_id").
|
||||
Ref("notifiers").
|
||||
Required().
|
||||
Unique(),
|
||||
edge.From("group", Group.Type).
|
||||
Field("group_id").
|
||||
Ref("notifiers").
|
||||
Required().
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Notifier) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("user_id"),
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/ent/schema/mixins"
|
||||
)
|
||||
|
||||
|
@ -59,3 +61,35 @@ func (User) Edges() []ent.Edge {
|
|||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// UserMixin when embedded in an ent.Schema, adds a reference to
|
||||
// the Group entity.
|
||||
type UserMixin struct {
|
||||
ref string
|
||||
field string
|
||||
mixin.Schema
|
||||
}
|
||||
|
||||
func (g UserMixin) Fields() []ent.Field {
|
||||
if g.field != "" {
|
||||
return []ent.Field{
|
||||
field.UUID(g.field, uuid.UUID{}),
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (g UserMixin) Edges() []ent.Edge {
|
||||
edge := edge.From("user", User.Type).
|
||||
Ref(g.ref).
|
||||
Unique().
|
||||
Required()
|
||||
|
||||
if g.field != "" {
|
||||
edge = edge.Field(g.field)
|
||||
}
|
||||
|
||||
return []ent.Edge{edge}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue