ent

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: GPL-3.0 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.
	TypeBook = "Book"
)

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 Book

type Book struct {

	// ID of the ent.
	ID string `json:"id,omitempty"`
	// Title holds the value of the "title" field.
	Title string `json:"title,omitempty"`
	// Author holds the value of the "author" field.
	Author string `json:"author,omitempty"`
	// Summary holds the value of the "summary" field.
	Summary string `json:"summary,omitempty"`
	// Description holds the value of the "description" field.
	Description string `json:"description,omitempty"`
	// Category holds the value of the "category" field.
	Category string `json:"category,omitempty"`
	// ImageLink holds the value of the "image_link" field.
	ImageLink string `json:"image_link,omitempty"`
	// Featured holds the value of the "featured" field.
	Featured bool `json:"featured,omitempty"`
	// contains filtered or unexported fields
}

Book is the model entity for the Book schema.

func (*Book) String

func (b *Book) String() string

String implements the fmt.Stringer.

func (*Book) Unwrap

func (b *Book) Unwrap() *Book

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

func (b *Book) Update() *BookUpdateOne

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

func (*Book) Value

func (b *Book) Value(name string) (ent.Value, error)

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

type BookClient

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

BookClient is a client for the Book schema.

func NewBookClient

func NewBookClient(c config) *BookClient

NewBookClient returns a client for the Book from the given config.

func (*BookClient) Create

func (c *BookClient) Create() *BookCreate

Create returns a builder for creating a Book entity.

func (*BookClient) CreateBulk

func (c *BookClient) CreateBulk(builders ...*BookCreate) *BookCreateBulk

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

func (*BookClient) Delete

func (c *BookClient) Delete() *BookDelete

Delete returns a delete builder for Book.

func (*BookClient) DeleteOne

func (c *BookClient) DeleteOne(b *Book) *BookDeleteOne

DeleteOne returns a builder for deleting the given entity.

func (*BookClient) DeleteOneID

func (c *BookClient) DeleteOneID(id string) *BookDeleteOne

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

func (*BookClient) Get

func (c *BookClient) Get(ctx context.Context, id string) (*Book, error)

Get returns a Book entity by its id.

func (*BookClient) GetX

func (c *BookClient) GetX(ctx context.Context, id string) *Book

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

func (*BookClient) Hooks

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

Hooks returns the client hooks.

func (*BookClient) Intercept

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

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

func (*BookClient) Interceptors

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

Interceptors returns the client interceptors.

func (*BookClient) MapCreateBulk

func (c *BookClient) MapCreateBulk(slice any, setFunc func(*BookCreate, int)) *BookCreateBulk

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

func (c *BookClient) Query() *BookQuery

Query returns a query builder for Book.

func (*BookClient) Update

func (c *BookClient) Update() *BookUpdate

Update returns an update builder for Book.

func (*BookClient) UpdateOne

func (c *BookClient) UpdateOne(b *Book) *BookUpdateOne

UpdateOne returns an update builder for the given entity.

func (*BookClient) UpdateOneID

func (c *BookClient) UpdateOneID(id string) *BookUpdateOne

UpdateOneID returns an update builder for the given id.

func (*BookClient) Use

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

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

type BookCreate

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

BookCreate is the builder for creating a Book entity.

func (*BookCreate) Exec

func (bc *BookCreate) Exec(ctx context.Context) error

Exec executes the query.

func (*BookCreate) ExecX

func (bc *BookCreate) ExecX(ctx context.Context)

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

func (*BookCreate) Mutation

func (bc *BookCreate) Mutation() *BookMutation

Mutation returns the BookMutation object of the builder.

func (*BookCreate) Save

func (bc *BookCreate) Save(ctx context.Context) (*Book, error)

Save creates the Book in the database.

func (*BookCreate) SaveX

func (bc *BookCreate) SaveX(ctx context.Context) *Book

SaveX calls Save and panics if Save returns an error.

func (*BookCreate) SetAuthor

func (bc *BookCreate) SetAuthor(s string) *BookCreate

SetAuthor sets the "author" field.

func (*BookCreate) SetCategory

func (bc *BookCreate) SetCategory(s string) *BookCreate

