ent

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package ent wraps generated and non-generated ent-related code.

Index

Constants

View Source
const (
	// Operation types.
	OpCreate    = ent.OpCreate
	OpDelete    = ent.OpDelete
	OpDeleteOne = ent.OpDeleteOne
	OpUpdate    = ent.OpUpdate
	OpUpdateOne = ent.OpUpdateOne

	// Node types.
	TypeTask = "Task"
)

Variables

View Source
var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")

ErrTxStarted is returned when trying to start a new transaction from a transactional client.

Functions

func Asc

func Asc(fields ...string) func(*sql.Selector)

Asc applies the given fields in ASC order.

func Desc

func Desc(fields ...string) func(*sql.Selector)

Desc applies the given fields in DESC order.

func IsConstraintError

func IsConstraintError(err error) bool

IsConstraintError returns a boolean indicating whether the error is a constraint failure.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns a boolean indicating whether the error is a not found error.

func IsNotLoaded

func IsNotLoaded(err error) bool

IsNotLoaded returns a boolean indicating whether the error is a not loaded error.

func IsNotSingular

func IsNotSingular(err error) bool

IsNotSingular returns a boolean indicating whether the error is a not singular error.

func IsValidationError

func IsValidationError(err error) bool

IsValidationError returns a boolean indicating whether the error is a validation error.

func MaskNotFound

func MaskNotFound(err error) error

MaskNotFound masks not found error.

func NewContext

func NewContext(parent context.Context, c *Client) context.Context

NewContext returns a new context with the given Client attached.

func NewTxContext

func NewTxContext(parent context.Context, tx *Tx) context.Context

NewTxContext returns a new context with the given Tx attached.

Types

type AggregateFunc

type AggregateFunc func(*sql.Selector) string

AggregateFunc applies an aggregation step on the group-by traversal/selector.

func As

As is a pseudo aggregation function for renaming another other functions with custom names. For example:

GroupBy(field1, field2).
Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
Scan(ctx, &v)

func Count

func Count() AggregateFunc

Count applies the "count" aggregation function on each group.

func Max

func Max(field string) AggregateFunc

Max applies the "max" aggregation function on the given field of each group.

func Mean

func Mean(field string) AggregateFunc

Mean applies the "mean" aggregation function on the given field of each group.

func Min

func Min(field string) AggregateFunc

Min applies the "min" aggregation function on the given field of each group.

func Sum

func Sum(field string) AggregateFunc

Sum applies the "sum" aggregation function on the given field of each group.

type Client

type Client struct {

	// Schema is the client for creating, migrating and dropping schema.
	Schema *migrate.Schema
	// Task is the client for interacting with the Task builders.
	Task *TaskClient
	// contains filtered or unexported fields
}

Client is the client that holds all ent builders.

func FromContext

func FromContext(ctx context.Context) *Client

FromContext returns a Client stored inside a context, or nil if there isn't one.

func NewClient

func NewClient(opts ...Option) *Client

NewClient creates a new client configured with the given options.

func Open

func Open(driverName, dataSourceName string, options ...Option) (*Client, error)

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 (*Client) BeginTx

func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)

BeginTx returns a transactional client with specified options.

func (*Client) Close

func (c *Client) Close() error

Close closes the database connection and prevents new queries from starting.

func (*Client) Debug

func (c *Client) Debug() *Client

Debug returns a new debug-client. It's used to get verbose logging on specific operations.

client.Debug().
	Task.
	Query().
	Count(ctx)

func (*Client) Intercept

func (c *Client) Intercept(interceptors ...Interceptor)

Intercept adds the query interceptors to all the entity clients. In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.

func (*Client) Mutate

func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error)

Mutate implements the ent.Mutator interface.

func (*Client) Tx

func (c *Client) Tx(ctx context.Context) (*Tx, error)

Tx returns a new transactional client. The provided context is used until the transaction is committed or rolled back.

func (*Client) Use

func (c *Client) Use(hooks ...Hook)

Use adds the mutation hooks to all the entity clients. In order to add hooks to a specific client, call: `client.Node.Use(...)`.

type CommitFunc

type CommitFunc func(context.Context, *Tx) error

The CommitFunc type is an adapter to allow the use of ordinary function as a Committer. If f is a function with the appropriate signature, CommitFunc(f) is a Committer that calls f.

func (CommitFunc) Commit

func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error

Commit calls f(ctx, m).

type CommitHook

type CommitHook func(Committer) Committer

CommitHook defines the "commit middleware". A function that gets a Committer and returns a Committer. For example:

hook := func(next ent.Committer) ent.Committer {
	return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error {
		// Do some stuff before.
		if err := next.Commit(ctx, tx); err != nil {
			return err
		}
		// Do some stuff after.
		return nil
	})
}

type Committer

type Committer interface {
	Commit(context.Context, *Tx) error
}

Committer is the interface that wraps the Commit method.

type ConstraintError

type ConstraintError struct {
	// contains filtered or unexported fields
}

ConstraintError returns when trying to create/update one or more entities and one or more of their constraints failed. For example, violation of edge or field uniqueness.

func (ConstraintError) Error

func (e ConstraintError) Error() string

Error implements the error interface.

func (*ConstraintError) Unwrap

func (e *ConstraintError) Unwrap() error

Unwrap implements the errors.Wrapper interface.

type Hook

type Hook = ent.Hook

ent aliases to avoid import conflicts in user's code.

type InterceptFunc

type InterceptFunc = ent.InterceptFunc

ent aliases to avoid import conflicts in user's code.

type Interceptor

type Interceptor = ent.Interceptor

ent aliases to avoid import conflicts in user's code.

type MutateFunc

type MutateFunc = ent.MutateFunc

ent aliases to avoid import conflicts in user's code.

type Mutation

type Mutation = ent.Mutation

ent aliases to avoid import conflicts in user's code.

type Mutator

type Mutator = ent.Mutator

