ent

package
v0.0.0-...-482f3e0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2021 License: Apache-2.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.
	TypeLocation = "Location"
)

Variables

This section is empty.

Functions

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 validaton error.

func MaskNotFound

func MaskNotFound(err error) error

MaskNotFound masks not found error.

func NewContext

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

NewContext returns a new context with the given Client attached.

func NewTxContext

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

NewTxContext returns a new context with the given Tx attached.

Types

type AggregateFunc

type AggregateFunc func(*sql.Selector) string

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

func As

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

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

func Count

func Count() AggregateFunc

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

func Max

func Max(field string) AggregateFunc

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

func Mean

func Mean(field string) AggregateFunc

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

func Min

func Min(field string) AggregateFunc

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

func Sum

func Sum(field string) AggregateFunc

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

type Client

type Client struct {

	// Schema is the client for creating, migrating and dropping schema.
	Schema *migrate.Schema
	// Location is the client for interacting with the Location builders.
	Location *LocationClient
	// 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().
	Location.
	Query().
	Count(ctx)

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(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 Committer 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 Location

type Location struct {

	// ID of the ent.
	ID int `json:"id,omitempty"`
	// Name holds the value of the "name" field.
	Name string `json:"name,omitempty"`
	// Coords holds the value of the "coords" field.
	Coords *schema.Point `json:"coords,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the LocationQuery when eager-loading is set.
	Edges LocationEdges `json:"edges"`
	// contains filtered or unexported fields
}

Location is the model entity for the Location schema.

func (*Location) QueryChildren

func (l *Location) QueryChildren() *LocationQuery

QueryChildren queries the "children" edge of the Location entity.

func (*Location) QueryParent

func (l *Location) QueryParent() *LocationQuery

QueryParent queries the "parent" edge of the Location entity.

func (*Location) String

func (l *Location) String() string

String implements the fmt.Stringer.

func (*Location) Unwrap

func (l *Location) Unwrap() *Location

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

func (l *Location) Update() *LocationUpdateOne

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

type LocationClient

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

LocationClient is a client for the Location schema.

func NewLocationClient

func NewLocationClient(c config) *LocationClient

NewLocationClient returns a client for the Location from the given config.

func (*LocationClient) Create

func (c *LocationClient) Create() *LocationCreate

Create returns a create builder for Location.

func (*LocationClient) CreateBulk

func (c *LocationClient) CreateBulk(builders ...*LocationCreate) *LocationCreateBulk

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

func (*LocationClient) Delete

func (c *LocationClient) Delete() *LocationDelete

Delete returns a delete builder for Location.

func (*LocationClient) DeleteOne

func (c *LocationClient) DeleteOne(l *Location) *LocationDeleteOne

DeleteOne returns a delete builder for the given entity.

func (*LocationClient) DeleteOneID

func (c *LocationClient) DeleteOneID(id int) *LocationDeleteOne

DeleteOneID returns a delete builder for the given id.

func (*LocationClient) Get

func (c *LocationClient) Get(ctx context.Context, id int) (*Location, error)

Get returns a Location entity by its id.

func (*LocationClient) GetX

func (c *LocationClient) GetX(ctx context.Context, id int) *Location

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

func (*LocationClient) Hooks

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

Hooks returns the client hooks.

func (*LocationClient) Query

func (c *LocationClient) Query() *LocationQuery

Query returns a query builder for Location.

func (*LocationClient) QueryChildren

func (c *LocationClient) QueryChildren(l *Location) *LocationQuery

QueryChildren queries the children edge of a Location.

func (*LocationClient) QueryParent

func (c *LocationClient) QueryParent(l *Location) *LocationQuery

QueryParent queries the parent edge of a Location.

func (*LocationClient) Update

func (c *LocationClient) Update() *LocationUpdate

Update returns an update builder for Location.

func (*LocationClient) UpdateOne

func (c *LocationClient) UpdateOne(l *Location) *LocationUpdateOne

UpdateOne returns an update builder for the given entity.

func (*LocationClient) UpdateOneID

func (c *LocationClient) UpdateOneID(id int) *LocationUpdateOne

UpdateOneID returns an update builder for the given id.

func (*LocationClient) Use

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

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

type LocationCreate

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

LocationCreate is the builder for creating a Location entity.

func (*LocationCreate) AddChildIDs

func (lc *LocationCreate) AddChildIDs(ids ...int) *LocationCreate

AddChildIDs adds the "children" edge to the Location entity by IDs.

func (*LocationCreate) AddChildren

func (lc *LocationCreate) AddChildren(l ...*Location) *LocationCreate

AddChildren adds the "children" edges to the Location entity.

func (*LocationCreate) Mutation

func (lc *LocationCreate) Mutation() *LocationMutation

Mutation returns the LocationMutation object of the builder.

func (*LocationCreate) Save

func (lc *LocationCreate) Save(ctx context.Context) (*Location, error)

Save creates the Location in the database.

func (*LocationCreate) SaveX

func (lc *LocationCreate) SaveX(ctx context.Context) *Location

SaveX calls Save and panics if Save returns an error.

func (*LocationCreate) SetCoords

func (lc *LocationCreate) SetCoords(s *schema.Point) *LocationCreate

SetCoords sets the "coords" field.

func (*LocationCreate) SetName

func (lc *LocationCreate) SetName(s string) *LocationCreate

SetName sets the "name" field.

func (*LocationCreate) SetNillableParentID

func (lc *LocationCreate) SetNillableParentID(id *int) *LocationCreate

SetNillableParentID sets the "parent" edge to the Location entity by ID if the given value is not nil.

func (*LocationCreate) SetParent

func (lc *LocationCreate) SetParent(l *Location) *LocationCreate

SetParent sets the "parent" edge to the Location entity.

func (*LocationCreate) SetParentID

func (lc *LocationCreate) SetParentID(id int) *LocationCreate

SetParentID sets the "parent" edge to the Location entity by ID.

type LocationCreateBulk

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

LocationCreateBulk is the builder for creating many Location entities in bulk.

func (*LocationCreateBulk) Save

func (lcb *LocationCreateBulk) Save(ctx context.Context) ([]*Location, error)

Save creates the Location entities in the database.

func (*LocationCreateBulk) SaveX

func (lcb *LocationCreateBulk) SaveX(ctx context.Context) []*Location

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

type LocationDelete

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

LocationDelete is the builder for deleting a Location entity.

func (*LocationDelete) Exec

func (ld *LocationDelete) Exec(ctx context.Context) (int, error)

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

func (*LocationDelete) ExecX

func (ld *LocationDelete) ExecX(ctx context.Context) int

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

func (*LocationDelete) Where

func (ld *LocationDelete) Where(ps ...predicate.Location) *LocationDelete

Where adds a new predicate to the LocationDelete builder.

type LocationDeleteOne

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

LocationDeleteOne is the builder for deleting a single Location entity.

func (*LocationDeleteOne) Exec

func (ldo *LocationDeleteOne) Exec(ctx context.Context) error

Exec executes the deletion query.

func (*LocationDeleteOne) ExecX

func (ldo *LocationDeleteOne) ExecX(ctx context.Context)

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

type LocationEdges

type LocationEdges struct {
	// Parent holds the value of the parent edge.
	Parent *Location `json:"parent,omitempty"`
	// Children holds the value of the children edge.
	Children []*Location `json:"children,omitempty"`
	// contains filtered or unexported fields
}

LocationEdges holds the relations/edges for other nodes in the graph.

func (LocationEdges) ChildrenOrErr

func (e LocationEdges) ChildrenOrErr() ([]*Location, error)

ChildrenOrErr returns the Children value or an error if the edge was not loaded in eager-loading.

func (LocationEdges) ParentOrErr

func (e LocationEdges) ParentOrErr() (*Location, error)

ParentOrErr returns the Parent value or an error if the edge was not loaded in eager-loading, or loaded but was not found.

type LocationGroupBy

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

LocationGroupBy is the group-by builder for Location entities.

func (*LocationGroupBy) Aggregate

func (lgb *LocationGroupBy) Aggregate(fns ...AggregateFunc) *LocationGroupBy

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

func (*LocationGroupBy) Bool

func (lgb *LocationGroupBy) Bool(ctx context.Context) (_ bool, err error)

Bool returns a single bool from a group-by query. It is only allowed when executing a group-by query with one field.

func (*LocationGroupBy) BoolX

func (lgb *LocationGroupBy) BoolX(ctx context.Context) bool

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

func (*LocationGroupBy) Bools

func (lgb *LocationGroupBy) Bools(ctx context.Context) ([]bool, error)

Bools returns list of bools from group-by. It is only allowed when executing a group-by query with one field.

func (*LocationGroupBy) BoolsX

func (lgb *LocationGroupBy) BoolsX(ctx context.Context) []bool

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

func (*LocationGroupBy) Float64

func (lgb *LocationGroupBy) Float64(ctx context.Context) (_ float64, err error)

Float64 returns a single float64 from a group-by query. It is only allowed when executing a group-by query with one field.

func (*LocationGroupBy) Float64X

func (lgb *LocationGroupBy) Float64X(ctx context.Context) float64

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

func (*LocationGroupBy) Float64s

func (lgb *LocationGroupBy) Float64s(ctx context.Context) ([]float64, error)

Float64s returns list of float64s from group-by. It is only allowed when executing a group-by query with one field.

func (*LocationGroupBy) Float64sX

func (lgb *LocationGroupBy) Float64sX(ctx context.Context) []float64

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

func (*LocationGroupBy) Int

func (lgb *LocationGroupBy) Int(ctx context.Context) (_ int, err error)

Int returns a single int from a group-by query. It is only allowed when executing a group-by query with one field.

func (*LocationGroupBy) IntX

func (lgb *LocationGroupBy) IntX(ctx context.Context) int

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

func (*LocationGroupBy) Ints

func (lgb *LocationGroupBy) Ints(ctx context.Context) ([]int, error)

Ints returns list of ints from group-by. It is only allowed when executing a group-by query with one field.

func (*LocationGroupBy) IntsX

func (lgb *LocationGroupBy) IntsX(ctx context.Context) []int

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

func (*LocationGroupBy) Scan

func (lgb *LocationGroupBy) Scan(ctx context.Context, v interface{}) error

Scan applies the group-by query and scans the result into the given value.

func (*LocationGroupBy) ScanX

func (lgb *LocationGroupBy) ScanX(ctx context.Context, v interface{})

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

func (*LocationGroupBy) String

func (lgb *LocationGroupBy) String(ctx context.Context) (_ string, err error)

String returns a single string from a group-by query. It is only allowed when executing a group-by query with one field.

func (*LocationGroupBy) StringX

func (lgb *LocationGroupBy) StringX(ctx context.Context) string

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

func (*LocationGroupBy) Strings

func (lgb *LocationGroupBy) Strings(ctx context.Context) ([]string, error)

Strings returns list of strings from group-by. It is only allowed when executing a group-by query with one field.

func (*LocationGroupBy) StringsX

func (lgb *LocationGroupBy) StringsX(ctx context.Context) []string

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

type LocationMutation

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

LocationMutation represents an operation that mutates the Location nodes in the graph.

func (*LocationMutation) AddChildIDs

func (m *LocationMutation) AddChildIDs(ids ...int)

AddChildIDs adds the "children" edge to the Location entity by ids.

func (*LocationMutation) AddField

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

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

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

func (*LocationMutation) AddedField

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

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

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

func (*LocationMutation) AddedIDs

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

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

func (*LocationMutation) ChildrenCleared

func (m *LocationMutation) ChildrenCleared() bool

ChildrenCleared returns if the "children" edge to the Location entity was cleared.

func (*LocationMutation) ChildrenIDs

func (m *LocationMutation) ChildrenIDs() (ids []int)

ChildrenIDs returns the "children" edge IDs in the mutation.

func (*LocationMutation) ClearChildren

func (m *LocationMutation) ClearChildren()

ClearChildren clears the "children" edge to the Location entity.

func (*LocationMutation) ClearEdge

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

func (m *LocationMutation) 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 (*LocationMutation) ClearParent

func (m *LocationMutation) ClearParent()

ClearParent clears the "parent" edge to the Location entity.

func (*LocationMutation) ClearedEdges

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

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

func (*LocationMutation) ClearedFields

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

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

func (LocationMutation) Client

func (m LocationMutation) 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 (*LocationMutation) Coords

func (m *LocationMutation) Coords() (r *schema.Point, exists bool)

Coords returns the value of the "coords" field in the mutation.

func (*LocationMutation) EdgeCleared

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

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

func (*LocationMutation) Field

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

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

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

func (*LocationMutation) Fields

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

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

ID returns the ID value in the mutation. Note that the ID is only available if it was provided to the builder.

func (*LocationMutation) Name

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

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

func (*LocationMutation) OldCoords

func (m *LocationMutation) OldCoords(ctx context.Context) (v *schema.Point, err error)

OldCoords returns the old "coords" field's value of the Location entity. If the Location 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 (*LocationMutation) OldField

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

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

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

func (m *LocationMutation) Op() Op

Op returns the operation name.

func (*LocationMutation) ParentCleared

func (m *LocationMutation) ParentCleared() bool

ParentCleared returns if the "parent" edge to the Location entity was cleared.

func (*LocationMutation) ParentID

func (m *LocationMutation) ParentID() (id int, exists bool)

ParentID returns the "parent" edge ID in the mutation.

func (*LocationMutation) ParentIDs

func (m *LocationMutation) ParentIDs() (ids []int)

ParentIDs returns the "parent" edge IDs in the mutation. Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use ParentID instead. It exists only for internal usage by the builders.

func (*LocationMutation) RemoveChildIDs

func (m *LocationMutation) RemoveChildIDs(ids ...int)

RemoveChildIDs removes the "children" edge to the Location entity by IDs.

func (*LocationMutation) RemovedChildrenIDs

func (m *LocationMutation) RemovedChildrenIDs() (ids []int)

RemovedChildren returns the removed IDs of the "children" edge to the Location entity.

func (*LocationMutation) RemovedEdges

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

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

func (*LocationMutation) RemovedIDs

func (m *LocationMutation) 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 (*LocationMutation) ResetChildren

func (m *LocationMutation) ResetChildren()

ResetChildren resets all changes to the "children" edge.

func (*LocationMutation) ResetCoords

func (m *LocationMutation) ResetCoords()

ResetCoords resets all changes to the "coords" field.

func (*LocationMutation) ResetEdge

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

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

func (m *LocationMutation) ResetName()

ResetName resets all changes to the "name" field.

func (*LocationMutation) ResetParent

func (m *LocationMutation) ResetParent()

ResetParent resets all changes to the "parent" edge.

func (*LocationMutation) SetCoords

func (m *LocationMutation) SetCoords(s *schema.Point)

SetCoords sets the "coords" field.

func (*LocationMutation) SetField

func (m *LocationMutation) 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 (*LocationMutation) SetName

func (m *LocationMutation) SetName(s string)

SetName sets the "name" field.

func (*LocationMutation) SetParentID

func (m *LocationMutation) SetParentID(id int)

SetParentID sets the "parent" edge to the Location entity by id.

func (LocationMutation) Tx

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

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

func (*LocationMutation) Type

func (m *LocationMutation) Type() string

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

type LocationQuery

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

LocationQuery is the builder for querying Location entities.

func (*LocationQuery) All

func (lq *LocationQuery) All(ctx context.Context) ([]*Location, error)

All executes the query and returns a list of Locations.

func (*LocationQuery) AllX

func (lq *LocationQuery) AllX(ctx context.Context) []*Location

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

func (*LocationQuery) Clone

func (lq *LocationQuery) Clone() *LocationQuery

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

func (*LocationQuery) Count

func (lq *LocationQuery) Count(ctx context.Context) (int, error)

Count returns the count of the given query.

func (*LocationQuery) CountX

func (lq *LocationQuery) CountX(ctx context.Context) int

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

func (*LocationQuery) Exist

func (lq *LocationQuery) Exist(ctx context.Context) (bool, error)

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

func (*LocationQuery) ExistX

func (lq *LocationQuery) ExistX(ctx context.Context) bool

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

func (*LocationQuery) First

func (lq *LocationQuery) First(ctx context.Context) (*Location, error)

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

func (*LocationQuery) FirstID

func (lq *LocationQuery) FirstID(ctx context.Context) (id int, err error)

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

func (*LocationQuery) FirstIDX

func (lq *LocationQuery) FirstIDX(ctx context.Context) int

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

func (*LocationQuery) FirstX

func (lq *LocationQuery) FirstX(ctx context.Context) *Location

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

func (*LocationQuery) GroupBy

func (lq *LocationQuery) GroupBy(field string, fields ...string) *LocationGroupBy

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

func (*LocationQuery) IDs

func (lq *LocationQuery) IDs(ctx context.Context) ([]int, error)

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

func (*LocationQuery) IDsX

func (lq *LocationQuery) IDsX(ctx context.Context) []int

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

func (*LocationQuery) Limit

func (lq *LocationQuery) Limit(limit int) *LocationQuery

Limit adds a limit step to the query.

func (*LocationQuery) Offset

func (lq *LocationQuery) Offset(offset int) *LocationQuery

Offset adds an offset step to the query.

func (*LocationQuery) Only

func (lq *LocationQuery) Only(ctx context.Context) (*Location, error)

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

func (*LocationQuery) OnlyID

func (lq *LocationQuery) OnlyID(ctx context.Context) (id int, err error)

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

func (*LocationQuery) OnlyIDX

func (lq *LocationQuery) OnlyIDX(ctx context.Context) int

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

func (*LocationQuery) OnlyX

func (lq *LocationQuery) OnlyX(ctx context.Context) *Location

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

func (*LocationQuery) Order

func (lq *LocationQuery) Order(o ...OrderFunc) *LocationQuery

Order adds an order step to the query.

func (*LocationQuery) QueryChildren

func (lq *LocationQuery) QueryChildren() *LocationQuery

QueryChildren chains the current query on the "children" edge.

func (*LocationQuery) QueryParent

func (lq *LocationQuery) QueryParent() *LocationQuery

QueryParent chains the current query on the "parent" edge.

func (*LocationQuery) Select

func (lq *LocationQuery) Select(field string, fields ...string) *LocationSelect

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

func (*LocationQuery) Unique

func (lq *LocationQuery) Unique(unique bool) *LocationQuery

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

func (lq *LocationQuery) Where(ps ...predicate.Location) *LocationQuery

Where adds a new predicate for the LocationQuery builder.

func (*LocationQuery) WithChildren

func (lq *LocationQuery) WithChildren(opts ...func(*LocationQuery)) *LocationQuery

WithChildren tells the query-builder to eager-load the nodes that are connected to the "children" edge. The optional arguments are used to configure the query builder of the edge.

func (*LocationQuery) WithParent

func (lq *LocationQuery) WithParent(opts ...func(*LocationQuery)) *LocationQuery

WithParent tells the query-builder to eager-load the nodes that are connected to the "parent" edge. The optional arguments are used to configure the query builder of the edge.

type LocationSelect

type LocationSelect struct {
	*LocationQuery
	// contains filtered or unexported fields
}

LocationSelect is the builder for selecting fields of Location entities.

func (*LocationSelect) Bool

func (ls *LocationSelect) Bool(ctx context.Context) (_ bool, err error)

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

func (*LocationSelect) BoolX

func (ls *LocationSelect) BoolX(ctx context.Context) bool

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

func (*LocationSelect) Bools

func (ls *LocationSelect) Bools(ctx context.Context) ([]bool, error)

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

func (*LocationSelect) BoolsX

func (ls *LocationSelect) BoolsX(ctx context.Context) []bool

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

func (*LocationSelect) Float64

func (ls *LocationSelect) Float64(ctx context.Context) (_ float64, err error)

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

func (*LocationSelect) Float64X

func (ls *LocationSelect) Float64X(ctx context.Context) float64

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

func (*LocationSelect) Float64s

func (ls *LocationSelect) Float64s(ctx context.Context) ([]float64, error)

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

func (*LocationSelect) Float64sX

func (ls *LocationSelect) Float64sX(ctx context.Context) []float64

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

func (*LocationSelect) Int

func (ls *LocationSelect) Int(ctx context.Context) (_ int, err error)

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

func (*LocationSelect) IntX

func (ls *LocationSelect) IntX(ctx context.Context) int

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

func (*LocationSelect) Ints

func (ls *LocationSelect) Ints(ctx context.Context) ([]int, error)

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

func (*LocationSelect) IntsX

func (ls *LocationSelect) IntsX(ctx context.Context) []int

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

func (*LocationSelect) Scan

func (ls *LocationSelect) Scan(ctx context.Context, v interface{}) error

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

func (*LocationSelect) ScanX

func (ls *LocationSelect) ScanX(ctx context.Context, v interface{})

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

func (*LocationSelect) String

func (ls *LocationSelect) String(ctx context.Context) (_ string, err error)

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

func (*LocationSelect) StringX

func (ls *LocationSelect) StringX(ctx context.Context) string

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

func (*LocationSelect) Strings

func (ls *LocationSelect) Strings(ctx context.Context) ([]string, error)

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

func (*LocationSelect) StringsX

func (ls *LocationSelect) StringsX(ctx context.Context) []string

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

type LocationUpdate

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

LocationUpdate is the builder for updating Location entities.

func (*LocationUpdate) AddChildIDs

func (lu *LocationUpdate) AddChildIDs(ids ...int) *LocationUpdate

AddChildIDs adds the "children" edge to the Location entity by IDs.

func (*LocationUpdate) AddChildren

func (lu *LocationUpdate) AddChildren(l ...*Location) *LocationUpdate

AddChildren adds the "children" edges to the Location entity.

func (*LocationUpdate) ClearChildren

func (lu *LocationUpdate) ClearChildren() *LocationUpdate

ClearChildren clears all "children" edges to the Location entity.

func (*LocationUpdate) ClearParent

func (lu *LocationUpdate) ClearParent() *LocationUpdate

ClearParent clears the "parent" edge to the Location entity.

func (*LocationUpdate) Exec

func (lu *LocationUpdate) Exec(ctx context.Context) error

Exec executes the query.

func (*LocationUpdate) ExecX

func (lu *LocationUpdate) ExecX(ctx context.Context)

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

func (*LocationUpdate) Mutation

func (lu *LocationUpdate) Mutation() *LocationMutation

Mutation returns the LocationMutation object of the builder.

func (*LocationUpdate) RemoveChildIDs

func (lu *LocationUpdate) RemoveChildIDs(ids ...int) *LocationUpdate

RemoveChildIDs removes the "children" edge to Location entities by IDs.

func (*LocationUpdate) RemoveChildren

func (lu *LocationUpdate) RemoveChildren(l ...*Location) *LocationUpdate

RemoveChildren removes "children" edges to Location entities.

func (*LocationUpdate) Save

func (lu *LocationUpdate) Save(ctx context.Context) (int, error)

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

func (*LocationUpdate) SaveX

func (lu *LocationUpdate) SaveX(ctx context.Context) int

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

func (*LocationUpdate) SetCoords

func (lu *LocationUpdate) SetCoords(s *schema.Point) *LocationUpdate

SetCoords sets the "coords" field.

func (*LocationUpdate) SetName

func (lu *LocationUpdate) SetName(s string) *LocationUpdate

SetName sets the "name" field.

func (*LocationUpdate) SetNillableParentID

func (lu *LocationUpdate) SetNillableParentID(id *int) *LocationUpdate

SetNillableParentID sets the "parent" edge to the Location entity by ID if the given value is not nil.

func (*LocationUpdate) SetParent

func (lu *LocationUpdate) SetParent(l *Location) *LocationUpdate

SetParent sets the "parent" edge to the Location entity.

func (*LocationUpdate) SetParentID

func (lu *LocationUpdate) SetParentID(id int) *LocationUpdate

SetParentID sets the "parent" edge to the Location entity by ID.

func (*LocationUpdate) Where

func (lu *LocationUpdate) Where(ps ...predicate.Location) *LocationUpdate

Where adds a new predicate for the LocationUpdate builder.

type LocationUpdateOne

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

LocationUpdateOne is the builder for updating a single Location entity.

func (*LocationUpdateOne) AddChildIDs

func (luo *LocationUpdateOne) AddChildIDs(ids ...int) *LocationUpdateOne

AddChildIDs adds the "children" edge to the Location entity by IDs.

func (*LocationUpdateOne) AddChildren

func (luo *LocationUpdateOne) AddChildren(l ...*Location) *LocationUpdateOne

AddChildren adds the "children" edges to the Location entity.

func (*LocationUpdateOne) ClearChildren

func (luo *LocationUpdateOne) ClearChildren() *LocationUpdateOne

ClearChildren clears all "children" edges to the Location entity.

func (*LocationUpdateOne) ClearParent

func (luo *LocationUpdateOne) ClearParent() *LocationUpdateOne

ClearParent clears the "parent" edge to the Location entity.

func (*LocationUpdateOne) Exec

func (luo *LocationUpdateOne) Exec(ctx context.Context) error

Exec executes the query on the entity.

func (*LocationUpdateOne) ExecX

func (luo *LocationUpdateOne) ExecX(ctx context.Context)

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

func (*LocationUpdateOne) Mutation

func (luo *LocationUpdateOne) Mutation() *LocationMutation

Mutation returns the LocationMutation object of the builder.

func (*LocationUpdateOne) RemoveChildIDs

func (luo *LocationUpdateOne) RemoveChildIDs(ids ...int) *LocationUpdateOne

RemoveChildIDs removes the "children" edge to Location entities by IDs.

func (*LocationUpdateOne) RemoveChildren

func (luo *LocationUpdateOne) RemoveChildren(l ...*Location) *LocationUpdateOne

RemoveChildren removes "children" edges to Location entities.

func (*LocationUpdateOne) Save

func (luo *LocationUpdateOne) Save(ctx context.Context) (*Location, error)

Save executes the query and returns the updated Location entity.

func (*LocationUpdateOne) SaveX

func (luo *LocationUpdateOne) SaveX(ctx context.Context) *Location

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

func (*LocationUpdateOne) Select

func (luo *LocationUpdateOne) Select(field string, fields ...string) *LocationUpdateOne

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

func (*LocationUpdateOne) SetCoords

func (luo *LocationUpdateOne) SetCoords(s *schema.Point) *LocationUpdateOne

SetCoords sets the "coords" field.

func (*LocationUpdateOne) SetName

func (luo *LocationUpdateOne) SetName(s string) *LocationUpdateOne

SetName sets the "name" field.

func (*LocationUpdateOne) SetNillableParentID

func (luo *LocationUpdateOne) SetNillableParentID(id *int) *LocationUpdateOne

SetNillableParentID sets the "parent" edge to the Location entity by ID if the given value is not nil.

func (*LocationUpdateOne) SetParent

func (luo *LocationUpdateOne) SetParent(l *Location) *LocationUpdateOne

SetParent sets the "parent" edge to the Location entity.

func (*LocationUpdateOne) SetParentID

func (luo *LocationUpdateOne) SetParentID(id int) *LocationUpdateOne

SetParentID sets the "parent" edge to the Location entity by ID.

type Locations

type Locations []*Location

Locations is a parsable slice of Location.

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(...interface{})) Option

Log sets the logging function for debug mode.

type OrderFunc

type OrderFunc func(*sql.Selector)

OrderFunc applies an ordering on the sql selector.

func Asc

func Asc(fields ...string) OrderFunc

Asc applies the given fields in ASC order.

func Desc

func Desc(fields ...string) OrderFunc

Desc applies the given fields in DESC order.

type Policy

type Policy = ent.Policy

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 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(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 Rollbacker method.

type Tx

type Tx struct {

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