SetCategory sets the "category" field.

func (*BookCreate) SetDescription

func (bc *BookCreate) SetDescription(s string) *BookCreate

SetDescription sets the "description" field.

func (*BookCreate) SetFeatured

func (bc *BookCreate) SetFeatured(b bool) *BookCreate

SetFeatured sets the "featured" field.

func (*BookCreate) SetID

func (bc *BookCreate) SetID(s string) *BookCreate

SetID sets the "id" field.

func (bc *BookCreate) SetImageLink(s string) *BookCreate

SetImageLink sets the "image_link" field.

func (*BookCreate) SetNillableFeatured

func (bc *BookCreate) SetNillableFeatured(b *bool) *BookCreate

SetNillableFeatured sets the "featured" field if the given value is not nil.

func (*BookCreate) SetSummary

func (bc *BookCreate) SetSummary(s string) *BookCreate

SetSummary sets the "summary" field.

func (*BookCreate) SetTitle

func (bc *BookCreate) SetTitle(s string) *BookCreate

SetTitle sets the "title" field.

type BookCreateBulk

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

BookCreateBulk is the builder for creating many Book entities in bulk.

func (*BookCreateBulk) Exec

func (bcb *BookCreateBulk) Exec(ctx context.Context) error

Exec executes the query.

func (*BookCreateBulk) ExecX

func (bcb *BookCreateBulk) ExecX(ctx context.Context)

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

func (*BookCreateBulk) Save

func (bcb *BookCreateBulk) Save(ctx context.Context) ([]*Book, error)

Save creates the Book entities in the database.

func (*BookCreateBulk) SaveX

func (bcb *BookCreateBulk) SaveX(ctx context.Context) []*Book

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

type BookDelete

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

BookDelete is the builder for deleting a Book entity.

func (*BookDelete) Exec

func (bd *BookDelete) Exec(ctx context.Context) (int, error)

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

func (*BookDelete) ExecX

func (bd *BookDelete) ExecX(ctx context.Context) int

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

func (*BookDelete) Where

func (bd *BookDelete) Where(ps ...predicate.Book) *BookDelete

Where appends a list predicates to the BookDelete builder.

type BookDeleteOne

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

BookDeleteOne is the builder for deleting a single Book entity.

func (*BookDeleteOne) Exec

func (bdo *BookDeleteOne) Exec(ctx context.Context) error

Exec executes the deletion query.

func (*BookDeleteOne) ExecX

func (bdo *BookDeleteOne) ExecX(ctx context.Context)

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

func (*BookDeleteOne) Where

func (bdo *BookDeleteOne) Where(ps ...predicate.Book) *BookDeleteOne

Where appends a list predicates to the BookDelete builder.

type BookGroupBy

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

BookGroupBy is the group-by builder for Book entities.

func (*BookGroupBy) Aggregate

func (bgb *BookGroupBy) Aggregate(fns ...AggregateFunc) *BookGroupBy

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

func (*BookGroupBy) Bool

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

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

func (*BookGroupBy) BoolX

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

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

func (*BookGroupBy) Bools

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

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

func (*BookGroupBy) BoolsX

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

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

func (*BookGroupBy) Float64

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

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

func (*BookGroupBy) Float64X

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

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

func (*BookGroupBy) Float64s

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

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

func (*BookGroupBy) Float64sX

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

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

func (*BookGroupBy) Int

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

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

func (*BookGroupBy) IntX

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

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

func (*BookGroupBy) Ints

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

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

func (*BookGroupBy) IntsX

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

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

func (*BookGroupBy) Scan

func (bgb *BookGroupBy) Scan(ctx context.Context, v any) error

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

func (*BookGroupBy) ScanX

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

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

func (*BookGroupBy) String

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

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

func (*BookGroupBy) StringX

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

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

func (*BookGroupBy) Strings

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

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

func (*BookGroupBy) StringsX

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

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

type BookMutation

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

BookMutation represents an operation that mutates the Book nodes in the graph.

func (*BookMutation) AddField

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

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

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

func (*BookMutation) AddedField

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

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

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

func (*BookMutation) AddedIDs

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

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

