Files
voidraft/internal/models/ent/mutation.go
2025-12-20 16:43:04 +08:00

3233 lines
95 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"sync"
"voidraft/internal/models/ent/document"
"voidraft/internal/models/ent/extension"
"voidraft/internal/models/ent/keybinding"
"voidraft/internal/models/ent/predicate"
"voidraft/internal/models/ent/theme"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
const (
// Operation types.
OpCreate = ent.OpCreate
OpDelete = ent.OpDelete
OpDeleteOne = ent.OpDeleteOne
OpUpdate = ent.OpUpdate
OpUpdateOne = ent.OpUpdateOne
// Node types.
TypeDocument = "Document"
TypeExtension = "Extension"
TypeKeyBinding = "KeyBinding"
TypeTheme = "Theme"
)
// DocumentMutation represents an operation that mutates the Document nodes in the graph.
type DocumentMutation struct {
config
op Op
typ string
id *int
uuid *string
created_at *string
updated_at *string
deleted_at *string
title *string
content *string
locked *bool
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*Document, error)
predicates []predicate.Document
}
var _ ent.Mutation = (*DocumentMutation)(nil)
// documentOption allows management of the mutation configuration using functional options.
type documentOption func(*DocumentMutation)
// newDocumentMutation creates new mutation for the Document entity.
func newDocumentMutation(c config, op Op, opts ...documentOption) *DocumentMutation {
m := &DocumentMutation{
config: c,
op: op,
typ: TypeDocument,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withDocumentID sets the ID field of the mutation.
func withDocumentID(id int) documentOption {
return func(m *DocumentMutation) {
var (
err error
once sync.Once
value *Document
)
m.oldValue = func(ctx context.Context) (*Document, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Document.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withDocument sets the old Document of the mutation.
func withDocument(node *Document) documentOption {
return func(m *DocumentMutation) {
m.oldValue = func(context.Context) (*Document, 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 DocumentMutation) 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 DocumentMutation) 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
}
// 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 *DocumentMutation) ID() (id int, 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 *DocumentMutation) IDs(ctx context.Context) ([]int, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().Document.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetUUID sets the "uuid" field.
func (m *DocumentMutation) SetUUID(s string) {
m.uuid = &s
}
// UUID returns the value of the "uuid" field in the mutation.
func (m *DocumentMutation) UUID() (r string, exists bool) {
v := m.uuid
if v == nil {
return
}
return *v, true
}
// OldUUID returns the old "uuid" field's value of the Document entity.
// If the Document 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 *DocumentMutation) OldUUID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUUID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUUID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUUID: %w", err)
}
return oldValue.UUID, nil
}
// ResetUUID resets all changes to the "uuid" field.
func (m *DocumentMutation) ResetUUID() {
m.uuid = nil
}
// SetCreatedAt sets the "created_at" field.
func (m *DocumentMutation) SetCreatedAt(s string) {
m.created_at = &s
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *DocumentMutation) CreatedAt() (r string, exists bool) {
v := m.created_at
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "created_at" field's value of the Document entity.
// If the Document 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 *DocumentMutation) OldCreatedAt(ctx context.Context) (v string, 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 *DocumentMutation) ResetCreatedAt() {
m.created_at = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *DocumentMutation) SetUpdatedAt(s string) {
m.updated_at = &s
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *DocumentMutation) UpdatedAt() (r string, exists bool) {
v := m.updated_at
if v == nil {
return
}
return *v, true
}
// OldUpdatedAt returns the old "updated_at" field's value of the Document entity.
// If the Document 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 *DocumentMutation) OldUpdatedAt(ctx context.Context) (v string, 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 *DocumentMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// SetDeletedAt sets the "deleted_at" field.
func (m *DocumentMutation) SetDeletedAt(s string) {
m.deleted_at = &s
}
// DeletedAt returns the value of the "deleted_at" field in the mutation.
func (m *DocumentMutation) DeletedAt() (r string, exists bool) {
v := m.deleted_at
if v == nil {
return
}
return *v, true
}
// OldDeletedAt returns the old "deleted_at" field's value of the Document entity.
// If the Document 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 *DocumentMutation) OldDeletedAt(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDeletedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
}
return oldValue.DeletedAt, nil
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *DocumentMutation) ClearDeletedAt() {
m.deleted_at = nil
m.clearedFields[document.FieldDeletedAt] = struct{}{}
}
// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *DocumentMutation) DeletedAtCleared() bool {
_, ok := m.clearedFields[document.FieldDeletedAt]
return ok
}
// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *DocumentMutation) ResetDeletedAt() {
m.deleted_at = nil
delete(m.clearedFields, document.FieldDeletedAt)
}
// SetTitle sets the "title" field.
func (m *DocumentMutation) SetTitle(s string) {
m.title = &s
}
// Title returns the value of the "title" field in the mutation.
func (m *DocumentMutation) Title() (r string, exists bool) {
v := m.title
if v == nil {
return
}
return *v, true
}
// OldTitle returns the old "title" field's value of the Document entity.
// If the Document 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 *DocumentMutation) OldTitle(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTitle is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTitle requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTitle: %w", err)
}
return oldValue.Title, nil
}
// ResetTitle resets all changes to the "title" field.
func (m *DocumentMutation) ResetTitle() {
m.title = nil
}
// SetContent sets the "content" field.
func (m *DocumentMutation) SetContent(s string) {
m.content = &s
}
// Content returns the value of the "content" field in the mutation.
func (m *DocumentMutation) Content() (r string, exists bool) {
v := m.content
if v == nil {
return
}
return *v, true
}
// OldContent returns the old "content" field's value of the Document entity.
// If the Document 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 *DocumentMutation) OldContent(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldContent is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldContent requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldContent: %w", err)
}
return oldValue.Content, nil
}
// ClearContent clears the value of the "content" field.
func (m *DocumentMutation) ClearContent() {
m.content = nil
m.clearedFields[document.FieldContent] = struct{}{}
}
// ContentCleared returns if the "content" field was cleared in this mutation.
func (m *DocumentMutation) ContentCleared() bool {
_, ok := m.clearedFields[document.FieldContent]
return ok
}
// ResetContent resets all changes to the "content" field.
func (m *DocumentMutation) ResetContent() {
m.content = nil
delete(m.clearedFields, document.FieldContent)
}
// SetLocked sets the "locked" field.
func (m *DocumentMutation) SetLocked(b bool) {
m.locked = &b
}
// Locked returns the value of the "locked" field in the mutation.
func (m *DocumentMutation) Locked() (r bool, exists bool) {
v := m.locked
if v == nil {
return
}
return *v, true
}
// OldLocked returns the old "locked" field's value of the Document entity.
// If the Document 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 *DocumentMutation) OldLocked(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldLocked is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldLocked requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldLocked: %w", err)
}
return oldValue.Locked, nil
}
// ResetLocked resets all changes to the "locked" field.
func (m *DocumentMutation) ResetLocked() {
m.locked = nil
}
// Where appends a list predicates to the DocumentMutation builder.
func (m *DocumentMutation) Where(ps ...predicate.Document) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the DocumentMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *DocumentMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.Document, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *DocumentMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *DocumentMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (Document).
func (m *DocumentMutation) 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 *DocumentMutation) Fields() []string {
fields := make([]string, 0, 7)
if m.uuid != nil {
fields = append(fields, document.FieldUUID)
}
if m.created_at != nil {
fields = append(fields, document.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, document.FieldUpdatedAt)
}
if m.deleted_at != nil {
fields = append(fields, document.FieldDeletedAt)
}
if m.title != nil {
fields = append(fields, document.FieldTitle)
}
if m.content != nil {
fields = append(fields, document.FieldContent)
}
if m.locked != nil {
fields = append(fields, document.FieldLocked)
}
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 *DocumentMutation) Field(name string) (ent.Value, bool) {
switch name {
case document.FieldUUID:
return m.UUID()
case document.FieldCreatedAt:
return m.CreatedAt()
case document.FieldUpdatedAt:
return m.UpdatedAt()
case document.FieldDeletedAt:
return m.DeletedAt()
case document.FieldTitle:
return m.Title()
case document.FieldContent:
return m.Content()
case document.FieldLocked:
return m.Locked()
}
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 *DocumentMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case document.FieldUUID:
return m.OldUUID(ctx)
case document.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case document.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
case document.FieldDeletedAt:
return m.OldDeletedAt(ctx)
case document.FieldTitle:
return m.OldTitle(ctx)
case document.FieldContent:
return m.OldContent(ctx)
case document.FieldLocked:
return m.OldLocked(ctx)
}
return nil, fmt.Errorf("unknown Document 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 *DocumentMutation) SetField(name string, value ent.Value) error {
switch name {
case document.FieldUUID:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUUID(v)
return nil
case document.FieldCreatedAt:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedAt(v)
return nil
case document.FieldUpdatedAt:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
case document.FieldDeletedAt:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDeletedAt(v)
return nil
case document.FieldTitle:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTitle(v)
return nil
case document.FieldContent:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetContent(v)
return nil
case document.FieldLocked:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetLocked(v)
return nil
}
return fmt.Errorf("unknown Document field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *DocumentMutation) 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 *DocumentMutation) 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 *DocumentMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown Document numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *DocumentMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(document.FieldDeletedAt) {
fields = append(fields, document.FieldDeletedAt)
}
if m.FieldCleared(document.FieldContent) {
fields = append(fields, document.FieldContent)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *DocumentMutation) 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 *DocumentMutation) ClearField(name string) error {
switch name {
case document.FieldDeletedAt:
m.ClearDeletedAt()
return nil
case document.FieldContent:
m.ClearContent()
return nil
}
return fmt.Errorf("unknown Document 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 *DocumentMutation) ResetField(name string) error {
switch name {
case document.FieldUUID:
m.ResetUUID()
return nil
case document.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case document.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
case document.FieldDeletedAt:
m.ResetDeletedAt()
return nil
case document.FieldTitle:
m.ResetTitle()
return nil
case document.FieldContent:
m.ResetContent()
return nil
case document.FieldLocked:
m.ResetLocked()
return nil
}
return fmt.Errorf("unknown Document field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *DocumentMutation) AddedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *DocumentMutation) AddedIDs(name string) []ent.Value {
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *DocumentMutation) RemovedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *DocumentMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *DocumentMutation) ClearedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *DocumentMutation) EdgeCleared(name string) bool {
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 *DocumentMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown Document 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 *DocumentMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown Document edge %s", name)
}
// ExtensionMutation represents an operation that mutates the Extension nodes in the graph.
type ExtensionMutation struct {
config
op Op
typ string
id *int
uuid *string
created_at *string
updated_at *string
deleted_at *string
name *string
enabled *bool
_config *map[string]interface{}
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*Extension, error)
predicates []predicate.Extension
}
var _ ent.Mutation = (*ExtensionMutation)(nil)
// extensionOption allows management of the mutation configuration using functional options.
type extensionOption func(*ExtensionMutation)
// newExtensionMutation creates new mutation for the Extension entity.
func newExtensionMutation(c config, op Op, opts ...extensionOption) *ExtensionMutation {
m := &ExtensionMutation{
config: c,
op: op,
typ: TypeExtension,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withExtensionID sets the ID field of the mutation.
func withExtensionID(id int) extensionOption {
return func(m *ExtensionMutation) {
var (
err error
once sync.Once
value *Extension
)
m.oldValue = func(ctx context.Context) (*Extension, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Extension.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withExtension sets the old Extension of the mutation.
func withExtension(node *Extension) extensionOption {
return func(m *ExtensionMutation) {
m.oldValue = func(context.Context) (*Extension, 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 ExtensionMutation) 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 ExtensionMutation) 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
}
// 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 *ExtensionMutation) ID() (id int, 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 *ExtensionMutation) IDs(ctx context.Context) ([]int, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().Extension.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetUUID sets the "uuid" field.
func (m *ExtensionMutation) SetUUID(s string) {
m.uuid = &s
}
// UUID returns the value of the "uuid" field in the mutation.
func (m *ExtensionMutation) UUID() (r string, exists bool) {
v := m.uuid
if v == nil {
return
}
return *v, true
}
// OldUUID returns the old "uuid" field's value of the Extension entity.
// If the Extension 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 *ExtensionMutation) OldUUID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUUID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUUID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUUID: %w", err)
}
return oldValue.UUID, nil
}
// ResetUUID resets all changes to the "uuid" field.
func (m *ExtensionMutation) ResetUUID() {
m.uuid = nil
}
// SetCreatedAt sets the "created_at" field.
func (m *ExtensionMutation) SetCreatedAt(s string) {
m.created_at = &s
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *ExtensionMutation) CreatedAt() (r string, exists bool) {
v := m.created_at
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "created_at" field's value of the Extension entity.
// If the Extension 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 *ExtensionMutation) OldCreatedAt(ctx context.Context) (v string, 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 *ExtensionMutation) ResetCreatedAt() {
m.created_at = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *ExtensionMutation) SetUpdatedAt(s string) {
m.updated_at = &s
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *ExtensionMutation) UpdatedAt() (r string, exists bool) {
v := m.updated_at
if v == nil {
return
}
return *v, true
}
// OldUpdatedAt returns the old "updated_at" field's value of the Extension entity.
// If the Extension 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 *ExtensionMutation) OldUpdatedAt(ctx context.Context) (v string, 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 *ExtensionMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// SetDeletedAt sets the "deleted_at" field.
func (m *ExtensionMutation) SetDeletedAt(s string) {
m.deleted_at = &s
}
// DeletedAt returns the value of the "deleted_at" field in the mutation.
func (m *ExtensionMutation) DeletedAt() (r string, exists bool) {
v := m.deleted_at
if v == nil {
return
}
return *v, true
}
// OldDeletedAt returns the old "deleted_at" field's value of the Extension entity.
// If the Extension 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 *ExtensionMutation) OldDeletedAt(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDeletedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
}
return oldValue.DeletedAt, nil
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *ExtensionMutation) ClearDeletedAt() {
m.deleted_at = nil
m.clearedFields[extension.FieldDeletedAt] = struct{}{}
}
// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *ExtensionMutation) DeletedAtCleared() bool {
_, ok := m.clearedFields[extension.FieldDeletedAt]
return ok
}
// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *ExtensionMutation) ResetDeletedAt() {
m.deleted_at = nil
delete(m.clearedFields, extension.FieldDeletedAt)
}
// SetName sets the "name" field.
func (m *ExtensionMutation) SetName(s string) {
m.name = &s
}
// Name returns the value of the "name" field in the mutation.
func (m *ExtensionMutation) 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 Extension entity.
// If the Extension 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 *ExtensionMutation) 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 *ExtensionMutation) ResetName() {
m.name = nil
}
// SetEnabled sets the "enabled" field.
func (m *ExtensionMutation) SetEnabled(b bool) {
m.enabled = &b
}
// Enabled returns the value of the "enabled" field in the mutation.
func (m *ExtensionMutation) Enabled() (r bool, exists bool) {
v := m.enabled
if v == nil {
return
}
return *v, true
}
// OldEnabled returns the old "enabled" field's value of the Extension entity.
// If the Extension 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 *ExtensionMutation) OldEnabled(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldEnabled is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldEnabled requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldEnabled: %w", err)
}
return oldValue.Enabled, nil
}
// ResetEnabled resets all changes to the "enabled" field.
func (m *ExtensionMutation) ResetEnabled() {
m.enabled = nil
}
// SetConfig sets the "config" field.
func (m *ExtensionMutation) SetConfig(value map[string]interface{}) {
m._config = &value
}
// Config returns the value of the "config" field in the mutation.
func (m *ExtensionMutation) Config() (r map[string]interface{}, exists bool) {
v := m._config
if v == nil {
return
}
return *v, true
}
// OldConfig returns the old "config" field's value of the Extension entity.
// If the Extension 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 *ExtensionMutation) OldConfig(ctx context.Context) (v map[string]interface{}, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldConfig is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldConfig requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldConfig: %w", err)
}
return oldValue.Config, nil
}
// ClearConfig clears the value of the "config" field.
func (m *ExtensionMutation) ClearConfig() {
m._config = nil
m.clearedFields[extension.FieldConfig] = struct{}{}
}
// ConfigCleared returns if the "config" field was cleared in this mutation.
func (m *ExtensionMutation) ConfigCleared() bool {
_, ok := m.clearedFields[extension.FieldConfig]
return ok
}
// ResetConfig resets all changes to the "config" field.
func (m *ExtensionMutation) ResetConfig() {
m._config = nil
delete(m.clearedFields, extension.FieldConfig)
}
// Where appends a list predicates to the ExtensionMutation builder.
func (m *ExtensionMutation) Where(ps ...predicate.Extension) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the ExtensionMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *ExtensionMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.Extension, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *ExtensionMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *ExtensionMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (Extension).
func (m *ExtensionMutation) 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 *ExtensionMutation) Fields() []string {
fields := make([]string, 0, 7)
if m.uuid != nil {
fields = append(fields, extension.FieldUUID)
}
if m.created_at != nil {
fields = append(fields, extension.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, extension.FieldUpdatedAt)
}
if m.deleted_at != nil {
fields = append(fields, extension.FieldDeletedAt)
}
if m.name != nil {
fields = append(fields, extension.FieldName)
}
if m.enabled != nil {
fields = append(fields, extension.FieldEnabled)
}
if m._config != nil {
fields = append(fields, extension.FieldConfig)
}
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 *ExtensionMutation) Field(name string) (ent.Value, bool) {
switch name {
case extension.FieldUUID:
return m.UUID()
case extension.FieldCreatedAt:
return m.CreatedAt()
case extension.FieldUpdatedAt:
return m.UpdatedAt()
case extension.FieldDeletedAt:
return m.DeletedAt()
case extension.FieldName:
return m.Name()
case extension.FieldEnabled:
return m.Enabled()
case extension.FieldConfig:
return m.Config()
}
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 *ExtensionMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case extension.FieldUUID:
return m.OldUUID(ctx)
case extension.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case extension.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
case extension.FieldDeletedAt:
return m.OldDeletedAt(ctx)
case extension.FieldName:
return m.OldName(ctx)
case extension.FieldEnabled:
return m.OldEnabled(ctx)
case extension.FieldConfig:
return m.OldConfig(ctx)
}
return nil, fmt.Errorf("unknown Extension 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 *ExtensionMutation) SetField(name string, value ent.Value) error {
switch name {
case extension.FieldUUID:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUUID(v)
return nil
case extension.FieldCreatedAt:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedAt(v)
return nil
case extension.FieldUpdatedAt:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
case extension.FieldDeletedAt:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDeletedAt(v)
return nil
case extension.FieldName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetName(v)
return nil
case extension.FieldEnabled:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetEnabled(v)
return nil
case extension.FieldConfig:
v, ok := value.(map[string]interface{})
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetConfig(v)
return nil
}
return fmt.Errorf("unknown Extension field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *ExtensionMutation) 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 *ExtensionMutation) 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 *ExtensionMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown Extension numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *ExtensionMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(extension.FieldDeletedAt) {
fields = append(fields, extension.FieldDeletedAt)
}
if m.FieldCleared(extension.FieldConfig) {
fields = append(fields, extension.FieldConfig)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *ExtensionMutation) 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 *ExtensionMutation) ClearField(name string) error {
switch name {
case extension.FieldDeletedAt:
m.ClearDeletedAt()
return nil
case extension.FieldConfig:
m.ClearConfig()
return nil
}
return fmt.Errorf("unknown Extension 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 *ExtensionMutation) ResetField(name string) error {
switch name {
case extension.FieldUUID:
m.ResetUUID()
return nil
case extension.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case extension.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
case extension.FieldDeletedAt:
m.ResetDeletedAt()
return nil
case extension.FieldName:
m.ResetName()
return nil
case extension.FieldEnabled:
m.ResetEnabled()
return nil
case extension.FieldConfig:
m.ResetConfig()
return nil
}
return fmt.Errorf("unknown Extension field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *ExtensionMutation) AddedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *ExtensionMutation) AddedIDs(name string) []ent.Value {
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *ExtensionMutation) RemovedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *ExtensionMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *ExtensionMutation) ClearedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *ExtensionMutation) EdgeCleared(name string) bool {
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 *ExtensionMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown Extension 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 *ExtensionMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown Extension edge %s", name)
}
// KeyBindingMutation represents an operation that mutates the KeyBinding nodes in the graph.
type KeyBindingMutation struct {
config
op Op
typ string
id *int
uuid *string
created_at *string
updated_at *string
deleted_at *string
name *string
_type *string
key *string
macos *string
windows *string
linux *string
extension *string
enabled *bool
prevent_default *bool
scope *string
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*KeyBinding, error)
predicates []predicate.KeyBinding
}
var _ ent.Mutation = (*KeyBindingMutation)(nil)
// keybindingOption allows management of the mutation configuration using functional options.
type keybindingOption func(*KeyBindingMutation)
// newKeyBindingMutation creates new mutation for the KeyBinding entity.
func newKeyBindingMutation(c config, op Op, opts ...keybindingOption) *KeyBindingMutation {
m := &KeyBindingMutation{
config: c,
op: op,
typ: TypeKeyBinding,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withKeyBindingID sets the ID field of the mutation.
func withKeyBindingID(id int) keybindingOption {
return func(m *KeyBindingMutation) {
var (
err error
once sync.Once
value *KeyBinding
)
m.oldValue = func(ctx context.Context) (*KeyBinding, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().KeyBinding.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withKeyBinding sets the old KeyBinding of the mutation.
func withKeyBinding(node *KeyBinding) keybindingOption {
return func(m *KeyBindingMutation) {
m.oldValue = func(context.Context) (*KeyBinding, 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 KeyBindingMutation) 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 KeyBindingMutation) 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
}
// 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 *KeyBindingMutation) ID() (id int, 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 *KeyBindingMutation) IDs(ctx context.Context) ([]int, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().KeyBinding.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetUUID sets the "uuid" field.
func (m *KeyBindingMutation) SetUUID(s string) {
m.uuid = &s
}
// UUID returns the value of the "uuid" field in the mutation.
func (m *KeyBindingMutation) UUID() (r string, exists bool) {
v := m.uuid
if v == nil {
return
}
return *v, true
}
// OldUUID returns the old "uuid" field's value of the KeyBinding entity.
// If the KeyBinding 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 *KeyBindingMutation) OldUUID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUUID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUUID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUUID: %w", err)
}
return oldValue.UUID, nil
}
// ResetUUID resets all changes to the "uuid" field.
func (m *KeyBindingMutation) ResetUUID() {
m.uuid = nil
}
// SetCreatedAt sets the "created_at" field.
func (m *KeyBindingMutation) SetCreatedAt(s string) {
m.created_at = &s
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *KeyBindingMutation) CreatedAt() (r string, exists bool) {
v := m.created_at
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "created_at" field's value of the KeyBinding entity.
// If the KeyBinding 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 *KeyBindingMutation) OldCreatedAt(ctx context.Context) (v string, 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 *KeyBindingMutation) ResetCreatedAt() {
m.created_at = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *KeyBindingMutation) SetUpdatedAt(s string) {
m.updated_at = &s
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *KeyBindingMutation) UpdatedAt() (r string, exists bool) {
v := m.updated_at
if v == nil {
return
}
return *v, true
}
// OldUpdatedAt returns the old "updated_at" field's value of the KeyBinding entity.
// If the KeyBinding 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 *KeyBindingMutation) OldUpdatedAt(ctx context.Context) (v string, 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 *KeyBindingMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// SetDeletedAt sets the "deleted_at" field.
func (m *KeyBindingMutation) SetDeletedAt(s string) {
m.deleted_at = &s
}
// DeletedAt returns the value of the "deleted_at" field in the mutation.
func (m *KeyBindingMutation) DeletedAt() (r string, exists bool) {
v := m.deleted_at
if v == nil {
return
}
return *v, true
}
// OldDeletedAt returns the old "deleted_at" field's value of the KeyBinding entity.
// If the KeyBinding 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 *KeyBindingMutation) OldDeletedAt(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDeletedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
}
return oldValue.DeletedAt, nil
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *KeyBindingMutation) ClearDeletedAt() {
m.deleted_at = nil
m.clearedFields[keybinding.FieldDeletedAt] = struct{}{}
}
// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *KeyBindingMutation) DeletedAtCleared() bool {
_, ok := m.clearedFields[keybinding.FieldDeletedAt]
return ok
}
// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *KeyBindingMutation) ResetDeletedAt() {
m.deleted_at = nil
delete(m.clearedFields, keybinding.FieldDeletedAt)
}
// SetName sets the "name" field.
func (m *KeyBindingMutation) SetName(s string) {
m.name = &s
}
// Name returns the value of the "name" field in the mutation.
func (m *KeyBindingMutation) 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 KeyBinding entity.
// If the KeyBinding 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 *KeyBindingMutation) 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 *KeyBindingMutation) ResetName() {
m.name = nil
}
// SetType sets the "type" field.
func (m *KeyBindingMutation) SetType(s string) {
m._type = &s
}
// GetType returns the value of the "type" field in the mutation.
func (m *KeyBindingMutation) GetType() (r string, exists bool) {
v := m._type
if v == nil {
return
}
return *v, true
}
// OldType returns the old "type" field's value of the KeyBinding entity.
// If the KeyBinding 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 *KeyBindingMutation) OldType(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldType is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldType requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldType: %w", err)
}
return oldValue.Type, nil
}
// ResetType resets all changes to the "type" field.
func (m *KeyBindingMutation) ResetType() {
m._type = nil
}
// SetKey sets the "key" field.
func (m *KeyBindingMutation) SetKey(s string) {
m.key = &s
}
// Key returns the value of the "key" field in the mutation.
func (m *KeyBindingMutation) Key() (r string, exists bool) {
v := m.key
if v == nil {
return
}
return *v, true
}
// OldKey returns the old "key" field's value of the KeyBinding entity.
// If the KeyBinding 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 *KeyBindingMutation) OldKey(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldKey is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldKey requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldKey: %w", err)
}
return oldValue.Key, nil
}
// ClearKey clears the value of the "key" field.
func (m *KeyBindingMutation) ClearKey() {
m.key = nil
m.clearedFields[keybinding.FieldKey] = struct{}{}
}
// KeyCleared returns if the "key" field was cleared in this mutation.
func (m *KeyBindingMutation) KeyCleared() bool {
_, ok := m.clearedFields[keybinding.FieldKey]
return ok
}
// ResetKey resets all changes to the "key" field.
func (m *KeyBindingMutation) ResetKey() {
m.key = nil
delete(m.clearedFields, keybinding.FieldKey)
}
// SetMacos sets the "macos" field.
func (m *KeyBindingMutation) SetMacos(s string) {
m.macos = &s
}
// Macos returns the value of the "macos" field in the mutation.
func (m *KeyBindingMutation) Macos() (r string, exists bool) {
v := m.macos
if v == nil {
return
}
return *v, true
}
// OldMacos returns the old "macos" field's value of the KeyBinding entity.
// If the KeyBinding 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 *KeyBindingMutation) OldMacos(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldMacos is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldMacos requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldMacos: %w", err)
}
return oldValue.Macos, nil
}
// ClearMacos clears the value of the "macos" field.
func (m *KeyBindingMutation) ClearMacos() {
m.macos = nil
m.clearedFields[keybinding.FieldMacos] = struct{}{}
}
// MacosCleared returns if the "macos" field was cleared in this mutation.
func (m *KeyBindingMutation) MacosCleared() bool {
_, ok := m.clearedFields[keybinding.FieldMacos]
return ok
}
// ResetMacos resets all changes to the "macos" field.
func (m *KeyBindingMutation) ResetMacos() {
m.macos = nil
delete(m.clearedFields, keybinding.FieldMacos)
}
// SetWindows sets the "windows" field.
func (m *KeyBindingMutation) SetWindows(s string) {
m.windows = &s
}
// Windows returns the value of the "windows" field in the mutation.
func (m *KeyBindingMutation) Windows() (r string, exists bool) {
v := m.windows
if v == nil {
return
}
return *v, true
}
// OldWindows returns the old "windows" field's value of the KeyBinding entity.
// If the KeyBinding 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 *KeyBindingMutation) OldWindows(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldWindows is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldWindows requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldWindows: %w", err)
}
return oldValue.Windows, nil
}
// ClearWindows clears the value of the "windows" field.
func (m *KeyBindingMutation) ClearWindows() {
m.windows = nil
m.clearedFields[keybinding.FieldWindows] = struct{}{}
}
// WindowsCleared returns if the "windows" field was cleared in this mutation.
func (m *KeyBindingMutation) WindowsCleared() bool {
_, ok := m.clearedFields[keybinding.FieldWindows]
return ok
}
// ResetWindows resets all changes to the "windows" field.
func (m *KeyBindingMutation) ResetWindows() {
m.windows = nil
delete(m.clearedFields, keybinding.FieldWindows)
}
// SetLinux sets the "linux" field.
func (m *KeyBindingMutation) SetLinux(s string) {
m.linux = &s
}
// Linux returns the value of the "linux" field in the mutation.
func (m *KeyBindingMutation) Linux() (r string, exists bool) {
v := m.linux
if v == nil {
return
}
return *v, true
}
// OldLinux returns the old "linux" field's value of the KeyBinding entity.
// If the KeyBinding 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 *KeyBindingMutation) OldLinux(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldLinux is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldLinux requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldLinux: %w", err)
}
return oldValue.Linux, nil
}
// ClearLinux clears the value of the "linux" field.
func (m *KeyBindingMutation) ClearLinux() {
m.linux = nil
m.clearedFields[keybinding.FieldLinux] = struct{}{}
}
// LinuxCleared returns if the "linux" field was cleared in this mutation.
func (m *KeyBindingMutation) LinuxCleared() bool {
_, ok := m.clearedFields[keybinding.FieldLinux]
return ok
}
// ResetLinux resets all changes to the "linux" field.
func (m *KeyBindingMutation) ResetLinux() {
m.linux = nil
delete(m.clearedFields, keybinding.FieldLinux)
}
// SetExtension sets the "extension" field.
func (m *KeyBindingMutation) SetExtension(s string) {
m.extension = &s
}
// Extension returns the value of the "extension" field in the mutation.
func (m *KeyBindingMutation) Extension() (r string, exists bool) {
v := m.extension
if v == nil {
return
}
return *v, true
}
// OldExtension returns the old "extension" field's value of the KeyBinding entity.
// If the KeyBinding 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 *KeyBindingMutation) OldExtension(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldExtension is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldExtension requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldExtension: %w", err)
}
return oldValue.Extension, nil
}
// ResetExtension resets all changes to the "extension" field.
func (m *KeyBindingMutation) ResetExtension() {
m.extension = nil
}
// SetEnabled sets the "enabled" field.
func (m *KeyBindingMutation) SetEnabled(b bool) {
m.enabled = &b
}
// Enabled returns the value of the "enabled" field in the mutation.
func (m *KeyBindingMutation) Enabled() (r bool, exists bool) {
v := m.enabled
if v == nil {
return
}
return *v, true
}
// OldEnabled returns the old "enabled" field's value of the KeyBinding entity.
// If the KeyBinding 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 *KeyBindingMutation) OldEnabled(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldEnabled is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldEnabled requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldEnabled: %w", err)
}
return oldValue.Enabled, nil
}
// ResetEnabled resets all changes to the "enabled" field.
func (m *KeyBindingMutation) ResetEnabled() {
m.enabled = nil
}
// SetPreventDefault sets the "prevent_default" field.
func (m *KeyBindingMutation) SetPreventDefault(b bool) {
m.prevent_default = &b
}
// PreventDefault returns the value of the "prevent_default" field in the mutation.
func (m *KeyBindingMutation) PreventDefault() (r bool, exists bool) {
v := m.prevent_default
if v == nil {
return
}
return *v, true
}
// OldPreventDefault returns the old "prevent_default" field's value of the KeyBinding entity.
// If the KeyBinding 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 *KeyBindingMutation) OldPreventDefault(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldPreventDefault is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldPreventDefault requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldPreventDefault: %w", err)
}
return oldValue.PreventDefault, nil
}
// ResetPreventDefault resets all changes to the "prevent_default" field.
func (m *KeyBindingMutation) ResetPreventDefault() {
m.prevent_default = nil
}
// SetScope sets the "scope" field.
func (m *KeyBindingMutation) SetScope(s string) {
m.scope = &s
}
// Scope returns the value of the "scope" field in the mutation.
func (m *KeyBindingMutation) Scope() (r string, exists bool) {
v := m.scope
if v == nil {
return
}
return *v, true
}
// OldScope returns the old "scope" field's value of the KeyBinding entity.
// If the KeyBinding 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 *KeyBindingMutation) OldScope(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldScope is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldScope requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldScope: %w", err)
}
return oldValue.Scope, nil
}
// ResetScope resets all changes to the "scope" field.
func (m *KeyBindingMutation) ResetScope() {
m.scope = nil
}
// Where appends a list predicates to the KeyBindingMutation builder.
func (m *KeyBindingMutation) Where(ps ...predicate.KeyBinding) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the KeyBindingMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *KeyBindingMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.KeyBinding, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *KeyBindingMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *KeyBindingMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (KeyBinding).
func (m *KeyBindingMutation) 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 *KeyBindingMutation) Fields() []string {
fields := make([]string, 0, 14)
if m.uuid != nil {
fields = append(fields, keybinding.FieldUUID)
}
if m.created_at != nil {
fields = append(fields, keybinding.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, keybinding.FieldUpdatedAt)
}
if m.deleted_at != nil {
fields = append(fields, keybinding.FieldDeletedAt)
}
if m.name != nil {
fields = append(fields, keybinding.FieldName)
}
if m._type != nil {
fields = append(fields, keybinding.FieldType)
}
if m.key != nil {
fields = append(fields, keybinding.FieldKey)
}
if m.macos != nil {
fields = append(fields, keybinding.FieldMacos)
}
if m.windows != nil {
fields = append(fields, keybinding.FieldWindows)
}
if m.linux != nil {
fields = append(fields, keybinding.FieldLinux)
}
if m.extension != nil {
fields = append(fields, keybinding.FieldExtension)
}
if m.enabled != nil {
fields = append(fields, keybinding.FieldEnabled)
}
if m.prevent_default != nil {
fields = append(fields, keybinding.FieldPreventDefault)
}
if m.scope != nil {
fields = append(fields, keybinding.FieldScope)
}
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 *KeyBindingMutation) Field(name string) (ent.Value, bool) {
switch name {
case keybinding.FieldUUID:
return m.UUID()
case keybinding.FieldCreatedAt:
return m.CreatedAt()
case keybinding.FieldUpdatedAt:
return m.UpdatedAt()
case keybinding.FieldDeletedAt:
return m.DeletedAt()
case keybinding.FieldName:
return m.Name()
case keybinding.FieldType:
return m.GetType()
case keybinding.FieldKey:
return m.Key()
case keybinding.FieldMacos:
return m.Macos()
case keybinding.FieldWindows:
return m.Windows()
case keybinding.FieldLinux:
return m.Linux()
case keybinding.FieldExtension:
return m.Extension()
case keybinding.FieldEnabled:
return m.Enabled()
case keybinding.FieldPreventDefault:
return m.PreventDefault()
case keybinding.FieldScope:
return m.Scope()
}
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 *KeyBindingMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case keybinding.FieldUUID:
return m.OldUUID(ctx)
case keybinding.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case keybinding.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
case keybinding.FieldDeletedAt:
return m.OldDeletedAt(ctx)
case keybinding.FieldName:
return m.OldName(ctx)
case keybinding.FieldType:
return m.OldType(ctx)
case keybinding.FieldKey:
return m.OldKey(ctx)
case keybinding.FieldMacos:
return m.OldMacos(ctx)
case keybinding.FieldWindows:
return m.OldWindows(ctx)
case keybinding.FieldLinux:
return m.OldLinux(ctx)
case keybinding.FieldExtension:
return m.OldExtension(ctx)
case keybinding.FieldEnabled:
return m.OldEnabled(ctx)
case keybinding.FieldPreventDefault:
return m.OldPreventDefault(ctx)
case keybinding.FieldScope:
return m.OldScope(ctx)
}
return nil, fmt.Errorf("unknown KeyBinding 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 *KeyBindingMutation) SetField(name string, value ent.Value) error {
switch name {
case keybinding.FieldUUID:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUUID(v)
return nil
case keybinding.FieldCreatedAt:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedAt(v)
return nil
case keybinding.FieldUpdatedAt:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
case keybinding.FieldDeletedAt:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDeletedAt(v)
return nil
case keybinding.FieldName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetName(v)
return nil
case keybinding.FieldType:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetType(v)
return nil
case keybinding.FieldKey:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetKey(v)
return nil
case keybinding.FieldMacos:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetMacos(v)
return nil
case keybinding.FieldWindows:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetWindows(v)
return nil
case keybinding.FieldLinux:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetLinux(v)
return nil
case keybinding.FieldExtension:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetExtension(v)
return nil
case keybinding.FieldEnabled:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetEnabled(v)
return nil
case keybinding.FieldPreventDefault:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPreventDefault(v)
return nil
case keybinding.FieldScope:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetScope(v)
return nil
}
return fmt.Errorf("unknown KeyBinding field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *KeyBindingMutation) 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 *KeyBindingMutation) 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 *KeyBindingMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown KeyBinding numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *KeyBindingMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(keybinding.FieldDeletedAt) {
fields = append(fields, keybinding.FieldDeletedAt)
}
if m.FieldCleared(keybinding.FieldKey) {
fields = append(fields, keybinding.FieldKey)
}
if m.FieldCleared(keybinding.FieldMacos) {
fields = append(fields, keybinding.FieldMacos)
}
if m.FieldCleared(keybinding.FieldWindows) {
fields = append(fields, keybinding.FieldWindows)
}
if m.FieldCleared(keybinding.FieldLinux) {
fields = append(fields, keybinding.FieldLinux)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *KeyBindingMutation) 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 *KeyBindingMutation) ClearField(name string) error {
switch name {
case keybinding.FieldDeletedAt:
m.ClearDeletedAt()
return nil
case keybinding.FieldKey:
m.ClearKey()
return nil
case keybinding.FieldMacos:
m.ClearMacos()
return nil
case keybinding.FieldWindows:
m.ClearWindows()
return nil
case keybinding.FieldLinux:
m.ClearLinux()
return nil
}
return fmt.Errorf("unknown KeyBinding 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 *KeyBindingMutation) ResetField(name string) error {
switch name {
case keybinding.FieldUUID:
m.ResetUUID()
return nil
case keybinding.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case keybinding.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
case keybinding.FieldDeletedAt:
m.ResetDeletedAt()
return nil
case keybinding.FieldName:
m.ResetName()
return nil
case keybinding.FieldType:
m.ResetType()
return nil
case keybinding.FieldKey:
m.ResetKey()
return nil
case keybinding.FieldMacos:
m.ResetMacos()
return nil
case keybinding.FieldWindows:
m.ResetWindows()
return nil
case keybinding.FieldLinux:
m.ResetLinux()
return nil
case keybinding.FieldExtension:
m.ResetExtension()
return nil
case keybinding.FieldEnabled:
m.ResetEnabled()
return nil
case keybinding.FieldPreventDefault:
m.ResetPreventDefault()
return nil
case keybinding.FieldScope:
m.ResetScope()
return nil
}
return fmt.Errorf("unknown KeyBinding field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *KeyBindingMutation) AddedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *KeyBindingMutation) AddedIDs(name string) []ent.Value {
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *KeyBindingMutation) RemovedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *KeyBindingMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *KeyBindingMutation) ClearedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *KeyBindingMutation) EdgeCleared(name string) bool {
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 *KeyBindingMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown KeyBinding 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 *KeyBindingMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown KeyBinding edge %s", name)
}
// ThemeMutation represents an operation that mutates the Theme nodes in the graph.
type ThemeMutation struct {
config
op Op
typ string
id *int
uuid *string
created_at *string
updated_at *string
deleted_at *string
name *string
_type *theme.Type
colors *map[string]interface{}
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*Theme, error)
predicates []predicate.Theme
}
var _ ent.Mutation = (*ThemeMutation)(nil)
// themeOption allows management of the mutation configuration using functional options.
type themeOption func(*ThemeMutation)
// newThemeMutation creates new mutation for the Theme entity.
func newThemeMutation(c config, op Op, opts ...themeOption) *ThemeMutation {
m := &ThemeMutation{
config: c,
op: op,
typ: TypeTheme,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withThemeID sets the ID field of the mutation.
func withThemeID(id int) themeOption {
return func(m *ThemeMutation) {
var (
err error
once sync.Once
value *Theme
)
m.oldValue = func(ctx context.Context) (*Theme, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Theme.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withTheme sets the old Theme of the mutation.
func withTheme(node *Theme) themeOption {
return func(m *ThemeMutation) {
m.oldValue = func(context.Context) (*Theme, 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 ThemeMutation) 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 ThemeMutation) 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
}
// 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 *ThemeMutation) ID() (id int, 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 *ThemeMutation) IDs(ctx context.Context) ([]int, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().Theme.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetUUID sets the "uuid" field.
func (m *ThemeMutation) SetUUID(s string) {
m.uuid = &s
}
// UUID returns the value of the "uuid" field in the mutation.
func (m *ThemeMutation) UUID() (r string, exists bool) {
v := m.uuid
if v == nil {
return
}
return *v, true
}
// OldUUID returns the old "uuid" field's value of the Theme entity.
// If the Theme 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 *ThemeMutation) OldUUID(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUUID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUUID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUUID: %w", err)
}
return oldValue.UUID, nil
}
// ResetUUID resets all changes to the "uuid" field.
func (m *ThemeMutation) ResetUUID() {
m.uuid = nil
}
// SetCreatedAt sets the "created_at" field.
func (m *ThemeMutation) SetCreatedAt(s string) {
m.created_at = &s
}
// CreatedAt returns the value of the "created_at" field in the mutation.
func (m *ThemeMutation) CreatedAt() (r string, exists bool) {
v := m.created_at
if v == nil {
return
}
return *v, true
}
// OldCreatedAt returns the old "created_at" field's value of the Theme entity.
// If the Theme 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 *ThemeMutation) OldCreatedAt(ctx context.Context) (v string, 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 *ThemeMutation) ResetCreatedAt() {
m.created_at = nil
}
// SetUpdatedAt sets the "updated_at" field.
func (m *ThemeMutation) SetUpdatedAt(s string) {
m.updated_at = &s
}
// UpdatedAt returns the value of the "updated_at" field in the mutation.
func (m *ThemeMutation) UpdatedAt() (r string, exists bool) {
v := m.updated_at
if v == nil {
return
}
return *v, true
}
// OldUpdatedAt returns the old "updated_at" field's value of the Theme entity.
// If the Theme 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 *ThemeMutation) OldUpdatedAt(ctx context.Context) (v string, 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 *ThemeMutation) ResetUpdatedAt() {
m.updated_at = nil
}
// SetDeletedAt sets the "deleted_at" field.
func (m *ThemeMutation) SetDeletedAt(s string) {
m.deleted_at = &s
}
// DeletedAt returns the value of the "deleted_at" field in the mutation.
func (m *ThemeMutation) DeletedAt() (r string, exists bool) {
v := m.deleted_at
if v == nil {
return
}
return *v, true
}
// OldDeletedAt returns the old "deleted_at" field's value of the Theme entity.
// If the Theme 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 *ThemeMutation) OldDeletedAt(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDeletedAt is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDeletedAt requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDeletedAt: %w", err)
}
return oldValue.DeletedAt, nil
}
// ClearDeletedAt clears the value of the "deleted_at" field.
func (m *ThemeMutation) ClearDeletedAt() {
m.deleted_at = nil
m.clearedFields[theme.FieldDeletedAt] = struct{}{}
}
// DeletedAtCleared returns if the "deleted_at" field was cleared in this mutation.
func (m *ThemeMutation) DeletedAtCleared() bool {
_, ok := m.clearedFields[theme.FieldDeletedAt]
return ok
}
// ResetDeletedAt resets all changes to the "deleted_at" field.
func (m *ThemeMutation) ResetDeletedAt() {
m.deleted_at = nil
delete(m.clearedFields, theme.FieldDeletedAt)
}
// SetName sets the "name" field.
func (m *ThemeMutation) SetName(s string) {
m.name = &s
}
// Name returns the value of the "name" field in the mutation.
func (m *ThemeMutation) 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 Theme entity.
// If the Theme 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 *ThemeMutation) 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 *ThemeMutation) ResetName() {
m.name = nil
}
// SetType sets the "type" field.
func (m *ThemeMutation) SetType(t theme.Type) {
m._type = &t
}
// GetType returns the value of the "type" field in the mutation.
func (m *ThemeMutation) GetType() (r theme.Type, exists bool) {
v := m._type
if v == nil {
return
}
return *v, true
}
// OldType returns the old "type" field's value of the Theme entity.
// If the Theme 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 *ThemeMutation) OldType(ctx context.Context) (v theme.Type, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldType is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldType requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldType: %w", err)
}
return oldValue.Type, nil
}
// ResetType resets all changes to the "type" field.
func (m *ThemeMutation) ResetType() {
m._type = nil
}
// SetColors sets the "colors" field.
func (m *ThemeMutation) SetColors(value map[string]interface{}) {
m.colors = &value
}
// Colors returns the value of the "colors" field in the mutation.
func (m *ThemeMutation) Colors() (r map[string]interface{}, exists bool) {
v := m.colors
if v == nil {
return
}
return *v, true
}
// OldColors returns the old "colors" field's value of the Theme entity.
// If the Theme 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 *ThemeMutation) OldColors(ctx context.Context) (v map[string]interface{}, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldColors is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldColors requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldColors: %w", err)
}
return oldValue.Colors, nil
}
// ClearColors clears the value of the "colors" field.
func (m *ThemeMutation) ClearColors() {
m.colors = nil
m.clearedFields[theme.FieldColors] = struct{}{}
}
// ColorsCleared returns if the "colors" field was cleared in this mutation.
func (m *ThemeMutation) ColorsCleared() bool {
_, ok := m.clearedFields[theme.FieldColors]
return ok
}
// ResetColors resets all changes to the "colors" field.
func (m *ThemeMutation) ResetColors() {
m.colors = nil
delete(m.clearedFields, theme.FieldColors)
}
// Where appends a list predicates to the ThemeMutation builder.
func (m *ThemeMutation) Where(ps ...predicate.Theme) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the ThemeMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *ThemeMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.Theme, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *ThemeMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *ThemeMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (Theme).
func (m *ThemeMutation) 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 *ThemeMutation) Fields() []string {
fields := make([]string, 0, 7)
if m.uuid != nil {
fields = append(fields, theme.FieldUUID)
}
if m.created_at != nil {
fields = append(fields, theme.FieldCreatedAt)
}
if m.updated_at != nil {
fields = append(fields, theme.FieldUpdatedAt)
}
if m.deleted_at != nil {
fields = append(fields, theme.FieldDeletedAt)
}
if m.name != nil {
fields = append(fields, theme.FieldName)
}
if m._type != nil {
fields = append(fields, theme.FieldType)
}
if m.colors != nil {
fields = append(fields, theme.FieldColors)
}
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 *ThemeMutation) Field(name string) (ent.Value, bool) {
switch name {
case theme.FieldUUID:
return m.UUID()
case theme.FieldCreatedAt:
return m.CreatedAt()
case theme.FieldUpdatedAt:
return m.UpdatedAt()
case theme.FieldDeletedAt:
return m.DeletedAt()
case theme.FieldName:
return m.Name()
case theme.FieldType:
return m.GetType()
case theme.FieldColors:
return m.Colors()
}
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 *ThemeMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case theme.FieldUUID:
return m.OldUUID(ctx)
case theme.FieldCreatedAt:
return m.OldCreatedAt(ctx)
case theme.FieldUpdatedAt:
return m.OldUpdatedAt(ctx)
case theme.FieldDeletedAt:
return m.OldDeletedAt(ctx)
case theme.FieldName:
return m.OldName(ctx)
case theme.FieldType:
return m.OldType(ctx)
case theme.FieldColors:
return m.OldColors(ctx)
}
return nil, fmt.Errorf("unknown Theme 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 *ThemeMutation) SetField(name string, value ent.Value) error {
switch name {
case theme.FieldUUID:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUUID(v)
return nil
case theme.FieldCreatedAt:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreatedAt(v)
return nil
case theme.FieldUpdatedAt:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUpdatedAt(v)
return nil
case theme.FieldDeletedAt:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDeletedAt(v)
return nil
case theme.FieldName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetName(v)
return nil
case theme.FieldType:
v, ok := value.(theme.Type)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetType(v)
return nil
case theme.FieldColors:
v, ok := value.(map[string]interface{})
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetColors(v)
return nil
}
return fmt.Errorf("unknown Theme field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *ThemeMutation) 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 *ThemeMutation) 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 *ThemeMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown Theme numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *ThemeMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(theme.FieldDeletedAt) {
fields = append(fields, theme.FieldDeletedAt)
}
if m.FieldCleared(theme.FieldColors) {
fields = append(fields, theme.FieldColors)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *ThemeMutation) 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 *ThemeMutation) ClearField(name string) error {
switch name {
case theme.FieldDeletedAt:
m.ClearDeletedAt()
return nil
case theme.FieldColors:
m.ClearColors()
return nil
}
return fmt.Errorf("unknown Theme 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 *ThemeMutation) ResetField(name string) error {
switch name {
case theme.FieldUUID:
m.ResetUUID()
return nil
case theme.FieldCreatedAt:
m.ResetCreatedAt()
return nil
case theme.FieldUpdatedAt:
m.ResetUpdatedAt()
return nil
case theme.FieldDeletedAt:
m.ResetDeletedAt()
return nil
case theme.FieldName:
m.ResetName()
return nil
case theme.FieldType:
m.ResetType()
return nil
case theme.FieldColors:
m.ResetColors()
return nil
}
return fmt.Errorf("unknown Theme field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *ThemeMutation) AddedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *ThemeMutation) AddedIDs(name string) []ent.Value {
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *ThemeMutation) RemovedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *ThemeMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *ThemeMutation) ClearedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *ThemeMutation) EdgeCleared(name string) bool {
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 *ThemeMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown Theme 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 *ThemeMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown Theme edge %s", name)
}