ent aliases to avoid import conflicts in user's code.

type NotFoundError

type NotFoundError struct {
	// contains filtered or unexported fields
}

NotFoundError returns when trying to fetch a specific entity and it was not found in the database.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

Error implements the error interface.

type NotLoadedError

type NotLoadedError struct {
	// contains filtered or unexported fields
}

NotLoadedError returns when trying to get a node that was not loaded by the query.

func (*NotLoadedError) Error

func (e *NotLoadedError) Error() string

Error implements the error interface.

type NotSingularError

type NotSingularError struct {
	// contains filtered or unexported fields
}

NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.

func (*NotSingularError) Error

func (e *NotSingularError) Error() string

Error implements the error interface.

type Op

type Op = ent.Op

ent aliases to avoid import conflicts in user's code.

type Option

type Option func(*config)

Option function to configure the client.

func Debug

func Debug() Option

Debug enables debug logging on the ent.Driver.

func Driver

func Driver(driver dialect.Driver) Option

Driver configures the client driver.

func Log

func Log(fn func(...any)) Option

Log sets the logging function for debug mode.

type OrderFunc

type OrderFunc func(*sql.Selector)

OrderFunc applies an ordering on the sql selector. Deprecated: Use Asc/Desc functions or the package builders instead.

type Policy

type Policy = ent.Policy

ent aliases to avoid import conflicts in user's code.

type Querier

type Querier = ent.Querier

ent aliases to avoid import conflicts in user's code.

type QuerierFunc

type QuerierFunc = ent.QuerierFunc

ent aliases to avoid import conflicts in user's code.

type Query

type Query = ent.Query

ent aliases to avoid import conflicts in user's code.

type QueryContext

type QueryContext = ent.QueryContext

ent aliases to avoid import conflicts in user's code.

type RollbackFunc

type RollbackFunc func(context.Context, *Tx) error

The RollbackFunc type is an adapter to allow the use of ordinary function as a Rollbacker. If f is a function with the appropriate signature, RollbackFunc(f) is a Rollbacker that calls f.

func (RollbackFunc) Rollback

func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error

Rollback calls f(ctx, m).

type RollbackHook

type RollbackHook func(Rollbacker) Rollbacker

RollbackHook defines the "rollback middleware". A function that gets a Rollbacker and returns a Rollbacker. For example:

hook := func(next ent.Rollbacker) ent.Rollbacker {
	return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error {
		// Do some stuff before.
		if err := next.Rollback(ctx, tx); err != nil {
			return err
		}
		// Do some stuff after.
		return nil
	})
}

type Rollbacker

type Rollbacker interface {
	Rollback(context.Context, *Tx) error
}

Rollbacker is the interface that wraps the Rollback method.

type Task added in v0.2.0

type Task struct {

	// ID of the ent.
	ID int `json:"id,omitempty"`
	// Title holds the value of the "title" field.
	Title string `json:"title,omitempty"`
	// contains filtered or unexported fields
}

Task is the model entity for the Task schema.

func (*Task) String added in v0.2.0

func (_m *Task) String() string

String implements the fmt.Stringer.

func (*Task) Unwrap added in v0.2.0

func (_m *Task) Unwrap() *Task

Unwrap unwraps the Task 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 (*Task) Update added in v0.2.0

func (_m *Task) Update() *TaskUpdateOne

Update returns a builder for updating this Task. Note that you need to call Task.Unwrap() before calling this method if this Task was returned from a transaction, and the transaction was committed or rolled back.

func (*Task) Value added in v0.2.0

func (_m *Task) Value(name string) (ent.Value, error)

Value returns the ent.Value that was dynamically selected and assigned to the Task. This includes values selected through modifiers, order, etc.

type TaskClient added in v0.2.0

type TaskClient struct {
	// contains filtered or unexported fields
}

TaskClient is a client for the Task schema.

func NewTaskClient added in v0.2.0

func NewTaskClient(c config) *TaskClient

NewTaskClient returns a client for the Task from the given config.

func (*TaskClient) Create added in v0.2.0

func (c *TaskClient) Create() *TaskCreate

Create returns a builder for creating a Task entity.

func (*TaskClient) CreateBulk added in v0.2.0

func (c *TaskClient) CreateBulk(builders ...*TaskCreate) *TaskCreateBulk

CreateBulk returns a builder for creating a bulk of Task entities.

func (*TaskClient) Delete added in v0.2.0

func (c *TaskClient) Delete() *TaskDelete

Delete returns a delete builder for Task.

func (*TaskClient) DeleteOne added in v0.2.0

func (c *TaskClient) DeleteOne(_m *Task) *TaskDeleteOne

DeleteOne returns a builder for deleting the given entity.

func (*TaskClient) DeleteOneID added in v0.2.0

func (c *TaskClient) DeleteOneID(id int) *TaskDeleteOne

DeleteOneID returns a builder for deleting the given entity by its id.

func (*TaskClient) Get added in v0.2.0

func (c *TaskClient) Get(ctx context.Context, id int) (*Task, error)

Get returns a Task entity by its id.

func (*TaskClient) GetX added in v0.2.0

func (c *TaskClient) GetX(ctx context.Context, id int) *Task

GetX is like Get, but panics if an error occurs.

func (*TaskClient) Hooks added in v0.2.0

func (c *TaskClient) Hooks() []Hook

Hooks returns the client hooks.

func (*TaskClient) Intercept added in v0.2.0

func (c *TaskClient) Intercept(interceptors ...Interceptor)

Intercept adds a list of query interceptors to the interceptors stack. A call to `Intercept(f, g, h)` equals to `task.Intercept(f(g(h())))`.

func (*TaskClient) Interceptors added in v0.2.0

func (c *TaskClient) Interceptors() []Interceptor

Interceptors returns the client interceptors.

func (*TaskClient) MapCreateBulk added in v0.2.0