func (*BookMutation) Author

func (m *BookMutation) Author() (r string, exists bool)

Author returns the value of the "author" field in the mutation.

func (*BookMutation) Category

func (m *BookMutation) Category() (r string, exists bool)

Category returns the value of the "category" field in the mutation.

func (*BookMutation) ClearEdge

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

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

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

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

func (*BookMutation) ClearedFields

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

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

func (BookMutation) Client

func (m BookMutation) 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 (*BookMutation) Description

func (m *BookMutation) Description() (r string, exists bool)

Description returns the value of the "description" field in the mutation.

func (*BookMutation) EdgeCleared

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

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

func (*BookMutation) Featured

func (m *BookMutation) Featured() (r bool, exists bool)

Featured returns the value of the "featured" field in the mutation.

func (*BookMutation) Field

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

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

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

func (*BookMutation) Fields

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

func (m *BookMutation) ID() (id string, exists bool)

ID returns the ID value in the mutation. Note that the ID is only available if it was provided to the builder or after it was returned from the database.

func (*BookMutation) IDs

func (m *BookMutation) IDs(ctx context.Context) ([]string, error)

IDs queries the database and returns the entity ids that match the mutation's predicate. That means, if the mutation is applied within a transaction with an isolation level such as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated or updated by the mutation.

func (m *BookMutation) ImageLink() (r string, exists bool)

ImageLink returns the value of the "image_link" field in the mutation.

func (*BookMutation) OldAuthor

func (m *BookMutation) OldAuthor(ctx context.Context) (v string, err error)

OldAuthor returns the old "author" field's value of the Book entity. If the Book 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 (*BookMutation) OldCategory

func (m *BookMutation) OldCategory(ctx context.Context) (v string, err error)

OldCategory returns the old "category" field's value of the Book entity. If the Book 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 (*BookMutation) OldDescription

func (m *BookMutation) OldDescription(ctx context.Context) (v string, err error)

OldDescription returns the old "description" field's value of the Book entity. If the Book 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 (*BookMutation) OldFeatured

func (m *BookMutation) OldFeatured(ctx context.Context) (v bool, err error)

OldFeatured returns the old "featured" field's value of the Book entity. If the Book 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 (*BookMutation) OldField

func (m *BookMutation) 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 (m *BookMutation) OldImageLink(ctx context.Context) (v string, err error)

OldImageLink returns the old "image_link" field's value of the Book entity. If the Book 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 (*BookMutation) OldSummary

func (m *BookMutation) OldSummary(ctx context.Context) (v string, err error)

OldSummary returns the old "summary" field's value of the Book entity. If the Book 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 (*BookMutation) OldTitle

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

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

func (m *BookMutation) Op() Op

Op returns the operation name.

func (*BookMutation) RemovedEdges

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

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

func (*BookMutation) RemovedIDs

func (m *BookMutation) 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 (*BookMutation) ResetAuthor

func (m *BookMutation) ResetAuthor()

ResetAuthor resets all changes to the "author" field.

func (*BookMutation) ResetCategory

func (m *BookMutation) ResetCategory()

ResetCategory resets all changes to the "category" field.

func (*BookMutation) ResetDescription

func (m *BookMutation) ResetDescription()

ResetDescription resets all changes to the "description" field.

func (*BookMutation) ResetEdge

func (m *BookMutation) 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 (*BookMutation) ResetFeatured

func (m *BookMutation) ResetFeatured()

ResetFeatured resets all changes to the "featured" field.

func (*BookMutation) ResetField

func (m *BookMutation) 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 (m *BookMutation) ResetImageLink()

ResetImageLink resets all changes to the "image_link" field.

func (*BookMutation) ResetSummary

func (m *BookMutation) ResetSummary()

ResetSummary resets all changes to the "summary" field.

func (*BookMutation) ResetTitle

func (m *BookMutation) ResetTitle()

ResetTitle resets all changes to the "title" field.

func (*BookMutation) SetAuthor

func (m *BookMutation) SetAuthor(s string)

SetAuthor sets the "author" field.

func (*BookMutation) SetCategory

func (m *BookMutation) SetCategory(s string)

