Files
holos/internal/ent/mutation.go
Jeff McCune 51b6575d9f (#171) Refactor to API Best Practices
This patch refactors the API to be resource-oriented around one service
per resource type.  PlatformService, OrganizationService, UserService,
etc...

Validation is improved to use CEL rules provided by [protovalidate][1].

Place holders for FieldMask and other best practices are added, but are
unimplemented as per [API Best Practices][2].

The intent is to set us up well for copying and pasting solid existing
examples as we add features.

With this patch the server and web app client are both updated to use
the refactored API, however the following are not working:

 1. Update the model.
 2. Field Masks.

[1]: https://buf.build/bufbuild/protovalidate
[2]: https://protobuf.dev/programming-guides/api/
2024-05-10 15:55:41 -07:00

2762 lines
81 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"sync"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/gofrs/uuid"
"github.com/holos-run/holos/internal/ent/organization"
"github.com/holos-run/holos/internal/ent/platform"
"github.com/holos-run/holos/internal/ent/predicate"
"github.com/holos-run/holos/internal/ent/user"
storage "github.com/holos-run/holos/service/gen/holos/storage/v1alpha1"
)
const (
// Operation types.
OpCreate = ent.OpCreate
OpDelete = ent.OpDelete
OpDeleteOne = ent.OpDeleteOne
OpUpdate = ent.OpUpdate
OpUpdateOne = ent.OpUpdateOne
// Node types.
TypeOrganization = "Organization"
TypePlatform = "Platform"
TypeUser = "User"
)
// OrganizationMutation represents an operation that mutates the Organization nodes in the graph.
type OrganizationMutation struct {
config
op Op
typ string
id *uuid.UUID
created_at *time.Time
updated_at *time.Time
name *string
display_name *string
clearedFields map[string]struct{}
creator *uuid.UUID
clearedcreator bool
editor *uuid.UUID
clearededitor bool
users map[uuid.UUID]struct{}
removedusers map[uuid.UUID]struct{}
clearedusers bool
platforms map[uuid.UUID]struct{}
removedplatforms map[uuid.UUID]struct{}
clearedplatforms bool
done bool
oldValue func(context.Context) (*Organization, error)
predicates []predicate.Organization
}
var _ ent.Mutation = (*OrganizationMutation)(nil)
// organizationOption allows management of the mutation configuration using functional options.
type organizationOption func(*OrganizationMutation)
// newOrganizationMutation creates new mutation for the Organization entity.
func newOrganizationMutation(c config, op Op, opts ...organizationOption) *OrganizationMutation {
m := &OrganizationMutation{
config: c,
op: op,
typ: TypeOrganization,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withOrganizationID sets the ID field of the mutation.
func withOrganizationID(id uuid.UUID) organizationOption {
return func(m *OrganizationMutation) {
var (
err error
once sync.Once
value *Organization
)
m.oldValue = func(ctx context.Context) (*Organization, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Organization.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withOrganization sets the old Organization of the mutation.
func withOrganization(node *Organization) organizationOption {
return func(m *OrganizationMutation) {
m.oldValue = func(context.Context) (*Organization, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m OrganizationMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m OrganizationMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Organization entities.
func (m *OrganizationMutation) SetID(id uuid.UUID) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *OrganizationMutation) ID() (id uuid.UUID, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *OrganizationMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []uuid.UUID{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().Organization.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreatedAt sets the "created_at" field.
func (m *OrganizationMutation) SetCreatedAt(t time.Time) {
m.created_at = &t
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *OrganizationMutation) CreatedAt() (r time.Time, exists bool) {
v := m.created_at
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "created_at" field's value of the Organization entity.
// If the Organization 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 *OrganizationMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
}
return oldValue.CreatedAt, nil
}
// ResetCreatedAt resets all changes to the "created_at" field.
func (m *OrganizationMutation) ResetCreatedAt() {
m.created_at = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *OrganizationMutation) SetUpdatedAt(t time.Time) {
m.updated_at = &t
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *OrganizationMutation) UpdatedAt() (r time.Time, exists bool) {
v := m.updated_at
if v == nil {
return
}
return *v, true
}
// OldUpdatedAt returns the old "updated_at" field's value of the Organization entity.
// If the Organization 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 *OrganizationMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
}
return oldValue.UpdatedAt, nil
}
// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *OrganizationMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// SetCreatedByID sets the "created_by_id" field.
func (m *OrganizationMutation) SetCreatedByID(u uuid.UUID) {
m.creator = &u
}
// CreatedByID returns the value of the "created_by_id" field in the mutation.
func (m *OrganizationMutation) CreatedByID() (r uuid.UUID, exists bool) {
v := m.creator
if v == nil {
return
}
return *v, true
}
// OldCreatedByID returns the old "created_by_id" field's value of the Organization entity.
// If the Organization 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 *OrganizationMutation) OldCreatedByID(ctx context.Context) (v uuid.UUID, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatedByID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatedByID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatedByID: %w", err)
}
return oldValue.CreatedByID, nil
}
// ResetCreatedByID resets all changes to the "created_by_id" field.
func (m *OrganizationMutation) ResetCreatedByID() {
m.creator = nil
}
// SetUpdatedByID sets the "updated_by_id" field.
func (m *OrganizationMutation) SetUpdatedByID(u uuid.UUID) {
m.editor = &u
}
// UpdatedByID returns the value of the "updated_by_id" field in the mutation.
func (m *OrganizationMutation) UpdatedByID() (r uuid.UUID, exists bool) {
v := m.editor
if v == nil {
return
}
return *v, true
}
// OldUpdatedByID returns the old "updated_by_id" field's value of the Organization entity.
// If the Organization 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 *OrganizationMutation) OldUpdatedByID(ctx context.Context) (v uuid.UUID, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdatedByID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdatedByID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdatedByID: %w", err)
}
return oldValue.UpdatedByID, nil
}
// ResetUpdatedByID resets all changes to the "updated_by_id" field.
func (m *OrganizationMutation) ResetUpdatedByID() {
m.editor = nil
}
// SetName sets the "name" field.
func (m *OrganizationMutation) SetName(s string) {
m.name = &s
}
// Name returns the value of the "name" field in the mutation.
func (m *OrganizationMutation) Name() (r string, exists bool) {
v := m.name
if v == nil {
return
}
return *v, true
}
// OldName returns the old "name" field's value of the Organization entity.
// If the Organization 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 *OrganizationMutation) OldName(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldName: %w", err)
}
return oldValue.Name, nil
}
// ResetName resets all changes to the "name" field.
func (m *OrganizationMutation) ResetName() {
m.name = nil
}
// SetDisplayName sets the "display_name" field.
func (m *OrganizationMutation) SetDisplayName(s string) {
m.display_name = &s
}
// DisplayName returns the value of the "display_name" field in the mutation.
func (m *OrganizationMutation) DisplayName() (r string, exists bool) {
v := m.display_name
if v == nil {
return
}
return *v, true
}
// OldDisplayName returns the old "display_name" field's value of the Organization entity.
// If the Organization 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 *OrganizationMutation) OldDisplayName(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDisplayName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDisplayName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDisplayName: %w", err)
}
return oldValue.DisplayName, nil
}
// ResetDisplayName resets all changes to the "display_name" field.
func (m *OrganizationMutation) ResetDisplayName() {
m.display_name = nil
}
// SetCreatorID sets the "creator" edge to the User entity by id.
func (m *OrganizationMutation) SetCreatorID(id uuid.UUID) {
m.creator = &id
}
// ClearCreator clears the "creator" edge to the User entity.
func (m *OrganizationMutation) ClearCreator() {
m.clearedcreator = true
m.clearedFields[organization.FieldCreatedByID] = struct{}{}
}
// CreatorCleared reports if the "creator" edge to the User entity was cleared.
func (m *OrganizationMutation) CreatorCleared() bool {
return m.clearedcreator
}
// CreatorID returns the "creator" edge ID in the mutation.
func (m *OrganizationMutation) CreatorID() (id uuid.UUID, exists bool) {
if m.creator != nil {
return *m.creator, true
}
return
}
// CreatorIDs returns the "creator" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// CreatorID instead. It exists only for internal usage by the builders.
func (m *OrganizationMutation) CreatorIDs() (ids []uuid.UUID) {
if id := m.creator; id != nil {
ids = append(ids, *id)
}
return
}
// ResetCreator resets all changes to the "creator" edge.
func (m *OrganizationMutation) ResetCreator() {
m.creator = nil
m.clearedcreator = false
}
// SetEditorID sets the "editor" edge to the User entity by id.
func (m *OrganizationMutation) SetEditorID(id uuid.UUID) {
m.editor = &id
}
// ClearEditor clears the "editor" edge to the User entity.
func (m *OrganizationMutation) ClearEditor() {
m.clearededitor = true
m.clearedFields[organization.FieldUpdatedByID] = struct{}{}
}
// EditorCleared reports if the "editor" edge to the User entity was cleared.
func (m *OrganizationMutation) EditorCleared() bool {
return m.clearededitor
}
// EditorID returns the "editor" edge ID in the mutation.
func (m *OrganizationMutation) EditorID() (id uuid.UUID, exists bool) {
if m.editor != nil {
return *m.editor, true
}
return
}
// EditorIDs returns the "editor" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// EditorID instead. It exists only for internal usage by the builders.
func (m *OrganizationMutation) EditorIDs() (ids []uuid.UUID) {
if id := m.editor; id != nil {
ids = append(ids, *id)
}
return
}
// ResetEditor resets all changes to the "editor" edge.
func (m *OrganizationMutation) ResetEditor() {
m.editor = nil
m.clearededitor = false
}
// AddUserIDs adds the "users" edge to the User entity by ids.
func (m *OrganizationMutation) AddUserIDs(ids ...uuid.UUID) {
if m.users == nil {
m.users = make(map[uuid.UUID]struct{})
}
for i := range ids {
m.users[ids[i]] = struct{}{}
}
}
// ClearUsers clears the "users" edge to the User entity.
func (m *OrganizationMutation) ClearUsers() {
m.clearedusers = true
}
// UsersCleared reports if the "users" edge to the User entity was cleared.
func (m *OrganizationMutation) UsersCleared() bool {
return m.clearedusers
}
// RemoveUserIDs removes the "users" edge to the User entity by IDs.
func (m *OrganizationMutation) RemoveUserIDs(ids ...uuid.UUID) {
if m.removedusers == nil {
m.removedusers = make(map[uuid.UUID]struct{})
}
for i := range ids {
delete(m.users, ids[i])
m.removedusers[ids[i]] = struct{}{}
}
}
// RemovedUsers returns the removed IDs of the "users" edge to the User entity.
func (m *OrganizationMutation) RemovedUsersIDs() (ids []uuid.UUID) {
for id := range m.removedusers {
ids = append(ids, id)
}
return
}
// UsersIDs returns the "users" edge IDs in the mutation.
func (m *OrganizationMutation) UsersIDs() (ids []uuid.UUID) {
for id := range m.users {
ids = append(ids, id)
}
return
}
// ResetUsers resets all changes to the "users" edge.
func (m *OrganizationMutation) ResetUsers() {
m.users = nil
m.clearedusers = false
m.removedusers = nil
}
// AddPlatformIDs adds the "platforms" edge to the Platform entity by ids.
func (m *OrganizationMutation) AddPlatformIDs(ids ...uuid.UUID) {
if m.platforms == nil {
m.platforms = make(map[uuid.UUID]struct{})
}
for i := range ids {
m.platforms[ids[i]] = struct{}{}
}
}
// ClearPlatforms clears the "platforms" edge to the Platform entity.
func (m *OrganizationMutation) ClearPlatforms() {
m.clearedplatforms = true
}
// PlatformsCleared reports if the "platforms" edge to the Platform entity was cleared.
func (m *OrganizationMutation) PlatformsCleared() bool {
return m.clearedplatforms
}
// RemovePlatformIDs removes the "platforms" edge to the Platform entity by IDs.
func (m *OrganizationMutation) RemovePlatformIDs(ids ...uuid.UUID) {
if m.removedplatforms == nil {
m.removedplatforms = make(map[uuid.UUID]struct{})
}
for i := range ids {
delete(m.platforms, ids[i])
m.removedplatforms[ids[i]] = struct{}{}
}
}
// RemovedPlatforms returns the removed IDs of the "platforms" edge to the Platform entity.
func (m *OrganizationMutation) RemovedPlatformsIDs() (ids []uuid.UUID) {
for id := range m.removedplatforms {
ids = append(ids, id)
}
return
}
// PlatformsIDs returns the "platforms" edge IDs in the mutation.
func (m *OrganizationMutation) PlatformsIDs() (ids []uuid.UUID) {
for id := range m.platforms {
ids = append(ids, id)
}
return
}
// ResetPlatforms resets all changes to the "platforms" edge.
func (m *OrganizationMutation) ResetPlatforms() {
m.platforms = nil
m.clearedplatforms = false
m.removedplatforms = nil
}
// Where appends a list predicates to the OrganizationMutation builder.
func (m *OrganizationMutation) Where(ps ...predicate.Organization) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the OrganizationMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *OrganizationMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.Organization, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *OrganizationMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *OrganizationMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (Organization).
func (m *OrganizationMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *OrganizationMutation) Fields() []string {
fields := make([]string, 0, 6)
if m.created_at != nil {
fields = append(fields, organization.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, organization.FieldUpdatedAt)
}
if m.creator != nil {
fields = append(fields, organization.FieldCreatedByID)
}
if m.editor != nil {
fields = append(fields, organization.FieldUpdatedByID)
}
if m.name != nil {
fields = append(fields, organization.FieldName)
}
if m.display_name != nil {
fields = append(fields, organization.FieldDisplayName)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *OrganizationMutation) Field(name string) (ent.Value, bool) {
switch name {
case organization.FieldCreatedAt:
return m.CreatedAt()
case organization.FieldUpdatedAt:
return m.UpdatedAt()
case organization.FieldCreatedByID:
return m.CreatedByID()
case organization.FieldUpdatedByID:
return m.UpdatedByID()
case organization.FieldName:
return m.Name()
case organization.FieldDisplayName:
return m.DisplayName()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *OrganizationMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case organization.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case organization.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
case organization.FieldCreatedByID:
return m.OldCreatedByID(ctx)
case organization.FieldUpdatedByID:
return m.OldUpdatedByID(ctx)
case organization.FieldName:
return m.OldName(ctx)
case organization.FieldDisplayName:
return m.OldDisplayName(ctx)
}
return nil, fmt.Errorf("unknown Organization field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *OrganizationMutation) SetField(name string, value ent.Value) error {
switch name {
case organization.FieldCreatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedAt(v)
return nil
case organization.FieldUpdatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
case organization.FieldCreatedByID:
v, ok := value.(uuid.UUID)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedByID(v)
return nil
case organization.FieldUpdatedByID:
v, ok := value.(uuid.UUID)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedByID(v)
return nil
case organization.FieldName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetName(v)
return nil
case organization.FieldDisplayName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDisplayName(v)
return nil
}
return fmt.Errorf("unknown Organization field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *OrganizationMutation) AddedFields() []string {
return nil
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *OrganizationMutation) AddedField(name string) (ent.Value, bool) {
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *OrganizationMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown Organization numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *OrganizationMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *OrganizationMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *OrganizationMutation) ClearField(name string) error {
return fmt.Errorf("unknown Organization nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *OrganizationMutation) ResetField(name string) error {
switch name {
case organization.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case organization.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
case organization.FieldCreatedByID:
m.ResetCreatedByID()
return nil
case organization.FieldUpdatedByID:
m.ResetUpdatedByID()
return nil
case organization.FieldName:
m.ResetName()
return nil
case organization.FieldDisplayName:
m.ResetDisplayName()
return nil
}
return fmt.Errorf("unknown Organization field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *OrganizationMutation) AddedEdges() []string {
edges := make([]string, 0, 4)
if m.creator != nil {
edges = append(edges, organization.EdgeCreator)
}
if m.editor != nil {
edges = append(edges, organization.EdgeEditor)
}
if m.users != nil {
edges = append(edges, organization.EdgeUsers)
}
if m.platforms != nil {
edges = append(edges, organization.EdgePlatforms)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *OrganizationMutation) AddedIDs(name string) []ent.Value {
switch name {
case organization.EdgeCreator:
if id := m.creator; id != nil {
return []ent.Value{*id}
}
case organization.EdgeEditor:
if id := m.editor; id != nil {
return []ent.Value{*id}
}
case organization.EdgeUsers:
ids := make([]ent.Value, 0, len(m.users))
for id := range m.users {
ids = append(ids, id)
}
return ids
case organization.EdgePlatforms:
ids := make([]ent.Value, 0, len(m.platforms))
for id := range m.platforms {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *OrganizationMutation) RemovedEdges() []string {
edges := make([]string, 0, 4)
if m.removedusers != nil {
edges = append(edges, organization.EdgeUsers)
}
if m.removedplatforms != nil {
edges = append(edges, organization.EdgePlatforms)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *OrganizationMutation) RemovedIDs(name string) []ent.Value {
switch name {
case organization.EdgeUsers:
ids := make([]ent.Value, 0, len(m.removedusers))
for id := range m.removedusers {
ids = append(ids, id)
}
return ids
case organization.EdgePlatforms:
ids := make([]ent.Value, 0, len(m.removedplatforms))
for id := range m.removedplatforms {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *OrganizationMutation) ClearedEdges() []string {
edges := make([]string, 0, 4)
if m.clearedcreator {
edges = append(edges, organization.EdgeCreator)
}
if m.clearededitor {
edges = append(edges, organization.EdgeEditor)
}
if m.clearedusers {
edges = append(edges, organization.EdgeUsers)
}
if m.clearedplatforms {
edges = append(edges, organization.EdgePlatforms)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *OrganizationMutation) EdgeCleared(name string) bool {
switch name {
case organization.EdgeCreator:
return m.clearedcreator
case organization.EdgeEditor:
return m.clearededitor
case organization.EdgeUsers:
return m.clearedusers
case organization.EdgePlatforms:
return m.clearedplatforms
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *OrganizationMutation) ClearEdge(name string) error {
switch name {
case organization.EdgeCreator:
m.ClearCreator()
return nil
case organization.EdgeEditor:
m.ClearEditor()
return nil
}
return fmt.Errorf("unknown Organization unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *OrganizationMutation) ResetEdge(name string) error {
switch name {
case organization.EdgeCreator:
m.ResetCreator()
return nil
case organization.EdgeEditor:
m.ResetEditor()
return nil
case organization.EdgeUsers:
m.ResetUsers()
return nil
case organization.EdgePlatforms:
m.ResetPlatforms()
return nil
}
return fmt.Errorf("unknown Organization edge %s", name)
}
// PlatformMutation represents an operation that mutates the Platform nodes in the graph.
type PlatformMutation struct {
config
op Op
typ string
id *uuid.UUID
created_at *time.Time
updated_at *time.Time
name *string
display_name *string
form **storage.Form
model **storage.Model
cue *[]byte
cue_definition *string
clearedFields map[string]struct{}
creator *uuid.UUID
clearedcreator bool
editor *uuid.UUID
clearededitor bool
organization *uuid.UUID
clearedorganization bool
done bool
oldValue func(context.Context) (*Platform, error)
predicates []predicate.Platform
}
var _ ent.Mutation = (*PlatformMutation)(nil)
// platformOption allows management of the mutation configuration using functional options.
type platformOption func(*PlatformMutation)
// newPlatformMutation creates new mutation for the Platform entity.
func newPlatformMutation(c config, op Op, opts ...platformOption) *PlatformMutation {
m := &PlatformMutation{
config: c,
op: op,
typ: TypePlatform,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withPlatformID sets the ID field of the mutation.
func withPlatformID(id uuid.UUID) platformOption {
return func(m *PlatformMutation) {
var (
err error
once sync.Once
value *Platform
)
m.oldValue = func(ctx context.Context) (*Platform, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Platform.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withPlatform sets the old Platform of the mutation.
func withPlatform(node *Platform) platformOption {
return func(m *PlatformMutation) {
m.oldValue = func(context.Context) (*Platform, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m PlatformMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m PlatformMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Platform entities.
func (m *PlatformMutation) SetID(id uuid.UUID) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *PlatformMutation) ID() (id uuid.UUID, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *PlatformMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []uuid.UUID{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().Platform.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreatedAt sets the "created_at" field.
func (m *PlatformMutation) SetCreatedAt(t time.Time) {
m.created_at = &t
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *PlatformMutation) CreatedAt() (r time.Time, exists bool) {
v := m.created_at
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "created_at" field's value of the Platform entity.
// If the Platform 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 *PlatformMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
}
return oldValue.CreatedAt, nil
}
// ResetCreatedAt resets all changes to the "created_at" field.
func (m *PlatformMutation) ResetCreatedAt() {
m.created_at = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *PlatformMutation) SetUpdatedAt(t time.Time) {
m.updated_at = &t
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *PlatformMutation) UpdatedAt() (r time.Time, exists bool) {
v := m.updated_at
if v == nil {
return
}
return *v, true
}
// OldUpdatedAt returns the old "updated_at" field's value of the Platform entity.
// If the Platform 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 *PlatformMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
}
return oldValue.UpdatedAt, nil
}
// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *PlatformMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// SetCreatedByID sets the "created_by_id" field.
func (m *PlatformMutation) SetCreatedByID(u uuid.UUID) {
m.creator = &u
}
// CreatedByID returns the value of the "created_by_id" field in the mutation.
func (m *PlatformMutation) CreatedByID() (r uuid.UUID, exists bool) {
v := m.creator
if v == nil {
return
}
return *v, true
}
// OldCreatedByID returns the old "created_by_id" field's value of the Platform entity.
// If the Platform 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 *PlatformMutation) OldCreatedByID(ctx context.Context) (v uuid.UUID, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatedByID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatedByID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatedByID: %w", err)
}
return oldValue.CreatedByID, nil
}
// ResetCreatedByID resets all changes to the "created_by_id" field.
func (m *PlatformMutation) ResetCreatedByID() {
m.creator = nil
}
// SetUpdatedByID sets the "updated_by_id" field.
func (m *PlatformMutation) SetUpdatedByID(u uuid.UUID) {
m.editor = &u
}
// UpdatedByID returns the value of the "updated_by_id" field in the mutation.
func (m *PlatformMutation) UpdatedByID() (r uuid.UUID, exists bool) {
v := m.editor
if v == nil {
return
}
return *v, true
}
// OldUpdatedByID returns the old "updated_by_id" field's value of the Platform entity.
// If the Platform 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 *PlatformMutation) OldUpdatedByID(ctx context.Context) (v uuid.UUID, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdatedByID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdatedByID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdatedByID: %w", err)
}
return oldValue.UpdatedByID, nil
}
// ResetUpdatedByID resets all changes to the "updated_by_id" field.
func (m *PlatformMutation) ResetUpdatedByID() {
m.editor = nil
}
// SetOrgID sets the "org_id" field.
func (m *PlatformMutation) SetOrgID(u uuid.UUID) {
m.organization = &u
}
// OrgID returns the value of the "org_id" field in the mutation.
func (m *PlatformMutation) OrgID() (r uuid.UUID, exists bool) {
v := m.organization
if v == nil {
return
}
return *v, true
}
// OldOrgID returns the old "org_id" field's value of the Platform entity.
// If the Platform 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 *PlatformMutation) OldOrgID(ctx context.Context) (v uuid.UUID, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldOrgID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldOrgID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldOrgID: %w", err)
}
return oldValue.OrgID, nil
}
// ResetOrgID resets all changes to the "org_id" field.
func (m *PlatformMutation) ResetOrgID() {
m.organization = nil
}
// SetName sets the "name" field.
func (m *PlatformMutation) SetName(s string) {
m.name = &s
}
// Name returns the value of the "name" field in the mutation.
func (m *PlatformMutation) Name() (r string, exists bool) {
v := m.name
if v == nil {
return
}
return *v, true
}
// OldName returns the old "name" field's value of the Platform entity.
// If the Platform 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 *PlatformMutation) OldName(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldName: %w", err)
}
return oldValue.Name, nil
}
// ResetName resets all changes to the "name" field.
func (m *PlatformMutation) ResetName() {
m.name = nil
}
// SetDisplayName sets the "display_name" field.
func (m *PlatformMutation) SetDisplayName(s string) {
m.display_name = &s
}
// DisplayName returns the value of the "display_name" field in the mutation.
func (m *PlatformMutation) DisplayName() (r string, exists bool) {
v := m.display_name
if v == nil {
return
}
return *v, true
}
// OldDisplayName returns the old "display_name" field's value of the Platform entity.
// If the Platform 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 *PlatformMutation) OldDisplayName(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDisplayName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDisplayName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDisplayName: %w", err)
}
return oldValue.DisplayName, nil
}
// ResetDisplayName resets all changes to the "display_name" field.
func (m *PlatformMutation) ResetDisplayName() {
m.display_name = nil
}
// SetForm sets the "form" field.
func (m *PlatformMutation) SetForm(s *storage.Form) {
m.form = &s
}
// Form returns the value of the "form" field in the mutation.
func (m *PlatformMutation) Form() (r *storage.Form, exists bool) {
v := m.form
if v == nil {
return
}
return *v, true
}
// OldForm returns the old "form" field's value of the Platform entity.
// If the Platform 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 *PlatformMutation) OldForm(ctx context.Context) (v *storage.Form, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldForm is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldForm requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldForm: %w", err)
}
return oldValue.Form, nil
}
// ClearForm clears the value of the "form" field.
func (m *PlatformMutation) ClearForm() {
m.form = nil
m.clearedFields[platform.FieldForm] = struct{}{}
}
// FormCleared returns if the "form" field was cleared in this mutation.
func (m *PlatformMutation) FormCleared() bool {
_, ok := m.clearedFields[platform.FieldForm]
return ok
}
// ResetForm resets all changes to the "form" field.
func (m *PlatformMutation) ResetForm() {
m.form = nil
delete(m.clearedFields, platform.FieldForm)
}
// SetModel sets the "model" field.
func (m *PlatformMutation) SetModel(s *storage.Model) {
m.model = &s
}
// Model returns the value of the "model" field in the mutation.
func (m *PlatformMutation) Model() (r *storage.Model, exists bool) {
v := m.model
if v == nil {
return
}
return *v, true
}
// OldModel returns the old "model" field's value of the Platform entity.
// If the Platform 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 *PlatformMutation) OldModel(ctx context.Context) (v *storage.Model, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldModel is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldModel requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldModel: %w", err)
}
return oldValue.Model, nil
}
// ClearModel clears the value of the "model" field.
func (m *PlatformMutation) ClearModel() {
m.model = nil
m.clearedFields[platform.FieldModel] = struct{}{}
}
// ModelCleared returns if the "model" field was cleared in this mutation.
func (m *PlatformMutation) ModelCleared() bool {
_, ok := m.clearedFields[platform.FieldModel]
return ok
}
// ResetModel resets all changes to the "model" field.
func (m *PlatformMutation) ResetModel() {
m.model = nil
delete(m.clearedFields, platform.FieldModel)
}
// SetCue sets the "cue" field.
func (m *PlatformMutation) SetCue(b []byte) {
m.cue = &b
}
// Cue returns the value of the "cue" field in the mutation.
func (m *PlatformMutation) Cue() (r []byte, exists bool) {
v := m.cue
if v == nil {
return
}
return *v, true
}
// OldCue returns the old "cue" field's value of the Platform entity.
// If the Platform 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 *PlatformMutation) OldCue(ctx context.Context) (v []byte, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCue is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCue requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCue: %w", err)
}
return oldValue.Cue, nil
}
// ClearCue clears the value of the "cue" field.
func (m *PlatformMutation) ClearCue() {
m.cue = nil
m.clearedFields[platform.FieldCue] = struct{}{}
}
// CueCleared returns if the "cue" field was cleared in this mutation.
func (m *PlatformMutation) CueCleared() bool {
_, ok := m.clearedFields[platform.FieldCue]
return ok
}
// ResetCue resets all changes to the "cue" field.
func (m *PlatformMutation) ResetCue() {
m.cue = nil
delete(m.clearedFields, platform.FieldCue)
}
// SetCueDefinition sets the "cue_definition" field.
func (m *PlatformMutation) SetCueDefinition(s string) {
m.cue_definition = &s
}
// CueDefinition returns the value of the "cue_definition" field in the mutation.
func (m *PlatformMutation) CueDefinition() (r string, exists bool) {
v := m.cue_definition
if v == nil {
return
}
return *v, true
}
// OldCueDefinition returns the old "cue_definition" field's value of the Platform entity.
// If the Platform 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 *PlatformMutation) OldCueDefinition(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCueDefinition is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCueDefinition requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCueDefinition: %w", err)
}
return oldValue.CueDefinition, nil
}
// ClearCueDefinition clears the value of the "cue_definition" field.
func (m *PlatformMutation) ClearCueDefinition() {
m.cue_definition = nil
m.clearedFields[platform.FieldCueDefinition] = struct{}{}
}
// CueDefinitionCleared returns if the "cue_definition" field was cleared in this mutation.
func (m *PlatformMutation) CueDefinitionCleared() bool {
_, ok := m.clearedFields[platform.FieldCueDefinition]
return ok
}
// ResetCueDefinition resets all changes to the "cue_definition" field.
func (m *PlatformMutation) ResetCueDefinition() {
m.cue_definition = nil
delete(m.clearedFields, platform.FieldCueDefinition)
}
// SetCreatorID sets the "creator" edge to the User entity by id.
func (m *PlatformMutation) SetCreatorID(id uuid.UUID) {
m.creator = &id
}
// ClearCreator clears the "creator" edge to the User entity.
func (m *PlatformMutation) ClearCreator() {
m.clearedcreator = true
m.clearedFields[platform.FieldCreatedByID] = struct{}{}
}
// CreatorCleared reports if the "creator" edge to the User entity was cleared.
func (m *PlatformMutation) CreatorCleared() bool {
return m.clearedcreator
}
// CreatorID returns the "creator" edge ID in the mutation.
func (m *PlatformMutation) CreatorID() (id uuid.UUID, exists bool) {
if m.creator != nil {
return *m.creator, true
}
return
}
// CreatorIDs returns the "creator" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// CreatorID instead. It exists only for internal usage by the builders.
func (m *PlatformMutation) CreatorIDs() (ids []uuid.UUID) {
if id := m.creator; id != nil {
ids = append(ids, *id)
}
return
}
// ResetCreator resets all changes to the "creator" edge.
func (m *PlatformMutation) ResetCreator() {
m.creator = nil
m.clearedcreator = false
}
// SetEditorID sets the "editor" edge to the User entity by id.
func (m *PlatformMutation) SetEditorID(id uuid.UUID) {
m.editor = &id
}
// ClearEditor clears the "editor" edge to the User entity.
func (m *PlatformMutation) ClearEditor() {
m.clearededitor = true
m.clearedFields[platform.FieldUpdatedByID] = struct{}{}
}
// EditorCleared reports if the "editor" edge to the User entity was cleared.
func (m *PlatformMutation) EditorCleared() bool {
return m.clearededitor
}
// EditorID returns the "editor" edge ID in the mutation.
func (m *PlatformMutation) EditorID() (id uuid.UUID, exists bool) {
if m.editor != nil {
return *m.editor, true
}
return
}
// EditorIDs returns the "editor" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// EditorID instead. It exists only for internal usage by the builders.
func (m *PlatformMutation) EditorIDs() (ids []uuid.UUID) {
if id := m.editor; id != nil {
ids = append(ids, *id)
}
return
}
// ResetEditor resets all changes to the "editor" edge.
func (m *PlatformMutation) ResetEditor() {
m.editor = nil
m.clearededitor = false
}
// SetOrganizationID sets the "organization" edge to the Organization entity by id.
func (m *PlatformMutation) SetOrganizationID(id uuid.UUID) {
m.organization = &id
}
// ClearOrganization clears the "organization" edge to the Organization entity.
func (m *PlatformMutation) ClearOrganization() {
m.clearedorganization = true
m.clearedFields[platform.FieldOrgID] = struct{}{}
}
// OrganizationCleared reports if the "organization" edge to the Organization entity was cleared.
func (m *PlatformMutation) OrganizationCleared() bool {
return m.clearedorganization
}
// OrganizationID returns the "organization" edge ID in the mutation.
func (m *PlatformMutation) OrganizationID() (id uuid.UUID, exists bool) {
if m.organization != nil {
return *m.organization, true
}
return
}
// OrganizationIDs returns the "organization" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// OrganizationID instead. It exists only for internal usage by the builders.
func (m *PlatformMutation) OrganizationIDs() (ids []uuid.UUID) {
if id := m.organization; id != nil {
ids = append(ids, *id)
}
return
}
// ResetOrganization resets all changes to the "organization" edge.
func (m *PlatformMutation) ResetOrganization() {
m.organization = nil
m.clearedorganization = false
}
// Where appends a list predicates to the PlatformMutation builder.
func (m *PlatformMutation) Where(ps ...predicate.Platform) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the PlatformMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *PlatformMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.Platform, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *PlatformMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *PlatformMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (Platform).
func (m *PlatformMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *PlatformMutation) Fields() []string {
fields := make([]string, 0, 11)
if m.created_at != nil {
fields = append(fields, platform.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, platform.FieldUpdatedAt)
}
if m.creator != nil {
fields = append(fields, platform.FieldCreatedByID)
}
if m.editor != nil {
fields = append(fields, platform.FieldUpdatedByID)
}
if m.organization != nil {
fields = append(fields, platform.FieldOrgID)
}
if m.name != nil {
fields = append(fields, platform.FieldName)
}
if m.display_name != nil {
fields = append(fields, platform.FieldDisplayName)
}
if m.form != nil {
fields = append(fields, platform.FieldForm)
}
if m.model != nil {
fields = append(fields, platform.FieldModel)
}
if m.cue != nil {
fields = append(fields, platform.FieldCue)
}
if m.cue_definition != nil {
fields = append(fields, platform.FieldCueDefinition)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *PlatformMutation) Field(name string) (ent.Value, bool) {
switch name {
case platform.FieldCreatedAt:
return m.CreatedAt()
case platform.FieldUpdatedAt:
return m.UpdatedAt()
case platform.FieldCreatedByID:
return m.CreatedByID()
case platform.FieldUpdatedByID:
return m.UpdatedByID()
case platform.FieldOrgID:
return m.OrgID()
case platform.FieldName:
return m.Name()
case platform.FieldDisplayName:
return m.DisplayName()
case platform.FieldForm:
return m.Form()
case platform.FieldModel:
return m.Model()
case platform.FieldCue:
return m.Cue()
case platform.FieldCueDefinition:
return m.CueDefinition()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *PlatformMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case platform.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case platform.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
case platform.FieldCreatedByID:
return m.OldCreatedByID(ctx)
case platform.FieldUpdatedByID:
return m.OldUpdatedByID(ctx)
case platform.FieldOrgID:
return m.OldOrgID(ctx)
case platform.FieldName:
return m.OldName(ctx)
case platform.FieldDisplayName:
return m.OldDisplayName(ctx)
case platform.FieldForm:
return m.OldForm(ctx)
case platform.FieldModel:
return m.OldModel(ctx)
case platform.FieldCue:
return m.OldCue(ctx)
case platform.FieldCueDefinition:
return m.OldCueDefinition(ctx)
}
return nil, fmt.Errorf("unknown Platform field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *PlatformMutation) SetField(name string, value ent.Value) error {
switch name {
case platform.FieldCreatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedAt(v)
return nil
case platform.FieldUpdatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
case platform.FieldCreatedByID:
v, ok := value.(uuid.UUID)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedByID(v)
return nil
case platform.FieldUpdatedByID:
v, ok := value.(uuid.UUID)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedByID(v)
return nil
case platform.FieldOrgID:
v, ok := value.(uuid.UUID)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetOrgID(v)
return nil
case platform.FieldName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetName(v)
return nil
case platform.FieldDisplayName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDisplayName(v)
return nil
case platform.FieldForm:
v, ok := value.(*storage.Form)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetForm(v)
return nil
case platform.FieldModel:
v, ok := value.(*storage.Model)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetModel(v)
return nil
case platform.FieldCue:
v, ok := value.([]byte)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCue(v)
return nil
case platform.FieldCueDefinition:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCueDefinition(v)
return nil
}
return fmt.Errorf("unknown Platform field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *PlatformMutation) AddedFields() []string {
return nil
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *PlatformMutation) AddedField(name string) (ent.Value, bool) {
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *PlatformMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown Platform numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *PlatformMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(platform.FieldForm) {
fields = append(fields, platform.FieldForm)
}
if m.FieldCleared(platform.FieldModel) {
fields = append(fields, platform.FieldModel)
}
if m.FieldCleared(platform.FieldCue) {
fields = append(fields, platform.FieldCue)
}
if m.FieldCleared(platform.FieldCueDefinition) {
fields = append(fields, platform.FieldCueDefinition)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *PlatformMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *PlatformMutation) ClearField(name string) error {
switch name {
case platform.FieldForm:
m.ClearForm()
return nil
case platform.FieldModel:
m.ClearModel()
return nil
case platform.FieldCue:
m.ClearCue()
return nil
case platform.FieldCueDefinition:
m.ClearCueDefinition()
return nil
}
return fmt.Errorf("unknown Platform nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *PlatformMutation) ResetField(name string) error {
switch name {
case platform.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case platform.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
case platform.FieldCreatedByID:
m.ResetCreatedByID()
return nil
case platform.FieldUpdatedByID:
m.ResetUpdatedByID()
return nil
case platform.FieldOrgID:
m.ResetOrgID()
return nil
case platform.FieldName:
m.ResetName()
return nil
case platform.FieldDisplayName:
m.ResetDisplayName()
return nil
case platform.FieldForm:
m.ResetForm()
return nil
case platform.FieldModel:
m.ResetModel()
return nil
case platform.FieldCue:
m.ResetCue()
return nil
case platform.FieldCueDefinition:
m.ResetCueDefinition()
return nil
}
return fmt.Errorf("unknown Platform field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *PlatformMutation) AddedEdges() []string {
edges := make([]string, 0, 3)
if m.creator != nil {
edges = append(edges, platform.EdgeCreator)
}
if m.editor != nil {
edges = append(edges, platform.EdgeEditor)
}
if m.organization != nil {
edges = append(edges, platform.EdgeOrganization)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *PlatformMutation) AddedIDs(name string) []ent.Value {
switch name {
case platform.EdgeCreator:
if id := m.creator; id != nil {
return []ent.Value{*id}
}
case platform.EdgeEditor:
if id := m.editor; id != nil {
return []ent.Value{*id}
}
case platform.EdgeOrganization:
if id := m.organization; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *PlatformMutation) RemovedEdges() []string {
edges := make([]string, 0, 3)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *PlatformMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *PlatformMutation) ClearedEdges() []string {
edges := make([]string, 0, 3)
if m.clearedcreator {
edges = append(edges, platform.EdgeCreator)
}
if m.clearededitor {
edges = append(edges, platform.EdgeEditor)
}
if m.clearedorganization {
edges = append(edges, platform.EdgeOrganization)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *PlatformMutation) EdgeCleared(name string) bool {
switch name {
case platform.EdgeCreator:
return m.clearedcreator
case platform.EdgeEditor:
return m.clearededitor
case platform.EdgeOrganization:
return m.clearedorganization
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *PlatformMutation) ClearEdge(name string) error {
switch name {
case platform.EdgeCreator:
m.ClearCreator()
return nil
case platform.EdgeEditor:
m.ClearEditor()
return nil
case platform.EdgeOrganization:
m.ClearOrganization()
return nil
}
return fmt.Errorf("unknown Platform unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *PlatformMutation) ResetEdge(name string) error {
switch name {
case platform.EdgeCreator:
m.ResetCreator()
return nil
case platform.EdgeEditor:
m.ResetEditor()
return nil
case platform.EdgeOrganization:
m.ResetOrganization()
return nil
}
return fmt.Errorf("unknown Platform edge %s", name)
}
// UserMutation represents an operation that mutates the User nodes in the graph.
type UserMutation struct {
config
op Op
typ string
id *uuid.UUID
created_at *time.Time
updated_at *time.Time
email *string
iss *string
sub *string
name *string
clearedFields map[string]struct{}
organizations map[uuid.UUID]struct{}
removedorganizations map[uuid.UUID]struct{}
clearedorganizations bool
done bool
oldValue func(context.Context) (*User, error)
predicates []predicate.User
}
var _ ent.Mutation = (*UserMutation)(nil)
// userOption allows management of the mutation configuration using functional options.
type userOption func(*UserMutation)
// newUserMutation creates new mutation for the User entity.
func newUserMutation(c config, op Op, opts ...userOption) *UserMutation {
m := &UserMutation{
config: c,
op: op,
typ: TypeUser,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withUserID sets the ID field of the mutation.
func withUserID(id uuid.UUID) userOption {
return func(m *UserMutation) {
var (
err error
once sync.Once
value *User
)
m.oldValue = func(ctx context.Context) (*User, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().User.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withUser sets the old User of the mutation.
func withUser(node *User) userOption {
return func(m *UserMutation) {
m.oldValue = func(context.Context) (*User, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m UserMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m UserMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of User entities.
func (m *UserMutation) SetID(id uuid.UUID) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *UserMutation) ID() (id uuid.UUID, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *UserMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []uuid.UUID{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().User.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreatedAt sets the "created_at" field.
func (m *UserMutation) SetCreatedAt(t time.Time) {
m.created_at = &t
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *UserMutation) CreatedAt() (r time.Time, exists bool) {
v := m.created_at
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "created_at" field's value of the User entity.
// If the User 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 *UserMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
}
return oldValue.CreatedAt, nil
}
// ResetCreatedAt resets all changes to the "created_at" field.
func (m *UserMutation) ResetCreatedAt() {
m.created_at = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *UserMutation) SetUpdatedAt(t time.Time) {
m.updated_at = &t
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *UserMutation) UpdatedAt() (r time.Time, exists bool) {
v := m.updated_at
if v == nil {
return
}
return *v, true
}
// OldUpdatedAt returns the old "updated_at" field's value of the User entity.
// If the User 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 *UserMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
}
return oldValue.UpdatedAt, nil
}
// ResetUpdatedAt resets all changes to the "updated_at" field.
func (m *UserMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// SetEmail sets the "email" field.
func (m *UserMutation) SetEmail(s string) {
m.email = &s
}
// Email returns the value of the "email" field in the mutation.
func (m *UserMutation) Email() (r string, exists bool) {
v := m.email
if v == nil {
return
}
return *v, true
}
// OldEmail returns the old "email" field's value of the User entity.
// If the User 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 *UserMutation) OldEmail(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldEmail is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldEmail requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldEmail: %w", err)
}
return oldValue.Email, nil
}
// ResetEmail resets all changes to the "email" field.
func (m *UserMutation) ResetEmail() {
m.email = nil
}
// SetIss sets the "iss" field.
func (m *UserMutation) SetIss(s string) {
m.iss = &s
}
// Iss returns the value of the "iss" field in the mutation.
func (m *UserMutation) Iss() (r string, exists bool) {
v := m.iss
if v == nil {
return
}
return *v, true
}
// OldIss returns the old "iss" field's value of the User entity.
// If the User 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 *UserMutation) OldIss(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIss is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIss requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIss: %w", err)
}
return oldValue.Iss, nil
}
// ResetIss resets all changes to the "iss" field.
func (m *UserMutation) ResetIss() {
m.iss = nil
}
// SetSub sets the "sub" field.
func (m *UserMutation) SetSub(s string) {
m.sub = &s
}
// Sub returns the value of the "sub" field in the mutation.
func (m *UserMutation) Sub() (r string, exists bool) {
v := m.sub
if v == nil {
return
}
return *v, true
}
// OldSub returns the old "sub" field's value of the User entity.
// If the User 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 *UserMutation) OldSub(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSub is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSub requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSub: %w", err)
}
return oldValue.Sub, nil
}
// ResetSub resets all changes to the "sub" field.
func (m *UserMutation) ResetSub() {
m.sub = nil
}
// SetName sets the "name" field.
func (m *UserMutation) SetName(s string) {
m.name = &s
}
// Name returns the value of the "name" field in the mutation.
func (m *UserMutation) Name() (r string, exists bool) {
v := m.name
if v == nil {
return
}
return *v, true
}
// OldName returns the old "name" field's value of the User entity.
// If the User 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 *UserMutation) OldName(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldName: %w", err)
}
return oldValue.Name, nil
}
// ResetName resets all changes to the "name" field.
func (m *UserMutation) ResetName() {
m.name = nil
}
// AddOrganizationIDs adds the "organizations" edge to the Organization entity by ids.
func (m *UserMutation) AddOrganizationIDs(ids ...uuid.UUID) {
if m.organizations == nil {
m.organizations = make(map[uuid.UUID]struct{})
}
for i := range ids {
m.organizations[ids[i]] = struct{}{}
}
}
// ClearOrganizations clears the "organizations" edge to the Organization entity.
func (m *UserMutation) ClearOrganizations() {
m.clearedorganizations = true
}
// OrganizationsCleared reports if the "organizations" edge to the Organization entity was cleared.
func (m *UserMutation) OrganizationsCleared() bool {
return m.clearedorganizations
}
// RemoveOrganizationIDs removes the "organizations" edge to the Organization entity by IDs.
func (m *UserMutation) RemoveOrganizationIDs(ids ...uuid.UUID) {
if m.removedorganizations == nil {
m.removedorganizations = make(map[uuid.UUID]struct{})
}
for i := range ids {
delete(m.organizations, ids[i])
m.removedorganizations[ids[i]] = struct{}{}
}
}
// RemovedOrganizations returns the removed IDs of the "organizations" edge to the Organization entity.
func (m *UserMutation) RemovedOrganizationsIDs() (ids []uuid.UUID) {
for id := range m.removedorganizations {
ids = append(ids, id)
}
return
}
// OrganizationsIDs returns the "organizations" edge IDs in the mutation.
func (m *UserMutation) OrganizationsIDs() (ids []uuid.UUID) {
for id := range m.organizations {
ids = append(ids, id)
}
return
}
// ResetOrganizations resets all changes to the "organizations" edge.
func (m *UserMutation) ResetOrganizations() {
m.organizations = nil
m.clearedorganizations = false
m.removedorganizations = nil
}
// Where appends a list predicates to the UserMutation builder.
func (m *UserMutation) Where(ps ...predicate.User) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the UserMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.User, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *UserMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *UserMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (User).
func (m *UserMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *UserMutation) Fields() []string {
fields := make([]string, 0, 6)
if m.created_at != nil {
fields = append(fields, user.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, user.FieldUpdatedAt)
}
if m.email != nil {
fields = append(fields, user.FieldEmail)
}
if m.iss != nil {
fields = append(fields, user.FieldIss)
}
if m.sub != nil {
fields = append(fields, user.FieldSub)
}
if m.name != nil {
fields = append(fields, user.FieldName)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *UserMutation) Field(name string) (ent.Value, bool) {
switch name {
case user.FieldCreatedAt:
return m.CreatedAt()
case user.FieldUpdatedAt:
return m.UpdatedAt()
case user.FieldEmail:
return m.Email()
case user.FieldIss:
return m.Iss()
case user.FieldSub:
return m.Sub()
case user.FieldName:
return m.Name()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case user.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case user.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
case user.FieldEmail:
return m.OldEmail(ctx)
case user.FieldIss:
return m.OldIss(ctx)
case user.FieldSub:
return m.OldSub(ctx)
case user.FieldName:
return m.OldName(ctx)
}
return nil, fmt.Errorf("unknown User field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *UserMutation) SetField(name string, value ent.Value) error {
switch name {
case user.FieldCreatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedAt(v)
return nil
case user.FieldUpdatedAt:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
case user.FieldEmail:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetEmail(v)
return nil
case user.FieldIss:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIss(v)
return nil
case user.FieldSub:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetSub(v)
return nil
case user.FieldName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetName(v)
return nil
}
return fmt.Errorf("unknown User field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *UserMutation) AddedFields() []string {
return nil
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *UserMutation) AddedField(name string) (ent.Value, bool) {
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *UserMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown User numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *UserMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *UserMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *UserMutation) ClearField(name string) error {
return fmt.Errorf("unknown User nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *UserMutation) ResetField(name string) error {
switch name {
case user.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case user.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
case user.FieldEmail:
m.ResetEmail()
return nil
case user.FieldIss:
m.ResetIss()
return nil
case user.FieldSub:
m.ResetSub()
return nil
case user.FieldName:
m.ResetName()
return nil
}
return fmt.Errorf("unknown User field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *UserMutation) AddedEdges() []string {
edges := make([]string, 0, 1)
if m.organizations != nil {
edges = append(edges, user.EdgeOrganizations)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *UserMutation) AddedIDs(name string) []ent.Value {
switch name {
case user.EdgeOrganizations:
ids := make([]ent.Value, 0, len(m.organizations))
for id := range m.organizations {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *UserMutation) RemovedEdges() []string {
edges := make([]string, 0, 1)
if m.removedorganizations != nil {
edges = append(edges, user.EdgeOrganizations)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *UserMutation) RemovedIDs(name string) []ent.Value {
switch name {
case user.EdgeOrganizations:
ids := make([]ent.Value, 0, len(m.removedorganizations))
for id := range m.removedorganizations {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *UserMutation) ClearedEdges() []string {
edges := make([]string, 0, 1)
if m.clearedorganizations {
edges = append(edges, user.EdgeOrganizations)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *UserMutation) EdgeCleared(name string) bool {
switch name {
case user.EdgeOrganizations:
return m.clearedorganizations
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *UserMutation) ClearEdge(name string) error {
switch name {
}
return fmt.Errorf("unknown User unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *UserMutation) ResetEdge(name string) error {
switch name {
case user.EdgeOrganizations:
m.ResetOrganizations()
return nil
}
return fmt.Errorf("unknown User edge %s", name)
}