gen

package
v0.0.36 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: MIT Imports: 17 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.
	TypeDefaultModel = "DefaultModel"
)

Variables

View Source
var ErrTxStarted = errors.New("gen: 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(gen.As(gen.Sum(field1), "sum_field1"), (gen.As(gen.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
	// DefaultModel is the client for interacting with the DefaultModel builders.
	DefaultModel *DefaultModelClient
	// 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().
	DefaultModel.
	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 DefaultModel

type DefaultModel struct {

	// ID of the ent.
	ID uuid.UUID `json:"id,omitempty"`
	// Name holds the value of the "name" field.
	Name string `json:"name,omitempty"`
	// contains filtered or unexported fields
}

DefaultModel is the model entity for the DefaultModel schema.

func (*DefaultModel) String

func (dm *DefaultModel) String() string

String implements the fmt.Stringer.

func (*DefaultModel) Unwrap

func (dm *DefaultModel) Unwrap() *DefaultModel

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

func (dm *DefaultModel) Update() *DefaultModelUpdateOne

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

func (*DefaultModel) Value

func (dm *DefaultModel) Value(name string) (ent.Value, error)

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

type DefaultModelClient

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

DefaultModelClient is a client for the DefaultModel schema.

func NewDefaultModelClient

func NewDefaultModelClient(c config) *DefaultModelClient

NewDefaultModelClient returns a client for the DefaultModel from the given config.

func (*DefaultModelClient) Create

Create returns a builder for creating a DefaultModel entity.

func (*DefaultModelClient) CreateBulk

func (c *DefaultModelClient) CreateBulk(builders ...*DefaultModelCreate) *DefaultModelCreateBulk

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

func (*DefaultModelClient) Delete

Delete returns a delete builder for DefaultModel.

func (*DefaultModelClient) DeleteOne

DeleteOne returns a builder for deleting the given entity.

func (*DefaultModelClient) DeleteOneID

func (c *DefaultModelClient) DeleteOneID(id uuid.UUID) *DefaultModelDeleteOne

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

func (*DefaultModelClient) Get

Get returns a DefaultModel entity by its id.

func (*DefaultModelClient) GetX

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

func (*DefaultModelClient) Hooks

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

Hooks returns the client hooks.

func (*DefaultModelClient) Intercept

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

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

func (*DefaultModelClient) Interceptors

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

Interceptors returns the client interceptors.

func (*DefaultModelClient) MapCreateBulk

func (c *DefaultModelClient) MapCreateBulk(slice any, setFunc func(*DefaultModelCreate, int)) *DefaultModelCreateBulk

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

Query returns a query builder for DefaultModel.

func (*DefaultModelClient) Update

Update returns an update builder for DefaultModel.

func (*DefaultModelClient) UpdateOne

UpdateOne returns an update builder for the given entity.

func (*DefaultModelClient) UpdateOneID

func (c *DefaultModelClient) UpdateOneID(id uuid.UUID) *DefaultModelUpdateOne

UpdateOneID returns an update builder for the given id.

func (*DefaultModelClient) Use

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

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

type DefaultModelCreate

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

DefaultModelCreate is the builder for creating a DefaultModel entity.

func (*DefaultModelCreate) Exec

func (dmc *DefaultModelCreate) Exec(ctx context.Context) error

Exec executes the query.

func (*DefaultModelCreate) ExecX

func (dmc *DefaultModelCreate) ExecX(ctx context.Context)

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

func (*DefaultModelCreate) Mutation

func (dmc *DefaultModelCreate) Mutation() *DefaultModelMutation

Mutation returns the DefaultModelMutation object of the builder.

func (*DefaultModelCreate) Save

Save creates the DefaultModel in the database.

func (*DefaultModelCreate) SaveX

SaveX calls Save and panics if Save returns an error.

func (*DefaultModelCreate) SetID

SetID sets the "id" field.

func (*DefaultModelCreate) SetName

func (dmc *DefaultModelCreate) SetName(s string) *DefaultModelCreate

SetName sets the "name" field.

type DefaultModelCreateBulk

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

DefaultModelCreateBulk is the builder for creating many DefaultModel entities in bulk.

func (*DefaultModelCreateBulk) Exec

func (dmcb *DefaultModelCreateBulk) Exec(ctx context.Context) error

Exec executes the query.

func (*DefaultModelCreateBulk) ExecX

func (dmcb *DefaultModelCreateBulk) ExecX(ctx context.Context)

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

func (*DefaultModelCreateBulk) Save

Save creates the DefaultModel entities in the database.

func (*DefaultModelCreateBulk) SaveX

func (dmcb *DefaultModelCreateBulk) SaveX(ctx context.Context) []*DefaultModel

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

type DefaultModelDelete

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

DefaultModelDelete is the builder for deleting a DefaultModel entity.

func (*DefaultModelDelete) Exec

func (dmd *DefaultModelDelete) Exec(ctx context.Context) (int, error)

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

func (*DefaultModelDelete) ExecX

func (dmd *DefaultModelDelete) ExecX(ctx context.Context) int

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

func (*DefaultModelDelete) Where

Where appends a list predicates to the DefaultModelDelete builder.

type DefaultModelDeleteOne

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

DefaultModelDeleteOne is the builder for deleting a single DefaultModel entity.

func (*DefaultModelDeleteOne) Exec

func (dmdo *DefaultModelDeleteOne) Exec(ctx context.Context) error

Exec executes the deletion query.

func (*DefaultModelDeleteOne) ExecX

func (dmdo *DefaultModelDeleteOne) ExecX(ctx context.Context)

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

func (*DefaultModelDeleteOne) Where

Where appends a list predicates to the DefaultModelDelete builder.

type DefaultModelGroupBy

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

DefaultModelGroupBy is the group-by builder for DefaultModel entities.

func (*DefaultModelGroupBy) Aggregate

func (dmgb *DefaultModelGroupBy) Aggregate(fns ...AggregateFunc) *DefaultModelGroupBy

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

func (*DefaultModelGroupBy) Bool

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

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

func (*DefaultModelGroupBy) BoolX

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

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

func (*DefaultModelGroupBy) Bools

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

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

func (*DefaultModelGroupBy) BoolsX

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

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

func (*DefaultModelGroupBy) Float64

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

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

func (*DefaultModelGroupBy) Float64X

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

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

func (*DefaultModelGroupBy) Float64s

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

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

func (*DefaultModelGroupBy) Float64sX

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

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

func (*DefaultModelGroupBy) Int

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

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

func (*DefaultModelGroupBy) IntX

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

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

func (*DefaultModelGroupBy) Ints

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

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

func (*DefaultModelGroupBy) IntsX

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

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

func (*DefaultModelGroupBy) Scan

func (dmgb *DefaultModelGroupBy) Scan(ctx context.Context, v any) error

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

func (*DefaultModelGroupBy) ScanX

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

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

func (*DefaultModelGroupBy) String

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

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

func (*DefaultModelGroupBy) StringX

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

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

func (*DefaultModelGroupBy) Strings

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

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

func (*DefaultModelGroupBy) StringsX

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

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

type DefaultModelMutation

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

DefaultModelMutation represents an operation that mutates the DefaultModel nodes in the graph.

func (*DefaultModelMutation) AddField

func (m *DefaultModelMutation) 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 (*DefaultModelMutation) AddedEdges

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

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

func (*DefaultModelMutation) AddedField

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

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

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

func (*DefaultModelMutation) AddedIDs

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

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

func (*DefaultModelMutation) ClearEdge

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

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

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

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

func (*DefaultModelMutation) ClearedFields

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

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

func (DefaultModelMutation) Client

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

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

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

func (*DefaultModelMutation) Field

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

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

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

func (*DefaultModelMutation) Fields

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

func (m *DefaultModelMutation) ID() (id uuid.UUID, 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 (*DefaultModelMutation) IDs

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 (*DefaultModelMutation) Name

func (m *DefaultModelMutation) Name() (r string, exists bool)

Name returns the value of the "name" field in the mutation.

func (*DefaultModelMutation) OldField

func (m *DefaultModelMutation) 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 (*DefaultModelMutation) OldName

func (m *DefaultModelMutation) OldName(ctx context.Context) (v string, err error)

OldName returns the old "name" field's value of the DefaultModel entity. If the DefaultModel 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 (*DefaultModelMutation) Op

func (m *DefaultModelMutation) Op() Op

Op returns the operation name.

func (*DefaultModelMutation) RemovedEdges

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

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

func (*DefaultModelMutation) RemovedIDs

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

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

func (m *DefaultModelMutation) 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 (*DefaultModelMutation) ResetName

func (m *DefaultModelMutation) ResetName()

ResetName resets all changes to the "name" field.

func (*DefaultModelMutation) SetField

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

func (m *DefaultModelMutation) SetID(id uuid.UUID)

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

func (*DefaultModelMutation) SetName

func (m *DefaultModelMutation) SetName(s string)

SetName sets the "name" field.

func (*DefaultModelMutation) SetOp

func (m *DefaultModelMutation) SetOp(op Op)

SetOp allows setting the mutation operation.

func (DefaultModelMutation) Tx

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

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

func (*DefaultModelMutation) Type

func (m *DefaultModelMutation) Type() string

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

func (*DefaultModelMutation) Where

Where appends a list predicates to the DefaultModelMutation builder.

func (*DefaultModelMutation) WhereP

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

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

type DefaultModelQuery

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

DefaultModelQuery is the builder for querying DefaultModel entities.

func (*DefaultModelQuery) Aggregate

func (dmq *DefaultModelQuery) Aggregate(fns ...AggregateFunc) *DefaultModelSelect

Aggregate returns a DefaultModelSelect configured with the given aggregations.

func (*DefaultModelQuery) All

func (dmq *DefaultModelQuery) All(ctx context.Context) ([]*DefaultModel, error)

All executes the query and returns a list of DefaultModels.

func (*DefaultModelQuery) AllX

func (dmq *DefaultModelQuery) AllX(ctx context.Context) []*DefaultModel

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

func (*DefaultModelQuery) Clone

func (dmq *DefaultModelQuery) Clone() *DefaultModelQuery

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

func (*DefaultModelQuery) Count

func (dmq *DefaultModelQuery) Count(ctx context.Context) (int, error)

Count returns the count of the given query.

func (*DefaultModelQuery) CountX

func (dmq *DefaultModelQuery) CountX(ctx context.Context) int

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

func (*DefaultModelQuery) Exist

func (dmq *DefaultModelQuery) Exist(ctx context.Context) (bool, error)

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

func (*DefaultModelQuery) ExistX

func (dmq *DefaultModelQuery) ExistX(ctx context.Context) bool

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

func (*DefaultModelQuery) First

func (dmq *DefaultModelQuery) First(ctx context.Context) (*DefaultModel, error)

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

func (*DefaultModelQuery) FirstID

func (dmq *DefaultModelQuery) FirstID(ctx context.Context) (id uuid.UUID, err error)

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

func (*DefaultModelQuery) FirstIDX

func (dmq *DefaultModelQuery) FirstIDX(ctx context.Context) uuid.UUID

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

func (*DefaultModelQuery) FirstX

func (dmq *DefaultModelQuery) FirstX(ctx context.Context) *DefaultModel

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

func (*DefaultModelQuery) GroupBy

func (dmq *DefaultModelQuery) GroupBy(field string, fields ...string) *DefaultModelGroupBy

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

client.DefaultModel.Query().
	GroupBy(defaultmodel.FieldName).
	Aggregate(gen.Count()).
	Scan(ctx, &v)

func (*DefaultModelQuery) IDs

func (dmq *DefaultModelQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error)

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

func (*DefaultModelQuery) IDsX

func (dmq *DefaultModelQuery) IDsX(ctx context.Context) []uuid.UUID

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

func (*DefaultModelQuery) Limit

func (dmq *DefaultModelQuery) Limit(limit int) *DefaultModelQuery

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

func (*DefaultModelQuery) Offset

func (dmq *DefaultModelQuery) Offset(offset int) *DefaultModelQuery

Offset to start from.

func (*DefaultModelQuery) Only

func (dmq *DefaultModelQuery) Only(ctx context.Context) (*DefaultModel, error)

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

func (*DefaultModelQuery) OnlyID

func (dmq *DefaultModelQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error)

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

func (*DefaultModelQuery) OnlyIDX

func (dmq *DefaultModelQuery) OnlyIDX(ctx context.Context) uuid.UUID

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

func (*DefaultModelQuery) OnlyX

func (dmq *DefaultModelQuery) OnlyX(ctx context.Context) *DefaultModel

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

func (*DefaultModelQuery) Order

Order specifies how the records should be ordered.

func (*DefaultModelQuery) Select

func (dmq *DefaultModelQuery) Select(fields ...string) *DefaultModelSelect

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

client.DefaultModel.Query().
	Select(defaultmodel.FieldName).
	Scan(ctx, &v)

func (*DefaultModelQuery) Unique

func (dmq *DefaultModelQuery) Unique(unique bool) *DefaultModelQuery

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

Where adds a new predicate for the DefaultModelQuery builder.

type DefaultModelSelect

type DefaultModelSelect struct {
	*DefaultModelQuery
	// contains filtered or unexported fields
}

DefaultModelSelect is the builder for selecting fields of DefaultModel entities.

func (*DefaultModelSelect) Aggregate

func (dms *DefaultModelSelect) Aggregate(fns ...AggregateFunc) *DefaultModelSelect

Aggregate adds the given aggregation functions to the selector query.

func (*DefaultModelSelect) Bool

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

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

func (*DefaultModelSelect) BoolX

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

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

func (*DefaultModelSelect) Bools

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

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

func (*DefaultModelSelect) BoolsX

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

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

func (*DefaultModelSelect) Float64

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

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

func (*DefaultModelSelect) Float64X

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

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

func (*DefaultModelSelect) Float64s

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

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

func (*DefaultModelSelect) Float64sX

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

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

func (*DefaultModelSelect) Int

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

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

func (*DefaultModelSelect) IntX

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

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

func (*DefaultModelSelect) Ints

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

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

func (*DefaultModelSelect) IntsX

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

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

func (*DefaultModelSelect) Scan

func (dms *DefaultModelSelect) Scan(ctx context.Context, v any) error

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

func (*DefaultModelSelect) ScanX

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

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

func (*DefaultModelSelect) String

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

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

func (*DefaultModelSelect) StringX

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

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

func (*DefaultModelSelect) Strings

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

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

func (*DefaultModelSelect) StringsX

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

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

type DefaultModelUpdate

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

DefaultModelUpdate is the builder for updating DefaultModel entities.

func (*DefaultModelUpdate) Exec

func (dmu *DefaultModelUpdate) Exec(ctx context.Context) error

Exec executes the query.

func (*DefaultModelUpdate) ExecX

func (dmu *DefaultModelUpdate) ExecX(ctx context.Context)

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

func (*DefaultModelUpdate) Mutation

func (dmu *DefaultModelUpdate) Mutation() *DefaultModelMutation

Mutation returns the DefaultModelMutation object of the builder.

func (*DefaultModelUpdate) Save

func (dmu *DefaultModelUpdate) Save(ctx context.Context) (int, error)

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

func (*DefaultModelUpdate) SaveX

func (dmu *DefaultModelUpdate) SaveX(ctx context.Context) int

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

func (*DefaultModelUpdate) SetName

func (dmu *DefaultModelUpdate) SetName(s string) *DefaultModelUpdate

SetName sets the "name" field.

func (*DefaultModelUpdate) SetNillableName

func (dmu *DefaultModelUpdate) SetNillableName(s *string) *DefaultModelUpdate

SetNillableName sets the "name" field if the given value is not nil.

func (*DefaultModelUpdate) Where

Where appends a list predicates to the DefaultModelUpdate builder.

type DefaultModelUpdateOne

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

DefaultModelUpdateOne is the builder for updating a single DefaultModel entity.

func (*DefaultModelUpdateOne) Exec

func (dmuo *DefaultModelUpdateOne) Exec(ctx context.Context) error

Exec executes the query on the entity.

func (*DefaultModelUpdateOne) ExecX

func (dmuo *DefaultModelUpdateOne) ExecX(ctx context.Context)

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

func (*DefaultModelUpdateOne) Mutation

func (dmuo *DefaultModelUpdateOne) Mutation() *DefaultModelMutation

Mutation returns the DefaultModelMutation object of the builder.

func (*DefaultModelUpdateOne) Save

Save executes the query and returns the updated DefaultModel entity.

func (*DefaultModelUpdateOne) SaveX

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

func (*DefaultModelUpdateOne) Select

func (dmuo *DefaultModelUpdateOne) Select(field string, fields ...string) *DefaultModelUpdateOne

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

func (*DefaultModelUpdateOne) SetName

SetName sets the "name" field.

func (*DefaultModelUpdateOne) SetNillableName

func (dmuo *DefaultModelUpdateOne) SetNillableName(s *string) *DefaultModelUpdateOne

SetNillableName sets the "name" field if the given value is not nil.

func (*DefaultModelUpdateOne) Where

Where appends a list predicates to the DefaultModelUpdate builder.

type DefaultModels

type DefaultModels []*DefaultModel

DefaultModels is a parsable slice of DefaultModel.

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 {

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