SetCategory sets the "category" field.

func (*BookMutation) SetDescription

func (m *BookMutation) SetDescription(s string)

SetDescription sets the "description" field.

func (*BookMutation) SetFeatured

func (m *BookMutation) SetFeatured(b bool)

SetFeatured sets the "featured" field.

func (*BookMutation) SetField

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

func (m *BookMutation) SetID(id string)

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

func (m *BookMutation) SetImageLink(s string)

SetImageLink sets the "image_link" field.

func (*BookMutation) SetOp

func (m *BookMutation) SetOp(op Op)

SetOp allows setting the mutation operation.

func (*BookMutation) SetSummary

func (m *BookMutation) SetSummary(s string)

SetSummary sets the "summary" field.

func (*BookMutation) SetTitle

func (m *BookMutation) SetTitle(s string)

SetTitle sets the "title" field.

func (*BookMutation) Summary

func (m *BookMutation) Summary() (r string, exists bool)

Summary returns the value of the "summary" field in the mutation.

func (*BookMutation) Title

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

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

func (BookMutation) Tx

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

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

func (*BookMutation) Type

func (m *BookMutation) Type() string

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

func (*BookMutation) Where

func (m *BookMutation) Where(ps ...predicate.Book)

Where appends a list predicates to the BookMutation builder.

func (*BookMutation) WhereP

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

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

type BookQuery

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

BookQuery is the builder for querying Book entities.

func (*BookQuery) Aggregate

func (bq *BookQuery) Aggregate(fns ...AggregateFunc) *BookSelect

Aggregate returns a BookSelect configured with the given aggregations.

func (*BookQuery) All

func (bq *BookQuery) All(ctx context.Context) ([]*Book, error)

All executes the query and returns a list of Books.

func (*BookQuery) AllX

func (bq *BookQuery) AllX(ctx context.Context) []*Book

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

func (*BookQuery) Clone

func (bq *BookQuery) Clone() *BookQuery

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

func (*BookQuery) Count

func (bq *BookQuery) Count(ctx context.Context) (int, error)

Count returns the count of the given query.

func (*BookQuery) CountX

func (bq *BookQuery) CountX(ctx context.Context) int

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

func (*BookQuery) Exist

func (bq *BookQuery) Exist(ctx context.Context) (bool, error)

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

func (*BookQuery) ExistX

func (bq *BookQuery) ExistX(ctx context.Context) bool

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

func (*BookQuery) First

func (bq *BookQuery) First(ctx context.Context) (*Book, error)

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

func (*BookQuery) FirstID

func (bq *BookQuery) FirstID(ctx context.Context) (id string, err error)

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

func (*BookQuery) FirstIDX

func (bq *BookQuery) FirstIDX(ctx context.Context) string

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

func (*BookQuery) FirstX

func (bq *BookQuery) FirstX(ctx context.Context) *Book

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

func (*BookQuery) GroupBy

func (bq *BookQuery) GroupBy(field string, fields ...string) *BookGroupBy

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

func (*BookQuery) IDs

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

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

func (*BookQuery) IDsX

func (bq *BookQuery) IDsX(ctx context.Context) []string

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

func (*BookQuery) Limit

func (bq *BookQuery) Limit(limit int) *BookQuery

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

func (*BookQuery) Offset

func (bq *BookQuery) Offset(offset int) *BookQuery

Offset to start from.

func (*BookQuery) Only

func (bq *BookQuery) Only(ctx context.Context) (*Book, error)

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

func (*BookQuery) OnlyID

func (bq *BookQuery) OnlyID(ctx context.Context) (id string, err error)

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

func (*BookQuery) OnlyIDX

func (bq *BookQuery) OnlyIDX(ctx context.Context) string

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

func (*BookQuery) OnlyX

func (bq *BookQuery) OnlyX(ctx context.Context) *Book

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

func (*BookQuery) Order

func (bq *BookQuery) Order(o ...book.OrderOption) *BookQuery

Order specifies how the records should be ordered.

func (*BookQuery) Select

func (bq *BookQuery) Select(fields ...string) *BookSelect

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

func (*BookQuery) Unique