func (c *TaskClient) MapCreateBulk(slice any, setFunc func(*TaskCreate, int)) *TaskCreateBulk

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 (*TaskClient) Query added in v0.2.0

func (c *TaskClient) Query() *TaskQuery

Query returns a query builder for Task.

func (*TaskClient) Update added in v0.2.0

func (c *TaskClient) Update() *TaskUpdate

Update returns an update builder for Task.

func (*TaskClient) UpdateOne added in v0.2.0

func (c *TaskClient) UpdateOne(_m *Task) *TaskUpdateOne

UpdateOne returns an update builder for the given entity.

func (*TaskClient) UpdateOneID added in v0.2.0

func (c *TaskClient) UpdateOneID(id int) *TaskUpdateOne

UpdateOneID returns an update builder for the given id.

func (*TaskClient) Use added in v0.2.0

func (c *TaskClient) Use(hooks ...Hook)

Use adds a list of mutation hooks to the hooks stack. A call to `Use(f, g, h)` equals to `task.Hooks(f(g(h())))`.

type TaskCreate added in v0.2.0

type TaskCreate struct {
	// contains filtered or unexported fields
}

TaskCreate is the builder for creating a Task entity.

func (*TaskCreate) Exec added in v0.2.0

func (_c *TaskCreate) Exec(ctx context.Context) error

Exec executes the query.

func (*TaskCreate) ExecX added in v0.2.0

func (_c *TaskCreate) ExecX(ctx context.Context)

ExecX is like Exec, but panics if an error occurs.

func (*TaskCreate) Mutation added in v0.2.0

func (_c *TaskCreate) Mutation() *TaskMutation

Mutation returns the TaskMutation object of the builder.

func (*TaskCreate) OnConflict added in v0.2.0

func (_c *TaskCreate) OnConflict(opts ...sql.ConflictOption) *TaskUpsertOne

OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause of the `INSERT` statement. For example:

client.Task.Create().
	SetTitle(v).
	OnConflict(
		// Update the row with the new values
		// the was proposed for insertion.
		sql.ResolveWithNewValues(),
	).
	// Override some of the fields with custom
	// update values.
	Update(func(u *ent.TaskUpsert) {
		SetTitle(v+v).
	}).
	Exec(ctx)

func (*TaskCreate) OnConflictColumns added in v0.2.0

func (_c *TaskCreate) OnConflictColumns(columns ...string) *TaskUpsertOne

OnConflictColumns calls `OnConflict` and configures the columns as conflict target. Using this option is equivalent to using:

client.Task.Create().
	OnConflict(sql.ConflictColumns(columns...)).
	Exec(ctx)

func (*TaskCreate) Save added in v0.2.0

func (_c *TaskCreate) Save(ctx context.Context) (*Task, error)

Save creates the Task in the database.

func (*TaskCreate) SaveX added in v0.2.0

func (_c *TaskCreate) SaveX(ctx context.Context) *Task

SaveX calls Save and panics if Save returns an error.

func (*TaskCreate) SetTitle added in v0.2.0

func (_c *TaskCreate) SetTitle(v string) *TaskCreate

SetTitle sets the "title" field.

type TaskCreateBulk added in v0.2.0

type TaskCreateBulk struct {
	// contains filtered or unexported fields
}

TaskCreateBulk is the builder for creating many Task entities in bulk.

func (*TaskCreateBulk) Exec added in v0.2.0

func (_c *TaskCreateBulk) Exec(ctx context.Context) error

Exec executes the query.

func (*TaskCreateBulk) ExecX added in v0.2.0

func (_c *TaskCreateBulk) ExecX(ctx context.Context)

ExecX is like Exec, but panics if an error occurs.

func (*TaskCreateBulk) OnConflict added in v0.2.0

func (_c *TaskCreateBulk) OnConflict(opts ...sql.ConflictOption) *TaskUpsertBulk

OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause of the `INSERT` statement. For example:

client.Task.CreateBulk(builders...).
	OnConflict(
		// Update the row with the new values
		// the was proposed for insertion.
		sql.ResolveWithNewValues(),
	).
	// Override some of the fields with custom
	// update values.
	Update(func(u *ent.TaskUpsert) {
		SetTitle(v+v).
	}).
	Exec(ctx)

func (*TaskCreateBulk) OnConflictColumns added in v0.2.0

func (_c *TaskCreateBulk) OnConflictColumns(columns ...string) *TaskUpsertBulk

OnConflictColumns calls `OnConflict` and configures the columns as conflict target. Using this option is equivalent to using:

client.Task.Create().
	OnConflict(sql.ConflictColumns(columns...)).
	Exec(ctx)

func (*TaskCreateBulk) Save added in v0.2.0

func (_c *TaskCreateBulk) Save(ctx context.Context) ([]*Task, error)

Save creates the Task entities in the database.

func (*TaskCreateBulk) SaveX added in v0.2.0

func (_c *TaskCreateBulk) SaveX(ctx context.Context) []*Task

SaveX is like Save, but panics if an error occurs.

type TaskDelete added in v0.2.0

type TaskDelete struct {
	// contains filtered or unexported fields
}

TaskDelete is the builder for deleting a Task entity.

func (*TaskDelete) Exec added in v0.2.0

func (_d *TaskDelete) Exec(ctx context.Context) (int, error)

Exec executes the deletion query and returns how many vertices were deleted.

func (*TaskDelete) ExecX added in v0.2.0

func (_d *TaskDelete) ExecX(ctx context.Context) int

ExecX is like Exec, but panics if an error occurs.

func (*TaskDelete) Where added in v0.2.0

func (_d *TaskDelete) Where(ps ...predicate.Task) *TaskDelete

Where appends a list predicates to the TaskDelete builder.

type TaskDeleteOne added in v0.2.0

type TaskDeleteOne struct {
	// contains filtered or unexported fields
}

TaskDeleteOne is the builder for deleting a single Task entity.

