ent

package
v0.0.0-...-690d607 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 19 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.
	TypeArticle = "Article"
	TypeAuthor  = "Author"
)

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 Article

type Article struct {

	// ID of the ent.
	ID int64 `json:"id,omitempty"`
	// Title holds the value of the "title" field.
	Title string `json:"title,omitempty"`
	// Body holds the value of the "body" field.
	Body string `json:"body,omitempty"`
	// PublishedAt holds the value of the "published_at" field.
	PublishedAt time.Time `json:"published_at,omitempty"`
	// contains filtered or unexported fields
}

Article is the model entity for the Article schema.

func (*Article) String

func (a *Article) String() string

String implements the fmt.Stringer.

func (*Article) Unwrap

func (a *Article) Unwrap() *Article

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

func (a *Article) Update() *ArticleUpdateOne

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

func (*Article) Value

func (a *Article) Value(name string) (ent.Value, error)

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

type ArticleClient

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

ArticleClient is a client for the Article schema.

func NewArticleClient

func NewArticleClient(c config) *ArticleClient

NewArticleClient returns a client for the Article from the given config.

func (*ArticleClient) Create

func (c *ArticleClient) Create() *ArticleCreate

Create returns a builder for creating a Article entity.

func (*ArticleClient) CreateBulk

func (c *ArticleClient) CreateBulk(builders ...*ArticleCreate) *ArticleCreateBulk

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

func (*ArticleClient) Delete

func (c *ArticleClient) Delete() *ArticleDelete

Delete returns a delete builder for Article.

func (*ArticleClient) DeleteOne

func (c *ArticleClient) DeleteOne(a *Article) *ArticleDeleteOne

DeleteOne returns a builder for deleting the given entity.

func (*ArticleClient) DeleteOneID

func (c *ArticleClient) DeleteOneID(id int64) *ArticleDeleteOne

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

func (*ArticleClient) Get

func (c *ArticleClient) Get(ctx context.Context, id int64) (*Article, error)

Get returns a Article entity by its id.

func (*ArticleClient) GetX

func (c *ArticleClient) GetX(ctx context.Context, id int64) *Article

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

func (*ArticleClient) Hooks

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

Hooks returns the client hooks.

func (*ArticleClient) Intercept

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

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

func (*ArticleClient) Interceptors

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

Interceptors returns the client interceptors.

func (*ArticleClient) MapCreateBulk

func (c *ArticleClient) MapCreateBulk(slice any, setFunc func(*ArticleCreate, int)) *ArticleCreateBulk

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

func (c *ArticleClient) Query() *ArticleQuery

Query returns a query builder for Article.

func (*ArticleClient) Update

func (c *ArticleClient) Update() *ArticleUpdate

Update returns an update builder for Article.

func (*ArticleClient) UpdateOne

func (c *ArticleClient) UpdateOne(a *Article) *ArticleUpdateOne

UpdateOne returns an update builder for the given entity.

func (*ArticleClient) UpdateOneID

func (c *ArticleClient) UpdateOneID(id int64) *ArticleUpdateOne

UpdateOneID returns an update builder for the given id.

func (*ArticleClient) Use

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

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

type ArticleCreate

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

ArticleCreate is the builder for creating a Article entity.

func (*ArticleCreate) Exec

func (ac *ArticleCreate) Exec(ctx context.Context) error

Exec executes the query.

func (*ArticleCreate) ExecX

func (ac *ArticleCreate) ExecX(ctx context.Context)

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

func (*ArticleCreate) Mutation

func (ac *ArticleCreate) Mutation() *ArticleMutation

Mutation returns the ArticleMutation object of the builder.

func (*ArticleCreate) Save

func (ac *ArticleCreate) Save(ctx context.Context) (*Article, error)

Save creates the Article in the database.

func (*ArticleCreate) SaveX

func (ac *ArticleCreate) SaveX(ctx context.Context) *Article

SaveX calls Save and panics if Save returns an error.

func (*ArticleCreate) SetBody

func (ac *ArticleCreate) SetBody(s string) *ArticleCreate

SetBody sets the "body" field.

func (*ArticleCreate) SetID

func (ac *ArticleCreate) SetID(i int64) *ArticleCreate

SetID sets the "id" field.

func (*ArticleCreate) SetNillableBody

func (ac *ArticleCreate) SetNillableBody(s *string) *ArticleCreate

SetNillableBody sets the "body" field if the given value is not nil.

func (*ArticleCreate) SetNillablePublishedAt

func (ac *ArticleCreate) SetNillablePublishedAt(t *time.Time) *ArticleCreate

SetNillablePublishedAt sets the "published_at" field if the given value is not nil.

func (*ArticleCreate) SetNillableTitle

