From bcc5c7493dcf2d5aeb70516639ce59b4512bd818 Mon Sep 17 00:00:00 2001 From: Achim Rohn Date: Sun, 16 Nov 2025 19:09:01 +0100 Subject: [PATCH] Add general queue --- cli/generate_schema.go | 18 + mapping.go | 39 + must.go | 7 + queue/general_queue.go | 395 ++++ schema/ent/client.go | 483 +++++ schema/ent/{example/ent => }/ent.go | 10 +- .../ent/{example/ent => }/enttest/enttest.go | 7 +- schema/ent/example/ent/client.go | 692 ------- schema/ent/example/ent/group.go | 170 -- schema/ent/example/ent/group/group.go | 141 -- schema/ent/example/ent/group/where.go | 277 --- schema/ent/example/ent/group_create.go | 316 --- schema/ent/example/ent/group_delete.go | 88 - schema/ent/example/ent/group_query.go | 712 ------- schema/ent/example/ent/group_update.go | 572 ------ schema/ent/example/ent/migrate/schema.go | 99 - schema/ent/example/ent/mutation.go | 1778 ----------------- schema/ent/example/ent/predicate/predicate.go | 16 - schema/ent/example/ent/runtime.go | 82 - schema/ent/example/ent/schema/group.go | 34 - schema/ent/example/ent/schema/todo.go | 32 - schema/ent/example/ent/schema/user.go | 35 - schema/ent/example/ent/todo.go | 180 -- schema/ent/example/ent/todo/todo.go | 121 -- schema/ent/example/ent/todo/where.go | 269 --- schema/ent/example/ent/todo_create.go | 314 --- schema/ent/example/ent/todo_delete.go | 88 - schema/ent/example/ent/todo_update.go | 389 ---- schema/ent/example/ent/user.go | 165 -- schema/ent/example/ent/user/user.go | 121 -- schema/ent/example/ent/user/where.go | 324 --- schema/ent/example/ent/user_create.go | 309 --- schema/ent/example/ent/user_delete.go | 88 - schema/ent/example/ent/user_update.go | 443 ---- schema/ent/example/generate_schema.go | 28 - schema/ent/example/start.go | 143 -- schema/ent/generalqueue.go | 225 +++ schema/ent/generalqueue/generalqueue.go | 146 ++ schema/ent/generalqueue/where.go | 495 +++++ schema/ent/generalqueue_create.go | 353 ++++ schema/ent/generalqueue_delete.go | 88 + .../todo_query.go => generalqueue_query.go} | 281 +-- schema/ent/generalqueue_update.go | 640 ++++++ schema/ent/generalqueuestate.go | 130 ++ .../generalqueuestate/generalqueuestate.go | 68 + schema/ent/generalqueuestate/where.go | 200 ++ schema/ent/generalqueuestate_create.go | 228 +++ schema/ent/generalqueuestate_delete.go | 88 + ...er_query.go => generalqueuestate_query.go} | 304 +-- schema/ent/generalqueuestate_update.go | 244 +++ schema/ent/{example/ent => }/hook/hook.go | 39 +- .../ent/{example/ent => }/migrate/migrate.go | 0 schema/ent/migrate/schema.go | 60 + schema/ent/mutation.go | 1478 ++++++++++++++ .../ent/{example/ent => }/pagination_query.go | 46 +- schema/ent/predicate/predicate.go | 13 + schema/ent/runtime.go | 31 + .../ent/{example/ent => }/runtime/runtime.go | 2 +- schema/ent/time_mixin.go | 2 +- schema/ent/{example/ent => }/tx.go | 17 +- 60 files changed, 5657 insertions(+), 8506 deletions(-) create mode 100644 cli/generate_schema.go create mode 100644 mapping.go create mode 100644 must.go create mode 100644 queue/general_queue.go create mode 100644 schema/ent/client.go rename schema/ent/{example/ent => }/ent.go (98%) rename schema/ent/{example/ent => }/enttest/enttest.go (90%) delete mode 100644 schema/ent/example/ent/client.go delete mode 100644 schema/ent/example/ent/group.go delete mode 100644 schema/ent/example/ent/group/group.go delete mode 100644 schema/ent/example/ent/group/where.go delete mode 100644 schema/ent/example/ent/group_create.go delete mode 100644 schema/ent/example/ent/group_delete.go delete mode 100644 schema/ent/example/ent/group_query.go delete mode 100644 schema/ent/example/ent/group_update.go delete mode 100644 schema/ent/example/ent/migrate/schema.go delete mode 100644 schema/ent/example/ent/mutation.go delete mode 100644 schema/ent/example/ent/predicate/predicate.go delete mode 100644 schema/ent/example/ent/runtime.go delete mode 100644 schema/ent/example/ent/schema/group.go delete mode 100644 schema/ent/example/ent/schema/todo.go delete mode 100644 schema/ent/example/ent/schema/user.go delete mode 100644 schema/ent/example/ent/todo.go delete mode 100644 schema/ent/example/ent/todo/todo.go delete mode 100644 schema/ent/example/ent/todo/where.go delete mode 100644 schema/ent/example/ent/todo_create.go delete mode 100644 schema/ent/example/ent/todo_delete.go delete mode 100644 schema/ent/example/ent/todo_update.go delete mode 100644 schema/ent/example/ent/user.go delete mode 100644 schema/ent/example/ent/user/user.go delete mode 100644 schema/ent/example/ent/user/where.go delete mode 100644 schema/ent/example/ent/user_create.go delete mode 100644 schema/ent/example/ent/user_delete.go delete mode 100644 schema/ent/example/ent/user_update.go delete mode 100644 schema/ent/example/generate_schema.go delete mode 100644 schema/ent/example/start.go create mode 100644 schema/ent/generalqueue.go create mode 100644 schema/ent/generalqueue/generalqueue.go create mode 100644 schema/ent/generalqueue/where.go create mode 100644 schema/ent/generalqueue_create.go create mode 100644 schema/ent/generalqueue_delete.go rename schema/ent/{example/ent/todo_query.go => generalqueue_query.go} (54%) create mode 100644 schema/ent/generalqueue_update.go create mode 100644 schema/ent/generalqueuestate.go create mode 100644 schema/ent/generalqueuestate/generalqueuestate.go create mode 100644 schema/ent/generalqueuestate/where.go create mode 100644 schema/ent/generalqueuestate_create.go create mode 100644 schema/ent/generalqueuestate_delete.go rename schema/ent/{example/ent/user_query.go => generalqueuestate_query.go} (51%) create mode 100644 schema/ent/generalqueuestate_update.go rename schema/ent/{example/ent => }/hook/hook.go (81%) rename schema/ent/{example/ent => }/migrate/migrate.go (100%) create mode 100644 schema/ent/migrate/schema.go create mode 100644 schema/ent/mutation.go rename schema/ent/{example/ent => }/pagination_query.go (55%) create mode 100644 schema/ent/predicate/predicate.go create mode 100644 schema/ent/runtime.go rename schema/ent/{example/ent => }/runtime/runtime.go (71%) rename schema/ent/{example/ent => }/tx.go (93%) diff --git a/cli/generate_schema.go b/cli/generate_schema.go new file mode 100644 index 0000000..7c47895 --- /dev/null +++ b/cli/generate_schema.go @@ -0,0 +1,18 @@ +package main + +import ( + . "git.gorlug.de/code/ersteller" + + "entgo.io/ent/entc" + "entgo.io/ent/entc/gen" +) + +func main() { + Debug("ersteller schema generation") + paginationPath := "starter/ent/schema/pagination_query.tmpl" + Must(entc.Generate( + "./schema/ent/schema", + &gen.Config{}, + entc.TemplateFiles(paginationPath), + )) +} diff --git a/mapping.go b/mapping.go new file mode 100644 index 0000000..3503703 --- /dev/null +++ b/mapping.go @@ -0,0 +1,39 @@ +package ersteller + +import "encoding/json" + +type JSONB map[string]interface{} + +func StructToMap(data interface{}) (JSONB, error) { + var result JSONB + + // Marshal struct to JSON bytes + jsonBytes, err := json.Marshal(data) + if err != nil { + return nil, err + } + + // Unmarshal JSON bytes to map + err = json.Unmarshal(jsonBytes, &result) + if err != nil { + return nil, err + } + + return result, nil +} + +func MapToStruct(data JSONB, result interface{}) error { + // Marshal map to JSON bytes + jsonBytes, err := json.Marshal(data) + if err != nil { + return err + } + + // Unmarshal JSON bytes to struct + err = json.Unmarshal(jsonBytes, result) + if err != nil { + return err + } + + return nil +} diff --git a/must.go b/must.go new file mode 100644 index 0000000..a4648c4 --- /dev/null +++ b/must.go @@ -0,0 +1,7 @@ +package ersteller + +func Must(err error) { + if err != nil { + Error(err) + } +} diff --git a/queue/general_queue.go b/queue/general_queue.go new file mode 100644 index 0000000..29936e0 --- /dev/null +++ b/queue/general_queue.go @@ -0,0 +1,395 @@ +package queue + +import ( + "context" + "fmt" + "log" + "time" + + . "git.gorlug.de/code/ersteller" + "git.gorlug.de/code/ersteller/schema/ent" + "git.gorlug.de/code/ersteller/schema/ent/generalqueue" + "git.gorlug.de/code/ersteller/schema/ent/generalqueuestate" +) + +type GeneralQueueStatus string + +const ( + GeneralQueueStatusPending GeneralQueueStatus = "pending" + GeneralQueueStatusInProgress GeneralQueueStatus = "in_progress" + GeneralQueueStatusCompleted GeneralQueueStatus = "completed" + GeneralQueueStatusFailed GeneralQueueStatus = "failed" +) + +type GeneralQueueJob struct { + ID int + CreatedAt time.Time + NumberOfTries int + Payload map[string]interface{} + Status GeneralQueueStatus + FailurePayload map[string]interface{} + ResultPayload map[string]interface{} +} + +type GeneralQueueHandlerResult struct { + ResultPayload map[string]interface{} + FailurePayload map[string]interface{} +} + +type GeneralQueueHandler func(ctx context.Context, job GeneralQueueJob) (GeneralQueueHandlerResult, error) + +type GeneralQueue struct { + Name string + client *ent.Client + running bool + stopChan chan bool + handler GeneralQueueHandler +} + +// NewGeneralQueue creates a new general queue instance +func NewGeneralQueue(name string, client *ent.Client, handler GeneralQueueHandler) *GeneralQueue { + return &GeneralQueue{ + Name: name, + client: client, + running: false, + stopChan: make(chan bool, 1), + handler: handler, + } +} + +// SetRunning persists the running state of the queue to the database +func (q *GeneralQueue) SetRunning(ctx context.Context, running bool) error { + now := time.Now() + + // Try to find existing state + existing, err := q.client.GeneralQueueState.Query(). + Where(generalqueuestate.NameEQ(q.Name)). + First(ctx) + + if err != nil && !ent.IsNotFound(err) { + return fmt.Errorf("failed to query queue state: %w", err) + } + + if existing != nil { + // Update existing + err = q.client.GeneralQueueState.UpdateOne(existing). + SetRunning(running). + SetUpdatedAt(now). + Exec(ctx) + if err != nil { + return fmt.Errorf("failed to update queue running state: %w", err) + } + } else { + // Create new + _, err = q.client.GeneralQueueState.Create(). + SetName(q.Name). + SetRunning(running). + SetUpdatedAt(now). + Save(ctx) + if err != nil { + return fmt.Errorf("failed to create queue running state: %w", err) + } + } + + return nil +} + +// IsRunning returns the persisted running state of the queue from the database +func (q *GeneralQueue) IsRunning(ctx context.Context) (bool, error) { + state, err := q.client.GeneralQueueState.Query(). + Where(generalqueuestate.NameEQ(q.Name)). + First(ctx) + + if err != nil { + if ent.IsNotFound(err) { + return false, nil // No state record means not running + } + return false, fmt.Errorf("failed to get queue running state: %w", err) + } + + return state.Running, nil +} + +// Start begins processing jobs from the queue in a background goroutine +func (q *GeneralQueue) Start(ctx context.Context) error { + if q.running { + return nil + } + q.running = true + if err := q.SetRunning(ctx, true); err != nil { + Error("Failed to persist queue running state (start):", err) + return err + } + go q.loop(ctx, q.handler) + LogDebug("Queue '%s' started", q.Name) + return nil +} + +// Stop stops the queue from processing new jobs +func (q *GeneralQueue) Stop(ctx context.Context) error { + if !q.running { + return nil + } + q.stopChan <- true + q.running = false + if err := q.SetRunning(ctx, false); err != nil { + Error("Failed to persist queue running state (stop):", err) + return err + } + LogDebug("Queue '%s' stopped", q.Name) + return nil +} + +// loop processes jobs continuously until stopped +func (q *GeneralQueue) loop(ctx context.Context, handler GeneralQueueHandler) { + ticker := time.NewTicker(5 * time.Second) + defer ticker.Stop() + + for { + select { + case <-q.stopChan: + return + case <-ctx.Done(): + q.running = false + if err := q.SetRunning(ctx, false); err != nil { + Error("Failed to persist queue running state (context done):", err) + } + return + case <-ticker.C: + // Process at most one job per tick + processed, err := q.processNext(ctx, handler) + if err != nil { + LogError("Queue '%s' processing error:", q.Name, err) + } + if !processed { + // No more jobs, auto-stop + q.running = false + if err := q.SetRunning(ctx, false); err != nil { + LogError("Failed to persist queue running state (auto-stop):", err) + } + LogDebug("Queue '%s' completed. Auto-stopping.", q.Name) + return + } + } + } +} + +// processNext processes the next pending job and returns true if a job was processed +func (q *GeneralQueue) processNext(ctx context.Context, handler GeneralQueueHandler) (bool, error) { + job, err := q.GetNextPendingJob(ctx) + if err != nil { + return false, err + } + if job == nil { + return false, nil // No pending jobs + } + + // Mark job as in progress + err = q.UpdateJobStatus(ctx, job.ID, generalqueue.StatusInProgress, "", nil, nil) + if err != nil { + log.Printf("Failed to mark job %d as in progress: %v", job.ID, err) + return true, err + } + + // Create job struct for handler + queueJob := GeneralQueueJob{ + ID: job.ID, + CreatedAt: job.CreatedAt, + NumberOfTries: job.NumberOfTries, + Payload: job.Payload, + Status: GeneralQueueStatus(job.Status), + FailurePayload: job.FailurePayload, + } + + // Create a context with 15-minute timeout for job processing + jobCtx, cancel := context.WithTimeout(ctx, 15*time.Minute) + defer cancel() + + // Process the job with timeout + type handlerResult struct { + err error + resultPayload any + errPayload any + } + resultChan := make(chan handlerResult, 1) + + go func() { + //handlerErr, handlerResultPayload, handlerErrPayload := handler(jobCtx, queueJob) + result, err := handler(jobCtx, queueJob) + resultChan <- handlerResult{err: err, resultPayload: result.ResultPayload, errPayload: result.FailurePayload} + }() + + var handlerErr error + var resultPayload any + var errPayload any + + select { + case result := <-resultChan: + handlerErr = result.err + resultPayload = result.resultPayload + errPayload = result.errPayload + case <-jobCtx.Done(): + // Timeout occurred + handlerErr = fmt.Errorf("job processing timeout after 15 minutes") + resultPayload = nil + errPayload = nil + } + + // Process the job + err = handlerErr + if err != nil { + // Increment tries + if incrementErr := q.IncrementTries(ctx, job.ID, job.NumberOfTries); incrementErr != nil { + log.Printf("Failed to increment tries for job %d: %v", job.ID, incrementErr) + } + + // Check if we should retry or fail + if job.NumberOfTries+1 >= job.MaxRetries { + errPayloadMap, mapErr := StructToMap(errPayload) + if mapErr != nil { + Error("failed to convert error payload to map:", mapErr) + errPayloadMap = map[string]interface{}{} + } + + // Max retries reached, mark as failed + failurePayload := map[string]interface{}{ + "error": err.Error(), + "errorPayload": errPayloadMap, + } + if updateErr := q.UpdateJobStatus(ctx, job.ID, generalqueue.StatusFailed, err.Error(), failurePayload, nil); updateErr != nil { + log.Printf("Failed to mark job %d as failed: %v", job.ID, updateErr) + } + } else { + // Retry - mark as pending again + if updateErr := q.UpdateJobStatus(ctx, job.ID, generalqueue.StatusPending, err.Error(), nil, nil); updateErr != nil { + log.Printf("Failed to mark job %d as pending for retry: %v", job.ID, updateErr) + } + } + return true, err + } + + // Job succeeded, mark as completed + resultPayloadMap, mapErr := StructToMap(resultPayload) + if mapErr != nil { + Error("failed to convert result payload to map:", mapErr) + resultPayloadMap = map[string]interface{}{} + } + + err = q.UpdateJobStatus(ctx, job.ID, generalqueue.StatusCompleted, "", nil, resultPayloadMap) + if err != nil { + log.Printf("Failed to mark job %d as completed: %v", job.ID, err) + } + + return true, nil +} + +// Enqueue adds a new job to the queue +func (q *GeneralQueue) Enqueue(ctx context.Context, payload any, maxRetries int, userId int, groupId int) (*ent.GeneralQueue, error) { + now := time.Now() + + payloadMap, err := StructToMap(payload) + if err != nil { + Error("failed to convert payload to map:", err) + return nil, fmt.Errorf("failed to convert payload to map: %w", err) + } + + create := q.client.GeneralQueue.Create(). + SetName(q.Name). + SetPayload(payloadMap). + SetStatus(generalqueue.StatusPending). + SetNumberOfTries(0). + SetMaxRetries(maxRetries). + SetCreatedAt(now). + SetUpdatedAt(now) + + job, err := create.Save(ctx) + + if err != nil { + return nil, fmt.Errorf("failed to enqueue job: %w", err) + } + + return job, nil +} + +// GetNextPendingJob retrieves the next pending job from the queue +func (q *GeneralQueue) GetNextPendingJob(ctx context.Context) (*ent.GeneralQueue, error) { + job, err := q.client.GeneralQueue.Query(). + Where( + generalqueue.NameEQ(q.Name), + generalqueue.StatusEQ(generalqueue.StatusPending), + ). + Order(ent.Asc(generalqueue.FieldCreatedAt)). + First(ctx) + + if err != nil { + if ent.IsNotFound(err) { + return nil, nil // No pending jobs + } + return nil, fmt.Errorf("failed to get next pending job: %w", err) + } + + return job, nil +} + +// UpdateJobStatus updates the status of a job +func (q *GeneralQueue) UpdateJobStatus(ctx context.Context, jobID int, status generalqueue.Status, errorMessage string, failurePayload map[string]interface{}, resultPayload map[string]interface{}) error { + update := q.client.GeneralQueue.UpdateOneID(jobID). + SetStatus(status). + SetUpdatedAt(time.Now()) + + if status == generalqueue.StatusCompleted || status == generalqueue.StatusFailed { + update = update.SetProcessedAt(time.Now()) + } + + if errorMessage != "" { + update = update.SetErrorMessage(errorMessage) + } + + if failurePayload != nil { + update = update.SetFailurePayload(failurePayload) + } + + if resultPayload != nil { + update = update.SetResultPayload(resultPayload) + } + + _, err := update.Save(ctx) + if err != nil { + return fmt.Errorf("failed to update job status: %w", err) + } + + return nil +} + +// IncrementTries increments the number of tries for a job +func (q *GeneralQueue) IncrementTries(ctx context.Context, jobID int, currentTries int) error { + _, err := q.client.GeneralQueue.UpdateOneID(jobID). + SetNumberOfTries(currentTries + 1). + SetUpdatedAt(time.Now()). + Save(ctx) + + if err != nil { + return fmt.Errorf("failed to increment tries: %w", err) + } + + return nil +} + +func (q *GeneralQueue) Resume(ctx context.Context) error { + // Check if queue should auto-start + if isRunning, err := q.IsRunning(ctx); err != nil { + Error("Failed to check ", q.Name, " queue state:", err) + } else if isRunning { + Debug("restarting ", q.Name, " queue") + err := q.Start(ctx) + if err != nil { + Error("Failed to restart ", q.Name, " queue:", err) + return err + } else { + Debug(q.Name, " queue auto-started") + } + } else { + Debug(q.Name, " queue not running") + } + return nil +} diff --git a/schema/ent/client.go b/schema/ent/client.go new file mode 100644 index 0000000..7ed8e15 --- /dev/null +++ b/schema/ent/client.go @@ -0,0 +1,483 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "log" + "reflect" + + "git.gorlug.de/code/ersteller/schema/ent/migrate" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "git.gorlug.de/code/ersteller/schema/ent/generalqueue" + "git.gorlug.de/code/ersteller/schema/ent/generalqueuestate" +) + +// Client is the client that holds all ent builders. +type Client struct { + config + // Schema is the client for creating, migrating and dropping schema. + Schema *migrate.Schema + // GeneralQueue is the client for interacting with the GeneralQueue builders. + GeneralQueue *GeneralQueueClient + // GeneralQueueState is the client for interacting with the GeneralQueueState builders. + GeneralQueueState *GeneralQueueStateClient +} + +// NewClient creates a new client configured with the given options. +func NewClient(opts ...Option) *Client { + client := &Client{config: newConfig(opts...)} + client.init() + return client +} + +func (c *Client) init() { + c.Schema = migrate.NewSchema(c.driver) + c.GeneralQueue = NewGeneralQueueClient(c.config) + c.GeneralQueueState = NewGeneralQueueStateClient(c.config) +} + +type ( + // config is the configuration for the client and its builder. + config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...any) + // hooks to execute on mutations. + hooks *hooks + // interceptors to execute on queries. + inters *inters + } + // Option function to configure the client. + Option func(*config) +) + +// newConfig creates a new config for the client. +func newConfig(opts ...Option) config { + cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} + cfg.options(opts...) + return cfg +} + +// options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...any)) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} + +// Open opens a database/sql.DB specified by the driver name and +// the data source name, and returns a new client attached to it. +// Optional parameters can be added for configuring the client. +func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { + switch driverName { + case dialect.MySQL, dialect.Postgres, dialect.SQLite: + drv, err := sql.Open(driverName, dataSourceName) + if err != nil { + return nil, err + } + return NewClient(append(options, Driver(drv))...), nil + default: + return nil, fmt.Errorf("unsupported driver: %q", driverName) + } +} + +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + +// Tx returns a new transactional client. The provided context +// is used until the transaction is committed or rolled back. +func (c *Client) Tx(ctx context.Context) (*Tx, error) { + if _, ok := c.driver.(*txDriver); ok { + return nil, ErrTxStarted + } + tx, err := newTx(ctx, c.driver) + if err != nil { + return nil, fmt.Errorf("ent: starting a transaction: %w", err) + } + cfg := c.config + cfg.driver = tx + return &Tx{ + ctx: ctx, + config: cfg, + GeneralQueue: NewGeneralQueueClient(cfg), + GeneralQueueState: NewGeneralQueueStateClient(cfg), + }, nil +} + +// BeginTx returns a transactional client with specified options. +func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { + if _, ok := c.driver.(*txDriver); ok { + return nil, errors.New("ent: cannot start a transaction within a transaction") + } + tx, err := c.driver.(interface { + BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) + }).BeginTx(ctx, opts) + if err != nil { + return nil, fmt.Errorf("ent: starting a transaction: %w", err) + } + cfg := c.config + cfg.driver = &txDriver{tx: tx, drv: c.driver} + return &Tx{ + ctx: ctx, + config: cfg, + GeneralQueue: NewGeneralQueueClient(cfg), + GeneralQueueState: NewGeneralQueueStateClient(cfg), + }, nil +} + +// Debug returns a new debug-client. It's used to get verbose logging on specific operations. +// +// client.Debug(). +// GeneralQueue. +// Query(). +// Count(ctx) +func (c *Client) Debug() *Client { + if c.debug { + return c + } + cfg := c.config + cfg.driver = dialect.Debug(c.driver, c.log) + client := &Client{config: cfg} + client.init() + return client +} + +// Close closes the database connection and prevents new queries from starting. +func (c *Client) Close() error { + return c.driver.Close() +} + +// Use adds the mutation hooks to all the entity clients. +// In order to add hooks to a specific client, call: `client.Node.Use(...)`. +func (c *Client) Use(hooks ...Hook) { + c.GeneralQueue.Use(hooks...) + c.GeneralQueueState.Use(hooks...) +} + +// Intercept adds the query interceptors to all the entity clients. +// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. +func (c *Client) Intercept(interceptors ...Interceptor) { + c.GeneralQueue.Intercept(interceptors...) + c.GeneralQueueState.Intercept(interceptors...) +} + +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *GeneralQueueMutation: + return c.GeneralQueue.mutate(ctx, m) + case *GeneralQueueStateMutation: + return c.GeneralQueueState.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + +// GeneralQueueClient is a client for the GeneralQueue schema. +type GeneralQueueClient struct { + config +} + +// NewGeneralQueueClient returns a client for the GeneralQueue from the given config. +func NewGeneralQueueClient(c config) *GeneralQueueClient { + return &GeneralQueueClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `generalqueue.Hooks(f(g(h())))`. +func (c *GeneralQueueClient) Use(hooks ...Hook) { + c.hooks.GeneralQueue = append(c.hooks.GeneralQueue, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `generalqueue.Intercept(f(g(h())))`. +func (c *GeneralQueueClient) Intercept(interceptors ...Interceptor) { + c.inters.GeneralQueue = append(c.inters.GeneralQueue, interceptors...) +} + +// Create returns a builder for creating a GeneralQueue entity. +func (c *GeneralQueueClient) Create() *GeneralQueueCreate { + mutation := newGeneralQueueMutation(c.config, OpCreate) + return &GeneralQueueCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of GeneralQueue entities. +func (c *GeneralQueueClient) CreateBulk(builders ...*GeneralQueueCreate) *GeneralQueueCreateBulk { + return &GeneralQueueCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *GeneralQueueClient) MapCreateBulk(slice any, setFunc func(*GeneralQueueCreate, int)) *GeneralQueueCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &GeneralQueueCreateBulk{err: fmt.Errorf("calling to GeneralQueueClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*GeneralQueueCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &GeneralQueueCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for GeneralQueue. +func (c *GeneralQueueClient) Update() *GeneralQueueUpdate { + mutation := newGeneralQueueMutation(c.config, OpUpdate) + return &GeneralQueueUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *GeneralQueueClient) UpdateOne(_m *GeneralQueue) *GeneralQueueUpdateOne { + mutation := newGeneralQueueMutation(c.config, OpUpdateOne, withGeneralQueue(_m)) + return &GeneralQueueUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *GeneralQueueClient) UpdateOneID(id int) *GeneralQueueUpdateOne { + mutation := newGeneralQueueMutation(c.config, OpUpdateOne, withGeneralQueueID(id)) + return &GeneralQueueUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for GeneralQueue. +func (c *GeneralQueueClient) Delete() *GeneralQueueDelete { + mutation := newGeneralQueueMutation(c.config, OpDelete) + return &GeneralQueueDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *GeneralQueueClient) DeleteOne(_m *GeneralQueue) *GeneralQueueDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *GeneralQueueClient) DeleteOneID(id int) *GeneralQueueDeleteOne { + builder := c.Delete().Where(generalqueue.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &GeneralQueueDeleteOne{builder} +} + +// Query returns a query builder for GeneralQueue. +func (c *GeneralQueueClient) Query() *GeneralQueueQuery { + return &GeneralQueueQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeGeneralQueue}, + inters: c.Interceptors(), + } +} + +// Get returns a GeneralQueue entity by its id. +func (c *GeneralQueueClient) Get(ctx context.Context, id int) (*GeneralQueue, error) { + return c.Query().Where(generalqueue.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *GeneralQueueClient) GetX(ctx context.Context, id int) *GeneralQueue { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *GeneralQueueClient) Hooks() []Hook { + return c.hooks.GeneralQueue +} + +// Interceptors returns the client interceptors. +func (c *GeneralQueueClient) Interceptors() []Interceptor { + return c.inters.GeneralQueue +} + +func (c *GeneralQueueClient) mutate(ctx context.Context, m *GeneralQueueMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GeneralQueueCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GeneralQueueUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GeneralQueueUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GeneralQueueDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown GeneralQueue mutation op: %q", m.Op()) + } +} + +// GeneralQueueStateClient is a client for the GeneralQueueState schema. +type GeneralQueueStateClient struct { + config +} + +// NewGeneralQueueStateClient returns a client for the GeneralQueueState from the given config. +func NewGeneralQueueStateClient(c config) *GeneralQueueStateClient { + return &GeneralQueueStateClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `generalqueuestate.Hooks(f(g(h())))`. +func (c *GeneralQueueStateClient) Use(hooks ...Hook) { + c.hooks.GeneralQueueState = append(c.hooks.GeneralQueueState, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `generalqueuestate.Intercept(f(g(h())))`. +func (c *GeneralQueueStateClient) Intercept(interceptors ...Interceptor) { + c.inters.GeneralQueueState = append(c.inters.GeneralQueueState, interceptors...) +} + +// Create returns a builder for creating a GeneralQueueState entity. +func (c *GeneralQueueStateClient) Create() *GeneralQueueStateCreate { + mutation := newGeneralQueueStateMutation(c.config, OpCreate) + return &GeneralQueueStateCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of GeneralQueueState entities. +func (c *GeneralQueueStateClient) CreateBulk(builders ...*GeneralQueueStateCreate) *GeneralQueueStateCreateBulk { + return &GeneralQueueStateCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *GeneralQueueStateClient) MapCreateBulk(slice any, setFunc func(*GeneralQueueStateCreate, int)) *GeneralQueueStateCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &GeneralQueueStateCreateBulk{err: fmt.Errorf("calling to GeneralQueueStateClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*GeneralQueueStateCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &GeneralQueueStateCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for GeneralQueueState. +func (c *GeneralQueueStateClient) Update() *GeneralQueueStateUpdate { + mutation := newGeneralQueueStateMutation(c.config, OpUpdate) + return &GeneralQueueStateUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *GeneralQueueStateClient) UpdateOne(_m *GeneralQueueState) *GeneralQueueStateUpdateOne { + mutation := newGeneralQueueStateMutation(c.config, OpUpdateOne, withGeneralQueueState(_m)) + return &GeneralQueueStateUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *GeneralQueueStateClient) UpdateOneID(id int) *GeneralQueueStateUpdateOne { + mutation := newGeneralQueueStateMutation(c.config, OpUpdateOne, withGeneralQueueStateID(id)) + return &GeneralQueueStateUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for GeneralQueueState. +func (c *GeneralQueueStateClient) Delete() *GeneralQueueStateDelete { + mutation := newGeneralQueueStateMutation(c.config, OpDelete) + return &GeneralQueueStateDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *GeneralQueueStateClient) DeleteOne(_m *GeneralQueueState) *GeneralQueueStateDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *GeneralQueueStateClient) DeleteOneID(id int) *GeneralQueueStateDeleteOne { + builder := c.Delete().Where(generalqueuestate.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &GeneralQueueStateDeleteOne{builder} +} + +// Query returns a query builder for GeneralQueueState. +func (c *GeneralQueueStateClient) Query() *GeneralQueueStateQuery { + return &GeneralQueueStateQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeGeneralQueueState}, + inters: c.Interceptors(), + } +} + +// Get returns a GeneralQueueState entity by its id. +func (c *GeneralQueueStateClient) Get(ctx context.Context, id int) (*GeneralQueueState, error) { + return c.Query().Where(generalqueuestate.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *GeneralQueueStateClient) GetX(ctx context.Context, id int) *GeneralQueueState { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *GeneralQueueStateClient) Hooks() []Hook { + return c.hooks.GeneralQueueState +} + +// Interceptors returns the client interceptors. +func (c *GeneralQueueStateClient) Interceptors() []Interceptor { + return c.inters.GeneralQueueState +} + +func (c *GeneralQueueStateClient) mutate(ctx context.Context, m *GeneralQueueStateMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GeneralQueueStateCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GeneralQueueStateUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GeneralQueueStateUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GeneralQueueStateDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown GeneralQueueState mutation op: %q", m.Op()) + } +} + +// hooks and interceptors per client, for fast access. +type ( + hooks struct { + GeneralQueue, GeneralQueueState []ent.Hook + } + inters struct { + GeneralQueue, GeneralQueueState []ent.Interceptor + } +) diff --git a/schema/ent/example/ent/ent.go b/schema/ent/ent.go similarity index 98% rename from schema/ent/example/ent/ent.go rename to schema/ent/ent.go index fe260db..e10d2f5 100644 --- a/schema/ent/example/ent/ent.go +++ b/schema/ent/ent.go @@ -6,15 +6,14 @@ import ( "context" "errors" "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/todo" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/user" "reflect" "sync" "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" + "git.gorlug.de/code/ersteller/schema/ent/generalqueue" + "git.gorlug.de/code/ersteller/schema/ent/generalqueuestate" ) // ent aliases to avoid import conflicts in user's code. @@ -75,9 +74,8 @@ var ( func checkColumn(t, c string) error { initCheck.Do(func() { columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ - group.Table: group.ValidColumn, - todo.Table: todo.ValidColumn, - user.Table: user.ValidColumn, + generalqueue.Table: generalqueue.ValidColumn, + generalqueuestate.Table: generalqueuestate.ValidColumn, }) }) return columnCheck(t, c) diff --git a/schema/ent/example/ent/enttest/enttest.go b/schema/ent/enttest/enttest.go similarity index 90% rename from schema/ent/example/ent/enttest/enttest.go rename to schema/ent/enttest/enttest.go index 6c05639..c134361 100644 --- a/schema/ent/example/ent/enttest/enttest.go +++ b/schema/ent/enttest/enttest.go @@ -5,13 +5,12 @@ package enttest import ( "context" - "git.gorlug.de/code/ersteller/schema/ent/example/ent" + "git.gorlug.de/code/ersteller/schema/ent" // required by schema hooks. - _ "git.gorlug.de/code/ersteller/schema/ent/example/ent/runtime" - - "git.gorlug.de/code/ersteller/schema/ent/example/ent/migrate" + _ "git.gorlug.de/code/ersteller/schema/ent/runtime" "entgo.io/ent/dialect/sql/schema" + "git.gorlug.de/code/ersteller/schema/ent/migrate" ) type ( diff --git a/schema/ent/example/ent/client.go b/schema/ent/example/ent/client.go deleted file mode 100644 index c0136d0..0000000 --- a/schema/ent/example/ent/client.go +++ /dev/null @@ -1,692 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "log" - "reflect" - - "git.gorlug.de/code/ersteller/schema/ent/example/ent/migrate" - - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/todo" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/user" - - "entgo.io/ent" - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" -) - -// Client is the client that holds all ent builders. -type Client struct { - config - // Schema is the client for creating, migrating and dropping schema. - Schema *migrate.Schema - // Group is the client for interacting with the Group builders. - Group *GroupClient - // Todo is the client for interacting with the Todo builders. - Todo *TodoClient - // User is the client for interacting with the User builders. - User *UserClient -} - -// NewClient creates a new client configured with the given options. -func NewClient(opts ...Option) *Client { - client := &Client{config: newConfig(opts...)} - client.init() - return client -} - -func (c *Client) init() { - c.Schema = migrate.NewSchema(c.driver) - c.Group = NewGroupClient(c.config) - c.Todo = NewTodoClient(c.config) - c.User = NewUserClient(c.config) -} - -type ( - // config is the configuration for the client and its builder. - config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters - } - // Option function to configure the client. - Option func(*config) -) - -// newConfig creates a new config for the client. -func newConfig(opts ...Option) config { - cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} - cfg.options(opts...) - return cfg -} - -// options applies the options on the config object. -func (c *config) options(opts ...Option) { - for _, opt := range opts { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} - -// Open opens a database/sql.DB specified by the driver name and -// the data source name, and returns a new client attached to it. -// Optional parameters can be added for configuring the client. -func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { - switch driverName { - case dialect.MySQL, dialect.Postgres, dialect.SQLite: - drv, err := sql.Open(driverName, dataSourceName) - if err != nil { - return nil, err - } - return NewClient(append(options, Driver(drv))...), nil - default: - return nil, fmt.Errorf("unsupported driver: %q", driverName) - } -} - -// ErrTxStarted is returned when trying to start a new transaction from a transactional client. -var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") - -// Tx returns a new transactional client. The provided context -// is used until the transaction is committed or rolled back. -func (c *Client) Tx(ctx context.Context) (*Tx, error) { - if _, ok := c.driver.(*txDriver); ok { - return nil, ErrTxStarted - } - tx, err := newTx(ctx, c.driver) - if err != nil { - return nil, fmt.Errorf("ent: starting a transaction: %w", err) - } - cfg := c.config - cfg.driver = tx - return &Tx{ - ctx: ctx, - config: cfg, - Group: NewGroupClient(cfg), - Todo: NewTodoClient(cfg), - User: NewUserClient(cfg), - }, nil -} - -// BeginTx returns a transactional client with specified options. -func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { - if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") - } - tx, err := c.driver.(interface { - BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) - }).BeginTx(ctx, opts) - if err != nil { - return nil, fmt.Errorf("ent: starting a transaction: %w", err) - } - cfg := c.config - cfg.driver = &txDriver{tx: tx, drv: c.driver} - return &Tx{ - ctx: ctx, - config: cfg, - Group: NewGroupClient(cfg), - Todo: NewTodoClient(cfg), - User: NewUserClient(cfg), - }, nil -} - -// Debug returns a new debug-client. It's used to get verbose logging on specific operations. -// -// client.Debug(). -// Group. -// Query(). -// Count(ctx) -func (c *Client) Debug() *Client { - if c.debug { - return c - } - cfg := c.config - cfg.driver = dialect.Debug(c.driver, c.log) - client := &Client{config: cfg} - client.init() - return client -} - -// Close closes the database connection and prevents new queries from starting. -func (c *Client) Close() error { - return c.driver.Close() -} - -// Use adds the mutation hooks to all the entity clients. -// In order to add hooks to a specific client, call: `client.Node.Use(...)`. -func (c *Client) Use(hooks ...Hook) { - c.Group.Use(hooks...) - c.Todo.Use(hooks...) - c.User.Use(hooks...) -} - -// Intercept adds the query interceptors to all the entity clients. -// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. -func (c *Client) Intercept(interceptors ...Interceptor) { - c.Group.Intercept(interceptors...) - c.Todo.Intercept(interceptors...) - c.User.Intercept(interceptors...) -} - -// Mutate implements the ent.Mutator interface. -func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { - switch m := m.(type) { - case *GroupMutation: - return c.Group.mutate(ctx, m) - case *TodoMutation: - return c.Todo.mutate(ctx, m) - case *UserMutation: - return c.User.mutate(ctx, m) - default: - return nil, fmt.Errorf("ent: unknown mutation type %T", m) - } -} - -// GroupClient is a client for the Group schema. -type GroupClient struct { - config -} - -// NewGroupClient returns a client for the Group from the given config. -func NewGroupClient(c config) *GroupClient { - return &GroupClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `group.Hooks(f(g(h())))`. -func (c *GroupClient) Use(hooks ...Hook) { - c.hooks.Group = append(c.hooks.Group, hooks...) -} - -// Intercept adds a list of query interceptors to the interceptors stack. -// A call to `Intercept(f, g, h)` equals to `group.Intercept(f(g(h())))`. -func (c *GroupClient) Intercept(interceptors ...Interceptor) { - c.inters.Group = append(c.inters.Group, interceptors...) -} - -// Create returns a builder for creating a Group entity. -func (c *GroupClient) Create() *GroupCreate { - mutation := newGroupMutation(c.config, OpCreate) - return &GroupCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of Group entities. -func (c *GroupClient) CreateBulk(builders ...*GroupCreate) *GroupCreateBulk { - return &GroupCreateBulk{config: c.config, builders: builders} -} - -// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates -// a builder and applies setFunc on it. -func (c *GroupClient) MapCreateBulk(slice any, setFunc func(*GroupCreate, int)) *GroupCreateBulk { - rv := reflect.ValueOf(slice) - if rv.Kind() != reflect.Slice { - return &GroupCreateBulk{err: fmt.Errorf("calling to GroupClient.MapCreateBulk with wrong type %T, need slice", slice)} - } - builders := make([]*GroupCreate, rv.Len()) - for i := 0; i < rv.Len(); i++ { - builders[i] = c.Create() - setFunc(builders[i], i) - } - return &GroupCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for Group. -func (c *GroupClient) Update() *GroupUpdate { - mutation := newGroupMutation(c.config, OpUpdate) - return &GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *GroupClient) UpdateOne(_m *Group) *GroupUpdateOne { - mutation := newGroupMutation(c.config, OpUpdateOne, withGroup(_m)) - return &GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *GroupClient) UpdateOneID(id int) *GroupUpdateOne { - mutation := newGroupMutation(c.config, OpUpdateOne, withGroupID(id)) - return &GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for Group. -func (c *GroupClient) Delete() *GroupDelete { - mutation := newGroupMutation(c.config, OpDelete) - return &GroupDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a builder for deleting the given entity. -func (c *GroupClient) DeleteOne(_m *Group) *GroupDeleteOne { - return c.DeleteOneID(_m.ID) -} - -// DeleteOneID returns a builder for deleting the given entity by its id. -func (c *GroupClient) DeleteOneID(id int) *GroupDeleteOne { - builder := c.Delete().Where(group.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &GroupDeleteOne{builder} -} - -// Query returns a query builder for Group. -func (c *GroupClient) Query() *GroupQuery { - return &GroupQuery{ - config: c.config, - ctx: &QueryContext{Type: TypeGroup}, - inters: c.Interceptors(), - } -} - -// Get returns a Group entity by its id. -func (c *GroupClient) Get(ctx context.Context, id int) (*Group, error) { - return c.Query().Where(group.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *GroupClient) GetX(ctx context.Context, id int) *Group { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// QueryUsers queries the users edge of a Group. -func (c *GroupClient) QueryUsers(_m *Group) *UserQuery { - query := (&UserClient{config: c.config}).Query() - query.path = func(context.Context) (fromV *sql.Selector, _ error) { - id := _m.ID - step := sqlgraph.NewStep( - sqlgraph.From(group.Table, group.FieldID, id), - sqlgraph.To(user.Table, user.FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, group.UsersTable, group.UsersPrimaryKey...), - ) - fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// QueryTodos queries the todos edge of a Group. -func (c *GroupClient) QueryTodos(_m *Group) *TodoQuery { - query := (&TodoClient{config: c.config}).Query() - query.path = func(context.Context) (fromV *sql.Selector, _ error) { - id := _m.ID - step := sqlgraph.NewStep( - sqlgraph.From(group.Table, group.FieldID, id), - sqlgraph.To(todo.Table, todo.FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, group.TodosTable, group.TodosColumn), - ) - fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// Hooks returns the client hooks. -func (c *GroupClient) Hooks() []Hook { - return c.hooks.Group -} - -// Interceptors returns the client interceptors. -func (c *GroupClient) Interceptors() []Interceptor { - return c.inters.Group -} - -func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) { - switch m.Op() { - case OpCreate: - return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdate: - return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdateOne: - return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpDelete, OpDeleteOne: - return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) - default: - return nil, fmt.Errorf("ent: unknown Group mutation op: %q", m.Op()) - } -} - -// TodoClient is a client for the Todo schema. -type TodoClient struct { - config -} - -// NewTodoClient returns a client for the Todo from the given config. -func NewTodoClient(c config) *TodoClient { - return &TodoClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `todo.Hooks(f(g(h())))`. -func (c *TodoClient) Use(hooks ...Hook) { - c.hooks.Todo = append(c.hooks.Todo, hooks...) -} - -// Intercept adds a list of query interceptors to the interceptors stack. -// A call to `Intercept(f, g, h)` equals to `todo.Intercept(f(g(h())))`. -func (c *TodoClient) Intercept(interceptors ...Interceptor) { - c.inters.Todo = append(c.inters.Todo, interceptors...) -} - -// Create returns a builder for creating a Todo entity. -func (c *TodoClient) Create() *TodoCreate { - mutation := newTodoMutation(c.config, OpCreate) - return &TodoCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of Todo entities. -func (c *TodoClient) CreateBulk(builders ...*TodoCreate) *TodoCreateBulk { - return &TodoCreateBulk{config: c.config, builders: builders} -} - -// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates -// a builder and applies setFunc on it. -func (c *TodoClient) MapCreateBulk(slice any, setFunc func(*TodoCreate, int)) *TodoCreateBulk { - rv := reflect.ValueOf(slice) - if rv.Kind() != reflect.Slice { - return &TodoCreateBulk{err: fmt.Errorf("calling to TodoClient.MapCreateBulk with wrong type %T, need slice", slice)} - } - builders := make([]*TodoCreate, rv.Len()) - for i := 0; i < rv.Len(); i++ { - builders[i] = c.Create() - setFunc(builders[i], i) - } - return &TodoCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for Todo. -func (c *TodoClient) Update() *TodoUpdate { - mutation := newTodoMutation(c.config, OpUpdate) - return &TodoUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *TodoClient) UpdateOne(_m *Todo) *TodoUpdateOne { - mutation := newTodoMutation(c.config, OpUpdateOne, withTodo(_m)) - return &TodoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *TodoClient) UpdateOneID(id int) *TodoUpdateOne { - mutation := newTodoMutation(c.config, OpUpdateOne, withTodoID(id)) - return &TodoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for Todo. -func (c *TodoClient) Delete() *TodoDelete { - mutation := newTodoMutation(c.config, OpDelete) - return &TodoDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a builder for deleting the given entity. -func (c *TodoClient) DeleteOne(_m *Todo) *TodoDeleteOne { - return c.DeleteOneID(_m.ID) -} - -// DeleteOneID returns a builder for deleting the given entity by its id. -func (c *TodoClient) DeleteOneID(id int) *TodoDeleteOne { - builder := c.Delete().Where(todo.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &TodoDeleteOne{builder} -} - -// Query returns a query builder for Todo. -func (c *TodoClient) Query() *TodoQuery { - return &TodoQuery{ - config: c.config, - ctx: &QueryContext{Type: TypeTodo}, - inters: c.Interceptors(), - } -} - -// Get returns a Todo entity by its id. -func (c *TodoClient) Get(ctx context.Context, id int) (*Todo, error) { - return c.Query().Where(todo.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *TodoClient) GetX(ctx context.Context, id int) *Todo { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// QueryGroup queries the group edge of a Todo. -func (c *TodoClient) QueryGroup(_m *Todo) *GroupQuery { - query := (&GroupClient{config: c.config}).Query() - query.path = func(context.Context) (fromV *sql.Selector, _ error) { - id := _m.ID - step := sqlgraph.NewStep( - sqlgraph.From(todo.Table, todo.FieldID, id), - sqlgraph.To(group.Table, group.FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, todo.GroupTable, todo.GroupColumn), - ) - fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// Hooks returns the client hooks. -func (c *TodoClient) Hooks() []Hook { - return c.hooks.Todo -} - -// Interceptors returns the client interceptors. -func (c *TodoClient) Interceptors() []Interceptor { - return c.inters.Todo -} - -func (c *TodoClient) mutate(ctx context.Context, m *TodoMutation) (Value, error) { - switch m.Op() { - case OpCreate: - return (&TodoCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdate: - return (&TodoUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdateOne: - return (&TodoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpDelete, OpDeleteOne: - return (&TodoDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) - default: - return nil, fmt.Errorf("ent: unknown Todo mutation op: %q", m.Op()) - } -} - -// UserClient is a client for the User schema. -type UserClient struct { - config -} - -// NewUserClient returns a client for the User from the given config. -func NewUserClient(c config) *UserClient { - return &UserClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `user.Hooks(f(g(h())))`. -func (c *UserClient) Use(hooks ...Hook) { - c.hooks.User = append(c.hooks.User, hooks...) -} - -// Intercept adds a list of query interceptors to the interceptors stack. -// A call to `Intercept(f, g, h)` equals to `user.Intercept(f(g(h())))`. -func (c *UserClient) Intercept(interceptors ...Interceptor) { - c.inters.User = append(c.inters.User, interceptors...) -} - -// Create returns a builder for creating a User entity. -func (c *UserClient) Create() *UserCreate { - mutation := newUserMutation(c.config, OpCreate) - return &UserCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of User entities. -func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { - return &UserCreateBulk{config: c.config, builders: builders} -} - -// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates -// a builder and applies setFunc on it. -func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { - rv := reflect.ValueOf(slice) - if rv.Kind() != reflect.Slice { - return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} - } - builders := make([]*UserCreate, rv.Len()) - for i := 0; i < rv.Len(); i++ { - builders[i] = c.Create() - setFunc(builders[i], i) - } - return &UserCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for User. -func (c *UserClient) Update() *UserUpdate { - mutation := newUserMutation(c.config, OpUpdate) - return &UserUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *UserClient) UpdateOne(_m *User) *UserUpdateOne { - mutation := newUserMutation(c.config, OpUpdateOne, withUser(_m)) - return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *UserClient) UpdateOneID(id int) *UserUpdateOne { - mutation := newUserMutation(c.config, OpUpdateOne, withUserID(id)) - return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for User. -func (c *UserClient) Delete() *UserDelete { - mutation := newUserMutation(c.config, OpDelete) - return &UserDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a builder for deleting the given entity. -func (c *UserClient) DeleteOne(_m *User) *UserDeleteOne { - return c.DeleteOneID(_m.ID) -} - -// DeleteOneID returns a builder for deleting the given entity by its id. -func (c *UserClient) DeleteOneID(id int) *UserDeleteOne { - builder := c.Delete().Where(user.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &UserDeleteOne{builder} -} - -// Query returns a query builder for User. -func (c *UserClient) Query() *UserQuery { - return &UserQuery{ - config: c.config, - ctx: &QueryContext{Type: TypeUser}, - inters: c.Interceptors(), - } -} - -// Get returns a User entity by its id. -func (c *UserClient) Get(ctx context.Context, id int) (*User, error) { - return c.Query().Where(user.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *UserClient) GetX(ctx context.Context, id int) *User { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// QueryGroup queries the group edge of a User. -func (c *UserClient) QueryGroup(_m *User) *GroupQuery { - query := (&GroupClient{config: c.config}).Query() - query.path = func(context.Context) (fromV *sql.Selector, _ error) { - id := _m.ID - step := sqlgraph.NewStep( - sqlgraph.From(user.Table, user.FieldID, id), - sqlgraph.To(group.Table, group.FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, user.GroupTable, user.GroupPrimaryKey...), - ) - fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step) - return fromV, nil - } - return query -} - -// Hooks returns the client hooks. -func (c *UserClient) Hooks() []Hook { - return c.hooks.User -} - -// Interceptors returns the client interceptors. -func (c *UserClient) Interceptors() []Interceptor { - return c.inters.User -} - -func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { - switch m.Op() { - case OpCreate: - return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdate: - return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdateOne: - return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpDelete, OpDeleteOne: - return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) - default: - return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) - } -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Group, Todo, User []ent.Hook - } - inters struct { - Group, Todo, User []ent.Interceptor - } -) diff --git a/schema/ent/example/ent/group.go b/schema/ent/example/ent/group.go deleted file mode 100644 index 8514859..0000000 --- a/schema/ent/example/ent/group.go +++ /dev/null @@ -1,170 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "strings" - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" -) - -// Group is the model entity for the Group schema. -type Group struct { - config `json:"-"` - // ID of the ent. - ID int `json:"id,omitempty"` - // CreatedAt holds the value of the "created_at" field. - CreatedAt time.Time `json:"created_at,omitempty"` - // UpdatedAt holds the value of the "updated_at" field. - UpdatedAt time.Time `json:"updated_at,omitempty"` - // Name holds the value of the "name" field. - Name string `json:"name,omitempty"` - // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the GroupQuery when eager-loading is set. - Edges GroupEdges `json:"edges"` - selectValues sql.SelectValues -} - -// GroupEdges holds the relations/edges for other nodes in the graph. -type GroupEdges struct { - // Users holds the value of the users edge. - Users []*User `json:"users,omitempty"` - // Todos holds the value of the todos edge. - Todos []*Todo `json:"todos,omitempty"` - // loadedTypes holds the information for reporting if a - // type was loaded (or requested) in eager-loading or not. - loadedTypes [2]bool -} - -// UsersOrErr returns the Users value or an error if the edge -// was not loaded in eager-loading. -func (e GroupEdges) UsersOrErr() ([]*User, error) { - if e.loadedTypes[0] { - return e.Users, nil - } - return nil, &NotLoadedError{edge: "users"} -} - -// TodosOrErr returns the Todos value or an error if the edge -// was not loaded in eager-loading. -func (e GroupEdges) TodosOrErr() ([]*Todo, error) { - if e.loadedTypes[1] { - return e.Todos, nil - } - return nil, &NotLoadedError{edge: "todos"} -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*Group) scanValues(columns []string) ([]any, error) { - values := make([]any, len(columns)) - for i := range columns { - switch columns[i] { - case group.FieldID: - values[i] = new(sql.NullInt64) - case group.FieldName: - values[i] = new(sql.NullString) - case group.FieldCreatedAt, group.FieldUpdatedAt: - values[i] = new(sql.NullTime) - default: - values[i] = new(sql.UnknownType) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the Group fields. -func (_m *Group) assignValues(columns []string, values []any) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case group.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - _m.ID = int(value.Int64) - case group.FieldCreatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[i]) - } else if value.Valid { - _m.CreatedAt = value.Time - } - case group.FieldUpdatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[i]) - } else if value.Valid { - _m.UpdatedAt = value.Time - } - case group.FieldName: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field name", values[i]) - } else if value.Valid { - _m.Name = value.String - } - default: - _m.selectValues.Set(columns[i], values[i]) - } - } - return nil -} - -// Value returns the ent.Value that was dynamically selected and assigned to the Group. -// This includes values selected through modifiers, order, etc. -func (_m *Group) Value(name string) (ent.Value, error) { - return _m.selectValues.Get(name) -} - -// QueryUsers queries the "users" edge of the Group entity. -func (_m *Group) QueryUsers() *UserQuery { - return NewGroupClient(_m.config).QueryUsers(_m) -} - -// QueryTodos queries the "todos" edge of the Group entity. -func (_m *Group) QueryTodos() *TodoQuery { - return NewGroupClient(_m.config).QueryTodos(_m) -} - -// Update returns a builder for updating this Group. -// Note that you need to call Group.Unwrap() before calling this method if this Group -// was returned from a transaction, and the transaction was committed or rolled back. -func (_m *Group) Update() *GroupUpdateOne { - return NewGroupClient(_m.config).UpdateOne(_m) -} - -// Unwrap unwraps the Group entity that was returned from a transaction after it was closed, -// so that all future queries will be executed through the driver which created the transaction. -func (_m *Group) Unwrap() *Group { - _tx, ok := _m.config.driver.(*txDriver) - if !ok { - panic("ent: Group is not a transactional entity") - } - _m.config.driver = _tx.drv - return _m -} - -// String implements the fmt.Stringer. -func (_m *Group) String() string { - var builder strings.Builder - builder.WriteString("Group(") - builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) - builder.WriteString("created_at=") - builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("updated_at=") - builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("name=") - builder.WriteString(_m.Name) - builder.WriteByte(')') - return builder.String() -} - -// Groups is a parsable slice of Group. -type Groups []*Group diff --git a/schema/ent/example/ent/group/group.go b/schema/ent/example/ent/group/group.go deleted file mode 100644 index b8588bc..0000000 --- a/schema/ent/example/ent/group/group.go +++ /dev/null @@ -1,141 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package group - -import ( - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" -) - -const ( - // Label holds the string label denoting the group type in the database. - Label = "group" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldCreatedAt holds the string denoting the created_at field in the database. - FieldCreatedAt = "created_at" - // FieldUpdatedAt holds the string denoting the updated_at field in the database. - FieldUpdatedAt = "updated_at" - // FieldName holds the string denoting the name field in the database. - FieldName = "name" - // EdgeUsers holds the string denoting the users edge name in mutations. - EdgeUsers = "users" - // EdgeTodos holds the string denoting the todos edge name in mutations. - EdgeTodos = "todos" - // Table holds the table name of the group in the database. - Table = "groups" - // UsersTable is the table that holds the users relation/edge. The primary key declared below. - UsersTable = "user_group" - // UsersInverseTable is the table name for the User entity. - // It exists in this package in order to avoid circular dependency with the "user" package. - UsersInverseTable = "users" - // TodosTable is the table that holds the todos relation/edge. - TodosTable = "todos" - // TodosInverseTable is the table name for the Todo entity. - // It exists in this package in order to avoid circular dependency with the "todo" package. - TodosInverseTable = "todos" - // TodosColumn is the table column denoting the todos relation/edge. - TodosColumn = "todo_group" -) - -// Columns holds all SQL columns for group fields. -var Columns = []string{ - FieldID, - FieldCreatedAt, - FieldUpdatedAt, - FieldName, -} - -var ( - // UsersPrimaryKey and UsersColumn2 are the table columns denoting the - // primary key for the users relation (M2M). - UsersPrimaryKey = []string{"user_id", "group_id"} -) - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - return false -} - -var ( - // DefaultCreatedAt holds the default value on creation for the "created_at" field. - DefaultCreatedAt func() time.Time - // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. - DefaultUpdatedAt func() time.Time - // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. - UpdateDefaultUpdatedAt func() time.Time - // DefaultName holds the default value on creation for the "name" field. - DefaultName string -) - -// OrderOption defines the ordering options for the Group queries. -type OrderOption func(*sql.Selector) - -// ByID orders the results by the id field. -func ByID(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldID, opts...).ToFunc() -} - -// ByCreatedAt orders the results by the created_at field. -func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() -} - -// ByUpdatedAt orders the results by the updated_at field. -func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() -} - -// ByName orders the results by the name field. -func ByName(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldName, opts...).ToFunc() -} - -// ByUsersCount orders the results by users count. -func ByUsersCount(opts ...sql.OrderTermOption) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborsCount(s, newUsersStep(), opts...) - } -} - -// ByUsers orders the results by users terms. -func ByUsers(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborTerms(s, newUsersStep(), append([]sql.OrderTerm{term}, terms...)...) - } -} - -// ByTodosCount orders the results by todos count. -func ByTodosCount(opts ...sql.OrderTermOption) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborsCount(s, newTodosStep(), opts...) - } -} - -// ByTodos orders the results by todos terms. -func ByTodos(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborTerms(s, newTodosStep(), append([]sql.OrderTerm{term}, terms...)...) - } -} -func newUsersStep() *sqlgraph.Step { - return sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(UsersInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, UsersTable, UsersPrimaryKey...), - ) -} -func newTodosStep() *sqlgraph.Step { - return sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TodosInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, TodosTable, TodosColumn), - ) -} diff --git a/schema/ent/example/ent/group/where.go b/schema/ent/example/ent/group/where.go deleted file mode 100644 index 5c8f339..0000000 --- a/schema/ent/example/ent/group/where.go +++ /dev/null @@ -1,277 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package group - -import ( - "git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" -) - -// ID filters vertices based on their ID field. -func ID(id int) predicate.Group { - return predicate.Group(sql.FieldEQ(FieldID, id)) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.Group { - return predicate.Group(sql.FieldEQ(FieldID, id)) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.Group { - return predicate.Group(sql.FieldNEQ(FieldID, id)) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.Group { - return predicate.Group(sql.FieldIn(FieldID, ids...)) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.Group { - return predicate.Group(sql.FieldNotIn(FieldID, ids...)) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.Group { - return predicate.Group(sql.FieldGT(FieldID, id)) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.Group { - return predicate.Group(sql.FieldGTE(FieldID, id)) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.Group { - return predicate.Group(sql.FieldLT(FieldID, id)) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.Group { - return predicate.Group(sql.FieldLTE(FieldID, id)) -} - -// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.Group { - return predicate.Group(sql.FieldEQ(FieldCreatedAt, v)) -} - -// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. -func UpdatedAt(v time.Time) predicate.Group { - return predicate.Group(sql.FieldEQ(FieldUpdatedAt, v)) -} - -// Name applies equality check predicate on the "name" field. It's identical to NameEQ. -func Name(v string) predicate.Group { - return predicate.Group(sql.FieldEQ(FieldName, v)) -} - -// CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v time.Time) predicate.Group { - return predicate.Group(sql.FieldEQ(FieldCreatedAt, v)) -} - -// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v time.Time) predicate.Group { - return predicate.Group(sql.FieldNEQ(FieldCreatedAt, v)) -} - -// CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...time.Time) predicate.Group { - return predicate.Group(sql.FieldIn(FieldCreatedAt, vs...)) -} - -// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...time.Time) predicate.Group { - return predicate.Group(sql.FieldNotIn(FieldCreatedAt, vs...)) -} - -// CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v time.Time) predicate.Group { - return predicate.Group(sql.FieldGT(FieldCreatedAt, v)) -} - -// CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v time.Time) predicate.Group { - return predicate.Group(sql.FieldGTE(FieldCreatedAt, v)) -} - -// CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v time.Time) predicate.Group { - return predicate.Group(sql.FieldLT(FieldCreatedAt, v)) -} - -// CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v time.Time) predicate.Group { - return predicate.Group(sql.FieldLTE(FieldCreatedAt, v)) -} - -// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. -func UpdatedAtEQ(v time.Time) predicate.Group { - return predicate.Group(sql.FieldEQ(FieldUpdatedAt, v)) -} - -// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. -func UpdatedAtNEQ(v time.Time) predicate.Group { - return predicate.Group(sql.FieldNEQ(FieldUpdatedAt, v)) -} - -// UpdatedAtIn applies the In predicate on the "updated_at" field. -func UpdatedAtIn(vs ...time.Time) predicate.Group { - return predicate.Group(sql.FieldIn(FieldUpdatedAt, vs...)) -} - -// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. -func UpdatedAtNotIn(vs ...time.Time) predicate.Group { - return predicate.Group(sql.FieldNotIn(FieldUpdatedAt, vs...)) -} - -// UpdatedAtGT applies the GT predicate on the "updated_at" field. -func UpdatedAtGT(v time.Time) predicate.Group { - return predicate.Group(sql.FieldGT(FieldUpdatedAt, v)) -} - -// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. -func UpdatedAtGTE(v time.Time) predicate.Group { - return predicate.Group(sql.FieldGTE(FieldUpdatedAt, v)) -} - -// UpdatedAtLT applies the LT predicate on the "updated_at" field. -func UpdatedAtLT(v time.Time) predicate.Group { - return predicate.Group(sql.FieldLT(FieldUpdatedAt, v)) -} - -// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. -func UpdatedAtLTE(v time.Time) predicate.Group { - return predicate.Group(sql.FieldLTE(FieldUpdatedAt, v)) -} - -// NameEQ applies the EQ predicate on the "name" field. -func NameEQ(v string) predicate.Group { - return predicate.Group(sql.FieldEQ(FieldName, v)) -} - -// NameNEQ applies the NEQ predicate on the "name" field. -func NameNEQ(v string) predicate.Group { - return predicate.Group(sql.FieldNEQ(FieldName, v)) -} - -// NameIn applies the In predicate on the "name" field. -func NameIn(vs ...string) predicate.Group { - return predicate.Group(sql.FieldIn(FieldName, vs...)) -} - -// NameNotIn applies the NotIn predicate on the "name" field. -func NameNotIn(vs ...string) predicate.Group { - return predicate.Group(sql.FieldNotIn(FieldName, vs...)) -} - -// NameGT applies the GT predicate on the "name" field. -func NameGT(v string) predicate.Group { - return predicate.Group(sql.FieldGT(FieldName, v)) -} - -// NameGTE applies the GTE predicate on the "name" field. -func NameGTE(v string) predicate.Group { - return predicate.Group(sql.FieldGTE(FieldName, v)) -} - -// NameLT applies the LT predicate on the "name" field. -func NameLT(v string) predicate.Group { - return predicate.Group(sql.FieldLT(FieldName, v)) -} - -// NameLTE applies the LTE predicate on the "name" field. -func NameLTE(v string) predicate.Group { - return predicate.Group(sql.FieldLTE(FieldName, v)) -} - -// NameContains applies the Contains predicate on the "name" field. -func NameContains(v string) predicate.Group { - return predicate.Group(sql.FieldContains(FieldName, v)) -} - -// NameHasPrefix applies the HasPrefix predicate on the "name" field. -func NameHasPrefix(v string) predicate.Group { - return predicate.Group(sql.FieldHasPrefix(FieldName, v)) -} - -// NameHasSuffix applies the HasSuffix predicate on the "name" field. -func NameHasSuffix(v string) predicate.Group { - return predicate.Group(sql.FieldHasSuffix(FieldName, v)) -} - -// NameEqualFold applies the EqualFold predicate on the "name" field. -func NameEqualFold(v string) predicate.Group { - return predicate.Group(sql.FieldEqualFold(FieldName, v)) -} - -// NameContainsFold applies the ContainsFold predicate on the "name" field. -func NameContainsFold(v string) predicate.Group { - return predicate.Group(sql.FieldContainsFold(FieldName, v)) -} - -// HasUsers applies the HasEdge predicate on the "users" edge. -func HasUsers() predicate.Group { - return predicate.Group(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, UsersTable, UsersPrimaryKey...), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasUsersWith applies the HasEdge predicate on the "users" edge with a given conditions (other predicates). -func HasUsersWith(preds ...predicate.User) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - step := newUsersStep() - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - -// HasTodos applies the HasEdge predicate on the "todos" edge. -func HasTodos() predicate.Group { - return predicate.Group(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, TodosTable, TodosColumn), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasTodosWith applies the HasEdge predicate on the "todos" edge with a given conditions (other predicates). -func HasTodosWith(preds ...predicate.Todo) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - step := newTodosStep() - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.Group) predicate.Group { - return predicate.Group(sql.AndPredicates(predicates...)) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.Group) predicate.Group { - return predicate.Group(sql.OrPredicates(predicates...)) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.Group) predicate.Group { - return predicate.Group(sql.NotPredicates(p)) -} diff --git a/schema/ent/example/ent/group_create.go b/schema/ent/example/ent/group_create.go deleted file mode 100644 index 67e30ed..0000000 --- a/schema/ent/example/ent/group_create.go +++ /dev/null @@ -1,316 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/todo" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/user" - "time" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// GroupCreate is the builder for creating a Group entity. -type GroupCreate struct { - config - mutation *GroupMutation - hooks []Hook -} - -// SetCreatedAt sets the "created_at" field. -func (_c *GroupCreate) SetCreatedAt(v time.Time) *GroupCreate { - _c.mutation.SetCreatedAt(v) - return _c -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (_c *GroupCreate) SetNillableCreatedAt(v *time.Time) *GroupCreate { - if v != nil { - _c.SetCreatedAt(*v) - } - return _c -} - -// SetUpdatedAt sets the "updated_at" field. -func (_c *GroupCreate) SetUpdatedAt(v time.Time) *GroupCreate { - _c.mutation.SetUpdatedAt(v) - return _c -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (_c *GroupCreate) SetNillableUpdatedAt(v *time.Time) *GroupCreate { - if v != nil { - _c.SetUpdatedAt(*v) - } - return _c -} - -// SetName sets the "name" field. -func (_c *GroupCreate) SetName(v string) *GroupCreate { - _c.mutation.SetName(v) - return _c -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (_c *GroupCreate) SetNillableName(v *string) *GroupCreate { - if v != nil { - _c.SetName(*v) - } - return _c -} - -// AddUserIDs adds the "users" edge to the User entity by IDs. -func (_c *GroupCreate) AddUserIDs(ids ...int) *GroupCreate { - _c.mutation.AddUserIDs(ids...) - return _c -} - -// AddUsers adds the "users" edges to the User entity. -func (_c *GroupCreate) AddUsers(v ...*User) *GroupCreate { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _c.AddUserIDs(ids...) -} - -// AddTodoIDs adds the "todos" edge to the Todo entity by IDs. -func (_c *GroupCreate) AddTodoIDs(ids ...int) *GroupCreate { - _c.mutation.AddTodoIDs(ids...) - return _c -} - -// AddTodos adds the "todos" edges to the Todo entity. -func (_c *GroupCreate) AddTodos(v ...*Todo) *GroupCreate { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _c.AddTodoIDs(ids...) -} - -// Mutation returns the GroupMutation object of the builder. -func (_c *GroupCreate) Mutation() *GroupMutation { - return _c.mutation -} - -// Save creates the Group in the database. -func (_c *GroupCreate) Save(ctx context.Context) (*Group, error) { - _c.defaults() - return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) -} - -// SaveX calls Save and panics if Save returns an error. -func (_c *GroupCreate) SaveX(ctx context.Context) *Group { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *GroupCreate) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *GroupCreate) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_c *GroupCreate) defaults() { - if _, ok := _c.mutation.CreatedAt(); !ok { - v := group.DefaultCreatedAt() - _c.mutation.SetCreatedAt(v) - } - if _, ok := _c.mutation.UpdatedAt(); !ok { - v := group.DefaultUpdatedAt() - _c.mutation.SetUpdatedAt(v) - } - if _, ok := _c.mutation.Name(); !ok { - v := group.DefaultName - _c.mutation.SetName(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_c *GroupCreate) check() error { - if _, ok := _c.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Group.created_at"`)} - } - if _, ok := _c.mutation.UpdatedAt(); !ok { - return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Group.updated_at"`)} - } - if _, ok := _c.mutation.Name(); !ok { - return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Group.name"`)} - } - return nil -} - -func (_c *GroupCreate) sqlSave(ctx context.Context) (*Group, error) { - if err := _c.check(); err != nil { - return nil, err - } - _node, _spec := _c.createSpec() - if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - id := _spec.ID.Value.(int64) - _node.ID = int(id) - _c.mutation.id = &_node.ID - _c.mutation.done = true - return _node, nil -} - -func (_c *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { - var ( - _node = &Group{config: _c.config} - _spec = sqlgraph.NewCreateSpec(group.Table, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt)) - ) - if value, ok := _c.mutation.CreatedAt(); ok { - _spec.SetField(group.FieldCreatedAt, field.TypeTime, value) - _node.CreatedAt = value - } - if value, ok := _c.mutation.UpdatedAt(); ok { - _spec.SetField(group.FieldUpdatedAt, field.TypeTime, value) - _node.UpdatedAt = value - } - if value, ok := _c.mutation.Name(); ok { - _spec.SetField(group.FieldName, field.TypeString, value) - _node.Name = value - } - if nodes := _c.mutation.UsersIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: group.UsersTable, - Columns: group.UsersPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } - if nodes := _c.mutation.TodosIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: group.TodosTable, - Columns: []string{group.TodosColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } - return _node, _spec -} - -// GroupCreateBulk is the builder for creating many Group entities in bulk. -type GroupCreateBulk struct { - config - err error - builders []*GroupCreate -} - -// Save creates the Group entities in the database. -func (_c *GroupCreateBulk) Save(ctx context.Context) ([]*Group, error) { - if _c.err != nil { - return nil, _c.err - } - specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) - nodes := make([]*Group, len(_c.builders)) - mutators := make([]Mutator, len(_c.builders)) - for i := range _c.builders { - func(i int, root context.Context) { - builder := _c.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*GroupMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - var err error - nodes[i], specs[i] = builder.createSpec() - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) - } else { - spec := &sqlgraph.BatchCreateSpec{Nodes: specs} - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - } - } - if err != nil { - return nil, err - } - mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) - } - mutation.done = true - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (_c *GroupCreateBulk) SaveX(ctx context.Context) []*Group { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *GroupCreateBulk) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *GroupCreateBulk) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/schema/ent/example/ent/group_delete.go b/schema/ent/example/ent/group_delete.go deleted file mode 100644 index 60c56a5..0000000 --- a/schema/ent/example/ent/group_delete.go +++ /dev/null @@ -1,88 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// GroupDelete is the builder for deleting a Group entity. -type GroupDelete struct { - config - hooks []Hook - mutation *GroupMutation -} - -// Where appends a list predicates to the GroupDelete builder. -func (_d *GroupDelete) Where(ps ...predicate.Group) *GroupDelete { - _d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (_d *GroupDelete) Exec(ctx context.Context) (int, error) { - return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *GroupDelete) ExecX(ctx context.Context) int { - n, err := _d.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (_d *GroupDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(group.Table, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt)) - if ps := _d.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) - if err != nil && sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - _d.mutation.done = true - return affected, err -} - -// GroupDeleteOne is the builder for deleting a single Group entity. -type GroupDeleteOne struct { - _d *GroupDelete -} - -// Where appends a list predicates to the GroupDelete builder. -func (_d *GroupDeleteOne) Where(ps ...predicate.Group) *GroupDeleteOne { - _d._d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query. -func (_d *GroupDeleteOne) Exec(ctx context.Context) error { - n, err := _d._d.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{group.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *GroupDeleteOne) ExecX(ctx context.Context) { - if err := _d.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/schema/ent/example/ent/group_query.go b/schema/ent/example/ent/group_query.go deleted file mode 100644 index 726dc01..0000000 --- a/schema/ent/example/ent/group_query.go +++ /dev/null @@ -1,712 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "database/sql/driver" - "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/todo" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/user" - "math" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// GroupQuery is the builder for querying Group entities. -type GroupQuery struct { - config - ctx *QueryContext - order []group.OrderOption - inters []Interceptor - predicates []predicate.Group - withUsers *UserQuery - withTodos *TodoQuery - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the GroupQuery builder. -func (_q *GroupQuery) Where(ps ...predicate.Group) *GroupQuery { - _q.predicates = append(_q.predicates, ps...) - return _q -} - -// Limit the number of records to be returned by this query. -func (_q *GroupQuery) Limit(limit int) *GroupQuery { - _q.ctx.Limit = &limit - return _q -} - -// Offset to start from. -func (_q *GroupQuery) Offset(offset int) *GroupQuery { - _q.ctx.Offset = &offset - return _q -} - -// Unique configures the query builder to filter duplicate records on query. -// By default, unique is set to true, and can be disabled using this method. -func (_q *GroupQuery) Unique(unique bool) *GroupQuery { - _q.ctx.Unique = &unique - return _q -} - -// Order specifies how the records should be ordered. -func (_q *GroupQuery) Order(o ...group.OrderOption) *GroupQuery { - _q.order = append(_q.order, o...) - return _q -} - -// QueryUsers chains the current query on the "users" edge. -func (_q *GroupQuery) QueryUsers() *UserQuery { - query := (&UserClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(group.Table, group.FieldID, selector), - sqlgraph.To(user.Table, user.FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, group.UsersTable, group.UsersPrimaryKey...), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// QueryTodos chains the current query on the "todos" edge. -func (_q *GroupQuery) QueryTodos() *TodoQuery { - query := (&TodoClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(group.Table, group.FieldID, selector), - sqlgraph.To(todo.Table, todo.FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, group.TodosTable, group.TodosColumn), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// First returns the first Group entity from the query. -// Returns a *NotFoundError when no Group was found. -func (_q *GroupQuery) First(ctx context.Context) (*Group, error) { - nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{group.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (_q *GroupQuery) FirstX(ctx context.Context) *Group { - node, err := _q.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first Group ID from the query. -// Returns a *NotFoundError when no Group ID was found. -func (_q *GroupQuery) FirstID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{group.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (_q *GroupQuery) FirstIDX(ctx context.Context) int { - id, err := _q.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single Group entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one Group entity is found. -// Returns a *NotFoundError when no Group entities are found. -func (_q *GroupQuery) Only(ctx context.Context) (*Group, error) { - nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{group.Label} - default: - return nil, &NotSingularError{group.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (_q *GroupQuery) OnlyX(ctx context.Context) *Group { - node, err := _q.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only Group ID in the query. -// Returns a *NotSingularError when more than one Group ID is found. -// Returns a *NotFoundError when no entities are found. -func (_q *GroupQuery) OnlyID(ctx context.Context) (id int, err error) { - var ids []int - if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{group.Label} - default: - err = &NotSingularError{group.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (_q *GroupQuery) OnlyIDX(ctx context.Context) int { - id, err := _q.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of Groups. -func (_q *GroupQuery) All(ctx context.Context) ([]*Group, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - qr := querierAll[[]*Group, *GroupQuery]() - return withInterceptors[[]*Group](ctx, _q, qr, _q.inters) -} - -// AllX is like All, but panics if an error occurs. -func (_q *GroupQuery) AllX(ctx context.Context) []*Group { - nodes, err := _q.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of Group IDs. -func (_q *GroupQuery) IDs(ctx context.Context) (ids []int, err error) { - if _q.ctx.Unique == nil && _q.path != nil { - _q.Unique(true) - } - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) - if err = _q.Select(group.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (_q *GroupQuery) IDsX(ctx context.Context) []int { - ids, err := _q.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (_q *GroupQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) - if err := _q.prepareQuery(ctx); err != nil { - return 0, err - } - return withInterceptors[int](ctx, _q, querierCount[*GroupQuery](), _q.inters) -} - -// CountX is like Count, but panics if an error occurs. -func (_q *GroupQuery) CountX(ctx context.Context) int { - count, err := _q.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (_q *GroupQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) - switch _, err := _q.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - -// ExistX is like Exist, but panics if an error occurs. -func (_q *GroupQuery) ExistX(ctx context.Context) bool { - exist, err := _q.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the GroupQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (_q *GroupQuery) Clone() *GroupQuery { - if _q == nil { - return nil - } - return &GroupQuery{ - config: _q.config, - ctx: _q.ctx.Clone(), - order: append([]group.OrderOption{}, _q.order...), - inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.Group{}, _q.predicates...), - withUsers: _q.withUsers.Clone(), - withTodos: _q.withTodos.Clone(), - // clone intermediate query. - sql: _q.sql.Clone(), - path: _q.path, - } -} - -// WithUsers tells the query-builder to eager-load the nodes that are connected to -// the "users" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *GroupQuery) WithUsers(opts ...func(*UserQuery)) *GroupQuery { - query := (&UserClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withUsers = query - return _q -} - -// WithTodos tells the query-builder to eager-load the nodes that are connected to -// the "todos" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *GroupQuery) WithTodos(opts ...func(*TodoQuery)) *GroupQuery { - query := (&TodoClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withTodos = query - return _q -} - -// GroupBy is used to group vertices by one or more fields/columns. -// It is often used with aggregate functions, like: count, max, mean, min, sum. -// -// Example: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.Group.Query(). -// GroupBy(group.FieldCreatedAt). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -func (_q *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy { - _q.ctx.Fields = append([]string{field}, fields...) - grbuild := &GroupGroupBy{build: _q} - grbuild.flds = &_q.ctx.Fields - grbuild.label = group.Label - grbuild.scan = grbuild.Scan - return grbuild -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` -// } -// -// client.Group.Query(). -// Select(group.FieldCreatedAt). -// Scan(ctx, &v) -func (_q *GroupQuery) Select(fields ...string) *GroupSelect { - _q.ctx.Fields = append(_q.ctx.Fields, fields...) - sbuild := &GroupSelect{GroupQuery: _q} - sbuild.label = group.Label - sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan - return sbuild -} - -// Aggregate returns a GroupSelect configured with the given aggregations. -func (_q *GroupQuery) Aggregate(fns ...AggregateFunc) *GroupSelect { - return _q.Select().Aggregate(fns...) -} - -func (_q *GroupQuery) prepareQuery(ctx context.Context) error { - for _, inter := range _q.inters { - if inter == nil { - return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") - } - if trv, ok := inter.(Traverser); ok { - if err := trv.Traverse(ctx, _q); err != nil { - return err - } - } - } - for _, f := range _q.ctx.Fields { - if !group.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if _q.path != nil { - prev, err := _q.path(ctx) - if err != nil { - return err - } - _q.sql = prev - } - return nil -} - -func (_q *GroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Group, error) { - var ( - nodes = []*Group{} - _spec = _q.querySpec() - loadedTypes = [2]bool{ - _q.withUsers != nil, - _q.withTodos != nil, - } - ) - _spec.ScanValues = func(columns []string) ([]any, error) { - return (*Group).scanValues(nil, columns) - } - _spec.Assign = func(columns []string, values []any) error { - node := &Group{config: _q.config} - nodes = append(nodes, node) - node.Edges.loadedTypes = loadedTypes - return node.assignValues(columns, values) - } - for i := range hooks { - hooks[i](ctx, _spec) - } - if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - if query := _q.withUsers; query != nil { - if err := _q.loadUsers(ctx, query, nodes, - func(n *Group) { n.Edges.Users = []*User{} }, - func(n *Group, e *User) { n.Edges.Users = append(n.Edges.Users, e) }); err != nil { - return nil, err - } - } - if query := _q.withTodos; query != nil { - if err := _q.loadTodos(ctx, query, nodes, - func(n *Group) { n.Edges.Todos = []*Todo{} }, - func(n *Group, e *Todo) { n.Edges.Todos = append(n.Edges.Todos, e) }); err != nil { - return nil, err - } - } - return nodes, nil -} - -func (_q *GroupQuery) loadUsers(ctx context.Context, query *UserQuery, nodes []*Group, init func(*Group), assign func(*Group, *User)) error { - edgeIDs := make([]driver.Value, len(nodes)) - byID := make(map[int]*Group) - nids := make(map[int]map[*Group]struct{}) - for i, node := range nodes { - edgeIDs[i] = node.ID - byID[node.ID] = node - if init != nil { - init(node) - } - } - query.Where(func(s *sql.Selector) { - joinT := sql.Table(group.UsersTable) - s.Join(joinT).On(s.C(user.FieldID), joinT.C(group.UsersPrimaryKey[0])) - s.Where(sql.InValues(joinT.C(group.UsersPrimaryKey[1]), edgeIDs...)) - columns := s.SelectedColumns() - s.Select(joinT.C(group.UsersPrimaryKey[1])) - s.AppendSelect(columns...) - s.SetDistinct(false) - }) - if err := query.prepareQuery(ctx); err != nil { - return err - } - qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { - return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { - assign := spec.Assign - values := spec.ScanValues - spec.ScanValues = func(columns []string) ([]any, error) { - values, err := values(columns[1:]) - if err != nil { - return nil, err - } - return append([]any{new(sql.NullInt64)}, values...), nil - } - spec.Assign = func(columns []string, values []any) error { - outValue := int(values[0].(*sql.NullInt64).Int64) - inValue := int(values[1].(*sql.NullInt64).Int64) - if nids[inValue] == nil { - nids[inValue] = map[*Group]struct{}{byID[outValue]: {}} - return assign(columns[1:], values[1:]) - } - nids[inValue][byID[outValue]] = struct{}{} - return nil - } - }) - }) - neighbors, err := withInterceptors[[]*User](ctx, query, qr, query.inters) - if err != nil { - return err - } - for _, n := range neighbors { - nodes, ok := nids[n.ID] - if !ok { - return fmt.Errorf(`unexpected "users" node returned %v`, n.ID) - } - for kn := range nodes { - assign(kn, n) - } - } - return nil -} -func (_q *GroupQuery) loadTodos(ctx context.Context, query *TodoQuery, nodes []*Group, init func(*Group), assign func(*Group, *Todo)) error { - fks := make([]driver.Value, 0, len(nodes)) - nodeids := make(map[int]*Group) - for i := range nodes { - fks = append(fks, nodes[i].ID) - nodeids[nodes[i].ID] = nodes[i] - if init != nil { - init(nodes[i]) - } - } - query.withFKs = true - query.Where(predicate.Todo(func(s *sql.Selector) { - s.Where(sql.InValues(s.C(group.TodosColumn), fks...)) - })) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - fk := n.todo_group - if fk == nil { - return fmt.Errorf(`foreign-key "todo_group" is nil for node %v`, n.ID) - } - node, ok := nodeids[*fk] - if !ok { - return fmt.Errorf(`unexpected referenced foreign-key "todo_group" returned %v for node %v`, *fk, n.ID) - } - assign(node, n) - } - return nil -} - -func (_q *GroupQuery) sqlCount(ctx context.Context) (int, error) { - _spec := _q.querySpec() - _spec.Node.Columns = _q.ctx.Fields - if len(_q.ctx.Fields) > 0 { - _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique - } - return sqlgraph.CountNodes(ctx, _q.driver, _spec) -} - -func (_q *GroupQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt)) - _spec.From = _q.sql - if unique := _q.ctx.Unique; unique != nil { - _spec.Unique = *unique - } else if _q.path != nil { - _spec.Unique = true - } - if fields := _q.ctx.Fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, group.FieldID) - for i := range fields { - if fields[i] != group.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := _q.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := _q.ctx.Limit; limit != nil { - _spec.Limit = *limit - } - if offset := _q.ctx.Offset; offset != nil { - _spec.Offset = *offset - } - if ps := _q.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return _spec -} - -func (_q *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(_q.driver.Dialect()) - t1 := builder.Table(group.Table) - columns := _q.ctx.Fields - if len(columns) == 0 { - columns = group.Columns - } - selector := builder.Select(t1.Columns(columns...)...).From(t1) - if _q.sql != nil { - selector = _q.sql - selector.Select(selector.Columns(columns...)...) - } - if _q.ctx.Unique != nil && *_q.ctx.Unique { - selector.Distinct() - } - for _, p := range _q.predicates { - p(selector) - } - for _, p := range _q.order { - p(selector) - } - if offset := _q.ctx.Offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := _q.ctx.Limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// GroupGroupBy is the group-by builder for Group entities. -type GroupGroupBy struct { - selector - build *GroupQuery -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (_g *GroupGroupBy) Aggregate(fns ...AggregateFunc) *GroupGroupBy { - _g.fns = append(_g.fns, fns...) - return _g -} - -// Scan applies the selector query and scans the result into the given value. -func (_g *GroupGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) - if err := _g.build.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*GroupQuery, *GroupGroupBy](ctx, _g.build, _g, _g.build.inters, v) -} - -func (_g *GroupGroupBy) sqlScan(ctx context.Context, root *GroupQuery, v any) error { - selector := root.sqlQuery(ctx).Select() - aggregation := make([]string, 0, len(_g.fns)) - for _, fn := range _g.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) - for _, f := range *_g.flds { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - selector.GroupBy(selector.Columns(*_g.flds...)...) - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -// GroupSelect is the builder for selecting fields of Group entities. -type GroupSelect struct { - *GroupQuery - selector -} - -// Aggregate adds the given aggregation functions to the selector query. -func (_s *GroupSelect) Aggregate(fns ...AggregateFunc) *GroupSelect { - _s.fns = append(_s.fns, fns...) - return _s -} - -// Scan applies the selector query and scans the result into the given value. -func (_s *GroupSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) - if err := _s.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*GroupQuery, *GroupSelect](ctx, _s.GroupQuery, _s, _s.inters, v) -} - -func (_s *GroupSelect) sqlScan(ctx context.Context, root *GroupQuery, v any) error { - selector := root.sqlQuery(ctx) - aggregation := make([]string, 0, len(_s.fns)) - for _, fn := range _s.fns { - aggregation = append(aggregation, fn(selector)) - } - switch n := len(*_s.selector.flds); { - case n == 0 && len(aggregation) > 0: - selector.Select(aggregation...) - case n != 0 && len(aggregation) > 0: - selector.AppendSelect(aggregation...) - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := _s.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} diff --git a/schema/ent/example/ent/group_update.go b/schema/ent/example/ent/group_update.go deleted file mode 100644 index 68ce307..0000000 --- a/schema/ent/example/ent/group_update.go +++ /dev/null @@ -1,572 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/todo" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/user" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// GroupUpdate is the builder for updating Group entities. -type GroupUpdate struct { - config - hooks []Hook - mutation *GroupMutation -} - -// Where appends a list predicates to the GroupUpdate builder. -func (_u *GroupUpdate) Where(ps ...predicate.Group) *GroupUpdate { - _u.mutation.Where(ps...) - return _u -} - -// SetUpdatedAt sets the "updated_at" field. -func (_u *GroupUpdate) SetUpdatedAt(v time.Time) *GroupUpdate { - _u.mutation.SetUpdatedAt(v) - return _u -} - -// SetName sets the "name" field. -func (_u *GroupUpdate) SetName(v string) *GroupUpdate { - _u.mutation.SetName(v) - return _u -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (_u *GroupUpdate) SetNillableName(v *string) *GroupUpdate { - if v != nil { - _u.SetName(*v) - } - return _u -} - -// AddUserIDs adds the "users" edge to the User entity by IDs. -func (_u *GroupUpdate) AddUserIDs(ids ...int) *GroupUpdate { - _u.mutation.AddUserIDs(ids...) - return _u -} - -// AddUsers adds the "users" edges to the User entity. -func (_u *GroupUpdate) AddUsers(v ...*User) *GroupUpdate { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddUserIDs(ids...) -} - -// AddTodoIDs adds the "todos" edge to the Todo entity by IDs. -func (_u *GroupUpdate) AddTodoIDs(ids ...int) *GroupUpdate { - _u.mutation.AddTodoIDs(ids...) - return _u -} - -// AddTodos adds the "todos" edges to the Todo entity. -func (_u *GroupUpdate) AddTodos(v ...*Todo) *GroupUpdate { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddTodoIDs(ids...) -} - -// Mutation returns the GroupMutation object of the builder. -func (_u *GroupUpdate) Mutation() *GroupMutation { - return _u.mutation -} - -// ClearUsers clears all "users" edges to the User entity. -func (_u *GroupUpdate) ClearUsers() *GroupUpdate { - _u.mutation.ClearUsers() - return _u -} - -// RemoveUserIDs removes the "users" edge to User entities by IDs. -func (_u *GroupUpdate) RemoveUserIDs(ids ...int) *GroupUpdate { - _u.mutation.RemoveUserIDs(ids...) - return _u -} - -// RemoveUsers removes "users" edges to User entities. -func (_u *GroupUpdate) RemoveUsers(v ...*User) *GroupUpdate { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveUserIDs(ids...) -} - -// ClearTodos clears all "todos" edges to the Todo entity. -func (_u *GroupUpdate) ClearTodos() *GroupUpdate { - _u.mutation.ClearTodos() - return _u -} - -// RemoveTodoIDs removes the "todos" edge to Todo entities by IDs. -func (_u *GroupUpdate) RemoveTodoIDs(ids ...int) *GroupUpdate { - _u.mutation.RemoveTodoIDs(ids...) - return _u -} - -// RemoveTodos removes "todos" edges to Todo entities. -func (_u *GroupUpdate) RemoveTodos(v ...*Todo) *GroupUpdate { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveTodoIDs(ids...) -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (_u *GroupUpdate) Save(ctx context.Context) (int, error) { - _u.defaults() - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *GroupUpdate) SaveX(ctx context.Context) int { - affected, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (_u *GroupUpdate) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *GroupUpdate) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_u *GroupUpdate) defaults() { - if _, ok := _u.mutation.UpdatedAt(); !ok { - v := group.UpdateDefaultUpdatedAt() - _u.mutation.SetUpdatedAt(v) - } -} - -func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) { - _spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt)) - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(group.FieldUpdatedAt, field.TypeTime, value) - } - if value, ok := _u.mutation.Name(); ok { - _spec.SetField(group.FieldName, field.TypeString, value) - } - if _u.mutation.UsersCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: group.UsersTable, - Columns: group.UsersPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedUsersIDs(); len(nodes) > 0 && !_u.mutation.UsersCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: group.UsersTable, - Columns: group.UsersPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.UsersIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: group.UsersTable, - Columns: group.UsersPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.TodosCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: group.TodosTable, - Columns: []string{group.TodosColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedTodosIDs(); len(nodes) > 0 && !_u.mutation.TodosCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: group.TodosTable, - Columns: []string{group.TodosColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.TodosIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: group.TodosTable, - Columns: []string{group.TodosColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{group.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - _u.mutation.done = true - return _node, nil -} - -// GroupUpdateOne is the builder for updating a single Group entity. -type GroupUpdateOne struct { - config - fields []string - hooks []Hook - mutation *GroupMutation -} - -// SetUpdatedAt sets the "updated_at" field. -func (_u *GroupUpdateOne) SetUpdatedAt(v time.Time) *GroupUpdateOne { - _u.mutation.SetUpdatedAt(v) - return _u -} - -// SetName sets the "name" field. -func (_u *GroupUpdateOne) SetName(v string) *GroupUpdateOne { - _u.mutation.SetName(v) - return _u -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (_u *GroupUpdateOne) SetNillableName(v *string) *GroupUpdateOne { - if v != nil { - _u.SetName(*v) - } - return _u -} - -// AddUserIDs adds the "users" edge to the User entity by IDs. -func (_u *GroupUpdateOne) AddUserIDs(ids ...int) *GroupUpdateOne { - _u.mutation.AddUserIDs(ids...) - return _u -} - -// AddUsers adds the "users" edges to the User entity. -func (_u *GroupUpdateOne) AddUsers(v ...*User) *GroupUpdateOne { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddUserIDs(ids...) -} - -// AddTodoIDs adds the "todos" edge to the Todo entity by IDs. -func (_u *GroupUpdateOne) AddTodoIDs(ids ...int) *GroupUpdateOne { - _u.mutation.AddTodoIDs(ids...) - return _u -} - -// AddTodos adds the "todos" edges to the Todo entity. -func (_u *GroupUpdateOne) AddTodos(v ...*Todo) *GroupUpdateOne { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddTodoIDs(ids...) -} - -// Mutation returns the GroupMutation object of the builder. -func (_u *GroupUpdateOne) Mutation() *GroupMutation { - return _u.mutation -} - -// ClearUsers clears all "users" edges to the User entity. -func (_u *GroupUpdateOne) ClearUsers() *GroupUpdateOne { - _u.mutation.ClearUsers() - return _u -} - -// RemoveUserIDs removes the "users" edge to User entities by IDs. -func (_u *GroupUpdateOne) RemoveUserIDs(ids ...int) *GroupUpdateOne { - _u.mutation.RemoveUserIDs(ids...) - return _u -} - -// RemoveUsers removes "users" edges to User entities. -func (_u *GroupUpdateOne) RemoveUsers(v ...*User) *GroupUpdateOne { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveUserIDs(ids...) -} - -// ClearTodos clears all "todos" edges to the Todo entity. -func (_u *GroupUpdateOne) ClearTodos() *GroupUpdateOne { - _u.mutation.ClearTodos() - return _u -} - -// RemoveTodoIDs removes the "todos" edge to Todo entities by IDs. -func (_u *GroupUpdateOne) RemoveTodoIDs(ids ...int) *GroupUpdateOne { - _u.mutation.RemoveTodoIDs(ids...) - return _u -} - -// RemoveTodos removes "todos" edges to Todo entities. -func (_u *GroupUpdateOne) RemoveTodos(v ...*Todo) *GroupUpdateOne { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveTodoIDs(ids...) -} - -// Where appends a list predicates to the GroupUpdate builder. -func (_u *GroupUpdateOne) Where(ps ...predicate.Group) *GroupUpdateOne { - _u.mutation.Where(ps...) - return _u -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (_u *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOne { - _u.fields = append([]string{field}, fields...) - return _u -} - -// Save executes the query and returns the updated Group entity. -func (_u *GroupUpdateOne) Save(ctx context.Context) (*Group, error) { - _u.defaults() - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *GroupUpdateOne) SaveX(ctx context.Context) *Group { - node, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (_u *GroupUpdateOne) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *GroupUpdateOne) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_u *GroupUpdateOne) defaults() { - if _, ok := _u.mutation.UpdatedAt(); !ok { - v := group.UpdateDefaultUpdatedAt() - _u.mutation.SetUpdatedAt(v) - } -} - -func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) { - _spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt)) - id, ok := _u.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Group.id" for update`)} - } - _spec.Node.ID.Value = id - if fields := _u.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, group.FieldID) - for _, f := range fields { - if !group.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != group.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(group.FieldUpdatedAt, field.TypeTime, value) - } - if value, ok := _u.mutation.Name(); ok { - _spec.SetField(group.FieldName, field.TypeString, value) - } - if _u.mutation.UsersCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: group.UsersTable, - Columns: group.UsersPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedUsersIDs(); len(nodes) > 0 && !_u.mutation.UsersCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: group.UsersTable, - Columns: group.UsersPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.UsersIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: true, - Table: group.UsersTable, - Columns: group.UsersPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _u.mutation.TodosCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: group.TodosTable, - Columns: []string{group.TodosColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedTodosIDs(); len(nodes) > 0 && !_u.mutation.TodosCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: group.TodosTable, - Columns: []string{group.TodosColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.TodosIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.O2M, - Inverse: true, - Table: group.TodosTable, - Columns: []string{group.TodosColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - _node = &Group{config: _u.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{group.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - _u.mutation.done = true - return _node, nil -} diff --git a/schema/ent/example/ent/migrate/schema.go b/schema/ent/example/ent/migrate/schema.go deleted file mode 100644 index f33d4e6..0000000 --- a/schema/ent/example/ent/migrate/schema.go +++ /dev/null @@ -1,99 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package migrate - -import ( - "entgo.io/ent/dialect/sql/schema" - "entgo.io/ent/schema/field" -) - -var ( - // GroupsColumns holds the columns for the "groups" table. - GroupsColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "created_at", Type: field.TypeTime}, - {Name: "updated_at", Type: field.TypeTime}, - {Name: "name", Type: field.TypeString, Default: ""}, - } - // GroupsTable holds the schema information for the "groups" table. - GroupsTable = &schema.Table{ - Name: "groups", - Columns: GroupsColumns, - PrimaryKey: []*schema.Column{GroupsColumns[0]}, - } - // TodosColumns holds the columns for the "todos" table. - TodosColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "created_at", Type: field.TypeTime}, - {Name: "updated_at", Type: field.TypeTime}, - {Name: "title", Type: field.TypeString, Default: ""}, - {Name: "completed", Type: field.TypeBool, Default: false}, - {Name: "todo_group", Type: field.TypeInt, Nullable: true}, - } - // TodosTable holds the schema information for the "todos" table. - TodosTable = &schema.Table{ - Name: "todos", - Columns: TodosColumns, - PrimaryKey: []*schema.Column{TodosColumns[0]}, - ForeignKeys: []*schema.ForeignKey{ - { - Symbol: "todos_groups_group", - Columns: []*schema.Column{TodosColumns[5]}, - RefColumns: []*schema.Column{GroupsColumns[0]}, - OnDelete: schema.SetNull, - }, - }, - } - // UsersColumns holds the columns for the "users" table. - UsersColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt, Increment: true}, - {Name: "created_at", Type: field.TypeTime}, - {Name: "updated_at", Type: field.TypeTime}, - {Name: "email", Type: field.TypeString, Default: "unknown@localhost"}, - {Name: "password", Type: field.TypeString, Default: ""}, - } - // UsersTable holds the schema information for the "users" table. - UsersTable = &schema.Table{ - Name: "users", - Columns: UsersColumns, - PrimaryKey: []*schema.Column{UsersColumns[0]}, - } - // UserGroupColumns holds the columns for the "user_group" table. - UserGroupColumns = []*schema.Column{ - {Name: "user_id", Type: field.TypeInt}, - {Name: "group_id", Type: field.TypeInt}, - } - // UserGroupTable holds the schema information for the "user_group" table. - UserGroupTable = &schema.Table{ - Name: "user_group", - Columns: UserGroupColumns, - PrimaryKey: []*schema.Column{UserGroupColumns[0], UserGroupColumns[1]}, - ForeignKeys: []*schema.ForeignKey{ - { - Symbol: "user_group_user_id", - Columns: []*schema.Column{UserGroupColumns[0]}, - RefColumns: []*schema.Column{UsersColumns[0]}, - OnDelete: schema.Cascade, - }, - { - Symbol: "user_group_group_id", - Columns: []*schema.Column{UserGroupColumns[1]}, - RefColumns: []*schema.Column{GroupsColumns[0]}, - OnDelete: schema.Cascade, - }, - }, - } - // Tables holds all the tables in the schema. - Tables = []*schema.Table{ - GroupsTable, - TodosTable, - UsersTable, - UserGroupTable, - } -) - -func init() { - TodosTable.ForeignKeys[0].RefTable = GroupsTable - UserGroupTable.ForeignKeys[0].RefTable = UsersTable - UserGroupTable.ForeignKeys[1].RefTable = GroupsTable -} diff --git a/schema/ent/example/ent/mutation.go b/schema/ent/example/ent/mutation.go deleted file mode 100644 index 8ac9fff..0000000 --- a/schema/ent/example/ent/mutation.go +++ /dev/null @@ -1,1778 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/todo" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/user" - "sync" - "time" - - "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. - TypeGroup = "Group" - TypeTodo = "Todo" - TypeUser = "User" -) - -// GroupMutation represents an operation that mutates the Group nodes in the graph. -type GroupMutation struct { - config - op Op - typ string - id *int - created_at *time.Time - updated_at *time.Time - name *string - clearedFields map[string]struct{} - users map[int]struct{} - removedusers map[int]struct{} - clearedusers bool - todos map[int]struct{} - removedtodos map[int]struct{} - clearedtodos bool - done bool - oldValue func(context.Context) (*Group, error) - predicates []predicate.Group -} - -var _ ent.Mutation = (*GroupMutation)(nil) - -// groupOption allows management of the mutation configuration using functional options. -type groupOption func(*GroupMutation) - -// newGroupMutation creates new mutation for the Group entity. -func newGroupMutation(c config, op Op, opts ...groupOption) *GroupMutation { - m := &GroupMutation{ - config: c, - op: op, - typ: TypeGroup, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withGroupID sets the ID field of the mutation. -func withGroupID(id int) groupOption { - return func(m *GroupMutation) { - var ( - err error - once sync.Once - value *Group - ) - m.oldValue = func(ctx context.Context) (*Group, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().Group.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withGroup sets the old Group of the mutation. -func withGroup(node *Group) groupOption { - return func(m *GroupMutation) { - m.oldValue = func(context.Context) (*Group, 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 GroupMutation) 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 GroupMutation) 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 *GroupMutation) 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 *GroupMutation) 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().Group.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } -} - -// SetCreatedAt sets the "created_at" field. -func (m *GroupMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *GroupMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return - } - return *v, true -} - -// OldCreatedAt returns the old "created_at" field's value of the Group entity. -// If the Group 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 *GroupMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) - } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *GroupMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetUpdatedAt sets the "updated_at" field. -func (m *GroupMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t -} - -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *GroupMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at - if v == nil { - return - } - return *v, true -} - -// OldUpdatedAt returns the old "updated_at" field's value of the Group entity. -// If the Group 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 *GroupMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldUpdatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) - } - return oldValue.UpdatedAt, nil -} - -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *GroupMutation) ResetUpdatedAt() { - m.updated_at = nil -} - -// SetName sets the "name" field. -func (m *GroupMutation) SetName(s string) { - m.name = &s -} - -// Name returns the value of the "name" field in the mutation. -func (m *GroupMutation) 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 Group entity. -// If the Group 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 *GroupMutation) 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 *GroupMutation) ResetName() { - m.name = nil -} - -// AddUserIDs adds the "users" edge to the User entity by ids. -func (m *GroupMutation) AddUserIDs(ids ...int) { - if m.users == nil { - m.users = make(map[int]struct{}) - } - for i := range ids { - m.users[ids[i]] = struct{}{} - } -} - -// ClearUsers clears the "users" edge to the User entity. -func (m *GroupMutation) ClearUsers() { - m.clearedusers = true -} - -// UsersCleared reports if the "users" edge to the User entity was cleared. -func (m *GroupMutation) UsersCleared() bool { - return m.clearedusers -} - -// RemoveUserIDs removes the "users" edge to the User entity by IDs. -func (m *GroupMutation) RemoveUserIDs(ids ...int) { - if m.removedusers == nil { - m.removedusers = make(map[int]struct{}) - } - for i := range ids { - delete(m.users, ids[i]) - m.removedusers[ids[i]] = struct{}{} - } -} - -// RemovedUsers returns the removed IDs of the "users" edge to the User entity. -func (m *GroupMutation) RemovedUsersIDs() (ids []int) { - for id := range m.removedusers { - ids = append(ids, id) - } - return -} - -// UsersIDs returns the "users" edge IDs in the mutation. -func (m *GroupMutation) UsersIDs() (ids []int) { - for id := range m.users { - ids = append(ids, id) - } - return -} - -// ResetUsers resets all changes to the "users" edge. -func (m *GroupMutation) ResetUsers() { - m.users = nil - m.clearedusers = false - m.removedusers = nil -} - -// AddTodoIDs adds the "todos" edge to the Todo entity by ids. -func (m *GroupMutation) AddTodoIDs(ids ...int) { - if m.todos == nil { - m.todos = make(map[int]struct{}) - } - for i := range ids { - m.todos[ids[i]] = struct{}{} - } -} - -// ClearTodos clears the "todos" edge to the Todo entity. -func (m *GroupMutation) ClearTodos() { - m.clearedtodos = true -} - -// TodosCleared reports if the "todos" edge to the Todo entity was cleared. -func (m *GroupMutation) TodosCleared() bool { - return m.clearedtodos -} - -// RemoveTodoIDs removes the "todos" edge to the Todo entity by IDs. -func (m *GroupMutation) RemoveTodoIDs(ids ...int) { - if m.removedtodos == nil { - m.removedtodos = make(map[int]struct{}) - } - for i := range ids { - delete(m.todos, ids[i]) - m.removedtodos[ids[i]] = struct{}{} - } -} - -// RemovedTodos returns the removed IDs of the "todos" edge to the Todo entity. -func (m *GroupMutation) RemovedTodosIDs() (ids []int) { - for id := range m.removedtodos { - ids = append(ids, id) - } - return -} - -// TodosIDs returns the "todos" edge IDs in the mutation. -func (m *GroupMutation) TodosIDs() (ids []int) { - for id := range m.todos { - ids = append(ids, id) - } - return -} - -// ResetTodos resets all changes to the "todos" edge. -func (m *GroupMutation) ResetTodos() { - m.todos = nil - m.clearedtodos = false - m.removedtodos = nil -} - -// Where appends a list predicates to the GroupMutation builder. -func (m *GroupMutation) Where(ps ...predicate.Group) { - m.predicates = append(m.predicates, ps...) -} - -// WhereP appends storage-level predicates to the GroupMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *GroupMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.Group, len(ps)) - for i := range ps { - p[i] = ps[i] - } - m.Where(p...) -} - -// Op returns the operation name. -func (m *GroupMutation) Op() Op { - return m.op -} - -// SetOp allows setting the mutation operation. -func (m *GroupMutation) SetOp(op Op) { - m.op = op -} - -// Type returns the node type of this mutation (Group). -func (m *GroupMutation) 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 *GroupMutation) Fields() []string { - fields := make([]string, 0, 3) - if m.created_at != nil { - fields = append(fields, group.FieldCreatedAt) - } - if m.updated_at != nil { - fields = append(fields, group.FieldUpdatedAt) - } - if m.name != nil { - fields = append(fields, group.FieldName) - } - return fields -} - -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *GroupMutation) Field(name string) (ent.Value, bool) { - switch name { - case group.FieldCreatedAt: - return m.CreatedAt() - case group.FieldUpdatedAt: - return m.UpdatedAt() - case group.FieldName: - return m.Name() - } - return nil, false -} - -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *GroupMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case group.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case group.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - case group.FieldName: - return m.OldName(ctx) - } - return nil, fmt.Errorf("unknown Group 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 *GroupMutation) SetField(name string, value ent.Value) error { - switch name { - case group.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case group.FieldUpdatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUpdatedAt(v) - return nil - case group.FieldName: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetName(v) - return nil - } - return fmt.Errorf("unknown Group field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *GroupMutation) 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 *GroupMutation) 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 *GroupMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown Group numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *GroupMutation) ClearedFields() []string { - return nil -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *GroupMutation) 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 *GroupMutation) ClearField(name string) error { - return fmt.Errorf("unknown Group 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 *GroupMutation) ResetField(name string) error { - switch name { - case group.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case group.FieldUpdatedAt: - m.ResetUpdatedAt() - return nil - case group.FieldName: - m.ResetName() - return nil - } - return fmt.Errorf("unknown Group field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *GroupMutation) AddedEdges() []string { - edges := make([]string, 0, 2) - if m.users != nil { - edges = append(edges, group.EdgeUsers) - } - if m.todos != nil { - edges = append(edges, group.EdgeTodos) - } - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *GroupMutation) AddedIDs(name string) []ent.Value { - switch name { - case group.EdgeUsers: - ids := make([]ent.Value, 0, len(m.users)) - for id := range m.users { - ids = append(ids, id) - } - return ids - case group.EdgeTodos: - ids := make([]ent.Value, 0, len(m.todos)) - for id := range m.todos { - ids = append(ids, id) - } - return ids - } - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *GroupMutation) RemovedEdges() []string { - edges := make([]string, 0, 2) - if m.removedusers != nil { - edges = append(edges, group.EdgeUsers) - } - if m.removedtodos != nil { - edges = append(edges, group.EdgeTodos) - } - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *GroupMutation) RemovedIDs(name string) []ent.Value { - switch name { - case group.EdgeUsers: - ids := make([]ent.Value, 0, len(m.removedusers)) - for id := range m.removedusers { - ids = append(ids, id) - } - return ids - case group.EdgeTodos: - ids := make([]ent.Value, 0, len(m.removedtodos)) - for id := range m.removedtodos { - ids = append(ids, id) - } - return ids - } - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *GroupMutation) ClearedEdges() []string { - edges := make([]string, 0, 2) - if m.clearedusers { - edges = append(edges, group.EdgeUsers) - } - if m.clearedtodos { - edges = append(edges, group.EdgeTodos) - } - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *GroupMutation) EdgeCleared(name string) bool { - switch name { - case group.EdgeUsers: - return m.clearedusers - case group.EdgeTodos: - return m.clearedtodos - } - 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 *GroupMutation) ClearEdge(name string) error { - switch name { - } - return fmt.Errorf("unknown Group 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 *GroupMutation) ResetEdge(name string) error { - switch name { - case group.EdgeUsers: - m.ResetUsers() - return nil - case group.EdgeTodos: - m.ResetTodos() - return nil - } - return fmt.Errorf("unknown Group edge %s", name) -} - -// TodoMutation represents an operation that mutates the Todo nodes in the graph. -type TodoMutation struct { - config - op Op - typ string - id *int - created_at *time.Time - updated_at *time.Time - title *string - completed *bool - clearedFields map[string]struct{} - group *int - clearedgroup bool - done bool - oldValue func(context.Context) (*Todo, error) - predicates []predicate.Todo -} - -var _ ent.Mutation = (*TodoMutation)(nil) - -// todoOption allows management of the mutation configuration using functional options. -type todoOption func(*TodoMutation) - -// newTodoMutation creates new mutation for the Todo entity. -func newTodoMutation(c config, op Op, opts ...todoOption) *TodoMutation { - m := &TodoMutation{ - config: c, - op: op, - typ: TypeTodo, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withTodoID sets the ID field of the mutation. -func withTodoID(id int) todoOption { - return func(m *TodoMutation) { - var ( - err error - once sync.Once - value *Todo - ) - m.oldValue = func(ctx context.Context) (*Todo, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().Todo.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withTodo sets the old Todo of the mutation. -func withTodo(node *Todo) todoOption { - return func(m *TodoMutation) { - m.oldValue = func(context.Context) (*Todo, 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 TodoMutation) 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 TodoMutation) 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 *TodoMutation) 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 *TodoMutation) 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().Todo.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } -} - -// SetCreatedAt sets the "created_at" field. -func (m *TodoMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *TodoMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return - } - return *v, true -} - -// OldCreatedAt returns the old "created_at" field's value of the Todo entity. -// If the Todo 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 *TodoMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) - } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *TodoMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetUpdatedAt sets the "updated_at" field. -func (m *TodoMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t -} - -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *TodoMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at - if v == nil { - return - } - return *v, true -} - -// OldUpdatedAt returns the old "updated_at" field's value of the Todo entity. -// If the Todo 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 *TodoMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldUpdatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) - } - return oldValue.UpdatedAt, nil -} - -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *TodoMutation) ResetUpdatedAt() { - m.updated_at = nil -} - -// SetTitle sets the "title" field. -func (m *TodoMutation) SetTitle(s string) { - m.title = &s -} - -// Title returns the value of the "title" field in the mutation. -func (m *TodoMutation) 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 Todo entity. -// If the Todo 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 *TodoMutation) 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 *TodoMutation) ResetTitle() { - m.title = nil -} - -// SetCompleted sets the "completed" field. -func (m *TodoMutation) SetCompleted(b bool) { - m.completed = &b -} - -// Completed returns the value of the "completed" field in the mutation. -func (m *TodoMutation) Completed() (r bool, exists bool) { - v := m.completed - if v == nil { - return - } - return *v, true -} - -// OldCompleted returns the old "completed" field's value of the Todo entity. -// If the Todo 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 *TodoMutation) OldCompleted(ctx context.Context) (v bool, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCompleted is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCompleted requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCompleted: %w", err) - } - return oldValue.Completed, nil -} - -// ResetCompleted resets all changes to the "completed" field. -func (m *TodoMutation) ResetCompleted() { - m.completed = nil -} - -// SetGroupID sets the "group" edge to the Group entity by id. -func (m *TodoMutation) SetGroupID(id int) { - m.group = &id -} - -// ClearGroup clears the "group" edge to the Group entity. -func (m *TodoMutation) ClearGroup() { - m.clearedgroup = true -} - -// GroupCleared reports if the "group" edge to the Group entity was cleared. -func (m *TodoMutation) GroupCleared() bool { - return m.clearedgroup -} - -// GroupID returns the "group" edge ID in the mutation. -func (m *TodoMutation) GroupID() (id int, exists bool) { - if m.group != nil { - return *m.group, true - } - return -} - -// GroupIDs returns the "group" edge IDs in the mutation. -// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use -// GroupID instead. It exists only for internal usage by the builders. -func (m *TodoMutation) GroupIDs() (ids []int) { - if id := m.group; id != nil { - ids = append(ids, *id) - } - return -} - -// ResetGroup resets all changes to the "group" edge. -func (m *TodoMutation) ResetGroup() { - m.group = nil - m.clearedgroup = false -} - -// Where appends a list predicates to the TodoMutation builder. -func (m *TodoMutation) Where(ps ...predicate.Todo) { - m.predicates = append(m.predicates, ps...) -} - -// WhereP appends storage-level predicates to the TodoMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *TodoMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.Todo, len(ps)) - for i := range ps { - p[i] = ps[i] - } - m.Where(p...) -} - -// Op returns the operation name. -func (m *TodoMutation) Op() Op { - return m.op -} - -// SetOp allows setting the mutation operation. -func (m *TodoMutation) SetOp(op Op) { - m.op = op -} - -// Type returns the node type of this mutation (Todo). -func (m *TodoMutation) 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 *TodoMutation) Fields() []string { - fields := make([]string, 0, 4) - if m.created_at != nil { - fields = append(fields, todo.FieldCreatedAt) - } - if m.updated_at != nil { - fields = append(fields, todo.FieldUpdatedAt) - } - if m.title != nil { - fields = append(fields, todo.FieldTitle) - } - if m.completed != nil { - fields = append(fields, todo.FieldCompleted) - } - 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 *TodoMutation) Field(name string) (ent.Value, bool) { - switch name { - case todo.FieldCreatedAt: - return m.CreatedAt() - case todo.FieldUpdatedAt: - return m.UpdatedAt() - case todo.FieldTitle: - return m.Title() - case todo.FieldCompleted: - return m.Completed() - } - 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 *TodoMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case todo.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case todo.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - case todo.FieldTitle: - return m.OldTitle(ctx) - case todo.FieldCompleted: - return m.OldCompleted(ctx) - } - return nil, fmt.Errorf("unknown Todo 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 *TodoMutation) SetField(name string, value ent.Value) error { - switch name { - case todo.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case todo.FieldUpdatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUpdatedAt(v) - return nil - case todo.FieldTitle: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetTitle(v) - return nil - case todo.FieldCompleted: - v, ok := value.(bool) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCompleted(v) - return nil - } - return fmt.Errorf("unknown Todo field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *TodoMutation) 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 *TodoMutation) 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 *TodoMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown Todo numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *TodoMutation) ClearedFields() []string { - return nil -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *TodoMutation) 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 *TodoMutation) ClearField(name string) error { - return fmt.Errorf("unknown Todo 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 *TodoMutation) ResetField(name string) error { - switch name { - case todo.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case todo.FieldUpdatedAt: - m.ResetUpdatedAt() - return nil - case todo.FieldTitle: - m.ResetTitle() - return nil - case todo.FieldCompleted: - m.ResetCompleted() - return nil - } - return fmt.Errorf("unknown Todo field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *TodoMutation) AddedEdges() []string { - edges := make([]string, 0, 1) - if m.group != nil { - edges = append(edges, todo.EdgeGroup) - } - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *TodoMutation) AddedIDs(name string) []ent.Value { - switch name { - case todo.EdgeGroup: - if id := m.group; id != nil { - return []ent.Value{*id} - } - } - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *TodoMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *TodoMutation) RemovedIDs(name string) []ent.Value { - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *TodoMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) - if m.clearedgroup { - edges = append(edges, todo.EdgeGroup) - } - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *TodoMutation) EdgeCleared(name string) bool { - switch name { - case todo.EdgeGroup: - return m.clearedgroup - } - 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 *TodoMutation) ClearEdge(name string) error { - switch name { - case todo.EdgeGroup: - m.ClearGroup() - return nil - } - return fmt.Errorf("unknown Todo 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 *TodoMutation) ResetEdge(name string) error { - switch name { - case todo.EdgeGroup: - m.ResetGroup() - return nil - } - return fmt.Errorf("unknown Todo edge %s", name) -} - -// UserMutation represents an operation that mutates the User nodes in the graph. -type UserMutation struct { - config - op Op - typ string - id *int - created_at *time.Time - updated_at *time.Time - email *string - password *string - clearedFields map[string]struct{} - group map[int]struct{} - removedgroup map[int]struct{} - clearedgroup bool - done bool - oldValue func(context.Context) (*User, error) - predicates []predicate.User -} - -var _ ent.Mutation = (*UserMutation)(nil) - -// userOption allows management of the mutation configuration using functional options. -type userOption func(*UserMutation) - -// newUserMutation creates new mutation for the User entity. -func newUserMutation(c config, op Op, opts ...userOption) *UserMutation { - m := &UserMutation{ - config: c, - op: op, - typ: TypeUser, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withUserID sets the ID field of the mutation. -func withUserID(id int) userOption { - return func(m *UserMutation) { - var ( - err error - once sync.Once - value *User - ) - m.oldValue = func(ctx context.Context) (*User, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().User.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withUser sets the old User of the mutation. -func withUser(node *User) userOption { - return func(m *UserMutation) { - m.oldValue = func(context.Context) (*User, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m UserMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m UserMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, errors.New("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *UserMutation) ID() (id 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 *UserMutation) 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().User.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } -} - -// SetCreatedAt sets the "created_at" field. -func (m *UserMutation) SetCreatedAt(t time.Time) { - m.created_at = &t -} - -// CreatedAt returns the value of the "created_at" field in the mutation. -func (m *UserMutation) CreatedAt() (r time.Time, exists bool) { - v := m.created_at - if v == nil { - return - } - return *v, true -} - -// OldCreatedAt returns the old "created_at" field's value of the User entity. -// If the User object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *UserMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) - } - return oldValue.CreatedAt, nil -} - -// ResetCreatedAt resets all changes to the "created_at" field. -func (m *UserMutation) ResetCreatedAt() { - m.created_at = nil -} - -// SetUpdatedAt sets the "updated_at" field. -func (m *UserMutation) SetUpdatedAt(t time.Time) { - m.updated_at = &t -} - -// UpdatedAt returns the value of the "updated_at" field in the mutation. -func (m *UserMutation) UpdatedAt() (r time.Time, exists bool) { - v := m.updated_at - if v == nil { - return - } - return *v, true -} - -// OldUpdatedAt returns the old "updated_at" field's value of the User entity. -// If the User object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *UserMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldUpdatedAt requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) - } - return oldValue.UpdatedAt, nil -} - -// ResetUpdatedAt resets all changes to the "updated_at" field. -func (m *UserMutation) ResetUpdatedAt() { - m.updated_at = nil -} - -// SetEmail sets the "email" field. -func (m *UserMutation) SetEmail(s string) { - m.email = &s -} - -// Email returns the value of the "email" field in the mutation. -func (m *UserMutation) Email() (r string, exists bool) { - v := m.email - if v == nil { - return - } - return *v, true -} - -// OldEmail returns the old "email" field's value of the User entity. -// If the User object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *UserMutation) OldEmail(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldEmail is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldEmail requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldEmail: %w", err) - } - return oldValue.Email, nil -} - -// ResetEmail resets all changes to the "email" field. -func (m *UserMutation) ResetEmail() { - m.email = nil -} - -// SetPassword sets the "password" field. -func (m *UserMutation) SetPassword(s string) { - m.password = &s -} - -// Password returns the value of the "password" field in the mutation. -func (m *UserMutation) Password() (r string, exists bool) { - v := m.password - if v == nil { - return - } - return *v, true -} - -// OldPassword returns the old "password" field's value of the User entity. -// If the User object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *UserMutation) OldPassword(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldPassword is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldPassword requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldPassword: %w", err) - } - return oldValue.Password, nil -} - -// ResetPassword resets all changes to the "password" field. -func (m *UserMutation) ResetPassword() { - m.password = nil -} - -// AddGroupIDs adds the "group" edge to the Group entity by ids. -func (m *UserMutation) AddGroupIDs(ids ...int) { - if m.group == nil { - m.group = make(map[int]struct{}) - } - for i := range ids { - m.group[ids[i]] = struct{}{} - } -} - -// ClearGroup clears the "group" edge to the Group entity. -func (m *UserMutation) ClearGroup() { - m.clearedgroup = true -} - -// GroupCleared reports if the "group" edge to the Group entity was cleared. -func (m *UserMutation) GroupCleared() bool { - return m.clearedgroup -} - -// RemoveGroupIDs removes the "group" edge to the Group entity by IDs. -func (m *UserMutation) RemoveGroupIDs(ids ...int) { - if m.removedgroup == nil { - m.removedgroup = make(map[int]struct{}) - } - for i := range ids { - delete(m.group, ids[i]) - m.removedgroup[ids[i]] = struct{}{} - } -} - -// RemovedGroup returns the removed IDs of the "group" edge to the Group entity. -func (m *UserMutation) RemovedGroupIDs() (ids []int) { - for id := range m.removedgroup { - ids = append(ids, id) - } - return -} - -// GroupIDs returns the "group" edge IDs in the mutation. -func (m *UserMutation) GroupIDs() (ids []int) { - for id := range m.group { - ids = append(ids, id) - } - return -} - -// ResetGroup resets all changes to the "group" edge. -func (m *UserMutation) ResetGroup() { - m.group = nil - m.clearedgroup = false - m.removedgroup = nil -} - -// Where appends a list predicates to the UserMutation builder. -func (m *UserMutation) Where(ps ...predicate.User) { - m.predicates = append(m.predicates, ps...) -} - -// WhereP appends storage-level predicates to the UserMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *UserMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.User, len(ps)) - for i := range ps { - p[i] = ps[i] - } - m.Where(p...) -} - -// Op returns the operation name. -func (m *UserMutation) Op() Op { - return m.op -} - -// SetOp allows setting the mutation operation. -func (m *UserMutation) SetOp(op Op) { - m.op = op -} - -// Type returns the node type of this mutation (User). -func (m *UserMutation) Type() string { - return m.typ -} - -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *UserMutation) Fields() []string { - fields := make([]string, 0, 4) - if m.created_at != nil { - fields = append(fields, user.FieldCreatedAt) - } - if m.updated_at != nil { - fields = append(fields, user.FieldUpdatedAt) - } - if m.email != nil { - fields = append(fields, user.FieldEmail) - } - if m.password != nil { - fields = append(fields, user.FieldPassword) - } - return fields -} - -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *UserMutation) Field(name string) (ent.Value, bool) { - switch name { - case user.FieldCreatedAt: - return m.CreatedAt() - case user.FieldUpdatedAt: - return m.UpdatedAt() - case user.FieldEmail: - return m.Email() - case user.FieldPassword: - return m.Password() - } - return nil, false -} - -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case user.FieldCreatedAt: - return m.OldCreatedAt(ctx) - case user.FieldUpdatedAt: - return m.OldUpdatedAt(ctx) - case user.FieldEmail: - return m.OldEmail(ctx) - case user.FieldPassword: - return m.OldPassword(ctx) - } - return nil, fmt.Errorf("unknown User field %s", name) -} - -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *UserMutation) SetField(name string, value ent.Value) error { - switch name { - case user.FieldCreatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreatedAt(v) - return nil - case user.FieldUpdatedAt: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUpdatedAt(v) - return nil - case user.FieldEmail: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetEmail(v) - return nil - case user.FieldPassword: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetPassword(v) - return nil - } - return fmt.Errorf("unknown User field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *UserMutation) AddedFields() []string { - return nil -} - -// AddedField returns the numeric value that was incremented/decremented on a field -// with the given name. The second boolean return value indicates that this field -// was not set, or was not defined in the schema. -func (m *UserMutation) AddedField(name string) (ent.Value, bool) { - return nil, false -} - -// AddField adds the value to the field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *UserMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown User numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *UserMutation) ClearedFields() []string { - return nil -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *UserMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// ClearField clears the value of the field with the given name. It returns an -// error if the field is not defined in the schema. -func (m *UserMutation) ClearField(name string) error { - return fmt.Errorf("unknown User nullable field %s", name) -} - -// ResetField resets all changes in the mutation for the field with the given name. -// It returns an error if the field is not defined in the schema. -func (m *UserMutation) ResetField(name string) error { - switch name { - case user.FieldCreatedAt: - m.ResetCreatedAt() - return nil - case user.FieldUpdatedAt: - m.ResetUpdatedAt() - return nil - case user.FieldEmail: - m.ResetEmail() - return nil - case user.FieldPassword: - m.ResetPassword() - return nil - } - return fmt.Errorf("unknown User field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *UserMutation) AddedEdges() []string { - edges := make([]string, 0, 1) - if m.group != nil { - edges = append(edges, user.EdgeGroup) - } - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *UserMutation) AddedIDs(name string) []ent.Value { - switch name { - case user.EdgeGroup: - ids := make([]ent.Value, 0, len(m.group)) - for id := range m.group { - ids = append(ids, id) - } - return ids - } - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *UserMutation) RemovedEdges() []string { - edges := make([]string, 0, 1) - if m.removedgroup != nil { - edges = append(edges, user.EdgeGroup) - } - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *UserMutation) RemovedIDs(name string) []ent.Value { - switch name { - case user.EdgeGroup: - ids := make([]ent.Value, 0, len(m.removedgroup)) - for id := range m.removedgroup { - ids = append(ids, id) - } - return ids - } - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *UserMutation) ClearedEdges() []string { - edges := make([]string, 0, 1) - if m.clearedgroup { - edges = append(edges, user.EdgeGroup) - } - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *UserMutation) EdgeCleared(name string) bool { - switch name { - case user.EdgeGroup: - return m.clearedgroup - } - return false -} - -// ClearEdge clears the value of the edge with the given name. It returns an error -// if that edge is not defined in the schema. -func (m *UserMutation) ClearEdge(name string) error { - switch name { - } - return fmt.Errorf("unknown User unique edge %s", name) -} - -// ResetEdge resets all changes to the edge with the given name in this mutation. -// It returns an error if the edge is not defined in the schema. -func (m *UserMutation) ResetEdge(name string) error { - switch name { - case user.EdgeGroup: - m.ResetGroup() - return nil - } - return fmt.Errorf("unknown User edge %s", name) -} diff --git a/schema/ent/example/ent/predicate/predicate.go b/schema/ent/example/ent/predicate/predicate.go deleted file mode 100644 index 36fc0bb..0000000 --- a/schema/ent/example/ent/predicate/predicate.go +++ /dev/null @@ -1,16 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package predicate - -import ( - "entgo.io/ent/dialect/sql" -) - -// Group is the predicate function for group builders. -type Group func(*sql.Selector) - -// Todo is the predicate function for todo builders. -type Todo func(*sql.Selector) - -// User is the predicate function for user builders. -type User func(*sql.Selector) diff --git a/schema/ent/example/ent/runtime.go b/schema/ent/example/ent/runtime.go deleted file mode 100644 index bf207ba..0000000 --- a/schema/ent/example/ent/runtime.go +++ /dev/null @@ -1,82 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/schema" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/todo" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/user" - "time" -) - -// The init function reads all schema descriptors with runtime code -// (default values, validators, hooks and policies) and stitches it -// to their package variables. -func init() { - groupMixin := schema.Group{}.Mixin() - groupMixinFields0 := groupMixin[0].Fields() - _ = groupMixinFields0 - groupFields := schema.Group{}.Fields() - _ = groupFields - // groupDescCreatedAt is the schema descriptor for created_at field. - groupDescCreatedAt := groupMixinFields0[0].Descriptor() - // group.DefaultCreatedAt holds the default value on creation for the created_at field. - group.DefaultCreatedAt = groupDescCreatedAt.Default.(func() time.Time) - // groupDescUpdatedAt is the schema descriptor for updated_at field. - groupDescUpdatedAt := groupMixinFields0[1].Descriptor() - // group.DefaultUpdatedAt holds the default value on creation for the updated_at field. - group.DefaultUpdatedAt = groupDescUpdatedAt.Default.(func() time.Time) - // group.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. - group.UpdateDefaultUpdatedAt = groupDescUpdatedAt.UpdateDefault.(func() time.Time) - // groupDescName is the schema descriptor for name field. - groupDescName := groupFields[0].Descriptor() - // group.DefaultName holds the default value on creation for the name field. - group.DefaultName = groupDescName.Default.(string) - todoMixin := schema.Todo{}.Mixin() - todoMixinFields0 := todoMixin[0].Fields() - _ = todoMixinFields0 - todoFields := schema.Todo{}.Fields() - _ = todoFields - // todoDescCreatedAt is the schema descriptor for created_at field. - todoDescCreatedAt := todoMixinFields0[0].Descriptor() - // todo.DefaultCreatedAt holds the default value on creation for the created_at field. - todo.DefaultCreatedAt = todoDescCreatedAt.Default.(func() time.Time) - // todoDescUpdatedAt is the schema descriptor for updated_at field. - todoDescUpdatedAt := todoMixinFields0[1].Descriptor() - // todo.DefaultUpdatedAt holds the default value on creation for the updated_at field. - todo.DefaultUpdatedAt = todoDescUpdatedAt.Default.(func() time.Time) - // todo.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. - todo.UpdateDefaultUpdatedAt = todoDescUpdatedAt.UpdateDefault.(func() time.Time) - // todoDescTitle is the schema descriptor for title field. - todoDescTitle := todoFields[0].Descriptor() - // todo.DefaultTitle holds the default value on creation for the title field. - todo.DefaultTitle = todoDescTitle.Default.(string) - // todoDescCompleted is the schema descriptor for completed field. - todoDescCompleted := todoFields[1].Descriptor() - // todo.DefaultCompleted holds the default value on creation for the completed field. - todo.DefaultCompleted = todoDescCompleted.Default.(bool) - userMixin := schema.User{}.Mixin() - userMixinFields0 := userMixin[0].Fields() - _ = userMixinFields0 - userFields := schema.User{}.Fields() - _ = userFields - // userDescCreatedAt is the schema descriptor for created_at field. - userDescCreatedAt := userMixinFields0[0].Descriptor() - // user.DefaultCreatedAt holds the default value on creation for the created_at field. - user.DefaultCreatedAt = userDescCreatedAt.Default.(func() time.Time) - // userDescUpdatedAt is the schema descriptor for updated_at field. - userDescUpdatedAt := userMixinFields0[1].Descriptor() - // user.DefaultUpdatedAt holds the default value on creation for the updated_at field. - user.DefaultUpdatedAt = userDescUpdatedAt.Default.(func() time.Time) - // user.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field. - user.UpdateDefaultUpdatedAt = userDescUpdatedAt.UpdateDefault.(func() time.Time) - // userDescEmail is the schema descriptor for email field. - userDescEmail := userFields[0].Descriptor() - // user.DefaultEmail holds the default value on creation for the email field. - user.DefaultEmail = userDescEmail.Default.(string) - // userDescPassword is the schema descriptor for password field. - userDescPassword := userFields[1].Descriptor() - // user.DefaultPassword holds the default value on creation for the password field. - user.DefaultPassword = userDescPassword.Default.(string) -} diff --git a/schema/ent/example/ent/schema/group.go b/schema/ent/example/ent/schema/group.go deleted file mode 100644 index 102f953..0000000 --- a/schema/ent/example/ent/schema/group.go +++ /dev/null @@ -1,34 +0,0 @@ -package schema - -import ( - "git.gorlug.de/code/ersteller/schema/ent" - - "entgo.io/ent" - "entgo.io/ent/schema/edge" - "entgo.io/ent/schema/field" -) - -type Group struct { - ent.Schema -} - -func (Group) Mixin() []ent.Mixin { - return []ent.Mixin{ - ersteller_ent.TimeMixin{}, - } -} - -func (Group) Fields() []ent.Field { - return []ent.Field{ - field.String("name").Default(""), - } -} - -func (Group) Edges() []ent.Edge { - return []ent.Edge{ - // Back-reference to users that belong to this group - edge.From("users", User.Type).Ref("group"), - // Back-reference to todos that belong to this group - edge.From("todos", Todo.Type).Ref("group"), - } -} diff --git a/schema/ent/example/ent/schema/todo.go b/schema/ent/example/ent/schema/todo.go deleted file mode 100644 index 80a2faf..0000000 --- a/schema/ent/example/ent/schema/todo.go +++ /dev/null @@ -1,32 +0,0 @@ -package schema - -import ( - "git.gorlug.de/code/ersteller/schema/ent" - - "entgo.io/ent" - "entgo.io/ent/schema/edge" - "entgo.io/ent/schema/field" -) - -type Todo struct { - ent.Schema -} - -func (Todo) Mixin() []ent.Mixin { - return []ent.Mixin{ - ersteller_ent.TimeMixin{}, - } -} - -func (Todo) Fields() []ent.Field { - return []ent.Field{ - field.String("title").Default(""), - field.Bool("completed").Default(false), - } -} - -func (Todo) Edges() []ent.Edge { - return []ent.Edge{ - edge.To("group", Group.Type).Unique(), - } -} diff --git a/schema/ent/example/ent/schema/user.go b/schema/ent/example/ent/schema/user.go deleted file mode 100644 index 14dbd54..0000000 --- a/schema/ent/example/ent/schema/user.go +++ /dev/null @@ -1,35 +0,0 @@ -package schema - -import ( - "git.gorlug.de/code/ersteller/schema/ent" - - "entgo.io/ent" - "entgo.io/ent/schema/edge" - "entgo.io/ent/schema/field" -) - -// User holds the schema definition for the User entity. -type User struct { - ent.Schema -} - -func (User) Mixin() []ent.Mixin { - return []ent.Mixin{ - ersteller_ent.TimeMixin{}, - } -} - -// Fields of the User. -func (User) Fields() []ent.Field { - return []ent.Field{ - field.String("email"). - Default("unknown@localhost"), - field.String("password").Default(""), - } -} - -func (User) Edges() []ent.Edge { - return []ent.Edge{ - edge.To("group", Group.Type), - } -} diff --git a/schema/ent/example/ent/todo.go b/schema/ent/example/ent/todo.go deleted file mode 100644 index 00081c7..0000000 --- a/schema/ent/example/ent/todo.go +++ /dev/null @@ -1,180 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/todo" - "strings" - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" -) - -// Todo is the model entity for the Todo schema. -type Todo struct { - config `json:"-"` - // ID of the ent. - ID int `json:"id,omitempty"` - // CreatedAt holds the value of the "created_at" field. - CreatedAt time.Time `json:"created_at,omitempty"` - // UpdatedAt holds the value of the "updated_at" field. - UpdatedAt time.Time `json:"updated_at,omitempty"` - // Title holds the value of the "title" field. - Title string `json:"title,omitempty"` - // Completed holds the value of the "completed" field. - Completed bool `json:"completed,omitempty"` - // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the TodoQuery when eager-loading is set. - Edges TodoEdges `json:"edges"` - todo_group *int - selectValues sql.SelectValues -} - -// TodoEdges holds the relations/edges for other nodes in the graph. -type TodoEdges struct { - // Group holds the value of the group edge. - Group *Group `json:"group,omitempty"` - // loadedTypes holds the information for reporting if a - // type was loaded (or requested) in eager-loading or not. - loadedTypes [1]bool -} - -// GroupOrErr returns the Group value or an error if the edge -// was not loaded in eager-loading, or loaded but was not found. -func (e TodoEdges) GroupOrErr() (*Group, error) { - if e.Group != nil { - return e.Group, nil - } else if e.loadedTypes[0] { - return nil, &NotFoundError{label: group.Label} - } - return nil, &NotLoadedError{edge: "group"} -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*Todo) scanValues(columns []string) ([]any, error) { - values := make([]any, len(columns)) - for i := range columns { - switch columns[i] { - case todo.FieldCompleted: - values[i] = new(sql.NullBool) - case todo.FieldID: - values[i] = new(sql.NullInt64) - case todo.FieldTitle: - values[i] = new(sql.NullString) - case todo.FieldCreatedAt, todo.FieldUpdatedAt: - values[i] = new(sql.NullTime) - case todo.ForeignKeys[0]: // todo_group - values[i] = new(sql.NullInt64) - default: - values[i] = new(sql.UnknownType) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the Todo fields. -func (_m *Todo) assignValues(columns []string, values []any) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case todo.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - _m.ID = int(value.Int64) - case todo.FieldCreatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[i]) - } else if value.Valid { - _m.CreatedAt = value.Time - } - case todo.FieldUpdatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[i]) - } else if value.Valid { - _m.UpdatedAt = value.Time - } - case todo.FieldTitle: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field title", values[i]) - } else if value.Valid { - _m.Title = value.String - } - case todo.FieldCompleted: - if value, ok := values[i].(*sql.NullBool); !ok { - return fmt.Errorf("unexpected type %T for field completed", values[i]) - } else if value.Valid { - _m.Completed = value.Bool - } - case todo.ForeignKeys[0]: - if value, ok := values[i].(*sql.NullInt64); !ok { - return fmt.Errorf("unexpected type %T for edge-field todo_group", value) - } else if value.Valid { - _m.todo_group = new(int) - *_m.todo_group = int(value.Int64) - } - default: - _m.selectValues.Set(columns[i], values[i]) - } - } - return nil -} - -// Value returns the ent.Value that was dynamically selected and assigned to the Todo. -// This includes values selected through modifiers, order, etc. -func (_m *Todo) Value(name string) (ent.Value, error) { - return _m.selectValues.Get(name) -} - -// QueryGroup queries the "group" edge of the Todo entity. -func (_m *Todo) QueryGroup() *GroupQuery { - return NewTodoClient(_m.config).QueryGroup(_m) -} - -// Update returns a builder for updating this Todo. -// Note that you need to call Todo.Unwrap() before calling this method if this Todo -// was returned from a transaction, and the transaction was committed or rolled back. -func (_m *Todo) Update() *TodoUpdateOne { - return NewTodoClient(_m.config).UpdateOne(_m) -} - -// Unwrap unwraps the Todo entity that was returned from a transaction after it was closed, -// so that all future queries will be executed through the driver which created the transaction. -func (_m *Todo) Unwrap() *Todo { - _tx, ok := _m.config.driver.(*txDriver) - if !ok { - panic("ent: Todo is not a transactional entity") - } - _m.config.driver = _tx.drv - return _m -} - -// String implements the fmt.Stringer. -func (_m *Todo) String() string { - var builder strings.Builder - builder.WriteString("Todo(") - builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) - builder.WriteString("created_at=") - builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("updated_at=") - builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("title=") - builder.WriteString(_m.Title) - builder.WriteString(", ") - builder.WriteString("completed=") - builder.WriteString(fmt.Sprintf("%v", _m.Completed)) - builder.WriteByte(')') - return builder.String() -} - -// Todos is a parsable slice of Todo. -type Todos []*Todo diff --git a/schema/ent/example/ent/todo/todo.go b/schema/ent/example/ent/todo/todo.go deleted file mode 100644 index 2d428ac..0000000 --- a/schema/ent/example/ent/todo/todo.go +++ /dev/null @@ -1,121 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package todo - -import ( - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" -) - -const ( - // Label holds the string label denoting the todo type in the database. - Label = "todo" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldCreatedAt holds the string denoting the created_at field in the database. - FieldCreatedAt = "created_at" - // FieldUpdatedAt holds the string denoting the updated_at field in the database. - FieldUpdatedAt = "updated_at" - // FieldTitle holds the string denoting the title field in the database. - FieldTitle = "title" - // FieldCompleted holds the string denoting the completed field in the database. - FieldCompleted = "completed" - // EdgeGroup holds the string denoting the group edge name in mutations. - EdgeGroup = "group" - // Table holds the table name of the todo in the database. - Table = "todos" - // GroupTable is the table that holds the group relation/edge. - GroupTable = "todos" - // GroupInverseTable is the table name for the Group entity. - // It exists in this package in order to avoid circular dependency with the "group" package. - GroupInverseTable = "groups" - // GroupColumn is the table column denoting the group relation/edge. - GroupColumn = "todo_group" -) - -// Columns holds all SQL columns for todo fields. -var Columns = []string{ - FieldID, - FieldCreatedAt, - FieldUpdatedAt, - FieldTitle, - FieldCompleted, -} - -// ForeignKeys holds the SQL foreign-keys that are owned by the "todos" -// table and are not defined as standalone fields in the schema. -var ForeignKeys = []string{ - "todo_group", -} - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - for i := range ForeignKeys { - if column == ForeignKeys[i] { - return true - } - } - return false -} - -var ( - // DefaultCreatedAt holds the default value on creation for the "created_at" field. - DefaultCreatedAt func() time.Time - // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. - DefaultUpdatedAt func() time.Time - // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. - UpdateDefaultUpdatedAt func() time.Time - // DefaultTitle holds the default value on creation for the "title" field. - DefaultTitle string - // DefaultCompleted holds the default value on creation for the "completed" field. - DefaultCompleted bool -) - -// OrderOption defines the ordering options for the Todo queries. -type OrderOption func(*sql.Selector) - -// ByID orders the results by the id field. -func ByID(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldID, opts...).ToFunc() -} - -// ByCreatedAt orders the results by the created_at field. -func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() -} - -// ByUpdatedAt orders the results by the updated_at field. -func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() -} - -// ByTitle orders the results by the title field. -func ByTitle(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldTitle, opts...).ToFunc() -} - -// ByCompleted orders the results by the completed field. -func ByCompleted(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldCompleted, opts...).ToFunc() -} - -// ByGroupField orders the results by group field. -func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...)) - } -} -func newGroupStep() *sqlgraph.Step { - return sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, GroupTable, GroupColumn), - ) -} diff --git a/schema/ent/example/ent/todo/where.go b/schema/ent/example/ent/todo/where.go deleted file mode 100644 index bd455be..0000000 --- a/schema/ent/example/ent/todo/where.go +++ /dev/null @@ -1,269 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package todo - -import ( - "git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" -) - -// ID filters vertices based on their ID field. -func ID(id int) predicate.Todo { - return predicate.Todo(sql.FieldEQ(FieldID, id)) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.Todo { - return predicate.Todo(sql.FieldEQ(FieldID, id)) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.Todo { - return predicate.Todo(sql.FieldNEQ(FieldID, id)) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.Todo { - return predicate.Todo(sql.FieldIn(FieldID, ids...)) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.Todo { - return predicate.Todo(sql.FieldNotIn(FieldID, ids...)) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.Todo { - return predicate.Todo(sql.FieldGT(FieldID, id)) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.Todo { - return predicate.Todo(sql.FieldGTE(FieldID, id)) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.Todo { - return predicate.Todo(sql.FieldLT(FieldID, id)) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.Todo { - return predicate.Todo(sql.FieldLTE(FieldID, id)) -} - -// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.Todo { - return predicate.Todo(sql.FieldEQ(FieldCreatedAt, v)) -} - -// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. -func UpdatedAt(v time.Time) predicate.Todo { - return predicate.Todo(sql.FieldEQ(FieldUpdatedAt, v)) -} - -// Title applies equality check predicate on the "title" field. It's identical to TitleEQ. -func Title(v string) predicate.Todo { - return predicate.Todo(sql.FieldEQ(FieldTitle, v)) -} - -// Completed applies equality check predicate on the "completed" field. It's identical to CompletedEQ. -func Completed(v bool) predicate.Todo { - return predicate.Todo(sql.FieldEQ(FieldCompleted, v)) -} - -// CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v time.Time) predicate.Todo { - return predicate.Todo(sql.FieldEQ(FieldCreatedAt, v)) -} - -// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v time.Time) predicate.Todo { - return predicate.Todo(sql.FieldNEQ(FieldCreatedAt, v)) -} - -// CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...time.Time) predicate.Todo { - return predicate.Todo(sql.FieldIn(FieldCreatedAt, vs...)) -} - -// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...time.Time) predicate.Todo { - return predicate.Todo(sql.FieldNotIn(FieldCreatedAt, vs...)) -} - -// CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v time.Time) predicate.Todo { - return predicate.Todo(sql.FieldGT(FieldCreatedAt, v)) -} - -// CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v time.Time) predicate.Todo { - return predicate.Todo(sql.FieldGTE(FieldCreatedAt, v)) -} - -// CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v time.Time) predicate.Todo { - return predicate.Todo(sql.FieldLT(FieldCreatedAt, v)) -} - -// CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v time.Time) predicate.Todo { - return predicate.Todo(sql.FieldLTE(FieldCreatedAt, v)) -} - -// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. -func UpdatedAtEQ(v time.Time) predicate.Todo { - return predicate.Todo(sql.FieldEQ(FieldUpdatedAt, v)) -} - -// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. -func UpdatedAtNEQ(v time.Time) predicate.Todo { - return predicate.Todo(sql.FieldNEQ(FieldUpdatedAt, v)) -} - -// UpdatedAtIn applies the In predicate on the "updated_at" field. -func UpdatedAtIn(vs ...time.Time) predicate.Todo { - return predicate.Todo(sql.FieldIn(FieldUpdatedAt, vs...)) -} - -// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. -func UpdatedAtNotIn(vs ...time.Time) predicate.Todo { - return predicate.Todo(sql.FieldNotIn(FieldUpdatedAt, vs...)) -} - -// UpdatedAtGT applies the GT predicate on the "updated_at" field. -func UpdatedAtGT(v time.Time) predicate.Todo { - return predicate.Todo(sql.FieldGT(FieldUpdatedAt, v)) -} - -// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. -func UpdatedAtGTE(v time.Time) predicate.Todo { - return predicate.Todo(sql.FieldGTE(FieldUpdatedAt, v)) -} - -// UpdatedAtLT applies the LT predicate on the "updated_at" field. -func UpdatedAtLT(v time.Time) predicate.Todo { - return predicate.Todo(sql.FieldLT(FieldUpdatedAt, v)) -} - -// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. -func UpdatedAtLTE(v time.Time) predicate.Todo { - return predicate.Todo(sql.FieldLTE(FieldUpdatedAt, v)) -} - -// TitleEQ applies the EQ predicate on the "title" field. -func TitleEQ(v string) predicate.Todo { - return predicate.Todo(sql.FieldEQ(FieldTitle, v)) -} - -// TitleNEQ applies the NEQ predicate on the "title" field. -func TitleNEQ(v string) predicate.Todo { - return predicate.Todo(sql.FieldNEQ(FieldTitle, v)) -} - -// TitleIn applies the In predicate on the "title" field. -func TitleIn(vs ...string) predicate.Todo { - return predicate.Todo(sql.FieldIn(FieldTitle, vs...)) -} - -// TitleNotIn applies the NotIn predicate on the "title" field. -func TitleNotIn(vs ...string) predicate.Todo { - return predicate.Todo(sql.FieldNotIn(FieldTitle, vs...)) -} - -// TitleGT applies the GT predicate on the "title" field. -func TitleGT(v string) predicate.Todo { - return predicate.Todo(sql.FieldGT(FieldTitle, v)) -} - -// TitleGTE applies the GTE predicate on the "title" field. -func TitleGTE(v string) predicate.Todo { - return predicate.Todo(sql.FieldGTE(FieldTitle, v)) -} - -// TitleLT applies the LT predicate on the "title" field. -func TitleLT(v string) predicate.Todo { - return predicate.Todo(sql.FieldLT(FieldTitle, v)) -} - -// TitleLTE applies the LTE predicate on the "title" field. -func TitleLTE(v string) predicate.Todo { - return predicate.Todo(sql.FieldLTE(FieldTitle, v)) -} - -// TitleContains applies the Contains predicate on the "title" field. -func TitleContains(v string) predicate.Todo { - return predicate.Todo(sql.FieldContains(FieldTitle, v)) -} - -// TitleHasPrefix applies the HasPrefix predicate on the "title" field. -func TitleHasPrefix(v string) predicate.Todo { - return predicate.Todo(sql.FieldHasPrefix(FieldTitle, v)) -} - -// TitleHasSuffix applies the HasSuffix predicate on the "title" field. -func TitleHasSuffix(v string) predicate.Todo { - return predicate.Todo(sql.FieldHasSuffix(FieldTitle, v)) -} - -// TitleEqualFold applies the EqualFold predicate on the "title" field. -func TitleEqualFold(v string) predicate.Todo { - return predicate.Todo(sql.FieldEqualFold(FieldTitle, v)) -} - -// TitleContainsFold applies the ContainsFold predicate on the "title" field. -func TitleContainsFold(v string) predicate.Todo { - return predicate.Todo(sql.FieldContainsFold(FieldTitle, v)) -} - -// CompletedEQ applies the EQ predicate on the "completed" field. -func CompletedEQ(v bool) predicate.Todo { - return predicate.Todo(sql.FieldEQ(FieldCompleted, v)) -} - -// CompletedNEQ applies the NEQ predicate on the "completed" field. -func CompletedNEQ(v bool) predicate.Todo { - return predicate.Todo(sql.FieldNEQ(FieldCompleted, v)) -} - -// HasGroup applies the HasEdge predicate on the "group" edge. -func HasGroup() predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, GroupTable, GroupColumn), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates). -func HasGroupWith(preds ...predicate.Group) predicate.Todo { - return predicate.Todo(func(s *sql.Selector) { - step := newGroupStep() - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.Todo) predicate.Todo { - return predicate.Todo(sql.AndPredicates(predicates...)) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.Todo) predicate.Todo { - return predicate.Todo(sql.OrPredicates(predicates...)) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.Todo) predicate.Todo { - return predicate.Todo(sql.NotPredicates(p)) -} diff --git a/schema/ent/example/ent/todo_create.go b/schema/ent/example/ent/todo_create.go deleted file mode 100644 index 804074e..0000000 --- a/schema/ent/example/ent/todo_create.go +++ /dev/null @@ -1,314 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/todo" - "time" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// TodoCreate is the builder for creating a Todo entity. -type TodoCreate struct { - config - mutation *TodoMutation - hooks []Hook -} - -// SetCreatedAt sets the "created_at" field. -func (_c *TodoCreate) SetCreatedAt(v time.Time) *TodoCreate { - _c.mutation.SetCreatedAt(v) - return _c -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (_c *TodoCreate) SetNillableCreatedAt(v *time.Time) *TodoCreate { - if v != nil { - _c.SetCreatedAt(*v) - } - return _c -} - -// SetUpdatedAt sets the "updated_at" field. -func (_c *TodoCreate) SetUpdatedAt(v time.Time) *TodoCreate { - _c.mutation.SetUpdatedAt(v) - return _c -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (_c *TodoCreate) SetNillableUpdatedAt(v *time.Time) *TodoCreate { - if v != nil { - _c.SetUpdatedAt(*v) - } - return _c -} - -// SetTitle sets the "title" field. -func (_c *TodoCreate) SetTitle(v string) *TodoCreate { - _c.mutation.SetTitle(v) - return _c -} - -// SetNillableTitle sets the "title" field if the given value is not nil. -func (_c *TodoCreate) SetNillableTitle(v *string) *TodoCreate { - if v != nil { - _c.SetTitle(*v) - } - return _c -} - -// SetCompleted sets the "completed" field. -func (_c *TodoCreate) SetCompleted(v bool) *TodoCreate { - _c.mutation.SetCompleted(v) - return _c -} - -// SetNillableCompleted sets the "completed" field if the given value is not nil. -func (_c *TodoCreate) SetNillableCompleted(v *bool) *TodoCreate { - if v != nil { - _c.SetCompleted(*v) - } - return _c -} - -// SetGroupID sets the "group" edge to the Group entity by ID. -func (_c *TodoCreate) SetGroupID(id int) *TodoCreate { - _c.mutation.SetGroupID(id) - return _c -} - -// SetNillableGroupID sets the "group" edge to the Group entity by ID if the given value is not nil. -func (_c *TodoCreate) SetNillableGroupID(id *int) *TodoCreate { - if id != nil { - _c = _c.SetGroupID(*id) - } - return _c -} - -// SetGroup sets the "group" edge to the Group entity. -func (_c *TodoCreate) SetGroup(v *Group) *TodoCreate { - return _c.SetGroupID(v.ID) -} - -// Mutation returns the TodoMutation object of the builder. -func (_c *TodoCreate) Mutation() *TodoMutation { - return _c.mutation -} - -// Save creates the Todo in the database. -func (_c *TodoCreate) Save(ctx context.Context) (*Todo, error) { - _c.defaults() - return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) -} - -// SaveX calls Save and panics if Save returns an error. -func (_c *TodoCreate) SaveX(ctx context.Context) *Todo { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *TodoCreate) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *TodoCreate) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_c *TodoCreate) defaults() { - if _, ok := _c.mutation.CreatedAt(); !ok { - v := todo.DefaultCreatedAt() - _c.mutation.SetCreatedAt(v) - } - if _, ok := _c.mutation.UpdatedAt(); !ok { - v := todo.DefaultUpdatedAt() - _c.mutation.SetUpdatedAt(v) - } - if _, ok := _c.mutation.Title(); !ok { - v := todo.DefaultTitle - _c.mutation.SetTitle(v) - } - if _, ok := _c.mutation.Completed(); !ok { - v := todo.DefaultCompleted - _c.mutation.SetCompleted(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_c *TodoCreate) check() error { - if _, ok := _c.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Todo.created_at"`)} - } - if _, ok := _c.mutation.UpdatedAt(); !ok { - return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Todo.updated_at"`)} - } - if _, ok := _c.mutation.Title(); !ok { - return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Todo.title"`)} - } - if _, ok := _c.mutation.Completed(); !ok { - return &ValidationError{Name: "completed", err: errors.New(`ent: missing required field "Todo.completed"`)} - } - return nil -} - -func (_c *TodoCreate) sqlSave(ctx context.Context) (*Todo, error) { - if err := _c.check(); err != nil { - return nil, err - } - _node, _spec := _c.createSpec() - if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - id := _spec.ID.Value.(int64) - _node.ID = int(id) - _c.mutation.id = &_node.ID - _c.mutation.done = true - return _node, nil -} - -func (_c *TodoCreate) createSpec() (*Todo, *sqlgraph.CreateSpec) { - var ( - _node = &Todo{config: _c.config} - _spec = sqlgraph.NewCreateSpec(todo.Table, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt)) - ) - if value, ok := _c.mutation.CreatedAt(); ok { - _spec.SetField(todo.FieldCreatedAt, field.TypeTime, value) - _node.CreatedAt = value - } - if value, ok := _c.mutation.UpdatedAt(); ok { - _spec.SetField(todo.FieldUpdatedAt, field.TypeTime, value) - _node.UpdatedAt = value - } - if value, ok := _c.mutation.Title(); ok { - _spec.SetField(todo.FieldTitle, field.TypeString, value) - _node.Title = value - } - if value, ok := _c.mutation.Completed(); ok { - _spec.SetField(todo.FieldCompleted, field.TypeBool, value) - _node.Completed = value - } - if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: todo.GroupTable, - Columns: []string{todo.GroupColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _node.todo_group = &nodes[0] - _spec.Edges = append(_spec.Edges, edge) - } - return _node, _spec -} - -// TodoCreateBulk is the builder for creating many Todo entities in bulk. -type TodoCreateBulk struct { - config - err error - builders []*TodoCreate -} - -// Save creates the Todo entities in the database. -func (_c *TodoCreateBulk) Save(ctx context.Context) ([]*Todo, error) { - if _c.err != nil { - return nil, _c.err - } - specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) - nodes := make([]*Todo, len(_c.builders)) - mutators := make([]Mutator, len(_c.builders)) - for i := range _c.builders { - func(i int, root context.Context) { - builder := _c.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*TodoMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - var err error - nodes[i], specs[i] = builder.createSpec() - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) - } else { - spec := &sqlgraph.BatchCreateSpec{Nodes: specs} - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - } - } - if err != nil { - return nil, err - } - mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) - } - mutation.done = true - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (_c *TodoCreateBulk) SaveX(ctx context.Context) []*Todo { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *TodoCreateBulk) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *TodoCreateBulk) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/schema/ent/example/ent/todo_delete.go b/schema/ent/example/ent/todo_delete.go deleted file mode 100644 index 1d7e152..0000000 --- a/schema/ent/example/ent/todo_delete.go +++ /dev/null @@ -1,88 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/todo" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// TodoDelete is the builder for deleting a Todo entity. -type TodoDelete struct { - config - hooks []Hook - mutation *TodoMutation -} - -// Where appends a list predicates to the TodoDelete builder. -func (_d *TodoDelete) Where(ps ...predicate.Todo) *TodoDelete { - _d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (_d *TodoDelete) Exec(ctx context.Context) (int, error) { - return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *TodoDelete) ExecX(ctx context.Context) int { - n, err := _d.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (_d *TodoDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(todo.Table, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt)) - if ps := _d.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) - if err != nil && sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - _d.mutation.done = true - return affected, err -} - -// TodoDeleteOne is the builder for deleting a single Todo entity. -type TodoDeleteOne struct { - _d *TodoDelete -} - -// Where appends a list predicates to the TodoDelete builder. -func (_d *TodoDeleteOne) Where(ps ...predicate.Todo) *TodoDeleteOne { - _d._d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query. -func (_d *TodoDeleteOne) Exec(ctx context.Context) error { - n, err := _d._d.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{todo.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *TodoDeleteOne) ExecX(ctx context.Context) { - if err := _d.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/schema/ent/example/ent/todo_update.go b/schema/ent/example/ent/todo_update.go deleted file mode 100644 index 42e7758..0000000 --- a/schema/ent/example/ent/todo_update.go +++ /dev/null @@ -1,389 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/todo" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// TodoUpdate is the builder for updating Todo entities. -type TodoUpdate struct { - config - hooks []Hook - mutation *TodoMutation -} - -// Where appends a list predicates to the TodoUpdate builder. -func (_u *TodoUpdate) Where(ps ...predicate.Todo) *TodoUpdate { - _u.mutation.Where(ps...) - return _u -} - -// SetUpdatedAt sets the "updated_at" field. -func (_u *TodoUpdate) SetUpdatedAt(v time.Time) *TodoUpdate { - _u.mutation.SetUpdatedAt(v) - return _u -} - -// SetTitle sets the "title" field. -func (_u *TodoUpdate) SetTitle(v string) *TodoUpdate { - _u.mutation.SetTitle(v) - return _u -} - -// SetNillableTitle sets the "title" field if the given value is not nil. -func (_u *TodoUpdate) SetNillableTitle(v *string) *TodoUpdate { - if v != nil { - _u.SetTitle(*v) - } - return _u -} - -// SetCompleted sets the "completed" field. -func (_u *TodoUpdate) SetCompleted(v bool) *TodoUpdate { - _u.mutation.SetCompleted(v) - return _u -} - -// SetNillableCompleted sets the "completed" field if the given value is not nil. -func (_u *TodoUpdate) SetNillableCompleted(v *bool) *TodoUpdate { - if v != nil { - _u.SetCompleted(*v) - } - return _u -} - -// SetGroupID sets the "group" edge to the Group entity by ID. -func (_u *TodoUpdate) SetGroupID(id int) *TodoUpdate { - _u.mutation.SetGroupID(id) - return _u -} - -// SetNillableGroupID sets the "group" edge to the Group entity by ID if the given value is not nil. -func (_u *TodoUpdate) SetNillableGroupID(id *int) *TodoUpdate { - if id != nil { - _u = _u.SetGroupID(*id) - } - return _u -} - -// SetGroup sets the "group" edge to the Group entity. -func (_u *TodoUpdate) SetGroup(v *Group) *TodoUpdate { - return _u.SetGroupID(v.ID) -} - -// Mutation returns the TodoMutation object of the builder. -func (_u *TodoUpdate) Mutation() *TodoMutation { - return _u.mutation -} - -// ClearGroup clears the "group" edge to the Group entity. -func (_u *TodoUpdate) ClearGroup() *TodoUpdate { - _u.mutation.ClearGroup() - return _u -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (_u *TodoUpdate) Save(ctx context.Context) (int, error) { - _u.defaults() - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *TodoUpdate) SaveX(ctx context.Context) int { - affected, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (_u *TodoUpdate) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *TodoUpdate) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_u *TodoUpdate) defaults() { - if _, ok := _u.mutation.UpdatedAt(); !ok { - v := todo.UpdateDefaultUpdatedAt() - _u.mutation.SetUpdatedAt(v) - } -} - -func (_u *TodoUpdate) sqlSave(ctx context.Context) (_node int, err error) { - _spec := sqlgraph.NewUpdateSpec(todo.Table, todo.Columns, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt)) - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(todo.FieldUpdatedAt, field.TypeTime, value) - } - if value, ok := _u.mutation.Title(); ok { - _spec.SetField(todo.FieldTitle, field.TypeString, value) - } - if value, ok := _u.mutation.Completed(); ok { - _spec.SetField(todo.FieldCompleted, field.TypeBool, value) - } - if _u.mutation.GroupCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: todo.GroupTable, - Columns: []string{todo.GroupColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: todo.GroupTable, - Columns: []string{todo.GroupColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{todo.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - _u.mutation.done = true - return _node, nil -} - -// TodoUpdateOne is the builder for updating a single Todo entity. -type TodoUpdateOne struct { - config - fields []string - hooks []Hook - mutation *TodoMutation -} - -// SetUpdatedAt sets the "updated_at" field. -func (_u *TodoUpdateOne) SetUpdatedAt(v time.Time) *TodoUpdateOne { - _u.mutation.SetUpdatedAt(v) - return _u -} - -// SetTitle sets the "title" field. -func (_u *TodoUpdateOne) SetTitle(v string) *TodoUpdateOne { - _u.mutation.SetTitle(v) - return _u -} - -// SetNillableTitle sets the "title" field if the given value is not nil. -func (_u *TodoUpdateOne) SetNillableTitle(v *string) *TodoUpdateOne { - if v != nil { - _u.SetTitle(*v) - } - return _u -} - -// SetCompleted sets the "completed" field. -func (_u *TodoUpdateOne) SetCompleted(v bool) *TodoUpdateOne { - _u.mutation.SetCompleted(v) - return _u -} - -// SetNillableCompleted sets the "completed" field if the given value is not nil. -func (_u *TodoUpdateOne) SetNillableCompleted(v *bool) *TodoUpdateOne { - if v != nil { - _u.SetCompleted(*v) - } - return _u -} - -// SetGroupID sets the "group" edge to the Group entity by ID. -func (_u *TodoUpdateOne) SetGroupID(id int) *TodoUpdateOne { - _u.mutation.SetGroupID(id) - return _u -} - -// SetNillableGroupID sets the "group" edge to the Group entity by ID if the given value is not nil. -func (_u *TodoUpdateOne) SetNillableGroupID(id *int) *TodoUpdateOne { - if id != nil { - _u = _u.SetGroupID(*id) - } - return _u -} - -// SetGroup sets the "group" edge to the Group entity. -func (_u *TodoUpdateOne) SetGroup(v *Group) *TodoUpdateOne { - return _u.SetGroupID(v.ID) -} - -// Mutation returns the TodoMutation object of the builder. -func (_u *TodoUpdateOne) Mutation() *TodoMutation { - return _u.mutation -} - -// ClearGroup clears the "group" edge to the Group entity. -func (_u *TodoUpdateOne) ClearGroup() *TodoUpdateOne { - _u.mutation.ClearGroup() - return _u -} - -// Where appends a list predicates to the TodoUpdate builder. -func (_u *TodoUpdateOne) Where(ps ...predicate.Todo) *TodoUpdateOne { - _u.mutation.Where(ps...) - return _u -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (_u *TodoUpdateOne) Select(field string, fields ...string) *TodoUpdateOne { - _u.fields = append([]string{field}, fields...) - return _u -} - -// Save executes the query and returns the updated Todo entity. -func (_u *TodoUpdateOne) Save(ctx context.Context) (*Todo, error) { - _u.defaults() - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *TodoUpdateOne) SaveX(ctx context.Context) *Todo { - node, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (_u *TodoUpdateOne) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *TodoUpdateOne) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_u *TodoUpdateOne) defaults() { - if _, ok := _u.mutation.UpdatedAt(); !ok { - v := todo.UpdateDefaultUpdatedAt() - _u.mutation.SetUpdatedAt(v) - } -} - -func (_u *TodoUpdateOne) sqlSave(ctx context.Context) (_node *Todo, err error) { - _spec := sqlgraph.NewUpdateSpec(todo.Table, todo.Columns, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt)) - id, ok := _u.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Todo.id" for update`)} - } - _spec.Node.ID.Value = id - if fields := _u.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, todo.FieldID) - for _, f := range fields { - if !todo.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != todo.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(todo.FieldUpdatedAt, field.TypeTime, value) - } - if value, ok := _u.mutation.Title(); ok { - _spec.SetField(todo.FieldTitle, field.TypeString, value) - } - if value, ok := _u.mutation.Completed(); ok { - _spec.SetField(todo.FieldCompleted, field.TypeBool, value) - } - if _u.mutation.GroupCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: todo.GroupTable, - Columns: []string{todo.GroupColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2O, - Inverse: false, - Table: todo.GroupTable, - Columns: []string{todo.GroupColumn}, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - _node = &Todo{config: _u.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{todo.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - _u.mutation.done = true - return _node, nil -} diff --git a/schema/ent/example/ent/user.go b/schema/ent/example/ent/user.go deleted file mode 100644 index 0f3d104..0000000 --- a/schema/ent/example/ent/user.go +++ /dev/null @@ -1,165 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/user" - "strings" - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" -) - -// User is the model entity for the User schema. -type User struct { - config `json:"-"` - // ID of the ent. - ID int `json:"id,omitempty"` - // CreatedAt holds the value of the "created_at" field. - CreatedAt time.Time `json:"created_at,omitempty"` - // UpdatedAt holds the value of the "updated_at" field. - UpdatedAt time.Time `json:"updated_at,omitempty"` - // Email holds the value of the "email" field. - Email string `json:"email,omitempty"` - // Password holds the value of the "password" field. - Password string `json:"password,omitempty"` - // Edges holds the relations/edges for other nodes in the graph. - // The values are being populated by the UserQuery when eager-loading is set. - Edges UserEdges `json:"edges"` - selectValues sql.SelectValues -} - -// UserEdges holds the relations/edges for other nodes in the graph. -type UserEdges struct { - // Group holds the value of the group edge. - Group []*Group `json:"group,omitempty"` - // loadedTypes holds the information for reporting if a - // type was loaded (or requested) in eager-loading or not. - loadedTypes [1]bool -} - -// GroupOrErr returns the Group value or an error if the edge -// was not loaded in eager-loading. -func (e UserEdges) GroupOrErr() ([]*Group, error) { - if e.loadedTypes[0] { - return e.Group, nil - } - return nil, &NotLoadedError{edge: "group"} -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*User) scanValues(columns []string) ([]any, error) { - values := make([]any, len(columns)) - for i := range columns { - switch columns[i] { - case user.FieldID: - values[i] = new(sql.NullInt64) - case user.FieldEmail, user.FieldPassword: - values[i] = new(sql.NullString) - case user.FieldCreatedAt, user.FieldUpdatedAt: - values[i] = new(sql.NullTime) - default: - values[i] = new(sql.UnknownType) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the User fields. -func (_m *User) assignValues(columns []string, values []any) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case user.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - _m.ID = int(value.Int64) - case user.FieldCreatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field created_at", values[i]) - } else if value.Valid { - _m.CreatedAt = value.Time - } - case user.FieldUpdatedAt: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field updated_at", values[i]) - } else if value.Valid { - _m.UpdatedAt = value.Time - } - case user.FieldEmail: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field email", values[i]) - } else if value.Valid { - _m.Email = value.String - } - case user.FieldPassword: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field password", values[i]) - } else if value.Valid { - _m.Password = value.String - } - default: - _m.selectValues.Set(columns[i], values[i]) - } - } - return nil -} - -// Value returns the ent.Value that was dynamically selected and assigned to the User. -// This includes values selected through modifiers, order, etc. -func (_m *User) Value(name string) (ent.Value, error) { - return _m.selectValues.Get(name) -} - -// QueryGroup queries the "group" edge of the User entity. -func (_m *User) QueryGroup() *GroupQuery { - return NewUserClient(_m.config).QueryGroup(_m) -} - -// Update returns a builder for updating this User. -// Note that you need to call User.Unwrap() before calling this method if this User -// was returned from a transaction, and the transaction was committed or rolled back. -func (_m *User) Update() *UserUpdateOne { - return NewUserClient(_m.config).UpdateOne(_m) -} - -// Unwrap unwraps the User entity that was returned from a transaction after it was closed, -// so that all future queries will be executed through the driver which created the transaction. -func (_m *User) Unwrap() *User { - _tx, ok := _m.config.driver.(*txDriver) - if !ok { - panic("ent: User is not a transactional entity") - } - _m.config.driver = _tx.drv - return _m -} - -// String implements the fmt.Stringer. -func (_m *User) String() string { - var builder strings.Builder - builder.WriteString("User(") - builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) - builder.WriteString("created_at=") - builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("updated_at=") - builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("email=") - builder.WriteString(_m.Email) - builder.WriteString(", ") - builder.WriteString("password=") - builder.WriteString(_m.Password) - builder.WriteByte(')') - return builder.String() -} - -// Users is a parsable slice of User. -type Users []*User diff --git a/schema/ent/example/ent/user/user.go b/schema/ent/example/ent/user/user.go deleted file mode 100644 index 42daa50..0000000 --- a/schema/ent/example/ent/user/user.go +++ /dev/null @@ -1,121 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package user - -import ( - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" -) - -const ( - // Label holds the string label denoting the user type in the database. - Label = "user" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldCreatedAt holds the string denoting the created_at field in the database. - FieldCreatedAt = "created_at" - // FieldUpdatedAt holds the string denoting the updated_at field in the database. - FieldUpdatedAt = "updated_at" - // FieldEmail holds the string denoting the email field in the database. - FieldEmail = "email" - // FieldPassword holds the string denoting the password field in the database. - FieldPassword = "password" - // EdgeGroup holds the string denoting the group edge name in mutations. - EdgeGroup = "group" - // Table holds the table name of the user in the database. - Table = "users" - // GroupTable is the table that holds the group relation/edge. The primary key declared below. - GroupTable = "user_group" - // GroupInverseTable is the table name for the Group entity. - // It exists in this package in order to avoid circular dependency with the "group" package. - GroupInverseTable = "groups" -) - -// Columns holds all SQL columns for user fields. -var Columns = []string{ - FieldID, - FieldCreatedAt, - FieldUpdatedAt, - FieldEmail, - FieldPassword, -} - -var ( - // GroupPrimaryKey and GroupColumn2 are the table columns denoting the - // primary key for the group relation (M2M). - GroupPrimaryKey = []string{"user_id", "group_id"} -) - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - return false -} - -var ( - // DefaultCreatedAt holds the default value on creation for the "created_at" field. - DefaultCreatedAt func() time.Time - // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. - DefaultUpdatedAt func() time.Time - // UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field. - UpdateDefaultUpdatedAt func() time.Time - // DefaultEmail holds the default value on creation for the "email" field. - DefaultEmail string - // DefaultPassword holds the default value on creation for the "password" field. - DefaultPassword string -) - -// OrderOption defines the ordering options for the User queries. -type OrderOption func(*sql.Selector) - -// ByID orders the results by the id field. -func ByID(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldID, opts...).ToFunc() -} - -// ByCreatedAt orders the results by the created_at field. -func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() -} - -// ByUpdatedAt orders the results by the updated_at field. -func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() -} - -// ByEmail orders the results by the email field. -func ByEmail(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldEmail, opts...).ToFunc() -} - -// ByPassword orders the results by the password field. -func ByPassword(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldPassword, opts...).ToFunc() -} - -// ByGroupCount orders the results by group count. -func ByGroupCount(opts ...sql.OrderTermOption) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborsCount(s, newGroupStep(), opts...) - } -} - -// ByGroup orders the results by group terms. -func ByGroup(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { - return func(s *sql.Selector) { - sqlgraph.OrderByNeighborTerms(s, newGroupStep(), append([]sql.OrderTerm{term}, terms...)...) - } -} -func newGroupStep() *sqlgraph.Step { - return sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, GroupTable, GroupPrimaryKey...), - ) -} diff --git a/schema/ent/example/ent/user/where.go b/schema/ent/example/ent/user/where.go deleted file mode 100644 index 93df583..0000000 --- a/schema/ent/example/ent/user/where.go +++ /dev/null @@ -1,324 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package user - -import ( - "git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" -) - -// ID filters vertices based on their ID field. -func ID(id int) predicate.User { - return predicate.User(sql.FieldEQ(FieldID, id)) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int) predicate.User { - return predicate.User(sql.FieldEQ(FieldID, id)) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int) predicate.User { - return predicate.User(sql.FieldNEQ(FieldID, id)) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int) predicate.User { - return predicate.User(sql.FieldIn(FieldID, ids...)) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int) predicate.User { - return predicate.User(sql.FieldNotIn(FieldID, ids...)) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int) predicate.User { - return predicate.User(sql.FieldGT(FieldID, id)) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int) predicate.User { - return predicate.User(sql.FieldGTE(FieldID, id)) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int) predicate.User { - return predicate.User(sql.FieldLT(FieldID, id)) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int) predicate.User { - return predicate.User(sql.FieldLTE(FieldID, id)) -} - -// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. -func CreatedAt(v time.Time) predicate.User { - return predicate.User(sql.FieldEQ(FieldCreatedAt, v)) -} - -// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. -func UpdatedAt(v time.Time) predicate.User { - return predicate.User(sql.FieldEQ(FieldUpdatedAt, v)) -} - -// Email applies equality check predicate on the "email" field. It's identical to EmailEQ. -func Email(v string) predicate.User { - return predicate.User(sql.FieldEQ(FieldEmail, v)) -} - -// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ. -func Password(v string) predicate.User { - return predicate.User(sql.FieldEQ(FieldPassword, v)) -} - -// CreatedAtEQ applies the EQ predicate on the "created_at" field. -func CreatedAtEQ(v time.Time) predicate.User { - return predicate.User(sql.FieldEQ(FieldCreatedAt, v)) -} - -// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. -func CreatedAtNEQ(v time.Time) predicate.User { - return predicate.User(sql.FieldNEQ(FieldCreatedAt, v)) -} - -// CreatedAtIn applies the In predicate on the "created_at" field. -func CreatedAtIn(vs ...time.Time) predicate.User { - return predicate.User(sql.FieldIn(FieldCreatedAt, vs...)) -} - -// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. -func CreatedAtNotIn(vs ...time.Time) predicate.User { - return predicate.User(sql.FieldNotIn(FieldCreatedAt, vs...)) -} - -// CreatedAtGT applies the GT predicate on the "created_at" field. -func CreatedAtGT(v time.Time) predicate.User { - return predicate.User(sql.FieldGT(FieldCreatedAt, v)) -} - -// CreatedAtGTE applies the GTE predicate on the "created_at" field. -func CreatedAtGTE(v time.Time) predicate.User { - return predicate.User(sql.FieldGTE(FieldCreatedAt, v)) -} - -// CreatedAtLT applies the LT predicate on the "created_at" field. -func CreatedAtLT(v time.Time) predicate.User { - return predicate.User(sql.FieldLT(FieldCreatedAt, v)) -} - -// CreatedAtLTE applies the LTE predicate on the "created_at" field. -func CreatedAtLTE(v time.Time) predicate.User { - return predicate.User(sql.FieldLTE(FieldCreatedAt, v)) -} - -// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. -func UpdatedAtEQ(v time.Time) predicate.User { - return predicate.User(sql.FieldEQ(FieldUpdatedAt, v)) -} - -// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. -func UpdatedAtNEQ(v time.Time) predicate.User { - return predicate.User(sql.FieldNEQ(FieldUpdatedAt, v)) -} - -// UpdatedAtIn applies the In predicate on the "updated_at" field. -func UpdatedAtIn(vs ...time.Time) predicate.User { - return predicate.User(sql.FieldIn(FieldUpdatedAt, vs...)) -} - -// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. -func UpdatedAtNotIn(vs ...time.Time) predicate.User { - return predicate.User(sql.FieldNotIn(FieldUpdatedAt, vs...)) -} - -// UpdatedAtGT applies the GT predicate on the "updated_at" field. -func UpdatedAtGT(v time.Time) predicate.User { - return predicate.User(sql.FieldGT(FieldUpdatedAt, v)) -} - -// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. -func UpdatedAtGTE(v time.Time) predicate.User { - return predicate.User(sql.FieldGTE(FieldUpdatedAt, v)) -} - -// UpdatedAtLT applies the LT predicate on the "updated_at" field. -func UpdatedAtLT(v time.Time) predicate.User { - return predicate.User(sql.FieldLT(FieldUpdatedAt, v)) -} - -// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. -func UpdatedAtLTE(v time.Time) predicate.User { - return predicate.User(sql.FieldLTE(FieldUpdatedAt, v)) -} - -// EmailEQ applies the EQ predicate on the "email" field. -func EmailEQ(v string) predicate.User { - return predicate.User(sql.FieldEQ(FieldEmail, v)) -} - -// EmailNEQ applies the NEQ predicate on the "email" field. -func EmailNEQ(v string) predicate.User { - return predicate.User(sql.FieldNEQ(FieldEmail, v)) -} - -// EmailIn applies the In predicate on the "email" field. -func EmailIn(vs ...string) predicate.User { - return predicate.User(sql.FieldIn(FieldEmail, vs...)) -} - -// EmailNotIn applies the NotIn predicate on the "email" field. -func EmailNotIn(vs ...string) predicate.User { - return predicate.User(sql.FieldNotIn(FieldEmail, vs...)) -} - -// EmailGT applies the GT predicate on the "email" field. -func EmailGT(v string) predicate.User { - return predicate.User(sql.FieldGT(FieldEmail, v)) -} - -// EmailGTE applies the GTE predicate on the "email" field. -func EmailGTE(v string) predicate.User { - return predicate.User(sql.FieldGTE(FieldEmail, v)) -} - -// EmailLT applies the LT predicate on the "email" field. -func EmailLT(v string) predicate.User { - return predicate.User(sql.FieldLT(FieldEmail, v)) -} - -// EmailLTE applies the LTE predicate on the "email" field. -func EmailLTE(v string) predicate.User { - return predicate.User(sql.FieldLTE(FieldEmail, v)) -} - -// EmailContains applies the Contains predicate on the "email" field. -func EmailContains(v string) predicate.User { - return predicate.User(sql.FieldContains(FieldEmail, v)) -} - -// EmailHasPrefix applies the HasPrefix predicate on the "email" field. -func EmailHasPrefix(v string) predicate.User { - return predicate.User(sql.FieldHasPrefix(FieldEmail, v)) -} - -// EmailHasSuffix applies the HasSuffix predicate on the "email" field. -func EmailHasSuffix(v string) predicate.User { - return predicate.User(sql.FieldHasSuffix(FieldEmail, v)) -} - -// EmailEqualFold applies the EqualFold predicate on the "email" field. -func EmailEqualFold(v string) predicate.User { - return predicate.User(sql.FieldEqualFold(FieldEmail, v)) -} - -// EmailContainsFold applies the ContainsFold predicate on the "email" field. -func EmailContainsFold(v string) predicate.User { - return predicate.User(sql.FieldContainsFold(FieldEmail, v)) -} - -// PasswordEQ applies the EQ predicate on the "password" field. -func PasswordEQ(v string) predicate.User { - return predicate.User(sql.FieldEQ(FieldPassword, v)) -} - -// PasswordNEQ applies the NEQ predicate on the "password" field. -func PasswordNEQ(v string) predicate.User { - return predicate.User(sql.FieldNEQ(FieldPassword, v)) -} - -// PasswordIn applies the In predicate on the "password" field. -func PasswordIn(vs ...string) predicate.User { - return predicate.User(sql.FieldIn(FieldPassword, vs...)) -} - -// PasswordNotIn applies the NotIn predicate on the "password" field. -func PasswordNotIn(vs ...string) predicate.User { - return predicate.User(sql.FieldNotIn(FieldPassword, vs...)) -} - -// PasswordGT applies the GT predicate on the "password" field. -func PasswordGT(v string) predicate.User { - return predicate.User(sql.FieldGT(FieldPassword, v)) -} - -// PasswordGTE applies the GTE predicate on the "password" field. -func PasswordGTE(v string) predicate.User { - return predicate.User(sql.FieldGTE(FieldPassword, v)) -} - -// PasswordLT applies the LT predicate on the "password" field. -func PasswordLT(v string) predicate.User { - return predicate.User(sql.FieldLT(FieldPassword, v)) -} - -// PasswordLTE applies the LTE predicate on the "password" field. -func PasswordLTE(v string) predicate.User { - return predicate.User(sql.FieldLTE(FieldPassword, v)) -} - -// PasswordContains applies the Contains predicate on the "password" field. -func PasswordContains(v string) predicate.User { - return predicate.User(sql.FieldContains(FieldPassword, v)) -} - -// PasswordHasPrefix applies the HasPrefix predicate on the "password" field. -func PasswordHasPrefix(v string) predicate.User { - return predicate.User(sql.FieldHasPrefix(FieldPassword, v)) -} - -// PasswordHasSuffix applies the HasSuffix predicate on the "password" field. -func PasswordHasSuffix(v string) predicate.User { - return predicate.User(sql.FieldHasSuffix(FieldPassword, v)) -} - -// PasswordEqualFold applies the EqualFold predicate on the "password" field. -func PasswordEqualFold(v string) predicate.User { - return predicate.User(sql.FieldEqualFold(FieldPassword, v)) -} - -// PasswordContainsFold applies the ContainsFold predicate on the "password" field. -func PasswordContainsFold(v string) predicate.User { - return predicate.User(sql.FieldContainsFold(FieldPassword, v)) -} - -// HasGroup applies the HasEdge predicate on the "group" edge. -func HasGroup() predicate.User { - return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, GroupTable, GroupPrimaryKey...), - ) - sqlgraph.HasNeighbors(s, step) - }) -} - -// HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates). -func HasGroupWith(preds ...predicate.Group) predicate.User { - return predicate.User(func(s *sql.Selector) { - step := newGroupStep() - sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { - for _, p := range preds { - p(s) - } - }) - }) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.User) predicate.User { - return predicate.User(sql.AndPredicates(predicates...)) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.User) predicate.User { - return predicate.User(sql.OrPredicates(predicates...)) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.User) predicate.User { - return predicate.User(sql.NotPredicates(p)) -} diff --git a/schema/ent/example/ent/user_create.go b/schema/ent/example/ent/user_create.go deleted file mode 100644 index e3b7b8d..0000000 --- a/schema/ent/example/ent/user_create.go +++ /dev/null @@ -1,309 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/user" - "time" - - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// UserCreate is the builder for creating a User entity. -type UserCreate struct { - config - mutation *UserMutation - hooks []Hook -} - -// SetCreatedAt sets the "created_at" field. -func (_c *UserCreate) SetCreatedAt(v time.Time) *UserCreate { - _c.mutation.SetCreatedAt(v) - return _c -} - -// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. -func (_c *UserCreate) SetNillableCreatedAt(v *time.Time) *UserCreate { - if v != nil { - _c.SetCreatedAt(*v) - } - return _c -} - -// SetUpdatedAt sets the "updated_at" field. -func (_c *UserCreate) SetUpdatedAt(v time.Time) *UserCreate { - _c.mutation.SetUpdatedAt(v) - return _c -} - -// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. -func (_c *UserCreate) SetNillableUpdatedAt(v *time.Time) *UserCreate { - if v != nil { - _c.SetUpdatedAt(*v) - } - return _c -} - -// SetEmail sets the "email" field. -func (_c *UserCreate) SetEmail(v string) *UserCreate { - _c.mutation.SetEmail(v) - return _c -} - -// SetNillableEmail sets the "email" field if the given value is not nil. -func (_c *UserCreate) SetNillableEmail(v *string) *UserCreate { - if v != nil { - _c.SetEmail(*v) - } - return _c -} - -// SetPassword sets the "password" field. -func (_c *UserCreate) SetPassword(v string) *UserCreate { - _c.mutation.SetPassword(v) - return _c -} - -// SetNillablePassword sets the "password" field if the given value is not nil. -func (_c *UserCreate) SetNillablePassword(v *string) *UserCreate { - if v != nil { - _c.SetPassword(*v) - } - return _c -} - -// AddGroupIDs adds the "group" edge to the Group entity by IDs. -func (_c *UserCreate) AddGroupIDs(ids ...int) *UserCreate { - _c.mutation.AddGroupIDs(ids...) - return _c -} - -// AddGroup adds the "group" edges to the Group entity. -func (_c *UserCreate) AddGroup(v ...*Group) *UserCreate { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _c.AddGroupIDs(ids...) -} - -// Mutation returns the UserMutation object of the builder. -func (_c *UserCreate) Mutation() *UserMutation { - return _c.mutation -} - -// Save creates the User in the database. -func (_c *UserCreate) Save(ctx context.Context) (*User, error) { - _c.defaults() - return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) -} - -// SaveX calls Save and panics if Save returns an error. -func (_c *UserCreate) SaveX(ctx context.Context) *User { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *UserCreate) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *UserCreate) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_c *UserCreate) defaults() { - if _, ok := _c.mutation.CreatedAt(); !ok { - v := user.DefaultCreatedAt() - _c.mutation.SetCreatedAt(v) - } - if _, ok := _c.mutation.UpdatedAt(); !ok { - v := user.DefaultUpdatedAt() - _c.mutation.SetUpdatedAt(v) - } - if _, ok := _c.mutation.Email(); !ok { - v := user.DefaultEmail - _c.mutation.SetEmail(v) - } - if _, ok := _c.mutation.Password(); !ok { - v := user.DefaultPassword - _c.mutation.SetPassword(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_c *UserCreate) check() error { - if _, ok := _c.mutation.CreatedAt(); !ok { - return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "User.created_at"`)} - } - if _, ok := _c.mutation.UpdatedAt(); !ok { - return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "User.updated_at"`)} - } - if _, ok := _c.mutation.Email(); !ok { - return &ValidationError{Name: "email", err: errors.New(`ent: missing required field "User.email"`)} - } - if _, ok := _c.mutation.Password(); !ok { - return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "User.password"`)} - } - return nil -} - -func (_c *UserCreate) sqlSave(ctx context.Context) (*User, error) { - if err := _c.check(); err != nil { - return nil, err - } - _node, _spec := _c.createSpec() - if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - id := _spec.ID.Value.(int64) - _node.ID = int(id) - _c.mutation.id = &_node.ID - _c.mutation.done = true - return _node, nil -} - -func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { - var ( - _node = &User{config: _c.config} - _spec = sqlgraph.NewCreateSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt)) - ) - if value, ok := _c.mutation.CreatedAt(); ok { - _spec.SetField(user.FieldCreatedAt, field.TypeTime, value) - _node.CreatedAt = value - } - if value, ok := _c.mutation.UpdatedAt(); ok { - _spec.SetField(user.FieldUpdatedAt, field.TypeTime, value) - _node.UpdatedAt = value - } - if value, ok := _c.mutation.Email(); ok { - _spec.SetField(user.FieldEmail, field.TypeString, value) - _node.Email = value - } - if value, ok := _c.mutation.Password(); ok { - _spec.SetField(user.FieldPassword, field.TypeString, value) - _node.Password = value - } - if nodes := _c.mutation.GroupIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: user.GroupTable, - Columns: user.GroupPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges = append(_spec.Edges, edge) - } - return _node, _spec -} - -// UserCreateBulk is the builder for creating many User entities in bulk. -type UserCreateBulk struct { - config - err error - builders []*UserCreate -} - -// Save creates the User entities in the database. -func (_c *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { - if _c.err != nil { - return nil, _c.err - } - specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) - nodes := make([]*User, len(_c.builders)) - mutators := make([]Mutator, len(_c.builders)) - for i := range _c.builders { - func(i int, root context.Context) { - builder := _c.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*UserMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - var err error - nodes[i], specs[i] = builder.createSpec() - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) - } else { - spec := &sqlgraph.BatchCreateSpec{Nodes: specs} - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - } - } - if err != nil { - return nil, err - } - mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int(id) - } - mutation.done = true - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (_c *UserCreateBulk) SaveX(ctx context.Context) []*User { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *UserCreateBulk) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *UserCreateBulk) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/schema/ent/example/ent/user_delete.go b/schema/ent/example/ent/user_delete.go deleted file mode 100644 index 744b79a..0000000 --- a/schema/ent/example/ent/user_delete.go +++ /dev/null @@ -1,88 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/user" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// UserDelete is the builder for deleting a User entity. -type UserDelete struct { - config - hooks []Hook - mutation *UserMutation -} - -// Where appends a list predicates to the UserDelete builder. -func (_d *UserDelete) Where(ps ...predicate.User) *UserDelete { - _d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (_d *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *UserDelete) ExecX(ctx context.Context) int { - n, err := _d.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (_d *UserDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt)) - if ps := _d.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) - if err != nil && sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - _d.mutation.done = true - return affected, err -} - -// UserDeleteOne is the builder for deleting a single User entity. -type UserDeleteOne struct { - _d *UserDelete -} - -// Where appends a list predicates to the UserDelete builder. -func (_d *UserDeleteOne) Where(ps ...predicate.User) *UserDeleteOne { - _d._d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query. -func (_d *UserDeleteOne) Exec(ctx context.Context) error { - n, err := _d._d.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{user.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *UserDeleteOne) ExecX(ctx context.Context) { - if err := _d.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/schema/ent/example/ent/user_update.go b/schema/ent/example/ent/user_update.go deleted file mode 100644 index f9bfb08..0000000 --- a/schema/ent/example/ent/user_update.go +++ /dev/null @@ -1,443 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/user" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" -) - -// UserUpdate is the builder for updating User entities. -type UserUpdate struct { - config - hooks []Hook - mutation *UserMutation -} - -// Where appends a list predicates to the UserUpdate builder. -func (_u *UserUpdate) Where(ps ...predicate.User) *UserUpdate { - _u.mutation.Where(ps...) - return _u -} - -// SetUpdatedAt sets the "updated_at" field. -func (_u *UserUpdate) SetUpdatedAt(v time.Time) *UserUpdate { - _u.mutation.SetUpdatedAt(v) - return _u -} - -// SetEmail sets the "email" field. -func (_u *UserUpdate) SetEmail(v string) *UserUpdate { - _u.mutation.SetEmail(v) - return _u -} - -// SetNillableEmail sets the "email" field if the given value is not nil. -func (_u *UserUpdate) SetNillableEmail(v *string) *UserUpdate { - if v != nil { - _u.SetEmail(*v) - } - return _u -} - -// SetPassword sets the "password" field. -func (_u *UserUpdate) SetPassword(v string) *UserUpdate { - _u.mutation.SetPassword(v) - return _u -} - -// SetNillablePassword sets the "password" field if the given value is not nil. -func (_u *UserUpdate) SetNillablePassword(v *string) *UserUpdate { - if v != nil { - _u.SetPassword(*v) - } - return _u -} - -// AddGroupIDs adds the "group" edge to the Group entity by IDs. -func (_u *UserUpdate) AddGroupIDs(ids ...int) *UserUpdate { - _u.mutation.AddGroupIDs(ids...) - return _u -} - -// AddGroup adds the "group" edges to the Group entity. -func (_u *UserUpdate) AddGroup(v ...*Group) *UserUpdate { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddGroupIDs(ids...) -} - -// Mutation returns the UserMutation object of the builder. -func (_u *UserUpdate) Mutation() *UserMutation { - return _u.mutation -} - -// ClearGroup clears all "group" edges to the Group entity. -func (_u *UserUpdate) ClearGroup() *UserUpdate { - _u.mutation.ClearGroup() - return _u -} - -// RemoveGroupIDs removes the "group" edge to Group entities by IDs. -func (_u *UserUpdate) RemoveGroupIDs(ids ...int) *UserUpdate { - _u.mutation.RemoveGroupIDs(ids...) - return _u -} - -// RemoveGroup removes "group" edges to Group entities. -func (_u *UserUpdate) RemoveGroup(v ...*Group) *UserUpdate { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveGroupIDs(ids...) -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (_u *UserUpdate) Save(ctx context.Context) (int, error) { - _u.defaults() - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *UserUpdate) SaveX(ctx context.Context) int { - affected, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (_u *UserUpdate) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *UserUpdate) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_u *UserUpdate) defaults() { - if _, ok := _u.mutation.UpdatedAt(); !ok { - v := user.UpdateDefaultUpdatedAt() - _u.mutation.SetUpdatedAt(v) - } -} - -func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) { - _spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt)) - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(user.FieldUpdatedAt, field.TypeTime, value) - } - if value, ok := _u.mutation.Email(); ok { - _spec.SetField(user.FieldEmail, field.TypeString, value) - } - if value, ok := _u.mutation.Password(); ok { - _spec.SetField(user.FieldPassword, field.TypeString, value) - } - if _u.mutation.GroupCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: user.GroupTable, - Columns: user.GroupPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedGroupIDs(); len(nodes) > 0 && !_u.mutation.GroupCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: user.GroupTable, - Columns: user.GroupPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: user.GroupTable, - Columns: user.GroupPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{user.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - _u.mutation.done = true - return _node, nil -} - -// UserUpdateOne is the builder for updating a single User entity. -type UserUpdateOne struct { - config - fields []string - hooks []Hook - mutation *UserMutation -} - -// SetUpdatedAt sets the "updated_at" field. -func (_u *UserUpdateOne) SetUpdatedAt(v time.Time) *UserUpdateOne { - _u.mutation.SetUpdatedAt(v) - return _u -} - -// SetEmail sets the "email" field. -func (_u *UserUpdateOne) SetEmail(v string) *UserUpdateOne { - _u.mutation.SetEmail(v) - return _u -} - -// SetNillableEmail sets the "email" field if the given value is not nil. -func (_u *UserUpdateOne) SetNillableEmail(v *string) *UserUpdateOne { - if v != nil { - _u.SetEmail(*v) - } - return _u -} - -// SetPassword sets the "password" field. -func (_u *UserUpdateOne) SetPassword(v string) *UserUpdateOne { - _u.mutation.SetPassword(v) - return _u -} - -// SetNillablePassword sets the "password" field if the given value is not nil. -func (_u *UserUpdateOne) SetNillablePassword(v *string) *UserUpdateOne { - if v != nil { - _u.SetPassword(*v) - } - return _u -} - -// AddGroupIDs adds the "group" edge to the Group entity by IDs. -func (_u *UserUpdateOne) AddGroupIDs(ids ...int) *UserUpdateOne { - _u.mutation.AddGroupIDs(ids...) - return _u -} - -// AddGroup adds the "group" edges to the Group entity. -func (_u *UserUpdateOne) AddGroup(v ...*Group) *UserUpdateOne { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.AddGroupIDs(ids...) -} - -// Mutation returns the UserMutation object of the builder. -func (_u *UserUpdateOne) Mutation() *UserMutation { - return _u.mutation -} - -// ClearGroup clears all "group" edges to the Group entity. -func (_u *UserUpdateOne) ClearGroup() *UserUpdateOne { - _u.mutation.ClearGroup() - return _u -} - -// RemoveGroupIDs removes the "group" edge to Group entities by IDs. -func (_u *UserUpdateOne) RemoveGroupIDs(ids ...int) *UserUpdateOne { - _u.mutation.RemoveGroupIDs(ids...) - return _u -} - -// RemoveGroup removes "group" edges to Group entities. -func (_u *UserUpdateOne) RemoveGroup(v ...*Group) *UserUpdateOne { - ids := make([]int, len(v)) - for i := range v { - ids[i] = v[i].ID - } - return _u.RemoveGroupIDs(ids...) -} - -// Where appends a list predicates to the UserUpdate builder. -func (_u *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne { - _u.mutation.Where(ps...) - return _u -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (_u *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne { - _u.fields = append([]string{field}, fields...) - return _u -} - -// Save executes the query and returns the updated User entity. -func (_u *UserUpdateOne) Save(ctx context.Context) (*User, error) { - _u.defaults() - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *UserUpdateOne) SaveX(ctx context.Context) *User { - node, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (_u *UserUpdateOne) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *UserUpdateOne) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_u *UserUpdateOne) defaults() { - if _, ok := _u.mutation.UpdatedAt(); !ok { - v := user.UpdateDefaultUpdatedAt() - _u.mutation.SetUpdatedAt(v) - } -} - -func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) { - _spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt)) - id, ok := _u.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "User.id" for update`)} - } - _spec.Node.ID.Value = id - if fields := _u.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, user.FieldID) - for _, f := range fields { - if !user.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != user.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.UpdatedAt(); ok { - _spec.SetField(user.FieldUpdatedAt, field.TypeTime, value) - } - if value, ok := _u.mutation.Email(); ok { - _spec.SetField(user.FieldEmail, field.TypeString, value) - } - if value, ok := _u.mutation.Password(); ok { - _spec.SetField(user.FieldPassword, field.TypeString, value) - } - if _u.mutation.GroupCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: user.GroupTable, - Columns: user.GroupPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt), - }, - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.RemovedGroupIDs(); len(nodes) > 0 && !_u.mutation.GroupCleared() { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: user.GroupTable, - Columns: user.GroupPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Clear = append(_spec.Edges.Clear, edge) - } - if nodes := _u.mutation.GroupIDs(); len(nodes) > 0 { - edge := &sqlgraph.EdgeSpec{ - Rel: sqlgraph.M2M, - Inverse: false, - Table: user.GroupTable, - Columns: user.GroupPrimaryKey, - Bidi: false, - Target: &sqlgraph.EdgeTarget{ - IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt), - }, - } - for _, k := range nodes { - edge.Target.Nodes = append(edge.Target.Nodes, k) - } - _spec.Edges.Add = append(_spec.Edges.Add, edge) - } - _node = &User{config: _u.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{user.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - _u.mutation.done = true - return _node, nil -} diff --git a/schema/ent/example/generate_schema.go b/schema/ent/example/generate_schema.go deleted file mode 100644 index 006bb1a..0000000 --- a/schema/ent/example/generate_schema.go +++ /dev/null @@ -1,28 +0,0 @@ -package main - -import ( - "log" - - "entgo.io/ent/entc" - "entgo.io/ent/entc/gen" -) - -func main() { - log.Println("ersteller start") - // Parse our custom pagination template (per-entity Query methods). - paginationPath := "schema/ent/pagination_query.tmpl" - //paginationTmpl := gen.MustParse(gen.NewTemplate("pagination_query"). - // ParseFiles(paginationPath)) - - must(entc.Generate( - "./schema/ent/example/ent/schema", - &gen.Config{}, - entc.TemplateFiles(paginationPath), - )) -} - -func must(err error) { - if err != nil { - log.Fatal(err) - } -} diff --git a/schema/ent/example/start.go b/schema/ent/example/start.go deleted file mode 100644 index bf5e8de..0000000 --- a/schema/ent/example/start.go +++ /dev/null @@ -1,143 +0,0 @@ -package main - -import ( - "context" - "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/todo" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/user" - "log" - "time" - - _ "github.com/mattn/go-sqlite3" -) - -func main() { - //client, err := ent.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") - client, err := ent.Open("sqlite3", "/tmp/ersteller_ent_example.db?_fk=1", - ent.Log(log.Println), ent.Debug()) - if err != nil { - log.Fatalf("failed opening connection to sqlite: %v", err) - } - log.Println("client", client) - defer client.Close() - - // Add authorization interceptor for Todo queries - client.Todo.Intercept(TodoAuthorizationInterceptor()) - - ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5) - defer cancel() - - if err := client.Schema.Create(ctx); err != nil { - log.Fatalf("failed creating schema resources: %v", err) - } - - testGroup, err := client.Group.Create().SetName("Test").Save(ctx) - if err != nil { - log.Fatalf("failed creating group: %w", err) - } - u, err := client.User. - Create(). - SetEmail("something@gorlug.de"). - SetPassword("uhoh"). - AddGroup(testGroup). - Save(ctx) - if err != nil { - log.Fatalf("failed creating user: %w", err) - } - log.Println("user was created: ", u) - - //time.Sleep(time.Second * 1) - //u, err = client.User.UpdateOneID(u.ID).SetPassword("wtf").Save(ctx) - //if err != nil { - // log.Fatalf("failed updating user: %w", err) - //}j - //log.Println("user was updated", u) - query := client.User.Query() - users, nextId, hasNext, err := query.PaginateAfterID(ctx, 0, 2) - if err != nil { - log.Fatalf("failed listing users: %w", err) - } - if hasNext { - log.Println("next id", nextId) - for _, u := range users { - log.Println("user", u.ID, u.Email, u.Password) - } - } - users, nextId, hasNext, err = query.PaginateAfterID(ctx, nextId, 2) - if err != nil { - log.Fatalf("failed listing users: %w", err) - } - if hasNext { - log.Println("2 next id", nextId) - for _, u := range users { - log.Println("2 user", u.ID, u.Email, u.Password) - } - } - - todoItem, err := client.Todo.Create().SetTitle("test"). - SetGroup(testGroup).Save(ctx) - if err != nil { - log.Fatalf("failed to create todo", err) - } - - // Add user ID to context for authorization - authorizedCtx := context.WithValue(ctx, UserIDKey, u.ID) - - // This should work - user is in the group - retrievedTodo, err := client.Todo.Get(authorizedCtx, todoItem.ID) - if err != nil { - log.Fatalf("failed getting todo with authorization: %v", err) - } - log.Println("retrieved todo:", retrievedTodo) - - // This should fail - no user ID in context - _, err = client.Todo.Get(ctx, todoItem.ID) - if err != nil { - log.Println("expected authorization error:", err) - } - - secondGroup, err := client.Group.Create().SetName("second").Save(ctx) - if err != nil { - log.Fatalf("failed creating group: %w", err) - } - secondUser, err := client.User.Create().SetEmail("abc@def.de").AddGroup(secondGroup).Save(ctx) - if err != nil { - log.Fatalf("failed creating user: %w", err) - } - - // Add user ID to context for authorization - secondUserAuthorizedCtx := context.WithValue(ctx, UserIDKey, secondUser.ID) - _, err = client.Todo.Get(secondUserAuthorizedCtx, todoItem.ID) - if err != nil { - log.Println("expected authorization error:", err) - } -} - -// UserIDKey is used to store user ID in context -type contextKey string - -const UserIDKey = contextKey("userID") - -// TodoAuthorizationInterceptor returns an interceptor that enforces user authorization for todos -func TodoAuthorizationInterceptor() ent.Interceptor { - return ent.InterceptFunc(func(next ent.Querier) ent.Querier { - return ent.QuerierFunc(func(ctx context.Context, query ent.Query) (ent.Value, error) { - // Get user ID from context - userID, ok := ctx.Value(UserIDKey).(int) - if !ok { - return nil, fmt.Errorf("user ID is required in context for todo operations") - } - - // Cast to TodoQuery to add authorization filter - if tq, ok := query.(*ent.TodoQuery); ok { - // Add predicate to ensure user is in the same group as the todo - tq = tq.Where(todo.HasGroupWith(group.HasUsersWith(user.ID(userID)))) - return next.Query(ctx, tq) - } - - return next.Query(ctx, query) - }) - }) -} diff --git a/schema/ent/generalqueue.go b/schema/ent/generalqueue.go new file mode 100644 index 0000000..8324c49 --- /dev/null +++ b/schema/ent/generalqueue.go @@ -0,0 +1,225 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "encoding/json" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "git.gorlug.de/code/ersteller/schema/ent/generalqueue" +) + +// GeneralQueue is the model entity for the GeneralQueue schema. +type GeneralQueue struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // Name holds the value of the "name" field. + Name string `json:"name,omitempty"` + // Payload holds the value of the "payload" field. + Payload map[string]interface{} `json:"payload,omitempty"` + // Status holds the value of the "status" field. + Status generalqueue.Status `json:"status,omitempty"` + // NumberOfTries holds the value of the "number_of_tries" field. + NumberOfTries int `json:"number_of_tries,omitempty"` + // MaxRetries holds the value of the "max_retries" field. + MaxRetries int `json:"max_retries,omitempty"` + // ErrorMessage holds the value of the "error_message" field. + ErrorMessage string `json:"error_message,omitempty"` + // FailurePayload holds the value of the "failure_payload" field. + FailurePayload map[string]interface{} `json:"failure_payload,omitempty"` + // ResultPayload holds the value of the "result_payload" field. + ResultPayload map[string]interface{} `json:"result_payload,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt time.Time `json:"updated_at,omitempty"` + // ProcessedAt holds the value of the "processed_at" field. + ProcessedAt time.Time `json:"processed_at,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*GeneralQueue) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case generalqueue.FieldPayload, generalqueue.FieldFailurePayload, generalqueue.FieldResultPayload: + values[i] = new([]byte) + case generalqueue.FieldID, generalqueue.FieldNumberOfTries, generalqueue.FieldMaxRetries: + values[i] = new(sql.NullInt64) + case generalqueue.FieldName, generalqueue.FieldStatus, generalqueue.FieldErrorMessage: + values[i] = new(sql.NullString) + case generalqueue.FieldCreatedAt, generalqueue.FieldUpdatedAt, generalqueue.FieldProcessedAt: + values[i] = new(sql.NullTime) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the GeneralQueue fields. +func (_m *GeneralQueue) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case generalqueue.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + _m.ID = int(value.Int64) + case generalqueue.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + _m.Name = value.String + } + case generalqueue.FieldPayload: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field payload", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.Payload); err != nil { + return fmt.Errorf("unmarshal field payload: %w", err) + } + } + case generalqueue.FieldStatus: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field status", values[i]) + } else if value.Valid { + _m.Status = generalqueue.Status(value.String) + } + case generalqueue.FieldNumberOfTries: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field number_of_tries", values[i]) + } else if value.Valid { + _m.NumberOfTries = int(value.Int64) + } + case generalqueue.FieldMaxRetries: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field max_retries", values[i]) + } else if value.Valid { + _m.MaxRetries = int(value.Int64) + } + case generalqueue.FieldErrorMessage: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field error_message", values[i]) + } else if value.Valid { + _m.ErrorMessage = value.String + } + case generalqueue.FieldFailurePayload: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field failure_payload", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.FailurePayload); err != nil { + return fmt.Errorf("unmarshal field failure_payload: %w", err) + } + } + case generalqueue.FieldResultPayload: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field result_payload", values[i]) + } else if value != nil && len(*value) > 0 { + if err := json.Unmarshal(*value, &_m.ResultPayload); err != nil { + return fmt.Errorf("unmarshal field result_payload: %w", err) + } + } + case generalqueue.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + case generalqueue.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + _m.UpdatedAt = value.Time + } + case generalqueue.FieldProcessedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field processed_at", values[i]) + } else if value.Valid { + _m.ProcessedAt = value.Time + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the GeneralQueue. +// This includes values selected through modifiers, order, etc. +func (_m *GeneralQueue) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this GeneralQueue. +// Note that you need to call GeneralQueue.Unwrap() before calling this method if this GeneralQueue +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *GeneralQueue) Update() *GeneralQueueUpdateOne { + return NewGeneralQueueClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the GeneralQueue entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *GeneralQueue) Unwrap() *GeneralQueue { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: GeneralQueue is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *GeneralQueue) String() string { + var builder strings.Builder + builder.WriteString("GeneralQueue(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("name=") + builder.WriteString(_m.Name) + builder.WriteString(", ") + builder.WriteString("payload=") + builder.WriteString(fmt.Sprintf("%v", _m.Payload)) + builder.WriteString(", ") + builder.WriteString("status=") + builder.WriteString(fmt.Sprintf("%v", _m.Status)) + builder.WriteString(", ") + builder.WriteString("number_of_tries=") + builder.WriteString(fmt.Sprintf("%v", _m.NumberOfTries)) + builder.WriteString(", ") + builder.WriteString("max_retries=") + builder.WriteString(fmt.Sprintf("%v", _m.MaxRetries)) + builder.WriteString(", ") + builder.WriteString("error_message=") + builder.WriteString(_m.ErrorMessage) + builder.WriteString(", ") + builder.WriteString("failure_payload=") + builder.WriteString(fmt.Sprintf("%v", _m.FailurePayload)) + builder.WriteString(", ") + builder.WriteString("result_payload=") + builder.WriteString(fmt.Sprintf("%v", _m.ResultPayload)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) + builder.WriteString(", ") + builder.WriteString("processed_at=") + builder.WriteString(_m.ProcessedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// GeneralQueues is a parsable slice of GeneralQueue. +type GeneralQueues []*GeneralQueue diff --git a/schema/ent/generalqueue/generalqueue.go b/schema/ent/generalqueue/generalqueue.go new file mode 100644 index 0000000..c782745 --- /dev/null +++ b/schema/ent/generalqueue/generalqueue.go @@ -0,0 +1,146 @@ +// Code generated by ent, DO NOT EDIT. + +package generalqueue + +import ( + "fmt" + + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the generalqueue type in the database. + Label = "general_queue" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldPayload holds the string denoting the payload field in the database. + FieldPayload = "payload" + // FieldStatus holds the string denoting the status field in the database. + FieldStatus = "status" + // FieldNumberOfTries holds the string denoting the number_of_tries field in the database. + FieldNumberOfTries = "number_of_tries" + // FieldMaxRetries holds the string denoting the max_retries field in the database. + FieldMaxRetries = "max_retries" + // FieldErrorMessage holds the string denoting the error_message field in the database. + FieldErrorMessage = "error_message" + // FieldFailurePayload holds the string denoting the failure_payload field in the database. + FieldFailurePayload = "failure_payload" + // FieldResultPayload holds the string denoting the result_payload field in the database. + FieldResultPayload = "result_payload" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // FieldProcessedAt holds the string denoting the processed_at field in the database. + FieldProcessedAt = "processed_at" + // Table holds the table name of the generalqueue in the database. + Table = "generalQueue" +) + +// Columns holds all SQL columns for generalqueue fields. +var Columns = []string{ + FieldID, + FieldName, + FieldPayload, + FieldStatus, + FieldNumberOfTries, + FieldMaxRetries, + FieldErrorMessage, + FieldFailurePayload, + FieldResultPayload, + FieldCreatedAt, + FieldUpdatedAt, + FieldProcessedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultNumberOfTries holds the default value on creation for the "number_of_tries" field. + DefaultNumberOfTries int + // DefaultMaxRetries holds the default value on creation for the "max_retries" field. + DefaultMaxRetries int +) + +// Status defines the type for the "status" enum field. +type Status string + +// Status values. +const ( + StatusPending Status = "pending" + StatusInProgress Status = "in_progress" + StatusCompleted Status = "completed" + StatusFailed Status = "failed" +) + +func (s Status) String() string { + return string(s) +} + +// StatusValidator is a validator for the "status" field enum values. It is called by the builders before save. +func StatusValidator(s Status) error { + switch s { + case StatusPending, StatusInProgress, StatusCompleted, StatusFailed: + return nil + default: + return fmt.Errorf("generalqueue: invalid enum value for status field: %q", s) + } +} + +// OrderOption defines the ordering options for the GeneralQueue queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByStatus orders the results by the status field. +func ByStatus(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStatus, opts...).ToFunc() +} + +// ByNumberOfTries orders the results by the number_of_tries field. +func ByNumberOfTries(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldNumberOfTries, opts...).ToFunc() +} + +// ByMaxRetries orders the results by the max_retries field. +func ByMaxRetries(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldMaxRetries, opts...).ToFunc() +} + +// ByErrorMessage orders the results by the error_message field. +func ByErrorMessage(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldErrorMessage, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByProcessedAt orders the results by the processed_at field. +func ByProcessedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldProcessedAt, opts...).ToFunc() +} diff --git a/schema/ent/generalqueue/where.go b/schema/ent/generalqueue/where.go new file mode 100644 index 0000000..832d45b --- /dev/null +++ b/schema/ent/generalqueue/where.go @@ -0,0 +1,495 @@ +// Code generated by ent, DO NOT EDIT. + +package generalqueue + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "git.gorlug.de/code/ersteller/schema/ent/predicate" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLTE(FieldID, id)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldName, v)) +} + +// NumberOfTries applies equality check predicate on the "number_of_tries" field. It's identical to NumberOfTriesEQ. +func NumberOfTries(v int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldNumberOfTries, v)) +} + +// MaxRetries applies equality check predicate on the "max_retries" field. It's identical to MaxRetriesEQ. +func MaxRetries(v int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldMaxRetries, v)) +} + +// ErrorMessage applies equality check predicate on the "error_message" field. It's identical to ErrorMessageEQ. +func ErrorMessage(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldErrorMessage, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// ProcessedAt applies equality check predicate on the "processed_at" field. It's identical to ProcessedAtEQ. +func ProcessedAt(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldProcessedAt, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldContainsFold(FieldName, v)) +} + +// StatusEQ applies the EQ predicate on the "status" field. +func StatusEQ(v Status) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldStatus, v)) +} + +// StatusNEQ applies the NEQ predicate on the "status" field. +func StatusNEQ(v Status) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNEQ(FieldStatus, v)) +} + +// StatusIn applies the In predicate on the "status" field. +func StatusIn(vs ...Status) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldIn(FieldStatus, vs...)) +} + +// StatusNotIn applies the NotIn predicate on the "status" field. +func StatusNotIn(vs ...Status) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNotIn(FieldStatus, vs...)) +} + +// NumberOfTriesEQ applies the EQ predicate on the "number_of_tries" field. +func NumberOfTriesEQ(v int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldNumberOfTries, v)) +} + +// NumberOfTriesNEQ applies the NEQ predicate on the "number_of_tries" field. +func NumberOfTriesNEQ(v int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNEQ(FieldNumberOfTries, v)) +} + +// NumberOfTriesIn applies the In predicate on the "number_of_tries" field. +func NumberOfTriesIn(vs ...int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldIn(FieldNumberOfTries, vs...)) +} + +// NumberOfTriesNotIn applies the NotIn predicate on the "number_of_tries" field. +func NumberOfTriesNotIn(vs ...int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNotIn(FieldNumberOfTries, vs...)) +} + +// NumberOfTriesGT applies the GT predicate on the "number_of_tries" field. +func NumberOfTriesGT(v int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGT(FieldNumberOfTries, v)) +} + +// NumberOfTriesGTE applies the GTE predicate on the "number_of_tries" field. +func NumberOfTriesGTE(v int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGTE(FieldNumberOfTries, v)) +} + +// NumberOfTriesLT applies the LT predicate on the "number_of_tries" field. +func NumberOfTriesLT(v int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLT(FieldNumberOfTries, v)) +} + +// NumberOfTriesLTE applies the LTE predicate on the "number_of_tries" field. +func NumberOfTriesLTE(v int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLTE(FieldNumberOfTries, v)) +} + +// MaxRetriesEQ applies the EQ predicate on the "max_retries" field. +func MaxRetriesEQ(v int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldMaxRetries, v)) +} + +// MaxRetriesNEQ applies the NEQ predicate on the "max_retries" field. +func MaxRetriesNEQ(v int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNEQ(FieldMaxRetries, v)) +} + +// MaxRetriesIn applies the In predicate on the "max_retries" field. +func MaxRetriesIn(vs ...int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldIn(FieldMaxRetries, vs...)) +} + +// MaxRetriesNotIn applies the NotIn predicate on the "max_retries" field. +func MaxRetriesNotIn(vs ...int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNotIn(FieldMaxRetries, vs...)) +} + +// MaxRetriesGT applies the GT predicate on the "max_retries" field. +func MaxRetriesGT(v int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGT(FieldMaxRetries, v)) +} + +// MaxRetriesGTE applies the GTE predicate on the "max_retries" field. +func MaxRetriesGTE(v int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGTE(FieldMaxRetries, v)) +} + +// MaxRetriesLT applies the LT predicate on the "max_retries" field. +func MaxRetriesLT(v int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLT(FieldMaxRetries, v)) +} + +// MaxRetriesLTE applies the LTE predicate on the "max_retries" field. +func MaxRetriesLTE(v int) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLTE(FieldMaxRetries, v)) +} + +// ErrorMessageEQ applies the EQ predicate on the "error_message" field. +func ErrorMessageEQ(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldErrorMessage, v)) +} + +// ErrorMessageNEQ applies the NEQ predicate on the "error_message" field. +func ErrorMessageNEQ(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNEQ(FieldErrorMessage, v)) +} + +// ErrorMessageIn applies the In predicate on the "error_message" field. +func ErrorMessageIn(vs ...string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldIn(FieldErrorMessage, vs...)) +} + +// ErrorMessageNotIn applies the NotIn predicate on the "error_message" field. +func ErrorMessageNotIn(vs ...string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNotIn(FieldErrorMessage, vs...)) +} + +// ErrorMessageGT applies the GT predicate on the "error_message" field. +func ErrorMessageGT(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGT(FieldErrorMessage, v)) +} + +// ErrorMessageGTE applies the GTE predicate on the "error_message" field. +func ErrorMessageGTE(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGTE(FieldErrorMessage, v)) +} + +// ErrorMessageLT applies the LT predicate on the "error_message" field. +func ErrorMessageLT(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLT(FieldErrorMessage, v)) +} + +// ErrorMessageLTE applies the LTE predicate on the "error_message" field. +func ErrorMessageLTE(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLTE(FieldErrorMessage, v)) +} + +// ErrorMessageContains applies the Contains predicate on the "error_message" field. +func ErrorMessageContains(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldContains(FieldErrorMessage, v)) +} + +// ErrorMessageHasPrefix applies the HasPrefix predicate on the "error_message" field. +func ErrorMessageHasPrefix(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldHasPrefix(FieldErrorMessage, v)) +} + +// ErrorMessageHasSuffix applies the HasSuffix predicate on the "error_message" field. +func ErrorMessageHasSuffix(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldHasSuffix(FieldErrorMessage, v)) +} + +// ErrorMessageIsNil applies the IsNil predicate on the "error_message" field. +func ErrorMessageIsNil() predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldIsNull(FieldErrorMessage)) +} + +// ErrorMessageNotNil applies the NotNil predicate on the "error_message" field. +func ErrorMessageNotNil() predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNotNull(FieldErrorMessage)) +} + +// ErrorMessageEqualFold applies the EqualFold predicate on the "error_message" field. +func ErrorMessageEqualFold(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEqualFold(FieldErrorMessage, v)) +} + +// ErrorMessageContainsFold applies the ContainsFold predicate on the "error_message" field. +func ErrorMessageContainsFold(v string) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldContainsFold(FieldErrorMessage, v)) +} + +// FailurePayloadIsNil applies the IsNil predicate on the "failure_payload" field. +func FailurePayloadIsNil() predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldIsNull(FieldFailurePayload)) +} + +// FailurePayloadNotNil applies the NotNil predicate on the "failure_payload" field. +func FailurePayloadNotNil() predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNotNull(FieldFailurePayload)) +} + +// ResultPayloadIsNil applies the IsNil predicate on the "result_payload" field. +func ResultPayloadIsNil() predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldIsNull(FieldResultPayload)) +} + +// ResultPayloadNotNil applies the NotNil predicate on the "result_payload" field. +func ResultPayloadNotNil() predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNotNull(FieldResultPayload)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// ProcessedAtEQ applies the EQ predicate on the "processed_at" field. +func ProcessedAtEQ(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldEQ(FieldProcessedAt, v)) +} + +// ProcessedAtNEQ applies the NEQ predicate on the "processed_at" field. +func ProcessedAtNEQ(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNEQ(FieldProcessedAt, v)) +} + +// ProcessedAtIn applies the In predicate on the "processed_at" field. +func ProcessedAtIn(vs ...time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldIn(FieldProcessedAt, vs...)) +} + +// ProcessedAtNotIn applies the NotIn predicate on the "processed_at" field. +func ProcessedAtNotIn(vs ...time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNotIn(FieldProcessedAt, vs...)) +} + +// ProcessedAtGT applies the GT predicate on the "processed_at" field. +func ProcessedAtGT(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGT(FieldProcessedAt, v)) +} + +// ProcessedAtGTE applies the GTE predicate on the "processed_at" field. +func ProcessedAtGTE(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldGTE(FieldProcessedAt, v)) +} + +// ProcessedAtLT applies the LT predicate on the "processed_at" field. +func ProcessedAtLT(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLT(FieldProcessedAt, v)) +} + +// ProcessedAtLTE applies the LTE predicate on the "processed_at" field. +func ProcessedAtLTE(v time.Time) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldLTE(FieldProcessedAt, v)) +} + +// ProcessedAtIsNil applies the IsNil predicate on the "processed_at" field. +func ProcessedAtIsNil() predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldIsNull(FieldProcessedAt)) +} + +// ProcessedAtNotNil applies the NotNil predicate on the "processed_at" field. +func ProcessedAtNotNil() predicate.GeneralQueue { + return predicate.GeneralQueue(sql.FieldNotNull(FieldProcessedAt)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.GeneralQueue) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.GeneralQueue) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.GeneralQueue) predicate.GeneralQueue { + return predicate.GeneralQueue(sql.NotPredicates(p)) +} diff --git a/schema/ent/generalqueue_create.go b/schema/ent/generalqueue_create.go new file mode 100644 index 0000000..847496b --- /dev/null +++ b/schema/ent/generalqueue_create.go @@ -0,0 +1,353 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "git.gorlug.de/code/ersteller/schema/ent/generalqueue" +) + +// GeneralQueueCreate is the builder for creating a GeneralQueue entity. +type GeneralQueueCreate struct { + config + mutation *GeneralQueueMutation + hooks []Hook +} + +// SetName sets the "name" field. +func (_c *GeneralQueueCreate) SetName(v string) *GeneralQueueCreate { + _c.mutation.SetName(v) + return _c +} + +// SetPayload sets the "payload" field. +func (_c *GeneralQueueCreate) SetPayload(v map[string]interface{}) *GeneralQueueCreate { + _c.mutation.SetPayload(v) + return _c +} + +// SetStatus sets the "status" field. +func (_c *GeneralQueueCreate) SetStatus(v generalqueue.Status) *GeneralQueueCreate { + _c.mutation.SetStatus(v) + return _c +} + +// SetNumberOfTries sets the "number_of_tries" field. +func (_c *GeneralQueueCreate) SetNumberOfTries(v int) *GeneralQueueCreate { + _c.mutation.SetNumberOfTries(v) + return _c +} + +// SetNillableNumberOfTries sets the "number_of_tries" field if the given value is not nil. +func (_c *GeneralQueueCreate) SetNillableNumberOfTries(v *int) *GeneralQueueCreate { + if v != nil { + _c.SetNumberOfTries(*v) + } + return _c +} + +// SetMaxRetries sets the "max_retries" field. +func (_c *GeneralQueueCreate) SetMaxRetries(v int) *GeneralQueueCreate { + _c.mutation.SetMaxRetries(v) + return _c +} + +// SetNillableMaxRetries sets the "max_retries" field if the given value is not nil. +func (_c *GeneralQueueCreate) SetNillableMaxRetries(v *int) *GeneralQueueCreate { + if v != nil { + _c.SetMaxRetries(*v) + } + return _c +} + +// SetErrorMessage sets the "error_message" field. +func (_c *GeneralQueueCreate) SetErrorMessage(v string) *GeneralQueueCreate { + _c.mutation.SetErrorMessage(v) + return _c +} + +// SetNillableErrorMessage sets the "error_message" field if the given value is not nil. +func (_c *GeneralQueueCreate) SetNillableErrorMessage(v *string) *GeneralQueueCreate { + if v != nil { + _c.SetErrorMessage(*v) + } + return _c +} + +// SetFailurePayload sets the "failure_payload" field. +func (_c *GeneralQueueCreate) SetFailurePayload(v map[string]interface{}) *GeneralQueueCreate { + _c.mutation.SetFailurePayload(v) + return _c +} + +// SetResultPayload sets the "result_payload" field. +func (_c *GeneralQueueCreate) SetResultPayload(v map[string]interface{}) *GeneralQueueCreate { + _c.mutation.SetResultPayload(v) + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *GeneralQueueCreate) SetCreatedAt(v time.Time) *GeneralQueueCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *GeneralQueueCreate) SetUpdatedAt(v time.Time) *GeneralQueueCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// SetProcessedAt sets the "processed_at" field. +func (_c *GeneralQueueCreate) SetProcessedAt(v time.Time) *GeneralQueueCreate { + _c.mutation.SetProcessedAt(v) + return _c +} + +// SetNillableProcessedAt sets the "processed_at" field if the given value is not nil. +func (_c *GeneralQueueCreate) SetNillableProcessedAt(v *time.Time) *GeneralQueueCreate { + if v != nil { + _c.SetProcessedAt(*v) + } + return _c +} + +// Mutation returns the GeneralQueueMutation object of the builder. +func (_c *GeneralQueueCreate) Mutation() *GeneralQueueMutation { + return _c.mutation +} + +// Save creates the GeneralQueue in the database. +func (_c *GeneralQueueCreate) Save(ctx context.Context) (*GeneralQueue, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *GeneralQueueCreate) SaveX(ctx context.Context) *GeneralQueue { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *GeneralQueueCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *GeneralQueueCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *GeneralQueueCreate) defaults() { + if _, ok := _c.mutation.NumberOfTries(); !ok { + v := generalqueue.DefaultNumberOfTries + _c.mutation.SetNumberOfTries(v) + } + if _, ok := _c.mutation.MaxRetries(); !ok { + v := generalqueue.DefaultMaxRetries + _c.mutation.SetMaxRetries(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *GeneralQueueCreate) check() error { + if _, ok := _c.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "GeneralQueue.name"`)} + } + if _, ok := _c.mutation.Payload(); !ok { + return &ValidationError{Name: "payload", err: errors.New(`ent: missing required field "GeneralQueue.payload"`)} + } + if _, ok := _c.mutation.Status(); !ok { + return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "GeneralQueue.status"`)} + } + if v, ok := _c.mutation.Status(); ok { + if err := generalqueue.StatusValidator(v); err != nil { + return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "GeneralQueue.status": %w`, err)} + } + } + if _, ok := _c.mutation.NumberOfTries(); !ok { + return &ValidationError{Name: "number_of_tries", err: errors.New(`ent: missing required field "GeneralQueue.number_of_tries"`)} + } + if _, ok := _c.mutation.MaxRetries(); !ok { + return &ValidationError{Name: "max_retries", err: errors.New(`ent: missing required field "GeneralQueue.max_retries"`)} + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "GeneralQueue.created_at"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "GeneralQueue.updated_at"`)} + } + return nil +} + +func (_c *GeneralQueueCreate) sqlSave(ctx context.Context) (*GeneralQueue, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + id := _spec.ID.Value.(int64) + _node.ID = int(id) + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *GeneralQueueCreate) createSpec() (*GeneralQueue, *sqlgraph.CreateSpec) { + var ( + _node = &GeneralQueue{config: _c.config} + _spec = sqlgraph.NewCreateSpec(generalqueue.Table, sqlgraph.NewFieldSpec(generalqueue.FieldID, field.TypeInt)) + ) + if value, ok := _c.mutation.Name(); ok { + _spec.SetField(generalqueue.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := _c.mutation.Payload(); ok { + _spec.SetField(generalqueue.FieldPayload, field.TypeJSON, value) + _node.Payload = value + } + if value, ok := _c.mutation.Status(); ok { + _spec.SetField(generalqueue.FieldStatus, field.TypeEnum, value) + _node.Status = value + } + if value, ok := _c.mutation.NumberOfTries(); ok { + _spec.SetField(generalqueue.FieldNumberOfTries, field.TypeInt, value) + _node.NumberOfTries = value + } + if value, ok := _c.mutation.MaxRetries(); ok { + _spec.SetField(generalqueue.FieldMaxRetries, field.TypeInt, value) + _node.MaxRetries = value + } + if value, ok := _c.mutation.ErrorMessage(); ok { + _spec.SetField(generalqueue.FieldErrorMessage, field.TypeString, value) + _node.ErrorMessage = value + } + if value, ok := _c.mutation.FailurePayload(); ok { + _spec.SetField(generalqueue.FieldFailurePayload, field.TypeJSON, value) + _node.FailurePayload = value + } + if value, ok := _c.mutation.ResultPayload(); ok { + _spec.SetField(generalqueue.FieldResultPayload, field.TypeJSON, value) + _node.ResultPayload = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(generalqueue.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(generalqueue.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + if value, ok := _c.mutation.ProcessedAt(); ok { + _spec.SetField(generalqueue.FieldProcessedAt, field.TypeTime, value) + _node.ProcessedAt = value + } + return _node, _spec +} + +// GeneralQueueCreateBulk is the builder for creating many GeneralQueue entities in bulk. +type GeneralQueueCreateBulk struct { + config + err error + builders []*GeneralQueueCreate +} + +// Save creates the GeneralQueue entities in the database. +func (_c *GeneralQueueCreateBulk) Save(ctx context.Context) ([]*GeneralQueue, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*GeneralQueue, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*GeneralQueueMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + if specs[i].ID.Value != nil { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int(id) + } + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *GeneralQueueCreateBulk) SaveX(ctx context.Context) []*GeneralQueue { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *GeneralQueueCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *GeneralQueueCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/schema/ent/generalqueue_delete.go b/schema/ent/generalqueue_delete.go new file mode 100644 index 0000000..79adc5c --- /dev/null +++ b/schema/ent/generalqueue_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "git.gorlug.de/code/ersteller/schema/ent/generalqueue" + "git.gorlug.de/code/ersteller/schema/ent/predicate" +) + +// GeneralQueueDelete is the builder for deleting a GeneralQueue entity. +type GeneralQueueDelete struct { + config + hooks []Hook + mutation *GeneralQueueMutation +} + +// Where appends a list predicates to the GeneralQueueDelete builder. +func (_d *GeneralQueueDelete) Where(ps ...predicate.GeneralQueue) *GeneralQueueDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *GeneralQueueDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *GeneralQueueDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *GeneralQueueDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(generalqueue.Table, sqlgraph.NewFieldSpec(generalqueue.FieldID, field.TypeInt)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// GeneralQueueDeleteOne is the builder for deleting a single GeneralQueue entity. +type GeneralQueueDeleteOne struct { + _d *GeneralQueueDelete +} + +// Where appends a list predicates to the GeneralQueueDelete builder. +func (_d *GeneralQueueDeleteOne) Where(ps ...predicate.GeneralQueue) *GeneralQueueDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *GeneralQueueDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{generalqueue.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *GeneralQueueDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/schema/ent/example/ent/todo_query.go b/schema/ent/generalqueue_query.go similarity index 54% rename from schema/ent/example/ent/todo_query.go rename to schema/ent/generalqueue_query.go index d67887f..958e0e2 100644 --- a/schema/ent/example/ent/todo_query.go +++ b/schema/ent/generalqueue_query.go @@ -5,99 +5,74 @@ package ent import ( "context" "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/todo" "math" "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.gorlug.de/code/ersteller/schema/ent/generalqueue" + "git.gorlug.de/code/ersteller/schema/ent/predicate" ) -// TodoQuery is the builder for querying Todo entities. -type TodoQuery struct { +// GeneralQueueQuery is the builder for querying GeneralQueue entities. +type GeneralQueueQuery struct { config ctx *QueryContext - order []todo.OrderOption + order []generalqueue.OrderOption inters []Interceptor - predicates []predicate.Todo - withGroup *GroupQuery - withFKs bool + predicates []predicate.GeneralQueue // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) } -// Where adds a new predicate for the TodoQuery builder. -func (_q *TodoQuery) Where(ps ...predicate.Todo) *TodoQuery { +// Where adds a new predicate for the GeneralQueueQuery builder. +func (_q *GeneralQueueQuery) Where(ps ...predicate.GeneralQueue) *GeneralQueueQuery { _q.predicates = append(_q.predicates, ps...) return _q } // Limit the number of records to be returned by this query. -func (_q *TodoQuery) Limit(limit int) *TodoQuery { +func (_q *GeneralQueueQuery) Limit(limit int) *GeneralQueueQuery { _q.ctx.Limit = &limit return _q } // Offset to start from. -func (_q *TodoQuery) Offset(offset int) *TodoQuery { +func (_q *GeneralQueueQuery) Offset(offset int) *GeneralQueueQuery { _q.ctx.Offset = &offset return _q } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. -func (_q *TodoQuery) Unique(unique bool) *TodoQuery { +func (_q *GeneralQueueQuery) Unique(unique bool) *GeneralQueueQuery { _q.ctx.Unique = &unique return _q } // Order specifies how the records should be ordered. -func (_q *TodoQuery) Order(o ...todo.OrderOption) *TodoQuery { +func (_q *GeneralQueueQuery) Order(o ...generalqueue.OrderOption) *GeneralQueueQuery { _q.order = append(_q.order, o...) return _q } -// QueryGroup chains the current query on the "group" edge. -func (_q *TodoQuery) QueryGroup() *GroupQuery { - query := (&GroupClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(todo.Table, todo.FieldID, selector), - sqlgraph.To(group.Table, group.FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, todo.GroupTable, todo.GroupColumn), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// First returns the first Todo entity from the query. -// Returns a *NotFoundError when no Todo was found. -func (_q *TodoQuery) First(ctx context.Context) (*Todo, error) { +// First returns the first GeneralQueue entity from the query. +// Returns a *NotFoundError when no GeneralQueue was found. +func (_q *GeneralQueueQuery) First(ctx context.Context) (*GeneralQueue, error) { nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } if len(nodes) == 0 { - return nil, &NotFoundError{todo.Label} + return nil, &NotFoundError{generalqueue.Label} } return nodes[0], nil } // FirstX is like First, but panics if an error occurs. -func (_q *TodoQuery) FirstX(ctx context.Context) *Todo { +func (_q *GeneralQueueQuery) FirstX(ctx context.Context) *GeneralQueue { node, err := _q.First(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -105,22 +80,22 @@ func (_q *TodoQuery) FirstX(ctx context.Context) *Todo { return node } -// FirstID returns the first Todo ID from the query. -// Returns a *NotFoundError when no Todo ID was found. -func (_q *TodoQuery) FirstID(ctx context.Context) (id int, err error) { +// FirstID returns the first GeneralQueue ID from the query. +// Returns a *NotFoundError when no GeneralQueue ID was found. +func (_q *GeneralQueueQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { - err = &NotFoundError{todo.Label} + err = &NotFoundError{generalqueue.Label} return } return ids[0], nil } // FirstIDX is like FirstID, but panics if an error occurs. -func (_q *TodoQuery) FirstIDX(ctx context.Context) int { +func (_q *GeneralQueueQuery) FirstIDX(ctx context.Context) int { id, err := _q.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -128,10 +103,10 @@ func (_q *TodoQuery) FirstIDX(ctx context.Context) int { return id } -// Only returns a single Todo entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one Todo entity is found. -// Returns a *NotFoundError when no Todo entities are found. -func (_q *TodoQuery) Only(ctx context.Context) (*Todo, error) { +// Only returns a single GeneralQueue entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one GeneralQueue entity is found. +// Returns a *NotFoundError when no GeneralQueue entities are found. +func (_q *GeneralQueueQuery) Only(ctx context.Context) (*GeneralQueue, error) { nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) if err != nil { return nil, err @@ -140,14 +115,14 @@ func (_q *TodoQuery) Only(ctx context.Context) (*Todo, error) { case 1: return nodes[0], nil case 0: - return nil, &NotFoundError{todo.Label} + return nil, &NotFoundError{generalqueue.Label} default: - return nil, &NotSingularError{todo.Label} + return nil, &NotSingularError{generalqueue.Label} } } // OnlyX is like Only, but panics if an error occurs. -func (_q *TodoQuery) OnlyX(ctx context.Context) *Todo { +func (_q *GeneralQueueQuery) OnlyX(ctx context.Context) *GeneralQueue { node, err := _q.Only(ctx) if err != nil { panic(err) @@ -155,10 +130,10 @@ func (_q *TodoQuery) OnlyX(ctx context.Context) *Todo { return node } -// OnlyID is like Only, but returns the only Todo ID in the query. -// Returns a *NotSingularError when more than one Todo ID is found. +// OnlyID is like Only, but returns the only GeneralQueue ID in the query. +// Returns a *NotSingularError when more than one GeneralQueue ID is found. // Returns a *NotFoundError when no entities are found. -func (_q *TodoQuery) OnlyID(ctx context.Context) (id int, err error) { +func (_q *GeneralQueueQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { return @@ -167,15 +142,15 @@ func (_q *TodoQuery) OnlyID(ctx context.Context) (id int, err error) { case 1: id = ids[0] case 0: - err = &NotFoundError{todo.Label} + err = &NotFoundError{generalqueue.Label} default: - err = &NotSingularError{todo.Label} + err = &NotSingularError{generalqueue.Label} } return } // OnlyIDX is like OnlyID, but panics if an error occurs. -func (_q *TodoQuery) OnlyIDX(ctx context.Context) int { +func (_q *GeneralQueueQuery) OnlyIDX(ctx context.Context) int { id, err := _q.OnlyID(ctx) if err != nil { panic(err) @@ -183,18 +158,18 @@ func (_q *TodoQuery) OnlyIDX(ctx context.Context) int { return id } -// All executes the query and returns a list of Todos. -func (_q *TodoQuery) All(ctx context.Context) ([]*Todo, error) { +// All executes the query and returns a list of GeneralQueues. +func (_q *GeneralQueueQuery) All(ctx context.Context) ([]*GeneralQueue, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) if err := _q.prepareQuery(ctx); err != nil { return nil, err } - qr := querierAll[[]*Todo, *TodoQuery]() - return withInterceptors[[]*Todo](ctx, _q, qr, _q.inters) + qr := querierAll[[]*GeneralQueue, *GeneralQueueQuery]() + return withInterceptors[[]*GeneralQueue](ctx, _q, qr, _q.inters) } // AllX is like All, but panics if an error occurs. -func (_q *TodoQuery) AllX(ctx context.Context) []*Todo { +func (_q *GeneralQueueQuery) AllX(ctx context.Context) []*GeneralQueue { nodes, err := _q.All(ctx) if err != nil { panic(err) @@ -202,20 +177,20 @@ func (_q *TodoQuery) AllX(ctx context.Context) []*Todo { return nodes } -// IDs executes the query and returns a list of Todo IDs. -func (_q *TodoQuery) IDs(ctx context.Context) (ids []int, err error) { +// IDs executes the query and returns a list of GeneralQueue IDs. +func (_q *GeneralQueueQuery) IDs(ctx context.Context) (ids []int, err error) { if _q.ctx.Unique == nil && _q.path != nil { _q.Unique(true) } ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) - if err = _q.Select(todo.FieldID).Scan(ctx, &ids); err != nil { + if err = _q.Select(generalqueue.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil } // IDsX is like IDs, but panics if an error occurs. -func (_q *TodoQuery) IDsX(ctx context.Context) []int { +func (_q *GeneralQueueQuery) IDsX(ctx context.Context) []int { ids, err := _q.IDs(ctx) if err != nil { panic(err) @@ -224,16 +199,16 @@ func (_q *TodoQuery) IDsX(ctx context.Context) []int { } // Count returns the count of the given query. -func (_q *TodoQuery) Count(ctx context.Context) (int, error) { +func (_q *GeneralQueueQuery) Count(ctx context.Context) (int, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) if err := _q.prepareQuery(ctx); err != nil { return 0, err } - return withInterceptors[int](ctx, _q, querierCount[*TodoQuery](), _q.inters) + return withInterceptors[int](ctx, _q, querierCount[*GeneralQueueQuery](), _q.inters) } // CountX is like Count, but panics if an error occurs. -func (_q *TodoQuery) CountX(ctx context.Context) int { +func (_q *GeneralQueueQuery) CountX(ctx context.Context) int { count, err := _q.Count(ctx) if err != nil { panic(err) @@ -242,7 +217,7 @@ func (_q *TodoQuery) CountX(ctx context.Context) int { } // Exist returns true if the query has elements in the graph. -func (_q *TodoQuery) Exist(ctx context.Context) (bool, error) { +func (_q *GeneralQueueQuery) Exist(ctx context.Context) (bool, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) switch _, err := _q.FirstID(ctx); { case IsNotFound(err): @@ -255,7 +230,7 @@ func (_q *TodoQuery) Exist(ctx context.Context) (bool, error) { } // ExistX is like Exist, but panics if an error occurs. -func (_q *TodoQuery) ExistX(ctx context.Context) bool { +func (_q *GeneralQueueQuery) ExistX(ctx context.Context) bool { exist, err := _q.Exist(ctx) if err != nil { panic(err) @@ -263,55 +238,43 @@ func (_q *TodoQuery) ExistX(ctx context.Context) bool { return exist } -// Clone returns a duplicate of the TodoQuery builder, including all associated steps. It can be +// Clone returns a duplicate of the GeneralQueueQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. -func (_q *TodoQuery) Clone() *TodoQuery { +func (_q *GeneralQueueQuery) Clone() *GeneralQueueQuery { if _q == nil { return nil } - return &TodoQuery{ + return &GeneralQueueQuery{ config: _q.config, ctx: _q.ctx.Clone(), - order: append([]todo.OrderOption{}, _q.order...), + order: append([]generalqueue.OrderOption{}, _q.order...), inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.Todo{}, _q.predicates...), - withGroup: _q.withGroup.Clone(), + predicates: append([]predicate.GeneralQueue{}, _q.predicates...), // clone intermediate query. sql: _q.sql.Clone(), path: _q.path, } } -// WithGroup tells the query-builder to eager-load the nodes that are connected to -// the "group" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *TodoQuery) WithGroup(opts ...func(*GroupQuery)) *TodoQuery { - query := (&GroupClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withGroup = query - return _q -} - // GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // // Example: // // var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` +// Name string `json:"name,omitempty"` // Count int `json:"count,omitempty"` // } // -// client.Todo.Query(). -// GroupBy(todo.FieldCreatedAt). +// client.GeneralQueue.Query(). +// GroupBy(generalqueue.FieldName). // Aggregate(ent.Count()). // Scan(ctx, &v) -func (_q *TodoQuery) GroupBy(field string, fields ...string) *TodoGroupBy { +func (_q *GeneralQueueQuery) GroupBy(field string, fields ...string) *GeneralQueueGroupBy { _q.ctx.Fields = append([]string{field}, fields...) - grbuild := &TodoGroupBy{build: _q} + grbuild := &GeneralQueueGroupBy{build: _q} grbuild.flds = &_q.ctx.Fields - grbuild.label = todo.Label + grbuild.label = generalqueue.Label grbuild.scan = grbuild.Scan return grbuild } @@ -322,26 +285,26 @@ func (_q *TodoQuery) GroupBy(field string, fields ...string) *TodoGroupBy { // Example: // // var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` +// Name string `json:"name,omitempty"` // } // -// client.Todo.Query(). -// Select(todo.FieldCreatedAt). +// client.GeneralQueue.Query(). +// Select(generalqueue.FieldName). // Scan(ctx, &v) -func (_q *TodoQuery) Select(fields ...string) *TodoSelect { +func (_q *GeneralQueueQuery) Select(fields ...string) *GeneralQueueSelect { _q.ctx.Fields = append(_q.ctx.Fields, fields...) - sbuild := &TodoSelect{TodoQuery: _q} - sbuild.label = todo.Label + sbuild := &GeneralQueueSelect{GeneralQueueQuery: _q} + sbuild.label = generalqueue.Label sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan return sbuild } -// Aggregate returns a TodoSelect configured with the given aggregations. -func (_q *TodoQuery) Aggregate(fns ...AggregateFunc) *TodoSelect { +// Aggregate returns a GeneralQueueSelect configured with the given aggregations. +func (_q *GeneralQueueQuery) Aggregate(fns ...AggregateFunc) *GeneralQueueSelect { return _q.Select().Aggregate(fns...) } -func (_q *TodoQuery) prepareQuery(ctx context.Context) error { +func (_q *GeneralQueueQuery) prepareQuery(ctx context.Context) error { for _, inter := range _q.inters { if inter == nil { return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") @@ -353,7 +316,7 @@ func (_q *TodoQuery) prepareQuery(ctx context.Context) error { } } for _, f := range _q.ctx.Fields { - if !todo.ValidColumn(f) { + if !generalqueue.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } } @@ -367,28 +330,17 @@ func (_q *TodoQuery) prepareQuery(ctx context.Context) error { return nil } -func (_q *TodoQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Todo, error) { +func (_q *GeneralQueueQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*GeneralQueue, error) { var ( - nodes = []*Todo{} - withFKs = _q.withFKs - _spec = _q.querySpec() - loadedTypes = [1]bool{ - _q.withGroup != nil, - } + nodes = []*GeneralQueue{} + _spec = _q.querySpec() ) - if _q.withGroup != nil { - withFKs = true - } - if withFKs { - _spec.Node.Columns = append(_spec.Node.Columns, todo.ForeignKeys...) - } _spec.ScanValues = func(columns []string) ([]any, error) { - return (*Todo).scanValues(nil, columns) + return (*GeneralQueue).scanValues(nil, columns) } _spec.Assign = func(columns []string, values []any) error { - node := &Todo{config: _q.config} + node := &GeneralQueue{config: _q.config} nodes = append(nodes, node) - node.Edges.loadedTypes = loadedTypes return node.assignValues(columns, values) } for i := range hooks { @@ -400,49 +352,10 @@ func (_q *TodoQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Todo, e if len(nodes) == 0 { return nodes, nil } - if query := _q.withGroup; query != nil { - if err := _q.loadGroup(ctx, query, nodes, nil, - func(n *Todo, e *Group) { n.Edges.Group = e }); err != nil { - return nil, err - } - } return nodes, nil } -func (_q *TodoQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*Todo, init func(*Todo), assign func(*Todo, *Group)) error { - ids := make([]int, 0, len(nodes)) - nodeids := make(map[int][]*Todo) - for i := range nodes { - if nodes[i].todo_group == nil { - continue - } - fk := *nodes[i].todo_group - if _, ok := nodeids[fk]; !ok { - ids = append(ids, fk) - } - nodeids[fk] = append(nodeids[fk], nodes[i]) - } - if len(ids) == 0 { - return nil - } - query.Where(group.IDIn(ids...)) - neighbors, err := query.All(ctx) - if err != nil { - return err - } - for _, n := range neighbors { - nodes, ok := nodeids[n.ID] - if !ok { - return fmt.Errorf(`unexpected foreign-key "todo_group" returned %v`, n.ID) - } - for i := range nodes { - assign(nodes[i], n) - } - } - return nil -} - -func (_q *TodoQuery) sqlCount(ctx context.Context) (int, error) { +func (_q *GeneralQueueQuery) sqlCount(ctx context.Context) (int, error) { _spec := _q.querySpec() _spec.Node.Columns = _q.ctx.Fields if len(_q.ctx.Fields) > 0 { @@ -451,8 +364,8 @@ func (_q *TodoQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, _q.driver, _spec) } -func (_q *TodoQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(todo.Table, todo.Columns, sqlgraph.NewFieldSpec(todo.FieldID, field.TypeInt)) +func (_q *GeneralQueueQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(generalqueue.Table, generalqueue.Columns, sqlgraph.NewFieldSpec(generalqueue.FieldID, field.TypeInt)) _spec.From = _q.sql if unique := _q.ctx.Unique; unique != nil { _spec.Unique = *unique @@ -461,9 +374,9 @@ func (_q *TodoQuery) querySpec() *sqlgraph.QuerySpec { } if fields := _q.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, todo.FieldID) + _spec.Node.Columns = append(_spec.Node.Columns, generalqueue.FieldID) for i := range fields { - if fields[i] != todo.FieldID { + if fields[i] != generalqueue.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) } } @@ -491,12 +404,12 @@ func (_q *TodoQuery) querySpec() *sqlgraph.QuerySpec { return _spec } -func (_q *TodoQuery) sqlQuery(ctx context.Context) *sql.Selector { +func (_q *GeneralQueueQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(_q.driver.Dialect()) - t1 := builder.Table(todo.Table) + t1 := builder.Table(generalqueue.Table) columns := _q.ctx.Fields if len(columns) == 0 { - columns = todo.Columns + columns = generalqueue.Columns } selector := builder.Select(t1.Columns(columns...)...).From(t1) if _q.sql != nil { @@ -523,28 +436,28 @@ func (_q *TodoQuery) sqlQuery(ctx context.Context) *sql.Selector { return selector } -// TodoGroupBy is the group-by builder for Todo entities. -type TodoGroupBy struct { +// GeneralQueueGroupBy is the group-by builder for GeneralQueue entities. +type GeneralQueueGroupBy struct { selector - build *TodoQuery + build *GeneralQueueQuery } // Aggregate adds the given aggregation functions to the group-by query. -func (_g *TodoGroupBy) Aggregate(fns ...AggregateFunc) *TodoGroupBy { +func (_g *GeneralQueueGroupBy) Aggregate(fns ...AggregateFunc) *GeneralQueueGroupBy { _g.fns = append(_g.fns, fns...) return _g } // Scan applies the selector query and scans the result into the given value. -func (_g *TodoGroupBy) Scan(ctx context.Context, v any) error { +func (_g *GeneralQueueGroupBy) Scan(ctx context.Context, v any) error { ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) if err := _g.build.prepareQuery(ctx); err != nil { return err } - return scanWithInterceptors[*TodoQuery, *TodoGroupBy](ctx, _g.build, _g, _g.build.inters, v) + return scanWithInterceptors[*GeneralQueueQuery, *GeneralQueueGroupBy](ctx, _g.build, _g, _g.build.inters, v) } -func (_g *TodoGroupBy) sqlScan(ctx context.Context, root *TodoQuery, v any) error { +func (_g *GeneralQueueGroupBy) sqlScan(ctx context.Context, root *GeneralQueueQuery, v any) error { selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(_g.fns)) for _, fn := range _g.fns { @@ -571,28 +484,28 @@ func (_g *TodoGroupBy) sqlScan(ctx context.Context, root *TodoQuery, v any) erro return sql.ScanSlice(rows, v) } -// TodoSelect is the builder for selecting fields of Todo entities. -type TodoSelect struct { - *TodoQuery +// GeneralQueueSelect is the builder for selecting fields of GeneralQueue entities. +type GeneralQueueSelect struct { + *GeneralQueueQuery selector } // Aggregate adds the given aggregation functions to the selector query. -func (_s *TodoSelect) Aggregate(fns ...AggregateFunc) *TodoSelect { +func (_s *GeneralQueueSelect) Aggregate(fns ...AggregateFunc) *GeneralQueueSelect { _s.fns = append(_s.fns, fns...) return _s } // Scan applies the selector query and scans the result into the given value. -func (_s *TodoSelect) Scan(ctx context.Context, v any) error { +func (_s *GeneralQueueSelect) Scan(ctx context.Context, v any) error { ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) if err := _s.prepareQuery(ctx); err != nil { return err } - return scanWithInterceptors[*TodoQuery, *TodoSelect](ctx, _s.TodoQuery, _s, _s.inters, v) + return scanWithInterceptors[*GeneralQueueQuery, *GeneralQueueSelect](ctx, _s.GeneralQueueQuery, _s, _s.inters, v) } -func (_s *TodoSelect) sqlScan(ctx context.Context, root *TodoQuery, v any) error { +func (_s *GeneralQueueSelect) sqlScan(ctx context.Context, root *GeneralQueueQuery, v any) error { selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(_s.fns)) for _, fn := range _s.fns { diff --git a/schema/ent/generalqueue_update.go b/schema/ent/generalqueue_update.go new file mode 100644 index 0000000..a48e841 --- /dev/null +++ b/schema/ent/generalqueue_update.go @@ -0,0 +1,640 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "git.gorlug.de/code/ersteller/schema/ent/generalqueue" + "git.gorlug.de/code/ersteller/schema/ent/predicate" +) + +// GeneralQueueUpdate is the builder for updating GeneralQueue entities. +type GeneralQueueUpdate struct { + config + hooks []Hook + mutation *GeneralQueueMutation +} + +// Where appends a list predicates to the GeneralQueueUpdate builder. +func (_u *GeneralQueueUpdate) Where(ps ...predicate.GeneralQueue) *GeneralQueueUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetName sets the "name" field. +func (_u *GeneralQueueUpdate) SetName(v string) *GeneralQueueUpdate { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *GeneralQueueUpdate) SetNillableName(v *string) *GeneralQueueUpdate { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetPayload sets the "payload" field. +func (_u *GeneralQueueUpdate) SetPayload(v map[string]interface{}) *GeneralQueueUpdate { + _u.mutation.SetPayload(v) + return _u +} + +// SetStatus sets the "status" field. +func (_u *GeneralQueueUpdate) SetStatus(v generalqueue.Status) *GeneralQueueUpdate { + _u.mutation.SetStatus(v) + return _u +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_u *GeneralQueueUpdate) SetNillableStatus(v *generalqueue.Status) *GeneralQueueUpdate { + if v != nil { + _u.SetStatus(*v) + } + return _u +} + +// SetNumberOfTries sets the "number_of_tries" field. +func (_u *GeneralQueueUpdate) SetNumberOfTries(v int) *GeneralQueueUpdate { + _u.mutation.ResetNumberOfTries() + _u.mutation.SetNumberOfTries(v) + return _u +} + +// SetNillableNumberOfTries sets the "number_of_tries" field if the given value is not nil. +func (_u *GeneralQueueUpdate) SetNillableNumberOfTries(v *int) *GeneralQueueUpdate { + if v != nil { + _u.SetNumberOfTries(*v) + } + return _u +} + +// AddNumberOfTries adds value to the "number_of_tries" field. +func (_u *GeneralQueueUpdate) AddNumberOfTries(v int) *GeneralQueueUpdate { + _u.mutation.AddNumberOfTries(v) + return _u +} + +// SetMaxRetries sets the "max_retries" field. +func (_u *GeneralQueueUpdate) SetMaxRetries(v int) *GeneralQueueUpdate { + _u.mutation.ResetMaxRetries() + _u.mutation.SetMaxRetries(v) + return _u +} + +// SetNillableMaxRetries sets the "max_retries" field if the given value is not nil. +func (_u *GeneralQueueUpdate) SetNillableMaxRetries(v *int) *GeneralQueueUpdate { + if v != nil { + _u.SetMaxRetries(*v) + } + return _u +} + +// AddMaxRetries adds value to the "max_retries" field. +func (_u *GeneralQueueUpdate) AddMaxRetries(v int) *GeneralQueueUpdate { + _u.mutation.AddMaxRetries(v) + return _u +} + +// SetErrorMessage sets the "error_message" field. +func (_u *GeneralQueueUpdate) SetErrorMessage(v string) *GeneralQueueUpdate { + _u.mutation.SetErrorMessage(v) + return _u +} + +// SetNillableErrorMessage sets the "error_message" field if the given value is not nil. +func (_u *GeneralQueueUpdate) SetNillableErrorMessage(v *string) *GeneralQueueUpdate { + if v != nil { + _u.SetErrorMessage(*v) + } + return _u +} + +// ClearErrorMessage clears the value of the "error_message" field. +func (_u *GeneralQueueUpdate) ClearErrorMessage() *GeneralQueueUpdate { + _u.mutation.ClearErrorMessage() + return _u +} + +// SetFailurePayload sets the "failure_payload" field. +func (_u *GeneralQueueUpdate) SetFailurePayload(v map[string]interface{}) *GeneralQueueUpdate { + _u.mutation.SetFailurePayload(v) + return _u +} + +// ClearFailurePayload clears the value of the "failure_payload" field. +func (_u *GeneralQueueUpdate) ClearFailurePayload() *GeneralQueueUpdate { + _u.mutation.ClearFailurePayload() + return _u +} + +// SetResultPayload sets the "result_payload" field. +func (_u *GeneralQueueUpdate) SetResultPayload(v map[string]interface{}) *GeneralQueueUpdate { + _u.mutation.SetResultPayload(v) + return _u +} + +// ClearResultPayload clears the value of the "result_payload" field. +func (_u *GeneralQueueUpdate) ClearResultPayload() *GeneralQueueUpdate { + _u.mutation.ClearResultPayload() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *GeneralQueueUpdate) SetCreatedAt(v time.Time) *GeneralQueueUpdate { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *GeneralQueueUpdate) SetNillableCreatedAt(v *time.Time) *GeneralQueueUpdate { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *GeneralQueueUpdate) SetUpdatedAt(v time.Time) *GeneralQueueUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_u *GeneralQueueUpdate) SetNillableUpdatedAt(v *time.Time) *GeneralQueueUpdate { + if v != nil { + _u.SetUpdatedAt(*v) + } + return _u +} + +// SetProcessedAt sets the "processed_at" field. +func (_u *GeneralQueueUpdate) SetProcessedAt(v time.Time) *GeneralQueueUpdate { + _u.mutation.SetProcessedAt(v) + return _u +} + +// SetNillableProcessedAt sets the "processed_at" field if the given value is not nil. +func (_u *GeneralQueueUpdate) SetNillableProcessedAt(v *time.Time) *GeneralQueueUpdate { + if v != nil { + _u.SetProcessedAt(*v) + } + return _u +} + +// ClearProcessedAt clears the value of the "processed_at" field. +func (_u *GeneralQueueUpdate) ClearProcessedAt() *GeneralQueueUpdate { + _u.mutation.ClearProcessedAt() + return _u +} + +// Mutation returns the GeneralQueueMutation object of the builder. +func (_u *GeneralQueueUpdate) Mutation() *GeneralQueueMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *GeneralQueueUpdate) Save(ctx context.Context) (int, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *GeneralQueueUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *GeneralQueueUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *GeneralQueueUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *GeneralQueueUpdate) check() error { + if v, ok := _u.mutation.Status(); ok { + if err := generalqueue.StatusValidator(v); err != nil { + return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "GeneralQueue.status": %w`, err)} + } + } + return nil +} + +func (_u *GeneralQueueUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(generalqueue.Table, generalqueue.Columns, sqlgraph.NewFieldSpec(generalqueue.FieldID, field.TypeInt)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(generalqueue.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.Payload(); ok { + _spec.SetField(generalqueue.FieldPayload, field.TypeJSON, value) + } + if value, ok := _u.mutation.Status(); ok { + _spec.SetField(generalqueue.FieldStatus, field.TypeEnum, value) + } + if value, ok := _u.mutation.NumberOfTries(); ok { + _spec.SetField(generalqueue.FieldNumberOfTries, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedNumberOfTries(); ok { + _spec.AddField(generalqueue.FieldNumberOfTries, field.TypeInt, value) + } + if value, ok := _u.mutation.MaxRetries(); ok { + _spec.SetField(generalqueue.FieldMaxRetries, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedMaxRetries(); ok { + _spec.AddField(generalqueue.FieldMaxRetries, field.TypeInt, value) + } + if value, ok := _u.mutation.ErrorMessage(); ok { + _spec.SetField(generalqueue.FieldErrorMessage, field.TypeString, value) + } + if _u.mutation.ErrorMessageCleared() { + _spec.ClearField(generalqueue.FieldErrorMessage, field.TypeString) + } + if value, ok := _u.mutation.FailurePayload(); ok { + _spec.SetField(generalqueue.FieldFailurePayload, field.TypeJSON, value) + } + if _u.mutation.FailurePayloadCleared() { + _spec.ClearField(generalqueue.FieldFailurePayload, field.TypeJSON) + } + if value, ok := _u.mutation.ResultPayload(); ok { + _spec.SetField(generalqueue.FieldResultPayload, field.TypeJSON, value) + } + if _u.mutation.ResultPayloadCleared() { + _spec.ClearField(generalqueue.FieldResultPayload, field.TypeJSON) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(generalqueue.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(generalqueue.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.ProcessedAt(); ok { + _spec.SetField(generalqueue.FieldProcessedAt, field.TypeTime, value) + } + if _u.mutation.ProcessedAtCleared() { + _spec.ClearField(generalqueue.FieldProcessedAt, field.TypeTime) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{generalqueue.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// GeneralQueueUpdateOne is the builder for updating a single GeneralQueue entity. +type GeneralQueueUpdateOne struct { + config + fields []string + hooks []Hook + mutation *GeneralQueueMutation +} + +// SetName sets the "name" field. +func (_u *GeneralQueueUpdateOne) SetName(v string) *GeneralQueueUpdateOne { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *GeneralQueueUpdateOne) SetNillableName(v *string) *GeneralQueueUpdateOne { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetPayload sets the "payload" field. +func (_u *GeneralQueueUpdateOne) SetPayload(v map[string]interface{}) *GeneralQueueUpdateOne { + _u.mutation.SetPayload(v) + return _u +} + +// SetStatus sets the "status" field. +func (_u *GeneralQueueUpdateOne) SetStatus(v generalqueue.Status) *GeneralQueueUpdateOne { + _u.mutation.SetStatus(v) + return _u +} + +// SetNillableStatus sets the "status" field if the given value is not nil. +func (_u *GeneralQueueUpdateOne) SetNillableStatus(v *generalqueue.Status) *GeneralQueueUpdateOne { + if v != nil { + _u.SetStatus(*v) + } + return _u +} + +// SetNumberOfTries sets the "number_of_tries" field. +func (_u *GeneralQueueUpdateOne) SetNumberOfTries(v int) *GeneralQueueUpdateOne { + _u.mutation.ResetNumberOfTries() + _u.mutation.SetNumberOfTries(v) + return _u +} + +// SetNillableNumberOfTries sets the "number_of_tries" field if the given value is not nil. +func (_u *GeneralQueueUpdateOne) SetNillableNumberOfTries(v *int) *GeneralQueueUpdateOne { + if v != nil { + _u.SetNumberOfTries(*v) + } + return _u +} + +// AddNumberOfTries adds value to the "number_of_tries" field. +func (_u *GeneralQueueUpdateOne) AddNumberOfTries(v int) *GeneralQueueUpdateOne { + _u.mutation.AddNumberOfTries(v) + return _u +} + +// SetMaxRetries sets the "max_retries" field. +func (_u *GeneralQueueUpdateOne) SetMaxRetries(v int) *GeneralQueueUpdateOne { + _u.mutation.ResetMaxRetries() + _u.mutation.SetMaxRetries(v) + return _u +} + +// SetNillableMaxRetries sets the "max_retries" field if the given value is not nil. +func (_u *GeneralQueueUpdateOne) SetNillableMaxRetries(v *int) *GeneralQueueUpdateOne { + if v != nil { + _u.SetMaxRetries(*v) + } + return _u +} + +// AddMaxRetries adds value to the "max_retries" field. +func (_u *GeneralQueueUpdateOne) AddMaxRetries(v int) *GeneralQueueUpdateOne { + _u.mutation.AddMaxRetries(v) + return _u +} + +// SetErrorMessage sets the "error_message" field. +func (_u *GeneralQueueUpdateOne) SetErrorMessage(v string) *GeneralQueueUpdateOne { + _u.mutation.SetErrorMessage(v) + return _u +} + +// SetNillableErrorMessage sets the "error_message" field if the given value is not nil. +func (_u *GeneralQueueUpdateOne) SetNillableErrorMessage(v *string) *GeneralQueueUpdateOne { + if v != nil { + _u.SetErrorMessage(*v) + } + return _u +} + +// ClearErrorMessage clears the value of the "error_message" field. +func (_u *GeneralQueueUpdateOne) ClearErrorMessage() *GeneralQueueUpdateOne { + _u.mutation.ClearErrorMessage() + return _u +} + +// SetFailurePayload sets the "failure_payload" field. +func (_u *GeneralQueueUpdateOne) SetFailurePayload(v map[string]interface{}) *GeneralQueueUpdateOne { + _u.mutation.SetFailurePayload(v) + return _u +} + +// ClearFailurePayload clears the value of the "failure_payload" field. +func (_u *GeneralQueueUpdateOne) ClearFailurePayload() *GeneralQueueUpdateOne { + _u.mutation.ClearFailurePayload() + return _u +} + +// SetResultPayload sets the "result_payload" field. +func (_u *GeneralQueueUpdateOne) SetResultPayload(v map[string]interface{}) *GeneralQueueUpdateOne { + _u.mutation.SetResultPayload(v) + return _u +} + +// ClearResultPayload clears the value of the "result_payload" field. +func (_u *GeneralQueueUpdateOne) ClearResultPayload() *GeneralQueueUpdateOne { + _u.mutation.ClearResultPayload() + return _u +} + +// SetCreatedAt sets the "created_at" field. +func (_u *GeneralQueueUpdateOne) SetCreatedAt(v time.Time) *GeneralQueueUpdateOne { + _u.mutation.SetCreatedAt(v) + return _u +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_u *GeneralQueueUpdateOne) SetNillableCreatedAt(v *time.Time) *GeneralQueueUpdateOne { + if v != nil { + _u.SetCreatedAt(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *GeneralQueueUpdateOne) SetUpdatedAt(v time.Time) *GeneralQueueUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_u *GeneralQueueUpdateOne) SetNillableUpdatedAt(v *time.Time) *GeneralQueueUpdateOne { + if v != nil { + _u.SetUpdatedAt(*v) + } + return _u +} + +// SetProcessedAt sets the "processed_at" field. +func (_u *GeneralQueueUpdateOne) SetProcessedAt(v time.Time) *GeneralQueueUpdateOne { + _u.mutation.SetProcessedAt(v) + return _u +} + +// SetNillableProcessedAt sets the "processed_at" field if the given value is not nil. +func (_u *GeneralQueueUpdateOne) SetNillableProcessedAt(v *time.Time) *GeneralQueueUpdateOne { + if v != nil { + _u.SetProcessedAt(*v) + } + return _u +} + +// ClearProcessedAt clears the value of the "processed_at" field. +func (_u *GeneralQueueUpdateOne) ClearProcessedAt() *GeneralQueueUpdateOne { + _u.mutation.ClearProcessedAt() + return _u +} + +// Mutation returns the GeneralQueueMutation object of the builder. +func (_u *GeneralQueueUpdateOne) Mutation() *GeneralQueueMutation { + return _u.mutation +} + +// Where appends a list predicates to the GeneralQueueUpdate builder. +func (_u *GeneralQueueUpdateOne) Where(ps ...predicate.GeneralQueue) *GeneralQueueUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *GeneralQueueUpdateOne) Select(field string, fields ...string) *GeneralQueueUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated GeneralQueue entity. +func (_u *GeneralQueueUpdateOne) Save(ctx context.Context) (*GeneralQueue, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *GeneralQueueUpdateOne) SaveX(ctx context.Context) *GeneralQueue { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *GeneralQueueUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *GeneralQueueUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_u *GeneralQueueUpdateOne) check() error { + if v, ok := _u.mutation.Status(); ok { + if err := generalqueue.StatusValidator(v); err != nil { + return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "GeneralQueue.status": %w`, err)} + } + } + return nil +} + +func (_u *GeneralQueueUpdateOne) sqlSave(ctx context.Context) (_node *GeneralQueue, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(generalqueue.Table, generalqueue.Columns, sqlgraph.NewFieldSpec(generalqueue.FieldID, field.TypeInt)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "GeneralQueue.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, generalqueue.FieldID) + for _, f := range fields { + if !generalqueue.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != generalqueue.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(generalqueue.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.Payload(); ok { + _spec.SetField(generalqueue.FieldPayload, field.TypeJSON, value) + } + if value, ok := _u.mutation.Status(); ok { + _spec.SetField(generalqueue.FieldStatus, field.TypeEnum, value) + } + if value, ok := _u.mutation.NumberOfTries(); ok { + _spec.SetField(generalqueue.FieldNumberOfTries, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedNumberOfTries(); ok { + _spec.AddField(generalqueue.FieldNumberOfTries, field.TypeInt, value) + } + if value, ok := _u.mutation.MaxRetries(); ok { + _spec.SetField(generalqueue.FieldMaxRetries, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedMaxRetries(); ok { + _spec.AddField(generalqueue.FieldMaxRetries, field.TypeInt, value) + } + if value, ok := _u.mutation.ErrorMessage(); ok { + _spec.SetField(generalqueue.FieldErrorMessage, field.TypeString, value) + } + if _u.mutation.ErrorMessageCleared() { + _spec.ClearField(generalqueue.FieldErrorMessage, field.TypeString) + } + if value, ok := _u.mutation.FailurePayload(); ok { + _spec.SetField(generalqueue.FieldFailurePayload, field.TypeJSON, value) + } + if _u.mutation.FailurePayloadCleared() { + _spec.ClearField(generalqueue.FieldFailurePayload, field.TypeJSON) + } + if value, ok := _u.mutation.ResultPayload(); ok { + _spec.SetField(generalqueue.FieldResultPayload, field.TypeJSON, value) + } + if _u.mutation.ResultPayloadCleared() { + _spec.ClearField(generalqueue.FieldResultPayload, field.TypeJSON) + } + if value, ok := _u.mutation.CreatedAt(); ok { + _spec.SetField(generalqueue.FieldCreatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(generalqueue.FieldUpdatedAt, field.TypeTime, value) + } + if value, ok := _u.mutation.ProcessedAt(); ok { + _spec.SetField(generalqueue.FieldProcessedAt, field.TypeTime, value) + } + if _u.mutation.ProcessedAtCleared() { + _spec.ClearField(generalqueue.FieldProcessedAt, field.TypeTime) + } + _node = &GeneralQueue{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{generalqueue.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/schema/ent/generalqueuestate.go b/schema/ent/generalqueuestate.go new file mode 100644 index 0000000..ac97d47 --- /dev/null +++ b/schema/ent/generalqueuestate.go @@ -0,0 +1,130 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "git.gorlug.de/code/ersteller/schema/ent/generalqueuestate" +) + +// GeneralQueueState is the model entity for the GeneralQueueState schema. +type GeneralQueueState struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // Name of the queue (e.g., 'email', 'notifications') + Name string `json:"name,omitempty"` + // Whether the queue is currently running + Running bool `json:"running,omitempty"` + // Last time the state was updated + UpdatedAt time.Time `json:"updated_at,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*GeneralQueueState) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case generalqueuestate.FieldRunning: + values[i] = new(sql.NullBool) + case generalqueuestate.FieldID: + values[i] = new(sql.NullInt64) + case generalqueuestate.FieldName: + values[i] = new(sql.NullString) + case generalqueuestate.FieldUpdatedAt: + values[i] = new(sql.NullTime) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the GeneralQueueState fields. +func (_m *GeneralQueueState) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case generalqueuestate.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + _m.ID = int(value.Int64) + case generalqueuestate.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + _m.Name = value.String + } + case generalqueuestate.FieldRunning: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field running", values[i]) + } else if value.Valid { + _m.Running = value.Bool + } + case generalqueuestate.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + _m.UpdatedAt = value.Time + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the GeneralQueueState. +// This includes values selected through modifiers, order, etc. +func (_m *GeneralQueueState) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this GeneralQueueState. +// Note that you need to call GeneralQueueState.Unwrap() before calling this method if this GeneralQueueState +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *GeneralQueueState) Update() *GeneralQueueStateUpdateOne { + return NewGeneralQueueStateClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the GeneralQueueState entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *GeneralQueueState) Unwrap() *GeneralQueueState { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: GeneralQueueState is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *GeneralQueueState) String() string { + var builder strings.Builder + builder.WriteString("GeneralQueueState(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("name=") + builder.WriteString(_m.Name) + builder.WriteString(", ") + builder.WriteString("running=") + builder.WriteString(fmt.Sprintf("%v", _m.Running)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(_m.UpdatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// GeneralQueueStates is a parsable slice of GeneralQueueState. +type GeneralQueueStates []*GeneralQueueState diff --git a/schema/ent/generalqueuestate/generalqueuestate.go b/schema/ent/generalqueuestate/generalqueuestate.go new file mode 100644 index 0000000..6c3d875 --- /dev/null +++ b/schema/ent/generalqueuestate/generalqueuestate.go @@ -0,0 +1,68 @@ +// Code generated by ent, DO NOT EDIT. + +package generalqueuestate + +import ( + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the generalqueuestate type in the database. + Label = "general_queue_state" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldRunning holds the string denoting the running field in the database. + FieldRunning = "running" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // Table holds the table name of the generalqueuestate in the database. + Table = "generalQueueState" +) + +// Columns holds all SQL columns for generalqueuestate fields. +var Columns = []string{ + FieldID, + FieldName, + FieldRunning, + FieldUpdatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultRunning holds the default value on creation for the "running" field. + DefaultRunning bool +) + +// OrderOption defines the ordering options for the GeneralQueueState queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByRunning orders the results by the running field. +func ByRunning(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldRunning, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} diff --git a/schema/ent/generalqueuestate/where.go b/schema/ent/generalqueuestate/where.go new file mode 100644 index 0000000..791d003 --- /dev/null +++ b/schema/ent/generalqueuestate/where.go @@ -0,0 +1,200 @@ +// Code generated by ent, DO NOT EDIT. + +package generalqueuestate + +import ( + "time" + + "entgo.io/ent/dialect/sql" + "git.gorlug.de/code/ersteller/schema/ent/predicate" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldLTE(FieldID, id)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldEQ(FieldName, v)) +} + +// Running applies equality check predicate on the "running" field. It's identical to RunningEQ. +func Running(v bool) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldEQ(FieldRunning, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v time.Time) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldContainsFold(FieldName, v)) +} + +// RunningEQ applies the EQ predicate on the "running" field. +func RunningEQ(v bool) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldEQ(FieldRunning, v)) +} + +// RunningNEQ applies the NEQ predicate on the "running" field. +func RunningNEQ(v bool) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldNEQ(FieldRunning, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v time.Time) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v time.Time) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...time.Time) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...time.Time) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v time.Time) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v time.Time) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v time.Time) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v time.Time) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.GeneralQueueState) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.GeneralQueueState) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.GeneralQueueState) predicate.GeneralQueueState { + return predicate.GeneralQueueState(sql.NotPredicates(p)) +} diff --git a/schema/ent/generalqueuestate_create.go b/schema/ent/generalqueuestate_create.go new file mode 100644 index 0000000..05a4d6e --- /dev/null +++ b/schema/ent/generalqueuestate_create.go @@ -0,0 +1,228 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "git.gorlug.de/code/ersteller/schema/ent/generalqueuestate" +) + +// GeneralQueueStateCreate is the builder for creating a GeneralQueueState entity. +type GeneralQueueStateCreate struct { + config + mutation *GeneralQueueStateMutation + hooks []Hook +} + +// SetName sets the "name" field. +func (_c *GeneralQueueStateCreate) SetName(v string) *GeneralQueueStateCreate { + _c.mutation.SetName(v) + return _c +} + +// SetRunning sets the "running" field. +func (_c *GeneralQueueStateCreate) SetRunning(v bool) *GeneralQueueStateCreate { + _c.mutation.SetRunning(v) + return _c +} + +// SetNillableRunning sets the "running" field if the given value is not nil. +func (_c *GeneralQueueStateCreate) SetNillableRunning(v *bool) *GeneralQueueStateCreate { + if v != nil { + _c.SetRunning(*v) + } + return _c +} + +// SetUpdatedAt sets the "updated_at" field. +func (_c *GeneralQueueStateCreate) SetUpdatedAt(v time.Time) *GeneralQueueStateCreate { + _c.mutation.SetUpdatedAt(v) + return _c +} + +// Mutation returns the GeneralQueueStateMutation object of the builder. +func (_c *GeneralQueueStateCreate) Mutation() *GeneralQueueStateMutation { + return _c.mutation +} + +// Save creates the GeneralQueueState in the database. +func (_c *GeneralQueueStateCreate) Save(ctx context.Context) (*GeneralQueueState, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *GeneralQueueStateCreate) SaveX(ctx context.Context) *GeneralQueueState { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *GeneralQueueStateCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *GeneralQueueStateCreate) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (_c *GeneralQueueStateCreate) defaults() { + if _, ok := _c.mutation.Running(); !ok { + v := generalqueuestate.DefaultRunning + _c.mutation.SetRunning(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *GeneralQueueStateCreate) check() error { + if _, ok := _c.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "GeneralQueueState.name"`)} + } + if _, ok := _c.mutation.Running(); !ok { + return &ValidationError{Name: "running", err: errors.New(`ent: missing required field "GeneralQueueState.running"`)} + } + if _, ok := _c.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "GeneralQueueState.updated_at"`)} + } + return nil +} + +func (_c *GeneralQueueStateCreate) sqlSave(ctx context.Context) (*GeneralQueueState, error) { + if err := _c.check(); err != nil { + return nil, err + } + _node, _spec := _c.createSpec() + if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + id := _spec.ID.Value.(int64) + _node.ID = int(id) + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *GeneralQueueStateCreate) createSpec() (*GeneralQueueState, *sqlgraph.CreateSpec) { + var ( + _node = &GeneralQueueState{config: _c.config} + _spec = sqlgraph.NewCreateSpec(generalqueuestate.Table, sqlgraph.NewFieldSpec(generalqueuestate.FieldID, field.TypeInt)) + ) + if value, ok := _c.mutation.Name(); ok { + _spec.SetField(generalqueuestate.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := _c.mutation.Running(); ok { + _spec.SetField(generalqueuestate.FieldRunning, field.TypeBool, value) + _node.Running = value + } + if value, ok := _c.mutation.UpdatedAt(); ok { + _spec.SetField(generalqueuestate.FieldUpdatedAt, field.TypeTime, value) + _node.UpdatedAt = value + } + return _node, _spec +} + +// GeneralQueueStateCreateBulk is the builder for creating many GeneralQueueState entities in bulk. +type GeneralQueueStateCreateBulk struct { + config + err error + builders []*GeneralQueueStateCreate +} + +// Save creates the GeneralQueueState entities in the database. +func (_c *GeneralQueueStateCreateBulk) Save(ctx context.Context) ([]*GeneralQueueState, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*GeneralQueueState, len(_c.builders)) + mutators := make([]Mutator, len(_c.builders)) + for i := range _c.builders { + func(i int, root context.Context) { + builder := _c.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*GeneralQueueStateMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + if specs[i].ID.Value != nil { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int(id) + } + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (_c *GeneralQueueStateCreateBulk) SaveX(ctx context.Context) []*GeneralQueueState { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *GeneralQueueStateCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *GeneralQueueStateCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/schema/ent/generalqueuestate_delete.go b/schema/ent/generalqueuestate_delete.go new file mode 100644 index 0000000..6d7181d --- /dev/null +++ b/schema/ent/generalqueuestate_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "git.gorlug.de/code/ersteller/schema/ent/generalqueuestate" + "git.gorlug.de/code/ersteller/schema/ent/predicate" +) + +// GeneralQueueStateDelete is the builder for deleting a GeneralQueueState entity. +type GeneralQueueStateDelete struct { + config + hooks []Hook + mutation *GeneralQueueStateMutation +} + +// Where appends a list predicates to the GeneralQueueStateDelete builder. +func (_d *GeneralQueueStateDelete) Where(ps ...predicate.GeneralQueueState) *GeneralQueueStateDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *GeneralQueueStateDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *GeneralQueueStateDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *GeneralQueueStateDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(generalqueuestate.Table, sqlgraph.NewFieldSpec(generalqueuestate.FieldID, field.TypeInt)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// GeneralQueueStateDeleteOne is the builder for deleting a single GeneralQueueState entity. +type GeneralQueueStateDeleteOne struct { + _d *GeneralQueueStateDelete +} + +// Where appends a list predicates to the GeneralQueueStateDelete builder. +func (_d *GeneralQueueStateDeleteOne) Where(ps ...predicate.GeneralQueueState) *GeneralQueueStateDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *GeneralQueueStateDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{generalqueuestate.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *GeneralQueueStateDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/schema/ent/example/ent/user_query.go b/schema/ent/generalqueuestate_query.go similarity index 51% rename from schema/ent/example/ent/user_query.go rename to schema/ent/generalqueuestate_query.go index ac56c09..1c8ef2b 100644 --- a/schema/ent/example/ent/user_query.go +++ b/schema/ent/generalqueuestate_query.go @@ -4,100 +4,75 @@ package ent import ( "context" - "database/sql/driver" "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/group" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/predicate" - "git.gorlug.de/code/ersteller/schema/ent/example/ent/user" "math" "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" + "git.gorlug.de/code/ersteller/schema/ent/generalqueuestate" + "git.gorlug.de/code/ersteller/schema/ent/predicate" ) -// UserQuery is the builder for querying User entities. -type UserQuery struct { +// GeneralQueueStateQuery is the builder for querying GeneralQueueState entities. +type GeneralQueueStateQuery struct { config ctx *QueryContext - order []user.OrderOption + order []generalqueuestate.OrderOption inters []Interceptor - predicates []predicate.User - withGroup *GroupQuery + predicates []predicate.GeneralQueueState // intermediate query (i.e. traversal path). sql *sql.Selector path func(context.Context) (*sql.Selector, error) } -// Where adds a new predicate for the UserQuery builder. -func (_q *UserQuery) Where(ps ...predicate.User) *UserQuery { +// Where adds a new predicate for the GeneralQueueStateQuery builder. +func (_q *GeneralQueueStateQuery) Where(ps ...predicate.GeneralQueueState) *GeneralQueueStateQuery { _q.predicates = append(_q.predicates, ps...) return _q } // Limit the number of records to be returned by this query. -func (_q *UserQuery) Limit(limit int) *UserQuery { +func (_q *GeneralQueueStateQuery) Limit(limit int) *GeneralQueueStateQuery { _q.ctx.Limit = &limit return _q } // Offset to start from. -func (_q *UserQuery) Offset(offset int) *UserQuery { +func (_q *GeneralQueueStateQuery) Offset(offset int) *GeneralQueueStateQuery { _q.ctx.Offset = &offset return _q } // Unique configures the query builder to filter duplicate records on query. // By default, unique is set to true, and can be disabled using this method. -func (_q *UserQuery) Unique(unique bool) *UserQuery { +func (_q *GeneralQueueStateQuery) Unique(unique bool) *GeneralQueueStateQuery { _q.ctx.Unique = &unique return _q } // Order specifies how the records should be ordered. -func (_q *UserQuery) Order(o ...user.OrderOption) *UserQuery { +func (_q *GeneralQueueStateQuery) Order(o ...generalqueuestate.OrderOption) *GeneralQueueStateQuery { _q.order = append(_q.order, o...) return _q } -// QueryGroup chains the current query on the "group" edge. -func (_q *UserQuery) QueryGroup() *GroupQuery { - query := (&GroupClient{config: _q.config}).Query() - query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - selector := _q.sqlQuery(ctx) - if err := selector.Err(); err != nil { - return nil, err - } - step := sqlgraph.NewStep( - sqlgraph.From(user.Table, user.FieldID, selector), - sqlgraph.To(group.Table, group.FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, user.GroupTable, user.GroupPrimaryKey...), - ) - fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step) - return fromU, nil - } - return query -} - -// First returns the first User entity from the query. -// Returns a *NotFoundError when no User was found. -func (_q *UserQuery) First(ctx context.Context) (*User, error) { +// First returns the first GeneralQueueState entity from the query. +// Returns a *NotFoundError when no GeneralQueueState was found. +func (_q *GeneralQueueStateQuery) First(ctx context.Context) (*GeneralQueueState, error) { nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } if len(nodes) == 0 { - return nil, &NotFoundError{user.Label} + return nil, &NotFoundError{generalqueuestate.Label} } return nodes[0], nil } // FirstX is like First, but panics if an error occurs. -func (_q *UserQuery) FirstX(ctx context.Context) *User { +func (_q *GeneralQueueStateQuery) FirstX(ctx context.Context) *GeneralQueueState { node, err := _q.First(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -105,22 +80,22 @@ func (_q *UserQuery) FirstX(ctx context.Context) *User { return node } -// FirstID returns the first User ID from the query. -// Returns a *NotFoundError when no User ID was found. -func (_q *UserQuery) FirstID(ctx context.Context) (id int, err error) { +// FirstID returns the first GeneralQueueState ID from the query. +// Returns a *NotFoundError when no GeneralQueueState ID was found. +func (_q *GeneralQueueStateQuery) FirstID(ctx context.Context) (id int, err error) { var ids []int if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { - err = &NotFoundError{user.Label} + err = &NotFoundError{generalqueuestate.Label} return } return ids[0], nil } // FirstIDX is like FirstID, but panics if an error occurs. -func (_q *UserQuery) FirstIDX(ctx context.Context) int { +func (_q *GeneralQueueStateQuery) FirstIDX(ctx context.Context) int { id, err := _q.FirstID(ctx) if err != nil && !IsNotFound(err) { panic(err) @@ -128,10 +103,10 @@ func (_q *UserQuery) FirstIDX(ctx context.Context) int { return id } -// Only returns a single User entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one User entity is found. -// Returns a *NotFoundError when no User entities are found. -func (_q *UserQuery) Only(ctx context.Context) (*User, error) { +// Only returns a single GeneralQueueState entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one GeneralQueueState entity is found. +// Returns a *NotFoundError when no GeneralQueueState entities are found. +func (_q *GeneralQueueStateQuery) Only(ctx context.Context) (*GeneralQueueState, error) { nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) if err != nil { return nil, err @@ -140,14 +115,14 @@ func (_q *UserQuery) Only(ctx context.Context) (*User, error) { case 1: return nodes[0], nil case 0: - return nil, &NotFoundError{user.Label} + return nil, &NotFoundError{generalqueuestate.Label} default: - return nil, &NotSingularError{user.Label} + return nil, &NotSingularError{generalqueuestate.Label} } } // OnlyX is like Only, but panics if an error occurs. -func (_q *UserQuery) OnlyX(ctx context.Context) *User { +func (_q *GeneralQueueStateQuery) OnlyX(ctx context.Context) *GeneralQueueState { node, err := _q.Only(ctx) if err != nil { panic(err) @@ -155,10 +130,10 @@ func (_q *UserQuery) OnlyX(ctx context.Context) *User { return node } -// OnlyID is like Only, but returns the only User ID in the query. -// Returns a *NotSingularError when more than one User ID is found. +// OnlyID is like Only, but returns the only GeneralQueueState ID in the query. +// Returns a *NotSingularError when more than one GeneralQueueState ID is found. // Returns a *NotFoundError when no entities are found. -func (_q *UserQuery) OnlyID(ctx context.Context) (id int, err error) { +func (_q *GeneralQueueStateQuery) OnlyID(ctx context.Context) (id int, err error) { var ids []int if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { return @@ -167,15 +142,15 @@ func (_q *UserQuery) OnlyID(ctx context.Context) (id int, err error) { case 1: id = ids[0] case 0: - err = &NotFoundError{user.Label} + err = &NotFoundError{generalqueuestate.Label} default: - err = &NotSingularError{user.Label} + err = &NotSingularError{generalqueuestate.Label} } return } // OnlyIDX is like OnlyID, but panics if an error occurs. -func (_q *UserQuery) OnlyIDX(ctx context.Context) int { +func (_q *GeneralQueueStateQuery) OnlyIDX(ctx context.Context) int { id, err := _q.OnlyID(ctx) if err != nil { panic(err) @@ -183,18 +158,18 @@ func (_q *UserQuery) OnlyIDX(ctx context.Context) int { return id } -// All executes the query and returns a list of Users. -func (_q *UserQuery) All(ctx context.Context) ([]*User, error) { +// All executes the query and returns a list of GeneralQueueStates. +func (_q *GeneralQueueStateQuery) All(ctx context.Context) ([]*GeneralQueueState, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) if err := _q.prepareQuery(ctx); err != nil { return nil, err } - qr := querierAll[[]*User, *UserQuery]() - return withInterceptors[[]*User](ctx, _q, qr, _q.inters) + qr := querierAll[[]*GeneralQueueState, *GeneralQueueStateQuery]() + return withInterceptors[[]*GeneralQueueState](ctx, _q, qr, _q.inters) } // AllX is like All, but panics if an error occurs. -func (_q *UserQuery) AllX(ctx context.Context) []*User { +func (_q *GeneralQueueStateQuery) AllX(ctx context.Context) []*GeneralQueueState { nodes, err := _q.All(ctx) if err != nil { panic(err) @@ -202,20 +177,20 @@ func (_q *UserQuery) AllX(ctx context.Context) []*User { return nodes } -// IDs executes the query and returns a list of User IDs. -func (_q *UserQuery) IDs(ctx context.Context) (ids []int, err error) { +// IDs executes the query and returns a list of GeneralQueueState IDs. +func (_q *GeneralQueueStateQuery) IDs(ctx context.Context) (ids []int, err error) { if _q.ctx.Unique == nil && _q.path != nil { _q.Unique(true) } ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) - if err = _q.Select(user.FieldID).Scan(ctx, &ids); err != nil { + if err = _q.Select(generalqueuestate.FieldID).Scan(ctx, &ids); err != nil { return nil, err } return ids, nil } // IDsX is like IDs, but panics if an error occurs. -func (_q *UserQuery) IDsX(ctx context.Context) []int { +func (_q *GeneralQueueStateQuery) IDsX(ctx context.Context) []int { ids, err := _q.IDs(ctx) if err != nil { panic(err) @@ -224,16 +199,16 @@ func (_q *UserQuery) IDsX(ctx context.Context) []int { } // Count returns the count of the given query. -func (_q *UserQuery) Count(ctx context.Context) (int, error) { +func (_q *GeneralQueueStateQuery) Count(ctx context.Context) (int, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) if err := _q.prepareQuery(ctx); err != nil { return 0, err } - return withInterceptors[int](ctx, _q, querierCount[*UserQuery](), _q.inters) + return withInterceptors[int](ctx, _q, querierCount[*GeneralQueueStateQuery](), _q.inters) } // CountX is like Count, but panics if an error occurs. -func (_q *UserQuery) CountX(ctx context.Context) int { +func (_q *GeneralQueueStateQuery) CountX(ctx context.Context) int { count, err := _q.Count(ctx) if err != nil { panic(err) @@ -242,7 +217,7 @@ func (_q *UserQuery) CountX(ctx context.Context) int { } // Exist returns true if the query has elements in the graph. -func (_q *UserQuery) Exist(ctx context.Context) (bool, error) { +func (_q *GeneralQueueStateQuery) Exist(ctx context.Context) (bool, error) { ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) switch _, err := _q.FirstID(ctx); { case IsNotFound(err): @@ -255,7 +230,7 @@ func (_q *UserQuery) Exist(ctx context.Context) (bool, error) { } // ExistX is like Exist, but panics if an error occurs. -func (_q *UserQuery) ExistX(ctx context.Context) bool { +func (_q *GeneralQueueStateQuery) ExistX(ctx context.Context) bool { exist, err := _q.Exist(ctx) if err != nil { panic(err) @@ -263,55 +238,43 @@ func (_q *UserQuery) ExistX(ctx context.Context) bool { return exist } -// Clone returns a duplicate of the UserQuery builder, including all associated steps. It can be +// Clone returns a duplicate of the GeneralQueueStateQuery builder, including all associated steps. It can be // used to prepare common query builders and use them differently after the clone is made. -func (_q *UserQuery) Clone() *UserQuery { +func (_q *GeneralQueueStateQuery) Clone() *GeneralQueueStateQuery { if _q == nil { return nil } - return &UserQuery{ + return &GeneralQueueStateQuery{ config: _q.config, ctx: _q.ctx.Clone(), - order: append([]user.OrderOption{}, _q.order...), + order: append([]generalqueuestate.OrderOption{}, _q.order...), inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.User{}, _q.predicates...), - withGroup: _q.withGroup.Clone(), + predicates: append([]predicate.GeneralQueueState{}, _q.predicates...), // clone intermediate query. sql: _q.sql.Clone(), path: _q.path, } } -// WithGroup tells the query-builder to eager-load the nodes that are connected to -// the "group" edge. The optional arguments are used to configure the query builder of the edge. -func (_q *UserQuery) WithGroup(opts ...func(*GroupQuery)) *UserQuery { - query := (&GroupClient{config: _q.config}).Query() - for _, opt := range opts { - opt(query) - } - _q.withGroup = query - return _q -} - // GroupBy is used to group vertices by one or more fields/columns. // It is often used with aggregate functions, like: count, max, mean, min, sum. // // Example: // // var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` +// Name string `json:"name,omitempty"` // Count int `json:"count,omitempty"` // } // -// client.User.Query(). -// GroupBy(user.FieldCreatedAt). +// client.GeneralQueueState.Query(). +// GroupBy(generalqueuestate.FieldName). // Aggregate(ent.Count()). // Scan(ctx, &v) -func (_q *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { +func (_q *GeneralQueueStateQuery) GroupBy(field string, fields ...string) *GeneralQueueStateGroupBy { _q.ctx.Fields = append([]string{field}, fields...) - grbuild := &UserGroupBy{build: _q} + grbuild := &GeneralQueueStateGroupBy{build: _q} grbuild.flds = &_q.ctx.Fields - grbuild.label = user.Label + grbuild.label = generalqueuestate.Label grbuild.scan = grbuild.Scan return grbuild } @@ -322,26 +285,26 @@ func (_q *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy { // Example: // // var v []struct { -// CreatedAt time.Time `json:"created_at,omitempty"` +// Name string `json:"name,omitempty"` // } // -// client.User.Query(). -// Select(user.FieldCreatedAt). +// client.GeneralQueueState.Query(). +// Select(generalqueuestate.FieldName). // Scan(ctx, &v) -func (_q *UserQuery) Select(fields ...string) *UserSelect { +func (_q *GeneralQueueStateQuery) Select(fields ...string) *GeneralQueueStateSelect { _q.ctx.Fields = append(_q.ctx.Fields, fields...) - sbuild := &UserSelect{UserQuery: _q} - sbuild.label = user.Label + sbuild := &GeneralQueueStateSelect{GeneralQueueStateQuery: _q} + sbuild.label = generalqueuestate.Label sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan return sbuild } -// Aggregate returns a UserSelect configured with the given aggregations. -func (_q *UserQuery) Aggregate(fns ...AggregateFunc) *UserSelect { +// Aggregate returns a GeneralQueueStateSelect configured with the given aggregations. +func (_q *GeneralQueueStateQuery) Aggregate(fns ...AggregateFunc) *GeneralQueueStateSelect { return _q.Select().Aggregate(fns...) } -func (_q *UserQuery) prepareQuery(ctx context.Context) error { +func (_q *GeneralQueueStateQuery) prepareQuery(ctx context.Context) error { for _, inter := range _q.inters { if inter == nil { return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") @@ -353,7 +316,7 @@ func (_q *UserQuery) prepareQuery(ctx context.Context) error { } } for _, f := range _q.ctx.Fields { - if !user.ValidColumn(f) { + if !generalqueuestate.ValidColumn(f) { return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} } } @@ -367,21 +330,17 @@ func (_q *UserQuery) prepareQuery(ctx context.Context) error { return nil } -func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, error) { +func (_q *GeneralQueueStateQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*GeneralQueueState, error) { var ( - nodes = []*User{} - _spec = _q.querySpec() - loadedTypes = [1]bool{ - _q.withGroup != nil, - } + nodes = []*GeneralQueueState{} + _spec = _q.querySpec() ) _spec.ScanValues = func(columns []string) ([]any, error) { - return (*User).scanValues(nil, columns) + return (*GeneralQueueState).scanValues(nil, columns) } _spec.Assign = func(columns []string, values []any) error { - node := &User{config: _q.config} + node := &GeneralQueueState{config: _q.config} nodes = append(nodes, node) - node.Edges.loadedTypes = loadedTypes return node.assignValues(columns, values) } for i := range hooks { @@ -393,79 +352,10 @@ func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e if len(nodes) == 0 { return nodes, nil } - if query := _q.withGroup; query != nil { - if err := _q.loadGroup(ctx, query, nodes, - func(n *User) { n.Edges.Group = []*Group{} }, - func(n *User, e *Group) { n.Edges.Group = append(n.Edges.Group, e) }); err != nil { - return nil, err - } - } return nodes, nil } -func (_q *UserQuery) loadGroup(ctx context.Context, query *GroupQuery, nodes []*User, init func(*User), assign func(*User, *Group)) error { - edgeIDs := make([]driver.Value, len(nodes)) - byID := make(map[int]*User) - nids := make(map[int]map[*User]struct{}) - for i, node := range nodes { - edgeIDs[i] = node.ID - byID[node.ID] = node - if init != nil { - init(node) - } - } - query.Where(func(s *sql.Selector) { - joinT := sql.Table(user.GroupTable) - s.Join(joinT).On(s.C(group.FieldID), joinT.C(user.GroupPrimaryKey[1])) - s.Where(sql.InValues(joinT.C(user.GroupPrimaryKey[0]), edgeIDs...)) - columns := s.SelectedColumns() - s.Select(joinT.C(user.GroupPrimaryKey[0])) - s.AppendSelect(columns...) - s.SetDistinct(false) - }) - if err := query.prepareQuery(ctx); err != nil { - return err - } - qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) { - return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) { - assign := spec.Assign - values := spec.ScanValues - spec.ScanValues = func(columns []string) ([]any, error) { - values, err := values(columns[1:]) - if err != nil { - return nil, err - } - return append([]any{new(sql.NullInt64)}, values...), nil - } - spec.Assign = func(columns []string, values []any) error { - outValue := int(values[0].(*sql.NullInt64).Int64) - inValue := int(values[1].(*sql.NullInt64).Int64) - if nids[inValue] == nil { - nids[inValue] = map[*User]struct{}{byID[outValue]: {}} - return assign(columns[1:], values[1:]) - } - nids[inValue][byID[outValue]] = struct{}{} - return nil - } - }) - }) - neighbors, err := withInterceptors[[]*Group](ctx, query, qr, query.inters) - if err != nil { - return err - } - for _, n := range neighbors { - nodes, ok := nids[n.ID] - if !ok { - return fmt.Errorf(`unexpected "group" node returned %v`, n.ID) - } - for kn := range nodes { - assign(kn, n) - } - } - return nil -} - -func (_q *UserQuery) sqlCount(ctx context.Context) (int, error) { +func (_q *GeneralQueueStateQuery) sqlCount(ctx context.Context) (int, error) { _spec := _q.querySpec() _spec.Node.Columns = _q.ctx.Fields if len(_q.ctx.Fields) > 0 { @@ -474,8 +364,8 @@ func (_q *UserQuery) sqlCount(ctx context.Context) (int, error) { return sqlgraph.CountNodes(ctx, _q.driver, _spec) } -func (_q *UserQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt)) +func (_q *GeneralQueueStateQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(generalqueuestate.Table, generalqueuestate.Columns, sqlgraph.NewFieldSpec(generalqueuestate.FieldID, field.TypeInt)) _spec.From = _q.sql if unique := _q.ctx.Unique; unique != nil { _spec.Unique = *unique @@ -484,9 +374,9 @@ func (_q *UserQuery) querySpec() *sqlgraph.QuerySpec { } if fields := _q.ctx.Fields; len(fields) > 0 { _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, user.FieldID) + _spec.Node.Columns = append(_spec.Node.Columns, generalqueuestate.FieldID) for i := range fields { - if fields[i] != user.FieldID { + if fields[i] != generalqueuestate.FieldID { _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) } } @@ -514,12 +404,12 @@ func (_q *UserQuery) querySpec() *sqlgraph.QuerySpec { return _spec } -func (_q *UserQuery) sqlQuery(ctx context.Context) *sql.Selector { +func (_q *GeneralQueueStateQuery) sqlQuery(ctx context.Context) *sql.Selector { builder := sql.Dialect(_q.driver.Dialect()) - t1 := builder.Table(user.Table) + t1 := builder.Table(generalqueuestate.Table) columns := _q.ctx.Fields if len(columns) == 0 { - columns = user.Columns + columns = generalqueuestate.Columns } selector := builder.Select(t1.Columns(columns...)...).From(t1) if _q.sql != nil { @@ -546,28 +436,28 @@ func (_q *UserQuery) sqlQuery(ctx context.Context) *sql.Selector { return selector } -// UserGroupBy is the group-by builder for User entities. -type UserGroupBy struct { +// GeneralQueueStateGroupBy is the group-by builder for GeneralQueueState entities. +type GeneralQueueStateGroupBy struct { selector - build *UserQuery + build *GeneralQueueStateQuery } // Aggregate adds the given aggregation functions to the group-by query. -func (_g *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy { +func (_g *GeneralQueueStateGroupBy) Aggregate(fns ...AggregateFunc) *GeneralQueueStateGroupBy { _g.fns = append(_g.fns, fns...) return _g } // Scan applies the selector query and scans the result into the given value. -func (_g *UserGroupBy) Scan(ctx context.Context, v any) error { +func (_g *GeneralQueueStateGroupBy) Scan(ctx context.Context, v any) error { ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) if err := _g.build.prepareQuery(ctx); err != nil { return err } - return scanWithInterceptors[*UserQuery, *UserGroupBy](ctx, _g.build, _g, _g.build.inters, v) + return scanWithInterceptors[*GeneralQueueStateQuery, *GeneralQueueStateGroupBy](ctx, _g.build, _g, _g.build.inters, v) } -func (_g *UserGroupBy) sqlScan(ctx context.Context, root *UserQuery, v any) error { +func (_g *GeneralQueueStateGroupBy) sqlScan(ctx context.Context, root *GeneralQueueStateQuery, v any) error { selector := root.sqlQuery(ctx).Select() aggregation := make([]string, 0, len(_g.fns)) for _, fn := range _g.fns { @@ -594,28 +484,28 @@ func (_g *UserGroupBy) sqlScan(ctx context.Context, root *UserQuery, v any) erro return sql.ScanSlice(rows, v) } -// UserSelect is the builder for selecting fields of User entities. -type UserSelect struct { - *UserQuery +// GeneralQueueStateSelect is the builder for selecting fields of GeneralQueueState entities. +type GeneralQueueStateSelect struct { + *GeneralQueueStateQuery selector } // Aggregate adds the given aggregation functions to the selector query. -func (_s *UserSelect) Aggregate(fns ...AggregateFunc) *UserSelect { +func (_s *GeneralQueueStateSelect) Aggregate(fns ...AggregateFunc) *GeneralQueueStateSelect { _s.fns = append(_s.fns, fns...) return _s } // Scan applies the selector query and scans the result into the given value. -func (_s *UserSelect) Scan(ctx context.Context, v any) error { +func (_s *GeneralQueueStateSelect) Scan(ctx context.Context, v any) error { ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) if err := _s.prepareQuery(ctx); err != nil { return err } - return scanWithInterceptors[*UserQuery, *UserSelect](ctx, _s.UserQuery, _s, _s.inters, v) + return scanWithInterceptors[*GeneralQueueStateQuery, *GeneralQueueStateSelect](ctx, _s.GeneralQueueStateQuery, _s, _s.inters, v) } -func (_s *UserSelect) sqlScan(ctx context.Context, root *UserQuery, v any) error { +func (_s *GeneralQueueStateSelect) sqlScan(ctx context.Context, root *GeneralQueueStateQuery, v any) error { selector := root.sqlQuery(ctx) aggregation := make([]string, 0, len(_s.fns)) for _, fn := range _s.fns { diff --git a/schema/ent/generalqueuestate_update.go b/schema/ent/generalqueuestate_update.go new file mode 100644 index 0000000..bed94fe --- /dev/null +++ b/schema/ent/generalqueuestate_update.go @@ -0,0 +1,244 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "git.gorlug.de/code/ersteller/schema/ent/generalqueuestate" + "git.gorlug.de/code/ersteller/schema/ent/predicate" +) + +// GeneralQueueStateUpdate is the builder for updating GeneralQueueState entities. +type GeneralQueueStateUpdate struct { + config + hooks []Hook + mutation *GeneralQueueStateMutation +} + +// Where appends a list predicates to the GeneralQueueStateUpdate builder. +func (_u *GeneralQueueStateUpdate) Where(ps ...predicate.GeneralQueueState) *GeneralQueueStateUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetRunning sets the "running" field. +func (_u *GeneralQueueStateUpdate) SetRunning(v bool) *GeneralQueueStateUpdate { + _u.mutation.SetRunning(v) + return _u +} + +// SetNillableRunning sets the "running" field if the given value is not nil. +func (_u *GeneralQueueStateUpdate) SetNillableRunning(v *bool) *GeneralQueueStateUpdate { + if v != nil { + _u.SetRunning(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *GeneralQueueStateUpdate) SetUpdatedAt(v time.Time) *GeneralQueueStateUpdate { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_u *GeneralQueueStateUpdate) SetNillableUpdatedAt(v *time.Time) *GeneralQueueStateUpdate { + if v != nil { + _u.SetUpdatedAt(*v) + } + return _u +} + +// Mutation returns the GeneralQueueStateMutation object of the builder. +func (_u *GeneralQueueStateUpdate) Mutation() *GeneralQueueStateMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *GeneralQueueStateUpdate) Save(ctx context.Context) (int, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *GeneralQueueStateUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *GeneralQueueStateUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *GeneralQueueStateUpdate) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +func (_u *GeneralQueueStateUpdate) sqlSave(ctx context.Context) (_node int, err error) { + _spec := sqlgraph.NewUpdateSpec(generalqueuestate.Table, generalqueuestate.Columns, sqlgraph.NewFieldSpec(generalqueuestate.FieldID, field.TypeInt)) + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Running(); ok { + _spec.SetField(generalqueuestate.FieldRunning, field.TypeBool, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(generalqueuestate.FieldUpdatedAt, field.TypeTime, value) + } + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{generalqueuestate.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// GeneralQueueStateUpdateOne is the builder for updating a single GeneralQueueState entity. +type GeneralQueueStateUpdateOne struct { + config + fields []string + hooks []Hook + mutation *GeneralQueueStateMutation +} + +// SetRunning sets the "running" field. +func (_u *GeneralQueueStateUpdateOne) SetRunning(v bool) *GeneralQueueStateUpdateOne { + _u.mutation.SetRunning(v) + return _u +} + +// SetNillableRunning sets the "running" field if the given value is not nil. +func (_u *GeneralQueueStateUpdateOne) SetNillableRunning(v *bool) *GeneralQueueStateUpdateOne { + if v != nil { + _u.SetRunning(*v) + } + return _u +} + +// SetUpdatedAt sets the "updated_at" field. +func (_u *GeneralQueueStateUpdateOne) SetUpdatedAt(v time.Time) *GeneralQueueStateUpdateOne { + _u.mutation.SetUpdatedAt(v) + return _u +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (_u *GeneralQueueStateUpdateOne) SetNillableUpdatedAt(v *time.Time) *GeneralQueueStateUpdateOne { + if v != nil { + _u.SetUpdatedAt(*v) + } + return _u +} + +// Mutation returns the GeneralQueueStateMutation object of the builder. +func (_u *GeneralQueueStateUpdateOne) Mutation() *GeneralQueueStateMutation { + return _u.mutation +} + +// Where appends a list predicates to the GeneralQueueStateUpdate builder. +func (_u *GeneralQueueStateUpdateOne) Where(ps ...predicate.GeneralQueueState) *GeneralQueueStateUpdateOne { + _u.mutation.Where(ps...) + return _u +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (_u *GeneralQueueStateUpdateOne) Select(field string, fields ...string) *GeneralQueueStateUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated GeneralQueueState entity. +func (_u *GeneralQueueStateUpdateOne) Save(ctx context.Context) (*GeneralQueueState, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *GeneralQueueStateUpdateOne) SaveX(ctx context.Context) *GeneralQueueState { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *GeneralQueueStateUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *GeneralQueueStateUpdateOne) ExecX(ctx context.Context) { + if err := _u.Exec(ctx); err != nil { + panic(err) + } +} + +func (_u *GeneralQueueStateUpdateOne) sqlSave(ctx context.Context) (_node *GeneralQueueState, err error) { + _spec := sqlgraph.NewUpdateSpec(generalqueuestate.Table, generalqueuestate.Columns, sqlgraph.NewFieldSpec(generalqueuestate.FieldID, field.TypeInt)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "GeneralQueueState.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := _u.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, generalqueuestate.FieldID) + for _, f := range fields { + if !generalqueuestate.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != generalqueuestate.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := _u.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := _u.mutation.Running(); ok { + _spec.SetField(generalqueuestate.FieldRunning, field.TypeBool, value) + } + if value, ok := _u.mutation.UpdatedAt(); ok { + _spec.SetField(generalqueuestate.FieldUpdatedAt, field.TypeTime, value) + } + _node = &GeneralQueueState{config: _u.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{generalqueuestate.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/schema/ent/example/ent/hook/hook.go b/schema/ent/hook/hook.go similarity index 81% rename from schema/ent/example/ent/hook/hook.go rename to schema/ent/hook/hook.go index 489867c..e8cfbf0 100644 --- a/schema/ent/example/ent/hook/hook.go +++ b/schema/ent/hook/hook.go @@ -5,43 +5,32 @@ package hook import ( "context" "fmt" - "git.gorlug.de/code/ersteller/schema/ent/example/ent" + + "git.gorlug.de/code/ersteller/schema/ent" ) -// The GroupFunc type is an adapter to allow the use of ordinary -// function as Group mutator. -type GroupFunc func(context.Context, *ent.GroupMutation) (ent.Value, error) +// The GeneralQueueFunc type is an adapter to allow the use of ordinary +// function as GeneralQueue mutator. +type GeneralQueueFunc func(context.Context, *ent.GeneralQueueMutation) (ent.Value, error) // Mutate calls f(ctx, m). -func (f GroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if mv, ok := m.(*ent.GroupMutation); ok { +func (f GeneralQueueFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.GeneralQueueMutation); ok { return f(ctx, mv) } - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GroupMutation", m) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GeneralQueueMutation", m) } -// The TodoFunc type is an adapter to allow the use of ordinary -// function as Todo mutator. -type TodoFunc func(context.Context, *ent.TodoMutation) (ent.Value, error) +// The GeneralQueueStateFunc type is an adapter to allow the use of ordinary +// function as GeneralQueueState mutator. +type GeneralQueueStateFunc func(context.Context, *ent.GeneralQueueStateMutation) (ent.Value, error) // Mutate calls f(ctx, m). -func (f TodoFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if mv, ok := m.(*ent.TodoMutation); ok { +func (f GeneralQueueStateFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.GeneralQueueStateMutation); ok { return f(ctx, mv) } - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TodoMutation", m) -} - -// The UserFunc type is an adapter to allow the use of ordinary -// function as User mutator. -type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f UserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if mv, ok := m.(*ent.UserMutation); ok { - return f(ctx, mv) - } - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m) + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.GeneralQueueStateMutation", m) } // Condition is a hook condition function. diff --git a/schema/ent/example/ent/migrate/migrate.go b/schema/ent/migrate/migrate.go similarity index 100% rename from schema/ent/example/ent/migrate/migrate.go rename to schema/ent/migrate/migrate.go diff --git a/schema/ent/migrate/schema.go b/schema/ent/migrate/schema.go new file mode 100644 index 0000000..234afe0 --- /dev/null +++ b/schema/ent/migrate/schema.go @@ -0,0 +1,60 @@ +// Code generated by ent, DO NOT EDIT. + +package migrate + +import ( + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/dialect/sql/schema" + "entgo.io/ent/schema/field" +) + +var ( + // GeneralQueueColumns holds the columns for the "generalQueue" table. + GeneralQueueColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "name", Type: field.TypeString}, + {Name: "payload", Type: field.TypeJSON}, + {Name: "status", Type: field.TypeEnum, Enums: []string{"pending", "in_progress", "completed", "failed"}}, + {Name: "number_of_tries", Type: field.TypeInt, Default: 0}, + {Name: "max_retries", Type: field.TypeInt, Default: 3}, + {Name: "error_message", Type: field.TypeString, Nullable: true}, + {Name: "failure_payload", Type: field.TypeJSON, Nullable: true}, + {Name: "result_payload", Type: field.TypeJSON, Nullable: true}, + {Name: "created_at", Type: field.TypeTime}, + {Name: "updated_at", Type: field.TypeTime}, + {Name: "processed_at", Type: field.TypeTime, Nullable: true}, + } + // GeneralQueueTable holds the schema information for the "generalQueue" table. + GeneralQueueTable = &schema.Table{ + Name: "generalQueue", + Columns: GeneralQueueColumns, + PrimaryKey: []*schema.Column{GeneralQueueColumns[0]}, + } + // GeneralQueueStateColumns holds the columns for the "generalQueueState" table. + GeneralQueueStateColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "name", Type: field.TypeString, Unique: true}, + {Name: "running", Type: field.TypeBool, Default: false}, + {Name: "updated_at", Type: field.TypeTime}, + } + // GeneralQueueStateTable holds the schema information for the "generalQueueState" table. + GeneralQueueStateTable = &schema.Table{ + Name: "generalQueueState", + Columns: GeneralQueueStateColumns, + PrimaryKey: []*schema.Column{GeneralQueueStateColumns[0]}, + } + // Tables holds all the tables in the schema. + Tables = []*schema.Table{ + GeneralQueueTable, + GeneralQueueStateTable, + } +) + +func init() { + GeneralQueueTable.Annotation = &entsql.Annotation{ + Table: "generalQueue", + } + GeneralQueueStateTable.Annotation = &entsql.Annotation{ + Table: "generalQueueState", + } +} diff --git a/schema/ent/mutation.go b/schema/ent/mutation.go new file mode 100644 index 0000000..f220339 --- /dev/null +++ b/schema/ent/mutation.go @@ -0,0 +1,1478 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "sync" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "git.gorlug.de/code/ersteller/schema/ent/generalqueue" + "git.gorlug.de/code/ersteller/schema/ent/generalqueuestate" + "git.gorlug.de/code/ersteller/schema/ent/predicate" +) + +const ( + // Operation types. + OpCreate = ent.OpCreate + OpDelete = ent.OpDelete + OpDeleteOne = ent.OpDeleteOne + OpUpdate = ent.OpUpdate + OpUpdateOne = ent.OpUpdateOne + + // Node types. + TypeGeneralQueue = "GeneralQueue" + TypeGeneralQueueState = "GeneralQueueState" +) + +// GeneralQueueMutation represents an operation that mutates the GeneralQueue nodes in the graph. +type GeneralQueueMutation struct { + config + op Op + typ string + id *int + name *string + payload *map[string]interface{} + status *generalqueue.Status + number_of_tries *int + addnumber_of_tries *int + max_retries *int + addmax_retries *int + error_message *string + failure_payload *map[string]interface{} + result_payload *map[string]interface{} + created_at *time.Time + updated_at *time.Time + processed_at *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*GeneralQueue, error) + predicates []predicate.GeneralQueue +} + +var _ ent.Mutation = (*GeneralQueueMutation)(nil) + +// generalqueueOption allows management of the mutation configuration using functional options. +type generalqueueOption func(*GeneralQueueMutation) + +// newGeneralQueueMutation creates new mutation for the GeneralQueue entity. +func newGeneralQueueMutation(c config, op Op, opts ...generalqueueOption) *GeneralQueueMutation { + m := &GeneralQueueMutation{ + config: c, + op: op, + typ: TypeGeneralQueue, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withGeneralQueueID sets the ID field of the mutation. +func withGeneralQueueID(id int) generalqueueOption { + return func(m *GeneralQueueMutation) { + var ( + err error + once sync.Once + value *GeneralQueue + ) + m.oldValue = func(ctx context.Context) (*GeneralQueue, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().GeneralQueue.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withGeneralQueue sets the old GeneralQueue of the mutation. +func withGeneralQueue(node *GeneralQueue) generalqueueOption { + return func(m *GeneralQueueMutation) { + m.oldValue = func(context.Context) (*GeneralQueue, 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 GeneralQueueMutation) 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 GeneralQueueMutation) 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 *GeneralQueueMutation) 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 *GeneralQueueMutation) 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().GeneralQueue.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetName sets the "name" field. +func (m *GeneralQueueMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *GeneralQueueMutation) 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 GeneralQueue entity. +// If the GeneralQueue 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 *GeneralQueueMutation) 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 *GeneralQueueMutation) ResetName() { + m.name = nil +} + +// SetPayload sets the "payload" field. +func (m *GeneralQueueMutation) SetPayload(value map[string]interface{}) { + m.payload = &value +} + +// Payload returns the value of the "payload" field in the mutation. +func (m *GeneralQueueMutation) Payload() (r map[string]interface{}, exists bool) { + v := m.payload + if v == nil { + return + } + return *v, true +} + +// OldPayload returns the old "payload" field's value of the GeneralQueue entity. +// If the GeneralQueue 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 *GeneralQueueMutation) OldPayload(ctx context.Context) (v map[string]interface{}, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPayload is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPayload requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPayload: %w", err) + } + return oldValue.Payload, nil +} + +// ResetPayload resets all changes to the "payload" field. +func (m *GeneralQueueMutation) ResetPayload() { + m.payload = nil +} + +// SetStatus sets the "status" field. +func (m *GeneralQueueMutation) SetStatus(ge generalqueue.Status) { + m.status = &ge +} + +// Status returns the value of the "status" field in the mutation. +func (m *GeneralQueueMutation) Status() (r generalqueue.Status, exists bool) { + v := m.status + if v == nil { + return + } + return *v, true +} + +// OldStatus returns the old "status" field's value of the GeneralQueue entity. +// If the GeneralQueue 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 *GeneralQueueMutation) OldStatus(ctx context.Context) (v generalqueue.Status, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldStatus is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldStatus requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldStatus: %w", err) + } + return oldValue.Status, nil +} + +// ResetStatus resets all changes to the "status" field. +func (m *GeneralQueueMutation) ResetStatus() { + m.status = nil +} + +// SetNumberOfTries sets the "number_of_tries" field. +func (m *GeneralQueueMutation) SetNumberOfTries(i int) { + m.number_of_tries = &i + m.addnumber_of_tries = nil +} + +// NumberOfTries returns the value of the "number_of_tries" field in the mutation. +func (m *GeneralQueueMutation) NumberOfTries() (r int, exists bool) { + v := m.number_of_tries + if v == nil { + return + } + return *v, true +} + +// OldNumberOfTries returns the old "number_of_tries" field's value of the GeneralQueue entity. +// If the GeneralQueue 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 *GeneralQueueMutation) OldNumberOfTries(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldNumberOfTries is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldNumberOfTries requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldNumberOfTries: %w", err) + } + return oldValue.NumberOfTries, nil +} + +// AddNumberOfTries adds i to the "number_of_tries" field. +func (m *GeneralQueueMutation) AddNumberOfTries(i int) { + if m.addnumber_of_tries != nil { + *m.addnumber_of_tries += i + } else { + m.addnumber_of_tries = &i + } +} + +// AddedNumberOfTries returns the value that was added to the "number_of_tries" field in this mutation. +func (m *GeneralQueueMutation) AddedNumberOfTries() (r int, exists bool) { + v := m.addnumber_of_tries + if v == nil { + return + } + return *v, true +} + +// ResetNumberOfTries resets all changes to the "number_of_tries" field. +func (m *GeneralQueueMutation) ResetNumberOfTries() { + m.number_of_tries = nil + m.addnumber_of_tries = nil +} + +// SetMaxRetries sets the "max_retries" field. +func (m *GeneralQueueMutation) SetMaxRetries(i int) { + m.max_retries = &i + m.addmax_retries = nil +} + +// MaxRetries returns the value of the "max_retries" field in the mutation. +func (m *GeneralQueueMutation) MaxRetries() (r int, exists bool) { + v := m.max_retries + if v == nil { + return + } + return *v, true +} + +// OldMaxRetries returns the old "max_retries" field's value of the GeneralQueue entity. +// If the GeneralQueue 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 *GeneralQueueMutation) OldMaxRetries(ctx context.Context) (v int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldMaxRetries is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldMaxRetries requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldMaxRetries: %w", err) + } + return oldValue.MaxRetries, nil +} + +// AddMaxRetries adds i to the "max_retries" field. +func (m *GeneralQueueMutation) AddMaxRetries(i int) { + if m.addmax_retries != nil { + *m.addmax_retries += i + } else { + m.addmax_retries = &i + } +} + +// AddedMaxRetries returns the value that was added to the "max_retries" field in this mutation. +func (m *GeneralQueueMutation) AddedMaxRetries() (r int, exists bool) { + v := m.addmax_retries + if v == nil { + return + } + return *v, true +} + +// ResetMaxRetries resets all changes to the "max_retries" field. +func (m *GeneralQueueMutation) ResetMaxRetries() { + m.max_retries = nil + m.addmax_retries = nil +} + +// SetErrorMessage sets the "error_message" field. +func (m *GeneralQueueMutation) SetErrorMessage(s string) { + m.error_message = &s +} + +// ErrorMessage returns the value of the "error_message" field in the mutation. +func (m *GeneralQueueMutation) ErrorMessage() (r string, exists bool) { + v := m.error_message + if v == nil { + return + } + return *v, true +} + +// OldErrorMessage returns the old "error_message" field's value of the GeneralQueue entity. +// If the GeneralQueue 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 *GeneralQueueMutation) OldErrorMessage(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldErrorMessage is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldErrorMessage requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldErrorMessage: %w", err) + } + return oldValue.ErrorMessage, nil +} + +// ClearErrorMessage clears the value of the "error_message" field. +func (m *GeneralQueueMutation) ClearErrorMessage() { + m.error_message = nil + m.clearedFields[generalqueue.FieldErrorMessage] = struct{}{} +} + +// ErrorMessageCleared returns if the "error_message" field was cleared in this mutation. +func (m *GeneralQueueMutation) ErrorMessageCleared() bool { + _, ok := m.clearedFields[generalqueue.FieldErrorMessage] + return ok +} + +// ResetErrorMessage resets all changes to the "error_message" field. +func (m *GeneralQueueMutation) ResetErrorMessage() { + m.error_message = nil + delete(m.clearedFields, generalqueue.FieldErrorMessage) +} + +// SetFailurePayload sets the "failure_payload" field. +func (m *GeneralQueueMutation) SetFailurePayload(value map[string]interface{}) { + m.failure_payload = &value +} + +// FailurePayload returns the value of the "failure_payload" field in the mutation. +func (m *GeneralQueueMutation) FailurePayload() (r map[string]interface{}, exists bool) { + v := m.failure_payload + if v == nil { + return + } + return *v, true +} + +// OldFailurePayload returns the old "failure_payload" field's value of the GeneralQueue entity. +// If the GeneralQueue 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 *GeneralQueueMutation) OldFailurePayload(ctx context.Context) (v map[string]interface{}, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldFailurePayload is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldFailurePayload requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldFailurePayload: %w", err) + } + return oldValue.FailurePayload, nil +} + +// ClearFailurePayload clears the value of the "failure_payload" field. +func (m *GeneralQueueMutation) ClearFailurePayload() { + m.failure_payload = nil + m.clearedFields[generalqueue.FieldFailurePayload] = struct{}{} +} + +// FailurePayloadCleared returns if the "failure_payload" field was cleared in this mutation. +func (m *GeneralQueueMutation) FailurePayloadCleared() bool { + _, ok := m.clearedFields[generalqueue.FieldFailurePayload] + return ok +} + +// ResetFailurePayload resets all changes to the "failure_payload" field. +func (m *GeneralQueueMutation) ResetFailurePayload() { + m.failure_payload = nil + delete(m.clearedFields, generalqueue.FieldFailurePayload) +} + +// SetResultPayload sets the "result_payload" field. +func (m *GeneralQueueMutation) SetResultPayload(value map[string]interface{}) { + m.result_payload = &value +} + +// ResultPayload returns the value of the "result_payload" field in the mutation. +func (m *GeneralQueueMutation) ResultPayload() (r map[string]interface{}, exists bool) { + v := m.result_payload + if v == nil { + return + } + return *v, true +} + +// OldResultPayload returns the old "result_payload" field's value of the GeneralQueue entity. +// If the GeneralQueue 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 *GeneralQueueMutation) OldResultPayload(ctx context.Context) (v map[string]interface{}, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldResultPayload is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldResultPayload requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldResultPayload: %w", err) + } + return oldValue.ResultPayload, nil +} + +// ClearResultPayload clears the value of the "result_payload" field. +func (m *GeneralQueueMutation) ClearResultPayload() { + m.result_payload = nil + m.clearedFields[generalqueue.FieldResultPayload] = struct{}{} +} + +// ResultPayloadCleared returns if the "result_payload" field was cleared in this mutation. +func (m *GeneralQueueMutation) ResultPayloadCleared() bool { + _, ok := m.clearedFields[generalqueue.FieldResultPayload] + return ok +} + +// ResetResultPayload resets all changes to the "result_payload" field. +func (m *GeneralQueueMutation) ResetResultPayload() { + m.result_payload = nil + delete(m.clearedFields, generalqueue.FieldResultPayload) +} + +// SetCreatedAt sets the "created_at" field. +func (m *GeneralQueueMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *GeneralQueueMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the GeneralQueue entity. +// If the GeneralQueue 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 *GeneralQueueMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *GeneralQueueMutation) ResetCreatedAt() { + m.created_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *GeneralQueueMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *GeneralQueueMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the GeneralQueue entity. +// If the GeneralQueue 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 *GeneralQueueMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *GeneralQueueMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// SetProcessedAt sets the "processed_at" field. +func (m *GeneralQueueMutation) SetProcessedAt(t time.Time) { + m.processed_at = &t +} + +// ProcessedAt returns the value of the "processed_at" field in the mutation. +func (m *GeneralQueueMutation) ProcessedAt() (r time.Time, exists bool) { + v := m.processed_at + if v == nil { + return + } + return *v, true +} + +// OldProcessedAt returns the old "processed_at" field's value of the GeneralQueue entity. +// If the GeneralQueue 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 *GeneralQueueMutation) OldProcessedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldProcessedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldProcessedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldProcessedAt: %w", err) + } + return oldValue.ProcessedAt, nil +} + +// ClearProcessedAt clears the value of the "processed_at" field. +func (m *GeneralQueueMutation) ClearProcessedAt() { + m.processed_at = nil + m.clearedFields[generalqueue.FieldProcessedAt] = struct{}{} +} + +// ProcessedAtCleared returns if the "processed_at" field was cleared in this mutation. +func (m *GeneralQueueMutation) ProcessedAtCleared() bool { + _, ok := m.clearedFields[generalqueue.FieldProcessedAt] + return ok +} + +// ResetProcessedAt resets all changes to the "processed_at" field. +func (m *GeneralQueueMutation) ResetProcessedAt() { + m.processed_at = nil + delete(m.clearedFields, generalqueue.FieldProcessedAt) +} + +// Where appends a list predicates to the GeneralQueueMutation builder. +func (m *GeneralQueueMutation) Where(ps ...predicate.GeneralQueue) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the GeneralQueueMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *GeneralQueueMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.GeneralQueue, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *GeneralQueueMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *GeneralQueueMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (GeneralQueue). +func (m *GeneralQueueMutation) 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 *GeneralQueueMutation) Fields() []string { + fields := make([]string, 0, 11) + if m.name != nil { + fields = append(fields, generalqueue.FieldName) + } + if m.payload != nil { + fields = append(fields, generalqueue.FieldPayload) + } + if m.status != nil { + fields = append(fields, generalqueue.FieldStatus) + } + if m.number_of_tries != nil { + fields = append(fields, generalqueue.FieldNumberOfTries) + } + if m.max_retries != nil { + fields = append(fields, generalqueue.FieldMaxRetries) + } + if m.error_message != nil { + fields = append(fields, generalqueue.FieldErrorMessage) + } + if m.failure_payload != nil { + fields = append(fields, generalqueue.FieldFailurePayload) + } + if m.result_payload != nil { + fields = append(fields, generalqueue.FieldResultPayload) + } + if m.created_at != nil { + fields = append(fields, generalqueue.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, generalqueue.FieldUpdatedAt) + } + if m.processed_at != nil { + fields = append(fields, generalqueue.FieldProcessedAt) + } + 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 *GeneralQueueMutation) Field(name string) (ent.Value, bool) { + switch name { + case generalqueue.FieldName: + return m.Name() + case generalqueue.FieldPayload: + return m.Payload() + case generalqueue.FieldStatus: + return m.Status() + case generalqueue.FieldNumberOfTries: + return m.NumberOfTries() + case generalqueue.FieldMaxRetries: + return m.MaxRetries() + case generalqueue.FieldErrorMessage: + return m.ErrorMessage() + case generalqueue.FieldFailurePayload: + return m.FailurePayload() + case generalqueue.FieldResultPayload: + return m.ResultPayload() + case generalqueue.FieldCreatedAt: + return m.CreatedAt() + case generalqueue.FieldUpdatedAt: + return m.UpdatedAt() + case generalqueue.FieldProcessedAt: + return m.ProcessedAt() + } + 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 *GeneralQueueMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case generalqueue.FieldName: + return m.OldName(ctx) + case generalqueue.FieldPayload: + return m.OldPayload(ctx) + case generalqueue.FieldStatus: + return m.OldStatus(ctx) + case generalqueue.FieldNumberOfTries: + return m.OldNumberOfTries(ctx) + case generalqueue.FieldMaxRetries: + return m.OldMaxRetries(ctx) + case generalqueue.FieldErrorMessage: + return m.OldErrorMessage(ctx) + case generalqueue.FieldFailurePayload: + return m.OldFailurePayload(ctx) + case generalqueue.FieldResultPayload: + return m.OldResultPayload(ctx) + case generalqueue.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case generalqueue.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + case generalqueue.FieldProcessedAt: + return m.OldProcessedAt(ctx) + } + return nil, fmt.Errorf("unknown GeneralQueue 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 *GeneralQueueMutation) SetField(name string, value ent.Value) error { + switch name { + case generalqueue.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case generalqueue.FieldPayload: + v, ok := value.(map[string]interface{}) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPayload(v) + return nil + case generalqueue.FieldStatus: + v, ok := value.(generalqueue.Status) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetStatus(v) + return nil + case generalqueue.FieldNumberOfTries: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetNumberOfTries(v) + return nil + case generalqueue.FieldMaxRetries: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetMaxRetries(v) + return nil + case generalqueue.FieldErrorMessage: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetErrorMessage(v) + return nil + case generalqueue.FieldFailurePayload: + v, ok := value.(map[string]interface{}) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetFailurePayload(v) + return nil + case generalqueue.FieldResultPayload: + v, ok := value.(map[string]interface{}) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetResultPayload(v) + return nil + case generalqueue.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case generalqueue.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + case generalqueue.FieldProcessedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetProcessedAt(v) + return nil + } + return fmt.Errorf("unknown GeneralQueue field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *GeneralQueueMutation) AddedFields() []string { + var fields []string + if m.addnumber_of_tries != nil { + fields = append(fields, generalqueue.FieldNumberOfTries) + } + if m.addmax_retries != nil { + fields = append(fields, generalqueue.FieldMaxRetries) + } + return fields +} + +// 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 *GeneralQueueMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case generalqueue.FieldNumberOfTries: + return m.AddedNumberOfTries() + case generalqueue.FieldMaxRetries: + return m.AddedMaxRetries() + } + 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 *GeneralQueueMutation) AddField(name string, value ent.Value) error { + switch name { + case generalqueue.FieldNumberOfTries: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddNumberOfTries(v) + return nil + case generalqueue.FieldMaxRetries: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddMaxRetries(v) + return nil + } + return fmt.Errorf("unknown GeneralQueue numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *GeneralQueueMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(generalqueue.FieldErrorMessage) { + fields = append(fields, generalqueue.FieldErrorMessage) + } + if m.FieldCleared(generalqueue.FieldFailurePayload) { + fields = append(fields, generalqueue.FieldFailurePayload) + } + if m.FieldCleared(generalqueue.FieldResultPayload) { + fields = append(fields, generalqueue.FieldResultPayload) + } + if m.FieldCleared(generalqueue.FieldProcessedAt) { + fields = append(fields, generalqueue.FieldProcessedAt) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *GeneralQueueMutation) 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 *GeneralQueueMutation) ClearField(name string) error { + switch name { + case generalqueue.FieldErrorMessage: + m.ClearErrorMessage() + return nil + case generalqueue.FieldFailurePayload: + m.ClearFailurePayload() + return nil + case generalqueue.FieldResultPayload: + m.ClearResultPayload() + return nil + case generalqueue.FieldProcessedAt: + m.ClearProcessedAt() + return nil + } + return fmt.Errorf("unknown GeneralQueue 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 *GeneralQueueMutation) ResetField(name string) error { + switch name { + case generalqueue.FieldName: + m.ResetName() + return nil + case generalqueue.FieldPayload: + m.ResetPayload() + return nil + case generalqueue.FieldStatus: + m.ResetStatus() + return nil + case generalqueue.FieldNumberOfTries: + m.ResetNumberOfTries() + return nil + case generalqueue.FieldMaxRetries: + m.ResetMaxRetries() + return nil + case generalqueue.FieldErrorMessage: + m.ResetErrorMessage() + return nil + case generalqueue.FieldFailurePayload: + m.ResetFailurePayload() + return nil + case generalqueue.FieldResultPayload: + m.ResetResultPayload() + return nil + case generalqueue.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case generalqueue.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + case generalqueue.FieldProcessedAt: + m.ResetProcessedAt() + return nil + } + return fmt.Errorf("unknown GeneralQueue field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *GeneralQueueMutation) 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 *GeneralQueueMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *GeneralQueueMutation) 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 *GeneralQueueMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *GeneralQueueMutation) 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 *GeneralQueueMutation) 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 *GeneralQueueMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown GeneralQueue 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 *GeneralQueueMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown GeneralQueue edge %s", name) +} + +// GeneralQueueStateMutation represents an operation that mutates the GeneralQueueState nodes in the graph. +type GeneralQueueStateMutation struct { + config + op Op + typ string + id *int + name *string + running *bool + updated_at *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*GeneralQueueState, error) + predicates []predicate.GeneralQueueState +} + +var _ ent.Mutation = (*GeneralQueueStateMutation)(nil) + +// generalqueuestateOption allows management of the mutation configuration using functional options. +type generalqueuestateOption func(*GeneralQueueStateMutation) + +// newGeneralQueueStateMutation creates new mutation for the GeneralQueueState entity. +func newGeneralQueueStateMutation(c config, op Op, opts ...generalqueuestateOption) *GeneralQueueStateMutation { + m := &GeneralQueueStateMutation{ + config: c, + op: op, + typ: TypeGeneralQueueState, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withGeneralQueueStateID sets the ID field of the mutation. +func withGeneralQueueStateID(id int) generalqueuestateOption { + return func(m *GeneralQueueStateMutation) { + var ( + err error + once sync.Once + value *GeneralQueueState + ) + m.oldValue = func(ctx context.Context) (*GeneralQueueState, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().GeneralQueueState.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withGeneralQueueState sets the old GeneralQueueState of the mutation. +func withGeneralQueueState(node *GeneralQueueState) generalqueuestateOption { + return func(m *GeneralQueueStateMutation) { + m.oldValue = func(context.Context) (*GeneralQueueState, 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 GeneralQueueStateMutation) 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 GeneralQueueStateMutation) 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 *GeneralQueueStateMutation) 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 *GeneralQueueStateMutation) 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().GeneralQueueState.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetName sets the "name" field. +func (m *GeneralQueueStateMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *GeneralQueueStateMutation) 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 GeneralQueueState entity. +// If the GeneralQueueState 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 *GeneralQueueStateMutation) 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 *GeneralQueueStateMutation) ResetName() { + m.name = nil +} + +// SetRunning sets the "running" field. +func (m *GeneralQueueStateMutation) SetRunning(b bool) { + m.running = &b +} + +// Running returns the value of the "running" field in the mutation. +func (m *GeneralQueueStateMutation) Running() (r bool, exists bool) { + v := m.running + if v == nil { + return + } + return *v, true +} + +// OldRunning returns the old "running" field's value of the GeneralQueueState entity. +// If the GeneralQueueState 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 *GeneralQueueStateMutation) OldRunning(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldRunning is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldRunning requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldRunning: %w", err) + } + return oldValue.Running, nil +} + +// ResetRunning resets all changes to the "running" field. +func (m *GeneralQueueStateMutation) ResetRunning() { + m.running = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *GeneralQueueStateMutation) SetUpdatedAt(t time.Time) { + m.updated_at = &t +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *GeneralQueueStateMutation) UpdatedAt() (r time.Time, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the GeneralQueueState entity. +// If the GeneralQueueState 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 *GeneralQueueStateMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *GeneralQueueStateMutation) ResetUpdatedAt() { + m.updated_at = nil +} + +// Where appends a list predicates to the GeneralQueueStateMutation builder. +func (m *GeneralQueueStateMutation) Where(ps ...predicate.GeneralQueueState) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the GeneralQueueStateMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *GeneralQueueStateMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.GeneralQueueState, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *GeneralQueueStateMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *GeneralQueueStateMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (GeneralQueueState). +func (m *GeneralQueueStateMutation) 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 *GeneralQueueStateMutation) Fields() []string { + fields := make([]string, 0, 3) + if m.name != nil { + fields = append(fields, generalqueuestate.FieldName) + } + if m.running != nil { + fields = append(fields, generalqueuestate.FieldRunning) + } + if m.updated_at != nil { + fields = append(fields, generalqueuestate.FieldUpdatedAt) + } + 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 *GeneralQueueStateMutation) Field(name string) (ent.Value, bool) { + switch name { + case generalqueuestate.FieldName: + return m.Name() + case generalqueuestate.FieldRunning: + return m.Running() + case generalqueuestate.FieldUpdatedAt: + return m.UpdatedAt() + } + 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 *GeneralQueueStateMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case generalqueuestate.FieldName: + return m.OldName(ctx) + case generalqueuestate.FieldRunning: + return m.OldRunning(ctx) + case generalqueuestate.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown GeneralQueueState 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 *GeneralQueueStateMutation) SetField(name string, value ent.Value) error { + switch name { + case generalqueuestate.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case generalqueuestate.FieldRunning: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetRunning(v) + return nil + case generalqueuestate.FieldUpdatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown GeneralQueueState field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *GeneralQueueStateMutation) 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 *GeneralQueueStateMutation) 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 *GeneralQueueStateMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown GeneralQueueState numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *GeneralQueueStateMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *GeneralQueueStateMutation) 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 *GeneralQueueStateMutation) ClearField(name string) error { + return fmt.Errorf("unknown GeneralQueueState 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 *GeneralQueueStateMutation) ResetField(name string) error { + switch name { + case generalqueuestate.FieldName: + m.ResetName() + return nil + case generalqueuestate.FieldRunning: + m.ResetRunning() + return nil + case generalqueuestate.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown GeneralQueueState field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *GeneralQueueStateMutation) 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 *GeneralQueueStateMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *GeneralQueueStateMutation) 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 *GeneralQueueStateMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *GeneralQueueStateMutation) 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 *GeneralQueueStateMutation) 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 *GeneralQueueStateMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown GeneralQueueState 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 *GeneralQueueStateMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown GeneralQueueState edge %s", name) +} diff --git a/schema/ent/example/ent/pagination_query.go b/schema/ent/pagination_query.go similarity index 55% rename from schema/ent/example/ent/pagination_query.go rename to schema/ent/pagination_query.go index 403c434..827f884 100644 --- a/schema/ent/example/ent/pagination_query.go +++ b/schema/ent/pagination_query.go @@ -10,10 +10,10 @@ import ( "entgo.io/ent/dialect/sql" ) -// PaginateAfterID paginates Group by monotonically increasing "id". +// PaginateAfterID paginates GeneralQueue by monotonically increasing "id". // It preserves any existing filters/joins applied to the query, fetches up to "limit" items, // and returns the next cursor (last ID of this page) and whether a next page exists. -func (q *GroupQuery) PaginateAfterID(ctx context.Context, afterID, limit int) ([]*Group, int, bool, error) { +func (q *GeneralQueueQuery) PaginateAfterID(ctx context.Context, afterID, limit int) ([]*GeneralQueue, int, bool, error) { if limit <= 0 { limit = 20 } @@ -48,48 +48,10 @@ func (q *GroupQuery) PaginateAfterID(ctx context.Context, afterID, limit int) ([ return rows, next, hasNext, nil } -// PaginateAfterID paginates Todo by monotonically increasing "id". +// PaginateAfterID paginates GeneralQueueState by monotonically increasing "id". // It preserves any existing filters/joins applied to the query, fetches up to "limit" items, // and returns the next cursor (last ID of this page) and whether a next page exists. -func (q *TodoQuery) PaginateAfterID(ctx context.Context, afterID, limit int) ([]*Todo, int, bool, error) { - if limit <= 0 { - limit = 20 - } - - qq := q.Clone(). - Order(func(s *sql.Selector) { - s.OrderBy(s.C("id")) - }). - Limit(limit + 1) // fetch one extra to detect "has next" - - if afterID > 0 { - qq = qq.Where(func(s *sql.Selector) { - s.Where(sql.GT(s.C("id"), afterID)) - }) - } - - rows, err := qq.All(ctx) - if err != nil { - return nil, 0, false, err - } - - hasNext := len(rows) > limit - if hasNext { - rows = rows[:limit] - } - - next := 0 - if len(rows) > 0 { - next = rows[len(rows)-1].ID - } - - return rows, next, hasNext, nil -} - -// PaginateAfterID paginates User by monotonically increasing "id". -// It preserves any existing filters/joins applied to the query, fetches up to "limit" items, -// and returns the next cursor (last ID of this page) and whether a next page exists. -func (q *UserQuery) PaginateAfterID(ctx context.Context, afterID, limit int) ([]*User, int, bool, error) { +func (q *GeneralQueueStateQuery) PaginateAfterID(ctx context.Context, afterID, limit int) ([]*GeneralQueueState, int, bool, error) { if limit <= 0 { limit = 20 } diff --git a/schema/ent/predicate/predicate.go b/schema/ent/predicate/predicate.go new file mode 100644 index 0000000..3ca7d2b --- /dev/null +++ b/schema/ent/predicate/predicate.go @@ -0,0 +1,13 @@ +// Code generated by ent, DO NOT EDIT. + +package predicate + +import ( + "entgo.io/ent/dialect/sql" +) + +// GeneralQueue is the predicate function for generalqueue builders. +type GeneralQueue func(*sql.Selector) + +// GeneralQueueState is the predicate function for generalqueuestate builders. +type GeneralQueueState func(*sql.Selector) diff --git a/schema/ent/runtime.go b/schema/ent/runtime.go new file mode 100644 index 0000000..006d7f6 --- /dev/null +++ b/schema/ent/runtime.go @@ -0,0 +1,31 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "git.gorlug.de/code/ersteller/schema/ent/generalqueue" + "git.gorlug.de/code/ersteller/schema/ent/generalqueuestate" + "git.gorlug.de/code/ersteller/schema/ent/schema" +) + +// The init function reads all schema descriptors with runtime code +// (default values, validators, hooks and policies) and stitches it +// to their package variables. +func init() { + generalqueueFields := schema.GeneralQueue{}.Fields() + _ = generalqueueFields + // generalqueueDescNumberOfTries is the schema descriptor for number_of_tries field. + generalqueueDescNumberOfTries := generalqueueFields[3].Descriptor() + // generalqueue.DefaultNumberOfTries holds the default value on creation for the number_of_tries field. + generalqueue.DefaultNumberOfTries = generalqueueDescNumberOfTries.Default.(int) + // generalqueueDescMaxRetries is the schema descriptor for max_retries field. + generalqueueDescMaxRetries := generalqueueFields[4].Descriptor() + // generalqueue.DefaultMaxRetries holds the default value on creation for the max_retries field. + generalqueue.DefaultMaxRetries = generalqueueDescMaxRetries.Default.(int) + generalqueuestateFields := schema.GeneralQueueState{}.Fields() + _ = generalqueuestateFields + // generalqueuestateDescRunning is the schema descriptor for running field. + generalqueuestateDescRunning := generalqueuestateFields[1].Descriptor() + // generalqueuestate.DefaultRunning holds the default value on creation for the running field. + generalqueuestate.DefaultRunning = generalqueuestateDescRunning.Default.(bool) +} diff --git a/schema/ent/example/ent/runtime/runtime.go b/schema/ent/runtime/runtime.go similarity index 71% rename from schema/ent/example/ent/runtime/runtime.go rename to schema/ent/runtime/runtime.go index c9c9059..a36a234 100644 --- a/schema/ent/example/ent/runtime/runtime.go +++ b/schema/ent/runtime/runtime.go @@ -2,7 +2,7 @@ package runtime -// The schema-stitching logic is generated in ersteller-lib/schema/ent/example/ent/runtime.go +// The schema-stitching logic is generated in git.gorlug.de/code/ersteller/schema/ent/runtime.go const ( Version = "v0.14.5" // Version of ent codegen. diff --git a/schema/ent/time_mixin.go b/schema/ent/time_mixin.go index f060f49..bc74b8c 100644 --- a/schema/ent/time_mixin.go +++ b/schema/ent/time_mixin.go @@ -1,4 +1,4 @@ -package ersteller_ent +package ent import ( "time" diff --git a/schema/ent/example/ent/tx.go b/schema/ent/tx.go similarity index 93% rename from schema/ent/example/ent/tx.go rename to schema/ent/tx.go index 2d67116..0908a2a 100644 --- a/schema/ent/example/ent/tx.go +++ b/schema/ent/tx.go @@ -12,12 +12,10 @@ import ( // Tx is a transactional client that is created by calling Client.Tx(). type Tx struct { config - // Group is the client for interacting with the Group builders. - Group *GroupClient - // Todo is the client for interacting with the Todo builders. - Todo *TodoClient - // User is the client for interacting with the User builders. - User *UserClient + // GeneralQueue is the client for interacting with the GeneralQueue builders. + GeneralQueue *GeneralQueueClient + // GeneralQueueState is the client for interacting with the GeneralQueueState builders. + GeneralQueueState *GeneralQueueStateClient // lazily loaded. client *Client @@ -149,9 +147,8 @@ func (tx *Tx) Client() *Client { } func (tx *Tx) init() { - tx.Group = NewGroupClient(tx.config) - tx.Todo = NewTodoClient(tx.config) - tx.User = NewUserClient(tx.config) + tx.GeneralQueue = NewGeneralQueueClient(tx.config) + tx.GeneralQueueState = NewGeneralQueueStateClient(tx.config) } // txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation. @@ -161,7 +158,7 @@ func (tx *Tx) init() { // of them in order to commit or rollback the transaction. // // If a closed transaction is embedded in one of the generated entities, and the entity -// applies a query, for example: Group.QueryXXX(), the query will be executed +// applies a query, for example: GeneralQueue.QueryXXX(), the query will be executed // through the driver which created this transaction. // // Note that txDriver is not goroutine safe.