ent

package
v0.0.0-...-4491578 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

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

	// Node types.
	TypeCounter = "Counter"
)

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
	// Counter is the client for interacting with the Counter builders.
	Counter *CounterClient
	// 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().
	Counter.
	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 Counter

type Counter struct {

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

Counter is the model entity for the Counter schema.

func (*Counter) GetValue

func (c *Counter) GetValue(name string) (ent.Value, error)

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

func (*Counter) String

func (c *Counter) String() string

String implements the fmt.Stringer.

func (*Counter) Unwrap

func (c *Counter) Unwrap() *Counter

Unwrap unwraps the Counter 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 (*Counter) Update

func (c *Counter) Update() *CounterUpdateOne

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

type CounterClient

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

CounterClient is a client for the Counter schema.

func NewCounterClient

func NewCounterClient(c config) *CounterClient

NewCounterClient returns a client for the Counter from the given config.

func (*CounterClient) Create

func (c *CounterClient) Create() *CounterCreate

Create returns a builder for creating a Counter entity.

func (*CounterClient) CreateBulk

func (c *CounterClient) CreateBulk(builders ...*CounterCreate) *CounterCreateBulk

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

func (*CounterClient) Delete

func (c *CounterClient) Delete() *CounterDelete

Delete returns a delete builder for Counter.

func (*CounterClient) DeleteOne

func (c *CounterClient) DeleteOne(co *Counter) *CounterDeleteOne

DeleteOne returns a builder for deleting the given entity.

func (*CounterClient) DeleteOneID

func (c *CounterClient) DeleteOneID(id string) *CounterDeleteOne

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

func (*CounterClient) Get

func (c *CounterClient) Get(ctx context.Context, id string) (*Counter, error)

Get returns a Counter entity by its id.

func (*CounterClient) GetX

func (c *CounterClient) GetX(ctx context.Context, id string) *Counter

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

func (*CounterClient) Hooks

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

Hooks returns the client hooks.

func (*CounterClient) Intercept

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

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

func (*CounterClient) Interceptors

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

Interceptors returns the client interceptors.

func (*CounterClient) MapCreateBulk

func (c *CounterClient) MapCreateBulk(slice any, setFunc func(*CounterCreate, int)) *CounterCreateBulk

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 (*CounterClient) Query

func (c *CounterClient) Query() *CounterQuery

Query returns a query builder for Counter.

func (*CounterClient) Update

func (c *CounterClient) Update() *CounterUpdate

Update returns an update builder for Counter.

func (*CounterClient) UpdateOne

func (c *CounterClient) UpdateOne(co *Counter) *CounterUpdateOne

UpdateOne returns an update builder for the given entity.

func (*CounterClient) UpdateOneID

func (c *CounterClient) UpdateOneID(id string) *CounterUpdateOne

UpdateOneID returns an update builder for the given id.

func (*CounterClient) Use

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

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

type CounterCreate

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

CounterCreate is the builder for creating a Counter entity.

func (*CounterCreate) Exec

func (cc *CounterCreate) Exec(ctx context.Context) error

Exec executes the query.

func (*CounterCreate) ExecX

func (cc *CounterCreate) ExecX(ctx context.Context)

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

func (*CounterCreate) Mutation

func (cc *CounterCreate) Mutation() *CounterMutation

Mutation returns the CounterMutation object of the builder.

func (*CounterCreate) Save

func (cc *CounterCreate) Save(ctx context.Context) (*Counter, error)

Save creates the Counter in the database.

func (*CounterCreate) SaveX

func (cc *CounterCreate) SaveX(ctx context.Context) *Counter

SaveX calls Save and panics if Save returns an error.

func (*CounterCreate) SetID

func (cc *CounterCreate) SetID(s string) *CounterCreate

SetID sets the "id" field.

func (*CounterCreate) SetValue

func (cc *CounterCreate) SetValue(i int64) *CounterCreate

SetValue sets the "value" field.

type CounterCreateBulk

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

CounterCreateBulk is the builder for creating many Counter entities in bulk.

func (*CounterCreateBulk) Exec

func (ccb *CounterCreateBulk) Exec(ctx context.Context) error

Exec executes the query.

func (*CounterCreateBulk) ExecX

func (ccb *CounterCreateBulk) ExecX(ctx context.Context)

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

func (*CounterCreateBulk) Save

func (ccb *CounterCreateBulk) Save(ctx context.Context) ([]*Counter, error)

Save creates the Counter entities in the database.

func (*CounterCreateBulk) SaveX

func (ccb *CounterCreateBulk) SaveX(ctx context.Context) []*Counter

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

type CounterDelete

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

CounterDelete is the builder for deleting a Counter entity.

func (*CounterDelete) Exec

func (cd *CounterDelete) Exec(ctx context.Context) (int, error)

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

func (*CounterDelete) ExecX

func (cd *CounterDelete) ExecX(ctx context.Context) int

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

func (*CounterDelete) Where

func (cd *CounterDelete) Where(ps ...predicate.Counter) *CounterDelete

Where appends a list predicates to the CounterDelete builder.

type CounterDeleteOne

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

CounterDeleteOne is the builder for deleting a single Counter entity.

func (*CounterDeleteOne) Exec

func (cdo *CounterDeleteOne) Exec(ctx context.Context) error

Exec executes the deletion query.

func (*CounterDeleteOne) ExecX

func (cdo *CounterDeleteOne) ExecX(ctx context.Context)

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

func (*CounterDeleteOne) Where

Where appends a list predicates to the CounterDelete builder.

type CounterGroupBy

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

CounterGroupBy is the group-by builder for Counter entities.

func (*CounterGroupBy) Aggregate

func (cgb *CounterGroupBy) Aggregate(fns ...AggregateFunc) *CounterGroupBy

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

func (*CounterGroupBy) Bool

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

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

func (*CounterGroupBy) BoolX

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

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

func (*CounterGroupBy) Bools

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

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

func (*CounterGroupBy) BoolsX

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

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

func (*CounterGroupBy) Float64

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

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

func (*CounterGroupBy) Float64X

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

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

func (*CounterGroupBy) Float64s

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

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

func (*CounterGroupBy) Float64sX

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

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

func (*CounterGroupBy) Int

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

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

func (*CounterGroupBy) IntX

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

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

func (*CounterGroupBy) Ints

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

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

func (*CounterGroupBy) IntsX

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

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

func (*CounterGroupBy) Scan

func (cgb *CounterGroupBy) Scan(ctx context.Context, v any) error

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

func (*CounterGroupBy) ScanX

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

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

func (*CounterGroupBy) String

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

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

func (*CounterGroupBy) StringX

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

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

func (*CounterGroupBy) Strings

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

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

func (*CounterGroupBy) StringsX

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

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

type CounterMutation

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

CounterMutation represents an operation that mutates the Counter nodes in the graph.

func (*CounterMutation) AddField

func (m *CounterMutation) 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 (*CounterMutation) AddValue

func (m *CounterMutation) AddValue(i int64)

AddValue adds i to the "value" field.

func (*CounterMutation) AddedEdges

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

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

func (*CounterMutation) AddedField

func (m *CounterMutation) 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 (*CounterMutation) AddedFields

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

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

func (*CounterMutation) AddedIDs

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

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

func (*CounterMutation) AddedValue

func (m *CounterMutation) AddedValue() (r int64, exists bool)

AddedValue returns the value that was added to the "value" field in this mutation.

func (*CounterMutation) ClearEdge

func (m *CounterMutation) 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 (*CounterMutation) ClearField

func (m *CounterMutation) 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 (*CounterMutation) ClearedEdges

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

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

func (*CounterMutation) ClearedFields

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

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

func (CounterMutation) Client

func (m CounterMutation) 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 (*CounterMutation) EdgeCleared

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

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

func (*CounterMutation) Field

func (m *CounterMutation) 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 (*CounterMutation) FieldCleared

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

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

func (*CounterMutation) Fields

func (m *CounterMutation) 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 (*CounterMutation) ID

func (m *CounterMutation) ID() (id string, 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 (*CounterMutation) IDs

func (m *CounterMutation) IDs(ctx context.Context) ([]string, 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 (*CounterMutation) OldField

func (m *CounterMutation) 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 (*CounterMutation) OldValue

func (m *CounterMutation) OldValue(ctx context.Context) (v int64, err error)

OldValue returns the old "value" field's value of the Counter entity. If the Counter 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 (*CounterMutation) Op

func (m *CounterMutation) Op() Op

Op returns the operation name.

func (*CounterMutation) RemovedEdges

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

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

func (*CounterMutation) RemovedIDs

func (m *CounterMutation) 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 (*CounterMutation) ResetEdge

func (m *CounterMutation) 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 (*CounterMutation) ResetField

func (m *CounterMutation) 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 (*CounterMutation) ResetValue

func (m *CounterMutation) ResetValue()

ResetValue resets all changes to the "value" field.

func (*CounterMutation) SetField

func (m *CounterMutation) 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 (*CounterMutation) SetID

func (m *CounterMutation) SetID(id string)

SetID sets the value of the id field. Note that this operation is only accepted on creation of Counter entities.

func (*CounterMutation) SetOp

func (m *CounterMutation) SetOp(op Op)

SetOp allows setting the mutation operation.

func (*CounterMutation) SetValue

func (m *CounterMutation) SetValue(i int64)

SetValue sets the "value" field.

func (CounterMutation) Tx

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

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

func (*CounterMutation) Type

func (m *CounterMutation) Type() string

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

func (*CounterMutation) Value

func (m *CounterMutation) Value() (r int64, exists bool)

Value returns the value of the "value" field in the mutation.

func (*CounterMutation) Where

func (m *CounterMutation) Where(ps ...predicate.Counter)

Where appends a list predicates to the CounterMutation builder.

func (*CounterMutation) WhereP

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

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

type CounterQuery

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

CounterQuery is the builder for querying Counter entities.

func (*CounterQuery) Aggregate

func (cq *CounterQuery) Aggregate(fns ...AggregateFunc) *CounterSelect

Aggregate returns a CounterSelect configured with the given aggregations.

func (*CounterQuery) All

func (cq *CounterQuery) All(ctx context.Context) ([]*Counter, error)

All executes the query and returns a list of Counters.

func (*CounterQuery) AllX

func (cq *CounterQuery) AllX(ctx context.Context) []*Counter

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

func (*CounterQuery) Clone

func (cq *CounterQuery) Clone() *CounterQuery

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

func (*CounterQuery) Count

func (cq *CounterQuery) Count(ctx context.Context) (int, error)

Count returns the count of the given query.

func (*CounterQuery) CountX

func (cq *CounterQuery) CountX(ctx context.Context) int

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

func (*CounterQuery) Exist

func (cq *CounterQuery) Exist(ctx context.Context) (bool, error)

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

func (*CounterQuery) ExistX

func (cq *CounterQuery) ExistX(ctx context.Context) bool

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

func (*CounterQuery) First

func (cq *CounterQuery) First(ctx context.Context) (*Counter, error)

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

func (*CounterQuery) FirstID

func (cq *CounterQuery) FirstID(ctx context.Context) (id string, err error)

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

func (*CounterQuery) FirstIDX

func (cq *CounterQuery) FirstIDX(ctx context.Context) string

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

func (*CounterQuery) FirstX

func (cq *CounterQuery) FirstX(ctx context.Context) *Counter

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

func (*CounterQuery) GroupBy

func (cq *CounterQuery) GroupBy(field string, fields ...string) *CounterGroupBy

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 {
	Value int64 `json:"value,omitempty"`
	Count int `json:"count,omitempty"`
}

client.Counter.Query().
	GroupBy(counter.FieldValue).
	Aggregate(ent.Count()).
	Scan(ctx, &v)

func (*CounterQuery) IDs

func (cq *CounterQuery) IDs(ctx context.Context) (ids []string, err error)

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

func (*CounterQuery) IDsX

func (cq *CounterQuery) IDsX(ctx context.Context) []string

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

func (*CounterQuery) Limit

func (cq *CounterQuery) Limit(limit int) *CounterQuery

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

func (*CounterQuery) Offset

func (cq *CounterQuery) Offset(offset int) *CounterQuery

Offset to start from.

func (*CounterQuery) Only

func (cq *CounterQuery) Only(ctx context.Context) (*Counter, error)

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

func (*CounterQuery) OnlyID

func (cq *CounterQuery) OnlyID(ctx context.Context) (id string, err error)

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

func (*CounterQuery) OnlyIDX

func (cq *CounterQuery) OnlyIDX(ctx context.Context) string

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

func (*CounterQuery) OnlyX

func (cq *CounterQuery) OnlyX(ctx context.Context) *Counter

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

func (*CounterQuery) Order

func (cq *CounterQuery) Order(o ...counter.OrderOption) *CounterQuery

Order specifies how the records should be ordered.

func (*CounterQuery) Select

func (cq *CounterQuery) Select(fields ...string) *CounterSelect

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 {
	Value int64 `json:"value,omitempty"`
}

client.Counter.Query().
	Select(counter.FieldValue).
	Scan(ctx, &v)

func (*CounterQuery) Unique

func (cq *CounterQuery) Unique(unique bool) *CounterQuery

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 (*CounterQuery) Where

func (cq *CounterQuery) Where(ps ...predicate.Counter) *CounterQuery

Where adds a new predicate for the CounterQuery builder.

type CounterSelect

type CounterSelect struct {
	*CounterQuery
	// contains filtered or unexported fields
}

CounterSelect is the builder for selecting fields of Counter entities.

func (*CounterSelect) Aggregate

func (cs *CounterSelect) Aggregate(fns ...AggregateFunc) *CounterSelect

Aggregate adds the given aggregation functions to the selector query.

func (*CounterSelect) Bool

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

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

func (*CounterSelect) BoolX

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

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

func (*CounterSelect) Bools

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

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

func (*CounterSelect) BoolsX

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

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

func (*CounterSelect) Float64

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

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

func (*CounterSelect) Float64X

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

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

func (*CounterSelect) Float64s

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

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

func (*CounterSelect) Float64sX

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

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

func (*CounterSelect) Int

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

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

func (*CounterSelect) IntX

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

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

func (*CounterSelect) Ints

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

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

func (*CounterSelect) IntsX

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

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

func (*CounterSelect) Scan

func (cs *CounterSelect) Scan(ctx context.Context, v any) error

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

func (*CounterSelect) ScanX

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

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

func (*CounterSelect) String

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

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

func (*CounterSelect) StringX

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

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

func (*CounterSelect) Strings

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

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

func (*CounterSelect) StringsX

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

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

type CounterUpdate

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

CounterUpdate is the builder for updating Counter entities.

func (*CounterUpdate) AddValue

func (cu *CounterUpdate) AddValue(i int64) *CounterUpdate

AddValue adds i to the "value" field.

func (*CounterUpdate) Exec

func (cu *CounterUpdate) Exec(ctx context.Context) error

Exec executes the query.

func (*CounterUpdate) ExecX

func (cu *CounterUpdate) ExecX(ctx context.Context)

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

func (*CounterUpdate) Mutation

func (cu *CounterUpdate) Mutation() *CounterMutation

Mutation returns the CounterMutation object of the builder.

func (*CounterUpdate) Save

func (cu *CounterUpdate) Save(ctx context.Context) (int, error)

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

func (*CounterUpdate) SaveX

func (cu *CounterUpdate) SaveX(ctx context.Context) int

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

func (*CounterUpdate) SetNillableValue

func (cu *CounterUpdate) SetNillableValue(i *int64) *CounterUpdate

SetNillableValue sets the "value" field if the given value is not nil.

func (*CounterUpdate) SetValue

func (cu *CounterUpdate) SetValue(i int64) *CounterUpdate

SetValue sets the "value" field.

func (*CounterUpdate) Where

func (cu *CounterUpdate) Where(ps ...predicate.Counter) *CounterUpdate

Where appends a list predicates to the CounterUpdate builder.

type CounterUpdateOne

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

CounterUpdateOne is the builder for updating a single Counter entity.

func (*CounterUpdateOne) AddValue

func (cuo *CounterUpdateOne) AddValue(i int64) *CounterUpdateOne

AddValue adds i to the "value" field.

func (*CounterUpdateOne) Exec

func (cuo *CounterUpdateOne) Exec(ctx context.Context) error

Exec executes the query on the entity.

func (*CounterUpdateOne) ExecX

func (cuo *CounterUpdateOne) ExecX(ctx context.Context)

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

func (*CounterUpdateOne) Mutation

func (cuo *CounterUpdateOne) Mutation() *CounterMutation

Mutation returns the CounterMutation object of the builder.

func (*CounterUpdateOne) Save

func (cuo *CounterUpdateOne) Save(ctx context.Context) (*Counter, error)

Save executes the query and returns the updated Counter entity.

func (*CounterUpdateOne) SaveX

func (cuo *CounterUpdateOne) SaveX(ctx context.Context) *Counter

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

func (*CounterUpdateOne) Select

func (cuo *CounterUpdateOne) Select(field string, fields ...string) *CounterUpdateOne

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

func (*CounterUpdateOne) SetNillableValue

func (cuo *CounterUpdateOne) SetNillableValue(i *int64) *CounterUpdateOne

SetNillableValue sets the "value" field if the given value is not nil.

func (*CounterUpdateOne) SetValue

func (cuo *CounterUpdateOne) SetValue(i int64) *CounterUpdateOne

SetValue sets the "value" field.

func (*CounterUpdateOne) Where

Where appends a list predicates to the CounterUpdate builder.

type Counters

type Counters []*Counter

Counters is a parsable slice of Counter.

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 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 {

	// Counter is the client for interacting with the Counter builders.
	Counter *CounterClient
	// 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