func (ac *ArticleCreate) SetNillableTitle(s *string) *ArticleCreate

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

func (*ArticleCreate) SetPublishedAt

func (ac *ArticleCreate) SetPublishedAt(t time.Time) *ArticleCreate

SetPublishedAt sets the "published_at" field.

func (*ArticleCreate) SetTitle

func (ac *ArticleCreate) SetTitle(s string) *ArticleCreate

SetTitle sets the "title" field.

type ArticleCreateBulk

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

ArticleCreateBulk is the builder for creating many Article entities in bulk.

func (*ArticleCreateBulk) Exec

func (acb *ArticleCreateBulk) Exec(ctx context.Context) error

Exec executes the query.

func (*ArticleCreateBulk) ExecX

func (acb *ArticleCreateBulk) ExecX(ctx context.Context)

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

func (*ArticleCreateBulk) Save

func (acb *ArticleCreateBulk) Save(ctx context.Context) ([]*Article, error)

Save creates the Article entities in the database.

func (*ArticleCreateBulk) SaveX

func (acb *ArticleCreateBulk) SaveX(ctx context.Context) []*Article

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

type ArticleDelete

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

ArticleDelete is the builder for deleting a Article entity.

func (*ArticleDelete) Exec

func (ad *ArticleDelete) Exec(ctx context.Context) (int, error)

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

func (*ArticleDelete) ExecX

func (ad *ArticleDelete) ExecX(ctx context.Context) int

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

func (*ArticleDelete) Where

func (ad *ArticleDelete) Where(ps ...predicate.Article) *ArticleDelete

Where appends a list predicates to the ArticleDelete builder.

type ArticleDeleteOne

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

ArticleDeleteOne is the builder for deleting a single Article entity.

func (*ArticleDeleteOne) Exec

func (ado *ArticleDeleteOne) Exec(ctx context.Context) error

Exec executes the deletion query.

func (*ArticleDeleteOne) ExecX

func (ado *ArticleDeleteOne) ExecX(ctx context.Context)

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

func (*ArticleDeleteOne) Where

Where appends a list predicates to the ArticleDelete builder.

type ArticleGroupBy

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

ArticleGroupBy is the group-by builder for Article entities.

func (*ArticleGroupBy) Aggregate

func (agb *ArticleGroupBy) Aggregate(fns ...AggregateFunc) *ArticleGroupBy

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

func (*ArticleGroupBy) Bool

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

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

func (*ArticleGroupBy) BoolX

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

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

func (*ArticleGroupBy) Bools

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

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

func (*ArticleGroupBy) BoolsX

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

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

func (*ArticleGroupBy) Float64

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

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

func (*ArticleGroupBy) Float64X

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

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

func (*ArticleGroupBy) Float64s

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

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

func (*ArticleGroupBy) Float64sX

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

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

func (*ArticleGroupBy) Int

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

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

func (*ArticleGroupBy) IntX

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

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

func (*ArticleGroupBy) Ints

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

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

func (*ArticleGroupBy) IntsX

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

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

func (*ArticleGroupBy) Scan

func (agb *ArticleGroupBy) Scan(ctx context.Context, v any) error

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

func (*ArticleGroupBy) ScanX

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

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

func (*ArticleGroupBy) String

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

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

func (*ArticleGroupBy) StringX

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

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

func (*ArticleGroupBy) Strings

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

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

func (*ArticleGroupBy) StringsX

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

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

type ArticleMutation

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

ArticleMutation represents an operation that mutates the Article nodes in the graph.

func (*ArticleMutation) AddField

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

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

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

func (*ArticleMutation) AddedField

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

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

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

func (*ArticleMutation) AddedIDs

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

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

func (*ArticleMutation) Body

func (m *ArticleMutation) Body() (r string, exists bool)

Body returns the value of the "body" field in the mutation.

func (*ArticleMutation) ClearEdge

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

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

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

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

func (*ArticleMutation) ClearedFields

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

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

func (ArticleMutation) Client

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

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

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

func (*ArticleMutation) Field

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

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

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

func (*ArticleMutation) Fields

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

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