func (bq *BookQuery) Unique(unique bool) *BookQuery

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

func (bq *BookQuery) Where(ps ...predicate.Book) *BookQuery

Where adds a new predicate for the BookQuery builder.

type BookSelect

type BookSelect struct {
	*BookQuery
	// contains filtered or unexported fields
}

BookSelect is the builder for selecting fields of Book entities.

func (*BookSelect) Aggregate

func (bs *BookSelect) Aggregate(fns ...AggregateFunc) *BookSelect

Aggregate adds the given aggregation functions to the selector query.

func (*BookSelect) Bool

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

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

func (*BookSelect) BoolX

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

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

func (*BookSelect) Bools

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

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

func (*BookSelect) BoolsX

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

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

func (*BookSelect) Float64

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

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

func (*BookSelect) Float64X

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

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

func (*BookSelect) Float64s

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

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

func (*BookSelect) Float64sX

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

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

func (*BookSelect) Int

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

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

func (*BookSelect) IntX

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

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

func (*BookSelect) Ints

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

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

func (*BookSelect) IntsX

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

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

func (*BookSelect) Scan

func (bs *BookSelect) Scan(ctx context.Context, v any) error

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

func (*BookSelect) ScanX

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

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

func (*BookSelect) String

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

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

func (*BookSelect) StringX

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

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

func (*BookSelect) Strings

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

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

func (*BookSelect) StringsX

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

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

type BookUpdate

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

BookUpdate is the builder for updating Book entities.

func (*BookUpdate) Exec

func (bu *BookUpdate) Exec(ctx context.Context) error

Exec executes the query.

func (*BookUpdate) ExecX

func (bu *BookUpdate) ExecX(ctx context.Context)

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

func (*BookUpdate) Mutation

func (bu *BookUpdate) Mutation() *BookMutation

Mutation returns the BookMutation object of the builder.

func (*BookUpdate) Save

func (bu *BookUpdate) Save(ctx context.Context) (int, error)

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

func (*BookUpdate) SaveX

func (bu *BookUpdate) SaveX(ctx context.Context) int

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

func (*BookUpdate) SetAuthor

func (bu *BookUpdate) SetAuthor(s string) *BookUpdate

SetAuthor sets the "author" field.

func (*BookUpdate) SetCategory

func (bu *BookUpdate) SetCategory(s string) *BookUpdate

SetCategory sets the "category" field.

func (*BookUpdate) SetDescription

func (bu *BookUpdate) SetDescription(s string) *BookUpdate

SetDescription sets the "description" field.

func (*BookUpdate) SetFeatured

func (bu *BookUpdate) SetFeatured(b bool) *BookUpdate

SetFeatured sets the "featured" field.

func (bu *BookUpdate) SetImageLink(s string) *BookUpdate

SetImageLink sets the "image_link" field.

func (*BookUpdate) SetNillableAuthor

func (bu *BookUpdate) SetNillableAuthor(s *string) *BookUpdate

SetNillableAuthor sets the "author" field if the given value is not nil.

func (*BookUpdate) SetNillableCategory

func (bu *BookUpdate) SetNillableCategory(s *string) *BookUpdate

SetNillableCategory sets the "category" field if the given value is not nil.

func (*BookUpdate) SetNillableDescription

func (bu *BookUpdate) SetNillableDescription(s *string) *BookUpdate

SetNillableDescription sets the "description" field if the given value is not nil.

func (*BookUpdate) SetNillableFeatured

func (bu *BookUpdate) SetNillableFeatured(b *bool) *BookUpdate

SetNillableFeatured sets the "featured" field if the given value is not nil.

func (bu *BookUpdate) SetNillableImageLink(s *string) *BookUpdate

SetNillableImageLink sets the "image_link" field if the given value is not nil.

func (*BookUpdate) SetNillableSummary

func (bu *BookUpdate) SetNillableSummary(s *string) *BookUpdate

SetNillableSummary sets the "summary" field if the given value is not nil.

func (*BookUpdate) SetNillableTitle

func (bu *BookUpdate) SetNillableTitle(s *string) *BookUpdate

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

func (*BookUpdate) SetSummary