func (*TaskDeleteOne) Exec added in v0.2.0

func (_d *TaskDeleteOne) Exec(ctx context.Context) error

Exec executes the deletion query.

func (*TaskDeleteOne) ExecX added in v0.2.0

func (_d *TaskDeleteOne) ExecX(ctx context.Context)

ExecX is like Exec, but panics if an error occurs.

func (*TaskDeleteOne) Where added in v0.2.0

func (_d *TaskDeleteOne) Where(ps ...predicate.Task) *TaskDeleteOne

Where appends a list predicates to the TaskDelete builder.

type TaskGroupBy added in v0.2.0

type TaskGroupBy struct {
	// contains filtered or unexported fields
}

TaskGroupBy is the group-by builder for Task entities.

func (*TaskGroupBy) Aggregate added in v0.2.0

func (_g *TaskGroupBy) Aggregate(fns ...AggregateFunc) *TaskGroupBy

Aggregate adds the given aggregation functions to the group-by query.

func (*TaskGroupBy) Bool added in v0.2.0

func (s *TaskGroupBy) Bool(ctx context.Context) (_ bool, err error)

Bool returns a single bool from a selector. It is only allowed when selecting one field.

func (*TaskGroupBy) BoolX added in v0.2.0

func (s *TaskGroupBy) BoolX(ctx context.Context) bool

BoolX is like Bool, but panics if an error occurs.

func (*TaskGroupBy) Bools added in v0.2.0

func (s *TaskGroupBy) Bools(ctx context.Context) ([]bool, error)

Bools returns list of bools from a selector. It is only allowed when selecting one field.

func (*TaskGroupBy) BoolsX added in v0.2.0

func (s *TaskGroupBy) BoolsX(ctx context.Context) []bool

BoolsX is like Bools, but panics if an error occurs.

func (*TaskGroupBy) Float64 added in v0.2.0

func (s *TaskGroupBy) Float64(ctx context.Context) (_ float64, err error)

Float64 returns a single float64 from a selector. It is only allowed when selecting one field.

func (*TaskGroupBy) Float64X added in v0.2.0

func (s *TaskGroupBy) Float64X(ctx context.Context) float64

Float64X is like Float64, but panics if an error occurs.

func (*TaskGroupBy) Float64s added in v0.2.0

func (s *TaskGroupBy) Float64s(ctx context.Context) ([]float64, error)

Float64s returns list of float64s from a selector. It is only allowed when selecting one field.

func (*TaskGroupBy) Float64sX added in v0.2.0

func (s *TaskGroupBy) Float64sX(ctx context.Context) []float64

Float64sX is like Float64s, but panics if an error occurs.

func (*TaskGroupBy) Int added in v0.2.0

func (s *TaskGroupBy) Int(ctx context.Context) (_ int, err error)

Int returns a single int from a selector. It is only allowed when selecting one field.

func (*TaskGroupBy) IntX added in v0.2.0

func (s *TaskGroupBy) IntX(ctx context.Context) int

IntX is like Int, but panics if an error occurs.

func (*TaskGroupBy) Ints added in v0.2.0

func (s *TaskGroupBy) Ints(ctx context.Context) ([]int, error)

Ints returns list of ints from a selector. It is only allowed when selecting one field.

func (*TaskGroupBy) IntsX added in v0.2.0

func (s *TaskGroupBy) IntsX(ctx context.Context) []int

IntsX is like Ints, but panics if an error occurs.

func (*TaskGroupBy) Scan added in v0.2.0

func (_g *TaskGroupBy) Scan(ctx context.Context, v any) error

Scan applies the selector query and scans the result into the given value.

func (*TaskGroupBy) ScanX added in v0.2.0

func (s *TaskGroupBy) ScanX(ctx context.Context, v any)

ScanX is like Scan, but panics if an error occurs.

func (*TaskGroupBy) String added in v0.2.0

func (s *TaskGroupBy) String(ctx context.Context) (_ string, err error)

String returns a single string from a selector. It is only allowed when selecting one field.

func (*TaskGroupBy) StringX added in v0.2.0

func (s *TaskGroupBy) StringX(ctx context.Context) string

StringX is like String, but panics if an error occurs.

func (*TaskGroupBy) Strings added in v0.2.0

func (s *TaskGroupBy) Strings(ctx context.Context) ([]string, error)

Strings returns list of strings from a selector. It is only allowed when selecting one field.

func (*TaskGroupBy) StringsX added in v0.2.0

func (s *TaskGroupBy) StringsX(ctx context.Context) []string

StringsX is like Strings, but panics if an error occurs.

type TaskMutation added in v0.2.0

type TaskMutation struct {
	// contains filtered or unexported fields
}

TaskMutation represents an operation that mutates the Task nodes in the graph.

func (*TaskMutation) AddField added in v0.2.0

func (m *TaskMutation) AddField(name string, value ent.Value) error

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 (*TaskMutation) AddedEdges added in v0.2.0

func (m *TaskMutation) AddedEdges() []string

AddedEdges returns all edge names that were set/added in this mutation.

func (*TaskMutation) AddedField added in v0.2.0

func (m *TaskMutation) AddedField(name string) (ent.Value, bool)

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 (*TaskMutation) AddedFields added in v0.2.0

func (m *TaskMutation) AddedFields() []string

AddedFields returns all numeric fields that were incremented/decremented during this mutation.

func (*TaskMutation) AddedIDs added in v0.2.0

func (m *TaskMutation) AddedIDs(name string) []ent.Value

AddedIDs returns all IDs (to other nodes) that were added for the given edge name in this mutation.

func (*TaskMutation) ClearEdge added in v0.2.0

func (m *TaskMutation) ClearEdge(name string) error

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 (*TaskMutation) ClearField added in v0.2.0

func (m *TaskMutation) ClearField(name string) error

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 (*TaskMutation) ClearedEdges added in v0.2.0

func (m *TaskMutation) ClearedEdges() []string