func (m *ArticleMutation) IDs(ctx context.Context) ([]int64, 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 (*ArticleMutation) OldBody

func (m *ArticleMutation) OldBody(ctx context.Context) (v string, err error)

OldBody returns the old "body" field's value of the Article entity. If the Article 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 (*ArticleMutation) OldField

func (m *ArticleMutation) 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 (*ArticleMutation) OldPublishedAt

func (m *ArticleMutation) OldPublishedAt(ctx context.Context) (v time.Time, err error)

OldPublishedAt returns the old "published_at" field's value of the Article entity. If the Article 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 (*ArticleMutation) OldTitle

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

OldTitle returns the old "title" field's value of the Article entity. If the Article 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 (*ArticleMutation) Op

func (m *ArticleMutation) Op() Op

Op returns the operation name.

func (*ArticleMutation) PublishedAt

func (m *ArticleMutation) PublishedAt() (r time.Time, exists bool)

PublishedAt returns the value of the "published_at" field in the mutation.

func (*ArticleMutation) RemovedEdges

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

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

func (*ArticleMutation) RemovedIDs

func (m *ArticleMutation) 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 (*ArticleMutation) ResetBody

func (m *ArticleMutation) ResetBody()

ResetBody resets all changes to the "body" field.

func (*ArticleMutation) ResetEdge

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

func (m *ArticleMutation) 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 (*ArticleMutation) ResetPublishedAt

func (m *ArticleMutation) ResetPublishedAt()

ResetPublishedAt resets all changes to the "published_at" field.

func (*ArticleMutation) ResetTitle

func (m *ArticleMutation) ResetTitle()

ResetTitle resets all changes to the "title" field.

func (*ArticleMutation) SetBody

func (m *ArticleMutation) SetBody(s string)

SetBody sets the "body" field.

func (*ArticleMutation) SetField

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

func (m *ArticleMutation) SetID(id int64)

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

func (*ArticleMutation) SetOp

func (m *ArticleMutation) SetOp(op Op)

SetOp allows setting the mutation operation.

func (*ArticleMutation) SetPublishedAt

func (m *ArticleMutation) SetPublishedAt(t time.Time)

SetPublishedAt sets the "published_at" field.

func (*ArticleMutation) SetTitle

func (m *ArticleMutation) SetTitle(s string)

SetTitle sets the "title" field.

func (*ArticleMutation) Title

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

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

func (ArticleMutation) Tx

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

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

func (*ArticleMutation) Type

func (m *ArticleMutation) Type() string

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

func (*ArticleMutation) Where

func (m *ArticleMutation) Where(ps ...predicate.Article)

Where appends a list predicates to the ArticleMutation builder.

func (*ArticleMutation) WhereP

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

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

type ArticleQuery

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

ArticleQuery is the builder for querying Article entities.

func (*ArticleQuery) Aggregate

func (aq *ArticleQuery) Aggregate(fns ...AggregateFunc) *ArticleSelect

Aggregate returns a ArticleSelect configured with the given aggregations.

func (*ArticleQuery) All

func (aq *ArticleQuery) All(ctx context.Context) ([]*Article, error)

All executes the query and returns a list of Articles.

func (*ArticleQuery) AllX

func (aq *ArticleQuery) AllX(ctx context.Context) []*Article

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

func (*ArticleQuery) Clone

func (aq *ArticleQuery) Clone() *ArticleQuery

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

func (*ArticleQuery) Count

func (aq *ArticleQuery) Count(ctx context.Context) (int, error)

Count returns the count of the given query.

func (*ArticleQuery) CountX

func (aq *ArticleQuery) CountX(ctx context.Context) int

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

func (*ArticleQuery) Exist

func (aq *ArticleQuery) Exist(ctx context.Context) (bool, error)

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

func (*ArticleQuery) ExistX

func (aq *ArticleQuery) ExistX(ctx context.Context) bool

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

func (*ArticleQuery) First

func (aq *ArticleQuery) First(ctx context.Context) (*Article, error)

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

func (*ArticleQuery) FirstID

func (aq *ArticleQuery) FirstID(ctx context.Context) (id int64, err error)

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

func (*ArticleQuery) FirstIDX

func (aq *ArticleQuery) FirstIDX(ctx context.Context) int64

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

func (*ArticleQuery) FirstX

func (aq *ArticleQuery) FirstX(ctx context.Context) *Article

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

func (*ArticleQuery) GroupBy

func (aq *ArticleQuery) GroupBy(field string, fields ...string) *ArticleGroupBy

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.Article.Query().
	GroupBy(article.FieldTitle).
	Aggregate(ent.Count()).
	Scan(ctx, &v)

func (*ArticleQuery) IDs

func (aq *ArticleQuery) IDs(ctx context.Context) (ids []int64, err error)

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

func (*ArticleQuery) IDsX

func (aq *ArticleQuery) IDsX(ctx context.Context) []int64

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

func (*ArticleQuery) Limit

func (aq *ArticleQuery) Limit(limit int) *ArticleQuery

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

func (*ArticleQuery) Offset

func (aq *ArticleQuery) Offset(offset int) *ArticleQuery

Offset to start from.

func (*ArticleQuery) Only

func (aq *ArticleQuery) Only(ctx context.Context) (*Article, error)

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

func (*ArticleQuery) OnlyID

func (aq *ArticleQuery) OnlyID(ctx context.Context) (id int64, err error)

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

func (*ArticleQuery) OnlyIDX

func (aq *ArticleQuery) OnlyIDX(ctx context.Context) int64

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

func (*ArticleQuery) OnlyX

func (aq *ArticleQuery) OnlyX(ctx context.Context) *Article

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

func (*ArticleQuery) Order

func (aq *ArticleQuery) Order(o ...article.OrderOption) *ArticleQuery

Order specifies how the records should be ordered.

func (*ArticleQuery) Select

func (aq *ArticleQuery) Select(fields ...string) *ArticleSelect

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.Article.Query().
	Select(article.FieldTitle).
	Scan(ctx, &v)

func (*ArticleQuery) Unique

func (aq *ArticleQuery) Unique(unique bool) *ArticleQuery

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

func (aq *ArticleQuery) Where(ps ...predicate.Article) *ArticleQuery

Where adds a new predicate for the ArticleQuery builder.

type ArticleSelect

type ArticleSelect struct {
	*ArticleQuery
	// contains filtered or unexported fields
}

ArticleSelect is the builder for selecting fields of Article entities.

func (*ArticleSelect) Aggregate

func (as *ArticleSelect) Aggregate(fns ...AggregateFunc) *ArticleSelect

Aggregate adds the given aggregation functions to the selector query.

func (*ArticleSelect) Bool

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

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

func (*ArticleSelect) BoolX

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

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

func (*ArticleSelect) Bools

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

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

func (*ArticleSelect) BoolsX

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

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

func (*ArticleSelect) Float64

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

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

func (*ArticleSelect) Float64X

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

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

func (*ArticleSelect) Float64s

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

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

func (*ArticleSelect) Float64sX

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

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

func (*ArticleSelect) Int

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

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

func (*ArticleSelect) IntX

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

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

func (*ArticleSelect) Ints

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

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

func (*ArticleSelect) IntsX

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

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

func (*ArticleSelect) Scan

func (as *ArticleSelect) Scan(ctx context.Context, v any) error

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

func (*ArticleSelect) ScanX

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

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

func (*ArticleSelect) String

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

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

func (*ArticleSelect) StringX

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

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

func (*ArticleSelect) Strings

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

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

func (*ArticleSelect) StringsX

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

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

type ArticleUpdate

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

ArticleUpdate is the builder for updating Article entities.

func (*ArticleUpdate) Exec

func (au *ArticleUpdate) Exec(ctx context.Context) error

Exec executes the query.

func (*ArticleUpdate) ExecX

func (au *ArticleUpdate) ExecX(ctx context.Context)

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

func (*ArticleUpdate) Mutation

func (au *ArticleUpdate) Mutation() *ArticleMutation

Mutation returns the ArticleMutation object of the builder.

func (*ArticleUpdate) Save

func (au *ArticleUpdate) Save(ctx context.Context) (int, error)

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

func (*ArticleUpdate) SaveX

func (au *ArticleUpdate) SaveX(ctx context.Context) int

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

func (*ArticleUpdate) SetBody

func (au *ArticleUpdate) SetBody(s string) *ArticleUpdate

SetBody sets the "body" field.

func (*ArticleUpdate) SetNillableBody

func (au *ArticleUpdate) SetNillableBody(s *string) *ArticleUpdate

SetNillableBody sets the "body" field if the given value is not nil.

func (*ArticleUpdate) SetNillablePublishedAt

func (au *ArticleUpdate) SetNillablePublishedAt(t *time.Time) *ArticleUpdate

SetNillablePublishedAt sets the "published_at" field if the given value is not nil.

func (*ArticleUpdate) SetNillableTitle

func (au *ArticleUpdate) SetNillableTitle(s *string) *ArticleUpdate

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

func (*ArticleUpdate) SetPublishedAt

func (au *ArticleUpdate) SetPublishedAt(t time.Time) *ArticleUpdate

SetPublishedAt sets the "published_at" field.

func (*ArticleUpdate) SetTitle

func (au *ArticleUpdate) SetTitle(s string) *ArticleUpdate

SetTitle sets the "title" field.

func (*ArticleUpdate) Where

func (au *ArticleUpdate) Where(ps ...predicate.Article) *ArticleUpdate

Where appends a list predicates to the ArticleUpdate builder.

type ArticleUpdateOne

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

ArticleUpdateOne is the builder for updating a single Article entity.

func (*ArticleUpdateOne) Exec

func (auo *ArticleUpdateOne) Exec(ctx context.Context) error

Exec executes the query on the entity.

func (*ArticleUpdateOne) ExecX

func (auo *ArticleUpdateOne) ExecX(ctx context.Context)

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

func (*ArticleUpdateOne) Mutation

func (auo *ArticleUpdateOne) Mutation() *ArticleMutation

Mutation returns the ArticleMutation object of the builder.

func (*ArticleUpdateOne) Save

func (auo *ArticleUpdateOne) Save(ctx context.Context) (*Article, error)

Save executes the query and returns the updated Article entity.

func (*ArticleUpdateOne) SaveX

func (auo *ArticleUpdateOne) SaveX(ctx context.Context) *Article

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

func (*ArticleUpdateOne) Select

func (auo *ArticleUpdateOne) Select(field string, fields ...string) *ArticleUpdateOne

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

func (*ArticleUpdateOne) SetBody

func (auo *ArticleUpdateOne) SetBody(s string) *ArticleUpdateOne

SetBody sets the "body" field.

func (*ArticleUpdateOne) SetNillableBody

func (auo *ArticleUpdateOne) SetNillableBody(s *string) *ArticleUpdateOne

SetNillableBody sets the "body" field if the given value is not nil.

func (*ArticleUpdateOne) SetNillablePublishedAt

func (auo *ArticleUpdateOne) SetNillablePublishedAt(t *time.Time) *ArticleUpdateOne

SetNillablePublishedAt sets the "published_at" field if the given value is not nil.

func (*ArticleUpdateOne) SetNillableTitle

func (auo *ArticleUpdateOne) SetNillableTitle(s *string) *ArticleUpdateOne

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

func (*ArticleUpdateOne) SetPublishedAt

func (auo *ArticleUpdateOne) SetPublishedAt(t time.Time) *ArticleUpdateOne

SetPublishedAt sets the "published_at" field.

func (*ArticleUpdateOne) SetTitle

func (auo *ArticleUpdateOne) SetTitle(s string) *ArticleUpdateOne

SetTitle sets the "title" field.

func (*ArticleUpdateOne) Where

Where appends a list predicates to the ArticleUpdate builder.

type Articles

type Articles []*Article

Articles is a parsable slice of Article.

type Author

type Author struct {

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

Author is the model entity for the Author schema.

func (*Author) String

func (a *Author) String() string

String implements the fmt.Stringer.

func (*Author) Unwrap

func (a *Author) Unwrap() *Author

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

func (a *Author) Update() *AuthorUpdateOne

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

func (*Author) Value

func (a *Author) Value(name string) (ent.Value, error)

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

type AuthorClient

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

AuthorClient is a client for the Author schema.

func NewAuthorClient

func NewAuthorClient(c config) *AuthorClient

NewAuthorClient returns a client for the Author from the given config.

func (*AuthorClient) Create

func (c *AuthorClient) Create() *AuthorCreate

Create returns a builder for creating a Author entity.

func (*AuthorClient) CreateBulk

func (c *AuthorClient) CreateBulk(builders ...*AuthorCreate) *AuthorCreateBulk

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

func (*AuthorClient) Delete

func (c *AuthorClient) Delete() *AuthorDelete

Delete returns a delete builder for Author.

func (*AuthorClient) DeleteOne

func (c *AuthorClient) DeleteOne(a *Author) *AuthorDeleteOne

DeleteOne returns a builder for deleting the given entity.

func (*AuthorClient) DeleteOneID

func (c *AuthorClient) DeleteOneID(id int64) *AuthorDeleteOne

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

func (*AuthorClient) Get

func (c *AuthorClient) Get(ctx context.Context, id int64) (*Author, error)

Get returns a Author entity by its id.

func (*AuthorClient) GetX

func (c *AuthorClient) GetX(ctx context.Context, id int64) *Author

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

func (*AuthorClient) Hooks

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

Hooks returns the client hooks.

func (*AuthorClient) Intercept

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

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

func (*AuthorClient) Interceptors

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

Interceptors returns the client interceptors.

func (*AuthorClient) MapCreateBulk

func (c *AuthorClient) MapCreateBulk(slice any, setFunc func(*AuthorCreate, int)) *AuthorCreateBulk

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

func (c *AuthorClient) Query() *AuthorQuery

Query returns a query builder for Author.

func (*AuthorClient) Update

func (c *AuthorClient) Update() *AuthorUpdate

Update returns an update builder for Author.

func (*AuthorClient) UpdateOne

func (c *AuthorClient) UpdateOne(a *Author) *AuthorUpdateOne

UpdateOne returns an update builder for the given entity.

func (*AuthorClient) UpdateOneID

func (c *AuthorClient) UpdateOneID(id int64) *AuthorUpdateOne

UpdateOneID returns an update builder for the given id.

func (*AuthorClient) Use

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

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

type AuthorCreate

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

AuthorCreate is the builder for creating a Author entity.

func (*AuthorCreate) Exec

func (ac *AuthorCreate) Exec(ctx context.Context) error

Exec executes the query.

func (*AuthorCreate) ExecX

func (ac *AuthorCreate) ExecX(ctx context.Context)

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

func (*AuthorCreate) Mutation

func (ac *AuthorCreate) Mutation() *AuthorMutation

Mutation returns the AuthorMutation object of the builder.

func (*AuthorCreate) Save

func (ac *AuthorCreate) Save(ctx context.Context) (*Author, error)

Save creates the Author in the database.

func (*AuthorCreate) SaveX

func (ac *AuthorCreate) SaveX(ctx context.Context) *Author

SaveX calls Save and panics if Save returns an error.

func (*AuthorCreate) SetID

func (ac *AuthorCreate) SetID(i int64) *AuthorCreate

SetID sets the "id" field.

func (*AuthorCreate) SetName

func (ac *AuthorCreate) SetName(s string) *AuthorCreate

SetName sets the "name" field.

func (*AuthorCreate) SetNillableName

func (ac *AuthorCreate) SetNillableName(s *string) *AuthorCreate

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

type AuthorCreateBulk

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

AuthorCreateBulk is the builder for creating many Author entities in bulk.

func (*AuthorCreateBulk) Exec

func (acb *AuthorCreateBulk) Exec(ctx context.Context) error

Exec executes the query.

func (*AuthorCreateBulk) ExecX

func (acb *AuthorCreateBulk) ExecX(ctx context.Context)

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

func (*AuthorCreateBulk) Save

func (acb *AuthorCreateBulk) Save(ctx context.Context) ([]*Author, error)

Save creates the Author entities in the database.

func (*AuthorCreateBulk) SaveX

func (acb *AuthorCreateBulk) SaveX(ctx context.Context) []*Author

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

type AuthorDelete

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

AuthorDelete is the builder for deleting a Author entity.

func (*AuthorDelete) Exec

func (ad *AuthorDelete) Exec(ctx context.Context) (int, error)

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

func (*AuthorDelete) ExecX

func (ad *AuthorDelete) ExecX(ctx context.Context) int

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

func (*AuthorDelete) Where

func (ad *AuthorDelete) Where(ps ...predicate.Author) *AuthorDelete

Where appends a list predicates to the AuthorDelete builder.

type AuthorDeleteOne

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

AuthorDeleteOne is the builder for deleting a single Author entity.

func (*AuthorDeleteOne) Exec

func (ado *AuthorDeleteOne) Exec(ctx context.Context) error

Exec executes the deletion query.

func (*AuthorDeleteOne) ExecX

func (ado *AuthorDeleteOne) ExecX(ctx context.Context)

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

func (*AuthorDeleteOne) Where

func (ado *AuthorDeleteOne) Where(ps ...predicate.Author) *AuthorDeleteOne

Where appends a list predicates to the AuthorDelete builder.

type AuthorGroupBy

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

AuthorGroupBy is the group-by builder for Author entities.

func (*AuthorGroupBy) Aggregate

func (agb *AuthorGroupBy) Aggregate(fns ...AggregateFunc) *AuthorGroupBy

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

func (*AuthorGroupBy) Bool

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

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

func (*AuthorGroupBy) BoolX

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

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

func (*AuthorGroupBy) Bools

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

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

func (*AuthorGroupBy) BoolsX

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

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

func (*AuthorGroupBy) Float64

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

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

func (*AuthorGroupBy) Float64X

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

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

func (*AuthorGroupBy) Float64s

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

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

func (*AuthorGroupBy) Float64sX

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

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

func (*AuthorGroupBy) Int

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

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

func (*AuthorGroupBy) IntX

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

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

func (*AuthorGroupBy) Ints

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

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

func (*AuthorGroupBy) IntsX

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

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

func (*AuthorGroupBy) Scan

func (agb *AuthorGroupBy) Scan(ctx context.Context, v any) error

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

func (*AuthorGroupBy) ScanX

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

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

func (*AuthorGroupBy) String

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

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

func (*AuthorGroupBy) StringX

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

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

func (*AuthorGroupBy) Strings

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

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

func (*AuthorGroupBy) StringsX

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

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

type AuthorMutation

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

AuthorMutation represents an operation that mutates the Author nodes in the graph.

func (*AuthorMutation) AddField

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

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

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

func (*AuthorMutation) AddedField

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

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

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

func (*AuthorMutation) AddedIDs

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

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

func (*AuthorMutation) ClearEdge

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

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

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

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

func (*AuthorMutation) ClearedFields

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

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

func (AuthorMutation) Client

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

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

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

func (*AuthorMutation) Field

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

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

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

func (*AuthorMutation) Fields

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

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

func (m *AuthorMutation) IDs(ctx context.Context) ([]int64, 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 (*AuthorMutation) Name

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

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

func (*AuthorMutation) OldField

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

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

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

func (m *AuthorMutation) Op() Op

Op returns the operation name.

func (*AuthorMutation) RemovedEdges

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

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

func (*AuthorMutation) RemovedIDs

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

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

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

func (m *AuthorMutation) ResetName()

ResetName resets all changes to the "name" field.

func (*AuthorMutation) SetField

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

func (m *AuthorMutation) SetID(id int64)

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

func (*AuthorMutation) SetName

func (m *AuthorMutation) SetName(s string)

SetName sets the "name" field.

func (*AuthorMutation) SetOp

func (m *AuthorMutation) SetOp(op Op)

SetOp allows setting the mutation operation.

func (AuthorMutation) Tx

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

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

func (*AuthorMutation) Type

func (m *AuthorMutation) Type() string

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

func (*AuthorMutation) Where

func (m *AuthorMutation) Where(ps ...predicate.Author)

Where appends a list predicates to the AuthorMutation builder.

func (*AuthorMutation) WhereP

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

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

type AuthorQuery

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

AuthorQuery is the builder for querying Author entities.

func (*AuthorQuery) Aggregate

func (aq *AuthorQuery) Aggregate(fns ...AggregateFunc) *AuthorSelect

Aggregate returns a AuthorSelect configured with the given aggregations.

func (*AuthorQuery) All

func (aq *AuthorQuery) All(ctx context.Context) ([]*Author, error)

All executes the query and returns a list of Authors.

func (*AuthorQuery) AllX

func (aq *AuthorQuery) AllX(ctx context.Context) []*Author

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

func (*AuthorQuery) Clone

func (aq *AuthorQuery) Clone() *AuthorQuery

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

func (*AuthorQuery) Count

func (aq *AuthorQuery) Count(ctx context.Context) (int, error)

Count returns the count of the given query.

func (*AuthorQuery) CountX

func (aq *AuthorQuery) CountX(ctx context.Context) int

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

func (*AuthorQuery) Exist

func (aq *AuthorQuery) Exist(ctx context.Context) (bool, error)

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

func (*AuthorQuery) ExistX

func (aq *AuthorQuery) ExistX(ctx context.Context) bool

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

func (*AuthorQuery) First

func (aq *AuthorQuery) First(ctx context.Context) (*Author, error)

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

func (*AuthorQuery) FirstID

func (aq *AuthorQuery) FirstID(ctx context.Context) (id int64, err error)

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

func (*AuthorQuery) FirstIDX

func (aq *AuthorQuery) FirstIDX(ctx context.Context) int64

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

func (*AuthorQuery) FirstX

func (aq *AuthorQuery) FirstX(ctx context.Context) *Author

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

func (*AuthorQuery) GroupBy

func (aq *AuthorQuery) GroupBy(field string, fields ...string) *AuthorGroupBy

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.Author.Query().
	GroupBy(author.FieldName).
	Aggregate(ent.Count()).
	Scan(ctx, &v)

func (*AuthorQuery) IDs

func (aq *AuthorQuery) IDs(ctx context.Context) (ids []int64, err error)

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

func (*AuthorQuery) IDsX

func (aq *AuthorQuery) IDsX(ctx context.Context) []int64

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

func (*AuthorQuery) Limit

func (aq *AuthorQuery) Limit(limit int) *AuthorQuery

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

func (*AuthorQuery) Offset

func (aq *AuthorQuery) Offset(offset int) *AuthorQuery

Offset to start from.

func (*AuthorQuery) Only

func (aq *AuthorQuery) Only(ctx context.Context) (*Author, error)

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

func (*AuthorQuery) OnlyID

func (aq *AuthorQuery) OnlyID(ctx context.Context) (id int64, err error)

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

func (*AuthorQuery) OnlyIDX

func (aq *AuthorQuery) OnlyIDX(ctx context.Context) int64

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

func (*AuthorQuery) OnlyX

func (aq *AuthorQuery) OnlyX(ctx context.Context) *Author

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

func (*AuthorQuery) Order

func (aq *AuthorQuery) Order(o ...author.OrderOption) *AuthorQuery

Order specifies how the records should be ordered.

func (*AuthorQuery) Select

func (aq *AuthorQuery) Select(fields ...string) *AuthorSelect

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.Author.Query().
	Select(author.FieldName).
	Scan(ctx, &v)

func (*AuthorQuery) Unique

func (aq *AuthorQuery) Unique(unique bool) *AuthorQuery

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

func (aq *AuthorQuery) Where(ps ...predicate.Author) *AuthorQuery

Where adds a new predicate for the AuthorQuery builder.

type AuthorSelect

type AuthorSelect struct {
	*AuthorQuery
	// contains filtered or unexported fields
}

AuthorSelect is the builder for selecting fields of Author entities.

func (*AuthorSelect) Aggregate

func (as *AuthorSelect) Aggregate(fns ...AggregateFunc) *AuthorSelect

Aggregate adds the given aggregation functions to the selector query.

func (*AuthorSelect) Bool

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

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

func (*AuthorSelect) BoolX

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

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

func (*AuthorSelect) Bools

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

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

func (*AuthorSelect) BoolsX

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

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

func (*AuthorSelect) Float64

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

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

func (*AuthorSelect) Float64X

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

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

func (*AuthorSelect) Float64s

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

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

func (*AuthorSelect) Float64sX

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

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

func (*AuthorSelect) Int

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

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

func (*AuthorSelect) IntX

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

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

func (*AuthorSelect) Ints

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

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

func (*AuthorSelect) IntsX

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

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

func (*AuthorSelect) Scan

func (as *AuthorSelect) Scan(ctx context.Context, v any) error

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

func (*AuthorSelect) ScanX

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

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

func (*AuthorSelect) String

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

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

func (*AuthorSelect) StringX

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

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

func (*AuthorSelect) Strings

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

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

func (*AuthorSelect) StringsX

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

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

type AuthorUpdate

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

AuthorUpdate is the builder for updating Author entities.

func (*AuthorUpdate) Exec

func (au *AuthorUpdate) Exec(ctx context.Context) error

Exec executes the query.

func (*AuthorUpdate) ExecX

func (au *AuthorUpdate) ExecX(ctx context.Context)

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

func (*AuthorUpdate) Mutation

func (au *AuthorUpdate) Mutation() *AuthorMutation

Mutation returns the AuthorMutation object of the builder.

func (*AuthorUpdate) Save

func (au *AuthorUpdate) Save(ctx context.Context) (int, error)

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

func (*AuthorUpdate) SaveX

func (au *AuthorUpdate) SaveX(ctx context.Context) int

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

func (*AuthorUpdate) SetName

func (au *AuthorUpdate) SetName(s string) *AuthorUpdate

SetName sets the "name" field.

func (*AuthorUpdate) SetNillableName

func (au *AuthorUpdate) SetNillableName(s *string) *AuthorUpdate

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

func (*AuthorUpdate) Where

func (au *AuthorUpdate) Where(ps ...predicate.Author) *AuthorUpdate

Where appends a list predicates to the AuthorUpdate builder.

type AuthorUpdateOne

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

AuthorUpdateOne is the builder for updating a single Author entity.

func (*AuthorUpdateOne) Exec

func (auo *AuthorUpdateOne) Exec(ctx context.Context) error

Exec executes the query on the entity.

func (*AuthorUpdateOne) ExecX

func (auo *AuthorUpdateOne) ExecX(ctx context.Context)

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

func (*AuthorUpdateOne) Mutation

func (auo *AuthorUpdateOne) Mutation() *AuthorMutation

Mutation returns the AuthorMutation object of the builder.

func (*AuthorUpdateOne) Save

func (auo *AuthorUpdateOne) Save(ctx context.Context) (*Author, error)

Save executes the query and returns the updated Author entity.

func (*AuthorUpdateOne) SaveX

func (auo *AuthorUpdateOne) SaveX(ctx context.Context) *Author

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

func (*AuthorUpdateOne) Select

func (auo *AuthorUpdateOne) Select(field string, fields ...string) *AuthorUpdateOne

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

func (*AuthorUpdateOne) SetName

func (auo *AuthorUpdateOne) SetName(s string) *AuthorUpdateOne

SetName sets the "name" field.

func (*AuthorUpdateOne) SetNillableName

func (auo *AuthorUpdateOne) SetNillableName(s *string) *AuthorUpdateOne

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

func (*AuthorUpdateOne) Where

func (auo *AuthorUpdateOne) Where(ps ...predicate.Author) *AuthorUpdateOne

Where appends a list predicates to the AuthorUpdate builder.

type Authors

type Authors []*Author

Authors is a parsable slice of Author.

type Client

type Client struct {

	// Schema is the client for creating, migrating and dropping schema.
	Schema *migrate.Schema
	// Article is the client for interacting with the Article builders.
	Article *ArticleClient
	// Author is the client for interacting with the Author builders.
	Author *AuthorClient
	// 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().
	Article.
	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 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 {

	// Article is the client for interacting with the Article builders.
	Article *ArticleClient
	// Author is the client for interacting with the Author builders.
	Author *AuthorClient
	// 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