func (bu *BookUpdate) SetSummary(s string) *BookUpdate

SetSummary sets the "summary" field.

func (*BookUpdate) SetTitle

func (bu *BookUpdate) SetTitle(s string) *BookUpdate

SetTitle sets the "title" field.

func (*BookUpdate) Where

func (bu *BookUpdate) Where(ps ...predicate.Book) *BookUpdate

Where appends a list predicates to the BookUpdate builder.

type BookUpdateOne

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

BookUpdateOne is the builder for updating a single Book entity.

func (*BookUpdateOne) Exec

func (buo *BookUpdateOne) Exec(ctx context.Context) error

Exec executes the query on the entity.

func (*BookUpdateOne) ExecX

func (buo *BookUpdateOne) ExecX(ctx context.Context)

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

func (*BookUpdateOne) Mutation

func (buo *BookUpdateOne) Mutation() *BookMutation

Mutation returns the BookMutation object of the builder.

func (*BookUpdateOne) Save

func (buo *BookUpdateOne) Save(ctx context.Context) (*Book, error)

Save executes the query and returns the updated Book entity.

func (*BookUpdateOne) SaveX

func (buo *BookUpdateOne) SaveX(ctx context.Context) *Book

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

func (*BookUpdateOne) Select

func (buo *BookUpdateOne) Select(field string, fields ...string) *BookUpdateOne

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

func (*BookUpdateOne) SetAuthor

func (buo *BookUpdateOne) SetAuthor(s string) *BookUpdateOne

SetAuthor sets the "author" field.

func (*BookUpdateOne) SetCategory

func (buo *BookUpdateOne) SetCategory(s string) *BookUpdateOne

SetCategory sets the "category" field.

func (*BookUpdateOne) SetDescription

func (buo *BookUpdateOne) SetDescription(s string) *BookUpdateOne

SetDescription sets the "description" field.

func (*BookUpdateOne) SetFeatured

func (buo *BookUpdateOne) SetFeatured(b bool) *BookUpdateOne

SetFeatured sets the "featured" field.

func (buo *BookUpdateOne) SetImageLink(s string) *BookUpdateOne

SetImageLink sets the "image_link" field.

func (*BookUpdateOne) SetNillableAuthor

func (buo *BookUpdateOne) SetNillableAuthor(s *string) *BookUpdateOne

SetNillableAuthor sets the "author" field if the given value is not nil.

func (*BookUpdateOne) SetNillableCategory

func (buo *BookUpdateOne) SetNillableCategory(s *string) *BookUpdateOne

SetNillableCategory sets the "category" field if the given value is not nil.

func (*BookUpdateOne) SetNillableDescription

func (buo *BookUpdateOne) SetNillableDescription(s *string) *BookUpdateOne

SetNillableDescription sets the "description" field if the given value is not nil.

func (*BookUpdateOne) SetNillableFeatured

func (buo *BookUpdateOne) SetNillableFeatured(b *bool) *BookUpdateOne

SetNillableFeatured sets the "featured" field if the given value is not nil.

func (buo *BookUpdateOne) SetNillableImageLink(s *string) *BookUpdateOne

SetNillableImageLink sets the "image_link" field if the given value is not nil.

func (*BookUpdateOne) SetNillableSummary

func (buo *BookUpdateOne) SetNillableSummary(s *string) *BookUpdateOne

SetNillableSummary sets the "summary" field if the given value is not nil.

func (*BookUpdateOne) SetNillableTitle

func (buo *BookUpdateOne) SetNillableTitle(s *string) *BookUpdateOne

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

func (*BookUpdateOne) SetSummary

func (buo *BookUpdateOne) SetSummary(s string) *BookUpdateOne

SetSummary sets the "summary" field.

func (*BookUpdateOne) SetTitle

func (buo *BookUpdateOne) SetTitle(s string) *BookUpdateOne

SetTitle sets the "title" field.

func (*BookUpdateOne) Where

func (buo *BookUpdateOne) Where(ps ...predicate.Book) *BookUpdateOne

Where appends a list predicates to the BookUpdate builder.

type Books

type Books []*Book

Books is a parsable slice of Book.

type Client

type Client struct {

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

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