ClearedEdges returns all edge names that were cleared in this mutation.

func (*TaskMutation) ClearedFields added in v0.2.0

func (m *TaskMutation) ClearedFields() []string

ClearedFields returns all nullable fields that were cleared during this mutation.

func (TaskMutation) Client added in v0.2.0

func (m TaskMutation) Client() *Client

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 (*TaskMutation) EdgeCleared added in v0.2.0

func (m *TaskMutation) EdgeCleared(name string) bool

EdgeCleared returns a boolean which indicates if the edge with the given name was cleared in this mutation.

func (*TaskMutation) Field added in v0.2.0

func (m *TaskMutation) Field(name string) (ent.Value, bool)

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 (*TaskMutation) FieldCleared added in v0.2.0

func (m *TaskMutation) FieldCleared(name string) bool

FieldCleared returns a boolean indicating if a field with the given name was cleared in this mutation.

func (*TaskMutation) Fields added in v0.2.0

func (m *TaskMutation) Fields() []string

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 (*TaskMutation) ID added in v0.2.0

func (m *TaskMutation) ID() (id int, exists bool)

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 (*TaskMutation) IDs added in v0.2.0

func (m *TaskMutation) IDs(ctx context.Context) ([]int, error)

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 (*TaskMutation) OldField added in v0.2.0

func (m *TaskMutation) OldField(ctx context.Context, name string) (ent.Value, error)

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 (*TaskMutation) OldTitle added in v0.2.0

func (m *TaskMutation) OldTitle(ctx context.Context) (v string, err error)

OldTitle returns the old "title" field's value of the Task entity. If the Task 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 (*TaskMutation) Op added in v0.2.0

func (m *TaskMutation) Op() Op

Op returns the operation name.

func (*TaskMutation) RemovedEdges added in v0.2.0

func (m *TaskMutation) RemovedEdges() []string

RemovedEdges returns all edge names that were removed in this mutation.

func (*TaskMutation) RemovedIDs added in v0.2.0

func (m *TaskMutation) RemovedIDs(name string) []ent.Value

RemovedIDs returns all IDs (to other nodes) that were removed for the edge with the given name in this mutation.

func (*TaskMutation) ResetEdge added in v0.2.0

func (m *TaskMutation) ResetEdge(name string) error

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 (*TaskMutation) ResetField added in v0.2.0

func (m *TaskMutation) ResetField(name string) error

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 (*TaskMutation) ResetTitle added in v0.2.0

func (m *TaskMutation) ResetTitle()

ResetTitle resets all changes to the "title" field.

func (*TaskMutation) SetField added in v0.2.0

func (m *TaskMutation) SetField(name string, value ent.Value) error

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 (*TaskMutation) SetOp added in v0.2.0

func (m *TaskMutation) SetOp(op Op)

SetOp allows setting the mutation operation.

func (*TaskMutation) SetTitle added in v0.2.0

func (m *TaskMutation) SetTitle(s string)

SetTitle sets the "title" field.

func (*TaskMutation) Title added in v0.2.0

func (m *TaskMutation) Title() (r string, exists bool)

Title returns the value of the "title" field in the mutation.

func (TaskMutation) Tx added in v0.2.0

func (m TaskMutation) Tx() (*Tx, error)

Tx returns an `ent.Tx` for mutations that were executed in transactions; it returns an error otherwise.

func (*TaskMutation) Type added in v0.2.0

func (m *TaskMutation) Type() string

Type returns the node type of this mutation (Task).

func (*TaskMutation) Where added in v0.2.0

func (m *TaskMutation) Where(ps ...predicate.Task)

Where appends a list predicates to the TaskMutation builder.

func (*TaskMutation) WhereP added in v0.2.0

func (m *TaskMutation) WhereP(ps ...func(*sql.Selector))

WhereP appends storage-level predicates to the TaskMutation builder. Using this method, users can use type-assertion to append predicates that do not depend on any generated package.

type TaskQuery added in v0.2.0

type TaskQuery struct {
	// contains filtered or unexported fields
}

TaskQuery is the builder for querying Task entities.

func (*TaskQuery) Aggregate added in v0.2.0

func (_q *TaskQuery) Aggregate(fns ...AggregateFunc) *TaskSelect

Aggregate returns a TaskSelect configured with the given aggregations.

func (*TaskQuery) All added in v0.2.0

func (_q *TaskQuery) All(ctx context.Context) ([]*Task, error)

All executes the query and returns a list of Tasks.

func (*TaskQuery) AllX added in v0.2.0

func (_q *TaskQuery) AllX(ctx context.Context) []*Task

AllX is like All, but panics if an error occurs.

func (*TaskQuery) Clone added in v0.2.0

func (_q *TaskQuery) Clone() *TaskQuery

Clone returns a duplicate of the TaskQuery builder, including all associated steps. It can be used to prepare common query builders and use them differently after the clone is made.

func (*TaskQuery) Count added in v0.2.0

func (_q *TaskQuery) Count(ctx context.Context) (int, error)

Count returns the count of the given query.

func (*TaskQuery) CountX added in v0.2.0

func (_q *TaskQuery) CountX(ctx context.Context) int

CountX is like Count, but panics if an error occurs.

func (*TaskQuery) Exist added in v0.2.0

func (_q *TaskQuery) Exist(ctx context.Context) (bool, error)

Exist returns true if the query has elements in the graph.

func (*TaskQuery) ExistX added in v0.2.0

func (_q *TaskQuery) ExistX(ctx context.Context) bool

ExistX is like Exist, but panics if an error occurs.

func (*TaskQuery) First added in v0.2.0

func (_q *TaskQuery) First(ctx context.Context) (*Task, error)

First returns the first Task entity from the query. Returns a *NotFoundError when no Task was found.

func (*TaskQuery) FirstID added in v0.2.0

func (_q *TaskQuery) FirstID(ctx context.Context) (id int, err error)

FirstID returns the first Task ID from the query. Returns a *NotFoundError when no Task ID was found.

func (*TaskQuery) FirstIDX added in v0.2.0

func (_q *TaskQuery) FirstIDX(ctx context.Context) int

FirstIDX is like FirstID, but panics if an error occurs.

func (*TaskQuery) FirstX added in v0.2.0

func (_q *TaskQuery) FirstX(ctx context.Context) *Task

FirstX is like First, but panics if an error occurs.

func (*TaskQuery) GroupBy added in v0.2.0

func (_q *TaskQuery) GroupBy(field string, fields ...string) *TaskGroupBy

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 {
	Title string `json:"title,omitempty"`
	Count int `json:"count,omitempty"`
}

client.Task.Query().
	GroupBy(task.FieldTitle).
	Aggregate(ent.Count()).
	Scan(ctx, &v)

func (*TaskQuery) IDs added in v0.2.0

func (_q *TaskQuery) IDs(ctx context.Context) (ids []int, err error)

IDs executes the query and returns a list of Task IDs.

func (*TaskQuery) IDsX added in v0.2.0

func (_q *TaskQuery) IDsX(ctx context.Context) []int

IDsX is like IDs, but panics if an error occurs.

func (*TaskQuery) Limit added in v0.2.0

func (_q *TaskQuery) Limit(limit int) *TaskQuery

Limit the number of records to be returned by this query.

func (*TaskQuery) Offset added in v0.2.0

func (_q *TaskQuery) Offset(offset int) *TaskQuery

Offset to start from.

func (*TaskQuery) Only added in v0.2.0

func (_q *TaskQuery) Only(ctx context.Context) (*Task, error)

Only returns a single Task entity found by the query, ensuring it only returns one. Returns a *NotSingularError when more than one Task entity is found. Returns a *NotFoundError when no Task entities are found.

func (*TaskQuery) OnlyID added in v0.2.0

func (_q *TaskQuery) OnlyID(ctx context.Context) (id int, err error)

OnlyID is like Only, but returns the only Task ID in the query. Returns a *NotSingularError when more than one Task ID is found. Returns a *NotFoundError when no entities are found.

func (*TaskQuery) OnlyIDX added in v0.2.0

func (_q *TaskQuery) OnlyIDX(ctx context.Context) int

OnlyIDX is like OnlyID, but panics if an error occurs.

func (*TaskQuery) OnlyX added in v0.2.0

func (_q *TaskQuery) OnlyX(ctx context.Context) *Task

OnlyX is like Only, but panics if an error occurs.

func (*TaskQuery) Order added in v0.2.0

func (_q *TaskQuery) Order(o ...task.OrderOption) *TaskQuery

Order specifies how the records should be ordered.

func (*TaskQuery) Select added in v0.2.0

func (_q *TaskQuery) Select(fields ...string) *TaskSelect

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 {
	Title string `json:"title,omitempty"`
}

client.Task.Query().
	Select(task.FieldTitle).
	Scan(ctx, &v)

func (*TaskQuery) Unique added in v0.2.0

func (_q *TaskQuery) Unique(unique bool) *TaskQuery

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 (*TaskQuery) Where added in v0.2.0

func (_q *TaskQuery) Where(ps ...predicate.Task) *TaskQuery

Where adds a new predicate for the TaskQuery builder.

type TaskSelect added in v0.2.0

type TaskSelect struct {
	*TaskQuery
	// contains filtered or unexported fields
}

TaskSelect is the builder for selecting fields of Task entities.

func (*TaskSelect) Aggregate added in v0.2.0

func (_s *TaskSelect) Aggregate(fns ...AggregateFunc) *TaskSelect

Aggregate adds the given aggregation functions to the selector query.

func (*TaskSelect) Bool added in v0.2.0

func (s *TaskSelect) Bool(ctx context.Context) (_ bool, err error)

Bool returns a single bool from a selector. It is only allowed when selecting one field.

func (*TaskSelect) BoolX added in v0.2.0

func (s *TaskSelect) BoolX(ctx context.Context) bool

BoolX is like Bool, but panics if an error occurs.

func (*TaskSelect) Bools added in v0.2.0

func (s *TaskSelect) Bools(ctx context.Context) ([]bool, error)

Bools returns list of bools from a selector. It is only allowed when selecting one field.

func (*TaskSelect) BoolsX added in v0.2.0

func (s *TaskSelect) BoolsX(ctx context.Context) []bool

BoolsX is like Bools, but panics if an error occurs.

func (*TaskSelect) Float64 added in v0.2.0

func (s *TaskSelect) Float64(ctx context.Context) (_ float64, err error)

Float64 returns a single float64 from a selector. It is only allowed when selecting one field.

func (*TaskSelect) Float64X added in v0.2.0

func (s *TaskSelect) Float64X(ctx context.Context) float64

Float64X is like Float64, but panics if an error occurs.

func (*TaskSelect) Float64s added in v0.2.0

func (s *TaskSelect) Float64s(ctx context.Context) ([]float64, error)

Float64s returns list of float64s from a selector. It is only allowed when selecting one field.

func (*TaskSelect) Float64sX added in v0.2.0

func (s *TaskSelect) Float64sX(ctx context.Context) []float64

Float64sX is like Float64s, but panics if an error occurs.

func (*TaskSelect) Int added in v0.2.0

func (s *TaskSelect) Int(ctx context.Context) (_ int, err error)

Int returns a single int from a selector. It is only allowed when selecting one field.

func (*TaskSelect) IntX added in v0.2.0

func (s *TaskSelect) IntX(ctx context.Context) int

IntX is like Int, but panics if an error occurs.

func (*TaskSelect) Ints added in v0.2.0

func (s *TaskSelect) Ints(ctx context.Context) ([]int, error)

Ints returns list of ints from a selector. It is only allowed when selecting one field.

func (*TaskSelect) IntsX added in v0.2.0

func (s *TaskSelect) IntsX(ctx context.Context) []int

IntsX is like Ints, but panics if an error occurs.

func (*TaskSelect) Scan added in v0.2.0

func (_s *TaskSelect) Scan(ctx context.Context, v any) error

Scan applies the selector query and scans the result into the given value.

func (*TaskSelect) ScanX added in v0.2.0

func (s *TaskSelect) ScanX(ctx context.Context, v any)

ScanX is like Scan, but panics if an error occurs.

func (*TaskSelect) String added in v0.2.0

func (s *TaskSelect) String(ctx context.Context) (_ string, err error)

String returns a single string from a selector. It is only allowed when selecting one field.

func (*TaskSelect) StringX added in v0.2.0

func (s *TaskSelect) StringX(ctx context.Context) string

StringX is like String, but panics if an error occurs.

func (*TaskSelect) Strings added in v0.2.0

func (s *TaskSelect) Strings(ctx context.Context) ([]string, error)

Strings returns list of strings from a selector. It is only allowed when selecting one field.

func (*TaskSelect) StringsX added in v0.2.0

func (s *TaskSelect) StringsX(ctx context.Context) []string

StringsX is like Strings, but panics if an error occurs.

type TaskUpdate added in v0.2.0

type TaskUpdate struct {
	// contains filtered or unexported fields
}

TaskUpdate is the builder for updating Task entities.

func (*TaskUpdate) Exec added in v0.2.0

func (_u *TaskUpdate) Exec(ctx context.Context) error

Exec executes the query.

func (*TaskUpdate) ExecX added in v0.2.0

func (_u *TaskUpdate) ExecX(ctx context.Context)

ExecX is like Exec, but panics if an error occurs.

func (*TaskUpdate) Mutation added in v0.2.0

func (_u *TaskUpdate) Mutation() *TaskMutation

Mutation returns the TaskMutation object of the builder.

func (*TaskUpdate) Save added in v0.2.0

func (_u *TaskUpdate) Save(ctx context.Context) (int, error)

Save executes the query and returns the number of nodes affected by the update operation.

func (*TaskUpdate) SaveX added in v0.2.0

func (_u *TaskUpdate) SaveX(ctx context.Context) int

SaveX is like Save, but panics if an error occurs.

func (*TaskUpdate) SetNillableTitle added in v0.2.0

func (_u *TaskUpdate) SetNillableTitle(v *string) *TaskUpdate

SetNillableTitle sets the "title" field if the given value is not nil.

func (*TaskUpdate) SetTitle added in v0.2.0

func (_u *TaskUpdate) SetTitle(v string) *TaskUpdate

SetTitle sets the "title" field.

func (*TaskUpdate) Where added in v0.2.0

func (_u *TaskUpdate) Where(ps ...predicate.Task) *TaskUpdate

Where appends a list predicates to the TaskUpdate builder.

type TaskUpdateOne added in v0.2.0

type TaskUpdateOne struct {
	// contains filtered or unexported fields
}

TaskUpdateOne is the builder for updating a single Task entity.

func (*TaskUpdateOne) Exec added in v0.2.0

func (_u *TaskUpdateOne) Exec(ctx context.Context) error

Exec executes the query on the entity.

func (*TaskUpdateOne) ExecX added in v0.2.0

func (_u *TaskUpdateOne) ExecX(ctx context.Context)

ExecX is like Exec, but panics if an error occurs.

func (*TaskUpdateOne) Mutation added in v0.2.0

func (_u *TaskUpdateOne) Mutation() *TaskMutation

Mutation returns the TaskMutation object of the builder.

func (*TaskUpdateOne) Save added in v0.2.0

func (_u *TaskUpdateOne) Save(ctx context.Context) (*Task, error)

Save executes the query and returns the updated Task entity.

func (*TaskUpdateOne) SaveX added in v0.2.0

func (_u *TaskUpdateOne) SaveX(ctx context.Context) *Task

SaveX is like Save, but panics if an error occurs.

func (*TaskUpdateOne) Select added in v0.2.0

func (_u *TaskUpdateOne) Select(field string, fields ...string) *TaskUpdateOne

Select allows selecting one or more fields (columns) of the returned entity. The default is selecting all fields defined in the entity schema.

func (*TaskUpdateOne) SetNillableTitle added in v0.2.0

func (_u *TaskUpdateOne) SetNillableTitle(v *string) *TaskUpdateOne

SetNillableTitle sets the "title" field if the given value is not nil.

func (*TaskUpdateOne) SetTitle added in v0.2.0

func (_u *TaskUpdateOne) SetTitle(v string) *TaskUpdateOne

SetTitle sets the "title" field.

func (*TaskUpdateOne) Where added in v0.2.0

func (_u *TaskUpdateOne) Where(ps ...predicate.Task) *TaskUpdateOne

Where appends a list predicates to the TaskUpdate builder.

type TaskUpsert added in v0.2.0

type TaskUpsert struct {
	*sql.UpdateSet
}

TaskUpsert is the "OnConflict" setter.

func (*TaskUpsert) SetTitle added in v0.2.0

func (u *TaskUpsert) SetTitle(v string) *TaskUpsert

SetTitle sets the "title" field.

func (*TaskUpsert) UpdateTitle added in v0.2.0

func (u *TaskUpsert) UpdateTitle() *TaskUpsert

UpdateTitle sets the "title" field to the value that was provided on create.

type TaskUpsertBulk added in v0.2.0

type TaskUpsertBulk struct {
	// contains filtered or unexported fields
}

TaskUpsertBulk is the builder for "upsert"-ing a bulk of Task nodes.

func (*TaskUpsertBulk) DoNothing added in v0.2.0

func (u *TaskUpsertBulk) DoNothing() *TaskUpsertBulk

DoNothing configures the conflict_action to `DO NOTHING`. Supported only by SQLite and PostgreSQL.

func (*TaskUpsertBulk) Exec added in v0.2.0

func (u *TaskUpsertBulk) Exec(ctx context.Context) error

Exec executes the query.

func (*TaskUpsertBulk) ExecX added in v0.2.0

func (u *TaskUpsertBulk) ExecX(ctx context.Context)

ExecX is like Exec, but panics if an error occurs.

func (*TaskUpsertBulk) Ignore added in v0.2.0

func (u *TaskUpsertBulk) Ignore() *TaskUpsertBulk

Ignore sets each column to itself in case of conflict. Using this option is equivalent to using:

client.Task.Create().
	OnConflict(sql.ResolveWithIgnore()).
	Exec(ctx)

func (*TaskUpsertBulk) SetTitle added in v0.2.0

func (u *TaskUpsertBulk) SetTitle(v string) *TaskUpsertBulk

SetTitle sets the "title" field.

func (*TaskUpsertBulk) Update added in v0.2.0

func (u *TaskUpsertBulk) Update(set func(*TaskUpsert)) *TaskUpsertBulk

Update allows overriding fields `UPDATE` values. See the TaskCreateBulk.OnConflict documentation for more info.

func (*TaskUpsertBulk) UpdateNewValues added in v0.2.0

func (u *TaskUpsertBulk) UpdateNewValues() *TaskUpsertBulk

UpdateNewValues updates the mutable fields using the new values that were set on create. Using this option is equivalent to using:

client.Task.Create().
	OnConflict(
		sql.ResolveWithNewValues(),
	).
	Exec(ctx)

func (*TaskUpsertBulk) UpdateTitle added in v0.2.0

func (u *TaskUpsertBulk) UpdateTitle() *TaskUpsertBulk

UpdateTitle sets the "title" field to the value that was provided on create.

type TaskUpsertOne added in v0.2.0

type TaskUpsertOne struct {
	// contains filtered or unexported fields
}

TaskUpsertOne is the builder for "upsert"-ing

one Task node.

func (*TaskUpsertOne) DoNothing added in v0.2.0

func (u *TaskUpsertOne) DoNothing() *TaskUpsertOne

DoNothing configures the conflict_action to `DO NOTHING`. Supported only by SQLite and PostgreSQL.

func (*TaskUpsertOne) Exec added in v0.2.0

func (u *TaskUpsertOne) Exec(ctx context.Context) error

Exec executes the query.

func (*TaskUpsertOne) ExecX added in v0.2.0

func (u *TaskUpsertOne) ExecX(ctx context.Context)

ExecX is like Exec, but panics if an error occurs.

func (*TaskUpsertOne) ID added in v0.2.0

func (u *TaskUpsertOne) ID(ctx context.Context) (id int, err error)

Exec executes the UPSERT query and returns the inserted/updated ID.

func (*TaskUpsertOne) IDX added in v0.2.0

func (u *TaskUpsertOne) IDX(ctx context.Context) int

IDX is like ID, but panics if an error occurs.

func (*TaskUpsertOne) Ignore added in v0.2.0

func (u *TaskUpsertOne) Ignore() *TaskUpsertOne

Ignore sets each column to itself in case of conflict. Using this option is equivalent to using:

client.Task.Create().
    OnConflict(sql.ResolveWithIgnore()).
    Exec(ctx)

func (*TaskUpsertOne) SetTitle added in v0.2.0

func (u *TaskUpsertOne) SetTitle(v string) *TaskUpsertOne

SetTitle sets the "title" field.

func (*TaskUpsertOne) Update added in v0.2.0

func (u *TaskUpsertOne) Update(set func(*TaskUpsert)) *TaskUpsertOne

Update allows overriding fields `UPDATE` values. See the TaskCreate.OnConflict documentation for more info.

func (*TaskUpsertOne) UpdateNewValues added in v0.2.0

func (u *TaskUpsertOne) UpdateNewValues() *TaskUpsertOne

UpdateNewValues updates the mutable fields using the new values that were set on create. Using this option is equivalent to using:

client.Task.Create().
	OnConflict(
		sql.ResolveWithNewValues(),
	).
	Exec(ctx)

func (*TaskUpsertOne) UpdateTitle added in v0.2.0

func (u *TaskUpsertOne) UpdateTitle() *TaskUpsertOne

UpdateTitle sets the "title" field to the value that was provided on create.

type Tasks added in v0.2.0

type Tasks []*Task

Tasks is a parsable slice of Task.

type TraverseFunc

type TraverseFunc = ent.TraverseFunc

ent aliases to avoid import conflicts in user's code.

type Traverser

type Traverser = ent.Traverser

ent aliases to avoid import conflicts in user's code.

type Tx

type Tx struct {

	// Task is the client for interacting with the Task builders.
	Task *TaskClient
	// contains filtered or unexported fields
}

Tx is a transactional client that is created by calling Client.Tx().

func TxFromContext

func TxFromContext(ctx context.Context) *Tx

TxFromContext returns a Tx stored inside a context, or nil if there isn't one.

func (*Tx) Client

func (tx *Tx) Client() *Client

Client returns a Client that binds to current transaction.

func (*Tx) Commit

func (tx *Tx) Commit() error

Commit commits the transaction.

func (*Tx) OnCommit

func (tx *Tx) OnCommit(f CommitHook)

OnCommit adds a hook to call on commit.

func (*Tx) OnRollback

func (tx *Tx) OnRollback(f RollbackHook)

OnRollback adds a hook to call on rollback.

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Rollback rollbacks the transaction.

type ValidationError

type ValidationError struct {
	Name string // Field or edge name.
	// contains filtered or unexported fields
}

ValidationError returns when validating a field or edge fails.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error implements the error interface.

func (*ValidationError) Unwrap

func (e *ValidationError) Unwrap() error

Unwrap implements the errors.Wrapper interface.

type Value

type Value = ent.Value

ent aliases to avoid import conflicts in user's code.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL