ent

package
v0.0.0-...-335ed28 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 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.
	TypeThought = "Thought"
)

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, func(string) bool) 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
	// Thought is the client for interacting with the Thought builders.
	Thought *ThoughtClient
	// 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().
	Thought.
	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 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, func(string) bool)

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 Thought

type Thought struct {

	// ID of the ent.
	ID int `json:"id,omitempty"`
	// Title holds the value of the "title" field.
	Title string `json:"title,omitempty"`
	// Body holds the value of the "body" field.
	Body string `json:"body,omitempty"`
	// ImageURL holds the value of the "imageURL" field.
	ImageURL string `json:"imageURL,omitempty"`
	// UserId holds the value of the "userId" field.
	UserId int64 `json:"userId,omitempty"`
	// contains filtered or unexported fields
}

Thought is the model entity for the Thought schema.

func (*Thought) String

func (t *Thought) String() string

String implements the fmt.Stringer.

func (*Thought) ToGraphQL

func (t *Thought) ToGraphQL() *model.Thought

Convert to GraphQL Schema

func (*Thought) Unwrap

func (t *Thought) Unwrap() *Thought

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

func (t *Thought) Update() *ThoughtUpdateOne

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

type ThoughtClient

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

ThoughtClient is a client for the Thought schema.

func NewThoughtClient

func NewThoughtClient(c config) *ThoughtClient

NewThoughtClient returns a client for the Thought from the given config.

func (*ThoughtClient) Create

func (c *ThoughtClient) Create() *ThoughtCreate

Create returns a create builder for Thought.

func (*ThoughtClient) CreateBulk

func (c *ThoughtClient) CreateBulk(builders ...*ThoughtCreate) *ThoughtCreateBulk

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

func (*ThoughtClient) Delete

func (c *ThoughtClient) Delete() *ThoughtDelete

Delete returns a delete builder for Thought.

func (*ThoughtClient) DeleteOne

func (c *ThoughtClient) DeleteOne(t *Thought) *ThoughtDeleteOne

DeleteOne returns a delete builder for the given entity.

func (*ThoughtClient) DeleteOneID

func (c *ThoughtClient) DeleteOneID(id int) *ThoughtDeleteOne

DeleteOneID returns a delete builder for the given id.

func (*ThoughtClient) Get

func (c *ThoughtClient) Get(ctx context.Context, id int) (*Thought, error)

Get returns a Thought entity by its id.

func (*ThoughtClient) GetX

func (c *ThoughtClient) GetX(ctx context.Context, id int) *Thought

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

func (*ThoughtClient) Hooks

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

Hooks returns the client hooks.

func (*ThoughtClient) Query

func (c *ThoughtClient) Query() *ThoughtQuery

Query returns a query builder for Thought.

func (*ThoughtClient) Update

func (c *ThoughtClient) Update() *ThoughtUpdate

Update returns an update builder for Thought.

func (*ThoughtClient) UpdateOne

func (c *ThoughtClient) UpdateOne(t *Thought) *ThoughtUpdateOne

UpdateOne returns an update builder for the given entity.

func (*ThoughtClient) UpdateOneID

func (c *ThoughtClient) UpdateOneID(id int) *ThoughtUpdateOne

UpdateOneID returns an update builder for the given id.

func (*ThoughtClient) Use

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

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

type ThoughtCreate

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

ThoughtCreate is the builder for creating a Thought entity.

func (*ThoughtCreate) Mutation

func (tc *ThoughtCreate) Mutation() *ThoughtMutation

Mutation returns the ThoughtMutation object of the builder.

func (*ThoughtCreate) Save

func (tc *ThoughtCreate) Save(ctx context.Context) (*Thought, error)

Save creates the Thought in the database.

func (*ThoughtCreate) SaveX

func (tc *ThoughtCreate) SaveX(ctx context.Context) *Thought

SaveX calls Save and panics if Save returns an error.

func (*ThoughtCreate) SetBody

func (tc *ThoughtCreate) SetBody(s string) *ThoughtCreate

SetBody sets the "body" field.

func (*ThoughtCreate) SetImageURL

func (tc *ThoughtCreate) SetImageURL(s string) *ThoughtCreate

SetImageURL sets the "imageURL" field.

func (*ThoughtCreate) SetNillableBody

func (tc *ThoughtCreate) SetNillableBody(s *string) *ThoughtCreate

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

func (*ThoughtCreate) SetTitle

func (tc *ThoughtCreate) SetTitle(s string) *ThoughtCreate

SetTitle sets the "title" field.

func (*ThoughtCreate) SetUserId

func (tc *ThoughtCreate) SetUserId(i int64) *ThoughtCreate

SetUserId sets the "userId" field.

type ThoughtCreateBulk

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

ThoughtCreateBulk is the builder for creating many Thought entities in bulk.

func (*ThoughtCreateBulk) Save

func (tcb *ThoughtCreateBulk) Save(ctx context.Context) ([]*Thought, error)

Save creates the Thought entities in the database.

func (*ThoughtCreateBulk) SaveX

func (tcb *ThoughtCreateBulk) SaveX(ctx context.Context) []*Thought

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

type ThoughtDelete

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

ThoughtDelete is the builder for deleting a Thought entity.

func (*ThoughtDelete) Exec

func (td *ThoughtDelete) Exec(ctx context.Context) (int, error)

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

func (*ThoughtDelete) ExecX

func (td *ThoughtDelete) ExecX(ctx context.Context) int

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

func (*ThoughtDelete) Where

func (td *ThoughtDelete) Where(ps ...predicate.Thought) *ThoughtDelete

Where adds a new predicate to the ThoughtDelete builder.

type ThoughtDeleteOne

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

ThoughtDeleteOne is the builder for deleting a single Thought entity.

func (*ThoughtDeleteOne) Exec

func (tdo *ThoughtDeleteOne) Exec(ctx context.Context) error

Exec executes the deletion query.

func (*ThoughtDeleteOne) ExecX

func (tdo *ThoughtDeleteOne) ExecX(ctx context.Context)

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

type ThoughtGroupBy

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

ThoughtGroupBy is the group-by builder for Thought entities.

func (*ThoughtGroupBy) Aggregate

func (tgb *ThoughtGroupBy) Aggregate(fns ...AggregateFunc) *ThoughtGroupBy

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

func (*ThoughtGroupBy) Bool

func (tgb *ThoughtGroupBy) 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 (*ThoughtGroupBy) BoolX

func (tgb *ThoughtGroupBy) BoolX(ctx context.Context) bool

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

func (*ThoughtGroupBy) Bools

func (tgb *ThoughtGroupBy) 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 (*ThoughtGroupBy) BoolsX

func (tgb *ThoughtGroupBy) BoolsX(ctx context.Context) []bool

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

func (*ThoughtGroupBy) Float64

func (tgb *ThoughtGroupBy) 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 (*ThoughtGroupBy) Float64X

func (tgb *ThoughtGroupBy) Float64X(ctx context.Context) float64

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

func (*ThoughtGroupBy) Float64s

func (tgb *ThoughtGroupBy) 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 (*ThoughtGroupBy) Float64sX

func (tgb *ThoughtGroupBy) Float64sX(ctx context.Context) []float64

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

func (*ThoughtGroupBy) Int

func (tgb *ThoughtGroupBy) 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 (*ThoughtGroupBy) IntX

func (tgb *ThoughtGroupBy) IntX(ctx context.Context) int

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

func (*ThoughtGroupBy) Ints

func (tgb *ThoughtGroupBy) 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 (*ThoughtGroupBy) IntsX

func (tgb *ThoughtGroupBy) IntsX(ctx context.Context) []int

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

func (*ThoughtGroupBy) Scan

func (tgb *ThoughtGroupBy) Scan(ctx context.Context, v interface{}) error

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

func (*ThoughtGroupBy) ScanX

func (tgb *ThoughtGroupBy) ScanX(ctx context.Context, v interface{})

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

func (*ThoughtGroupBy) String

func (tgb *ThoughtGroupBy) 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 (*ThoughtGroupBy) StringX

func (tgb *ThoughtGroupBy) StringX(ctx context.Context) string

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

func (*ThoughtGroupBy) Strings

func (tgb *ThoughtGroupBy) 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 (*ThoughtGroupBy) StringsX

func (tgb *ThoughtGroupBy) StringsX(ctx context.Context) []string

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

type ThoughtMutation

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

ThoughtMutation represents an operation that mutates the Thought nodes in the graph.

func (*ThoughtMutation) AddField

func (m *ThoughtMutation) 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 (*ThoughtMutation) AddUserId

func (m *ThoughtMutation) AddUserId(i int64)

AddUserId adds i to the "userId" field.

func (*ThoughtMutation) AddedEdges

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

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

func (*ThoughtMutation) AddedField

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

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

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

func (*ThoughtMutation) AddedIDs

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

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

func (*ThoughtMutation) AddedUserId

func (m *ThoughtMutation) AddedUserId() (r int64, exists bool)

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

func (*ThoughtMutation) Body

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

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

func (*ThoughtMutation) ClearEdge

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

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

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

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

func (*ThoughtMutation) ClearedFields

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

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

func (ThoughtMutation) Client

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

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

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

func (*ThoughtMutation) Field

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

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

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

func (*ThoughtMutation) Fields

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

func (m *ThoughtMutation) 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 (*ThoughtMutation) ImageURL

func (m *ThoughtMutation) ImageURL() (r string, exists bool)

ImageURL returns the value of the "imageURL" field in the mutation.

func (*ThoughtMutation) OldBody

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

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

func (m *ThoughtMutation) 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 (*ThoughtMutation) OldImageURL

func (m *ThoughtMutation) OldImageURL(ctx context.Context) (v string, err error)

OldImageURL returns the old "imageURL" field's value of the Thought entity. If the Thought 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 (*ThoughtMutation) OldTitle

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

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

func (m *ThoughtMutation) OldUserId(ctx context.Context) (v int64, err error)

OldUserId returns the old "userId" field's value of the Thought entity. If the Thought 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 (*ThoughtMutation) Op

func (m *ThoughtMutation) Op() Op

Op returns the operation name.

func (*ThoughtMutation) RemovedEdges

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

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

func (*ThoughtMutation) RemovedIDs

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

func (m *ThoughtMutation) ResetBody()

ResetBody resets all changes to the "body" field.

func (*ThoughtMutation) ResetEdge

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

func (m *ThoughtMutation) 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 (*ThoughtMutation) ResetImageURL

func (m *ThoughtMutation) ResetImageURL()

ResetImageURL resets all changes to the "imageURL" field.

func (*ThoughtMutation) ResetTitle

func (m *ThoughtMutation) ResetTitle()

ResetTitle resets all changes to the "title" field.

func (*ThoughtMutation) ResetUserId

func (m *ThoughtMutation) ResetUserId()

ResetUserId resets all changes to the "userId" field.

func (*ThoughtMutation) SetBody

func (m *ThoughtMutation) SetBody(s string)

SetBody sets the "body" field.

func (*ThoughtMutation) SetField

func (m *ThoughtMutation) 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 (*ThoughtMutation) SetImageURL

func (m *ThoughtMutation) SetImageURL(s string)

SetImageURL sets the "imageURL" field.

func (*ThoughtMutation) SetTitle

func (m *ThoughtMutation) SetTitle(s string)

SetTitle sets the "title" field.

func (*ThoughtMutation) SetUserId

func (m *ThoughtMutation) SetUserId(i int64)

SetUserId sets the "userId" field.

func (*ThoughtMutation) Title

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

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

func (ThoughtMutation) Tx

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

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

func (*ThoughtMutation) Type

func (m *ThoughtMutation) Type() string

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

func (*ThoughtMutation) UserId

func (m *ThoughtMutation) UserId() (r int64, exists bool)

UserId returns the value of the "userId" field in the mutation.

type ThoughtQuery

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

ThoughtQuery is the builder for querying Thought entities.

func (*ThoughtQuery) All

func (tq *ThoughtQuery) All(ctx context.Context) ([]*Thought, error)

All executes the query and returns a list of Thoughts.

func (*ThoughtQuery) AllX

func (tq *ThoughtQuery) AllX(ctx context.Context) []*Thought

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

func (*ThoughtQuery) Clone

func (tq *ThoughtQuery) Clone() *ThoughtQuery

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

func (*ThoughtQuery) Count

func (tq *ThoughtQuery) Count(ctx context.Context) (int, error)

Count returns the count of the given query.

func (*ThoughtQuery) CountX

func (tq *ThoughtQuery) CountX(ctx context.Context) int

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

func (*ThoughtQuery) Exist

func (tq *ThoughtQuery) Exist(ctx context.Context) (bool, error)

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

func (*ThoughtQuery) ExistX

func (tq *ThoughtQuery) ExistX(ctx context.Context) bool

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

func (*ThoughtQuery) First

func (tq *ThoughtQuery) First(ctx context.Context) (*Thought, error)

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

func (*ThoughtQuery) FirstID

func (tq *ThoughtQuery) FirstID(ctx context.Context) (id int, err error)

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

func (*ThoughtQuery) FirstIDX

func (tq *ThoughtQuery) FirstIDX(ctx context.Context) int

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

func (*ThoughtQuery) FirstX

func (tq *ThoughtQuery) FirstX(ctx context.Context) *Thought

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

func (*ThoughtQuery) GroupBy

func (tq *ThoughtQuery) GroupBy(field string, fields ...string) *ThoughtGroupBy

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

func (*ThoughtQuery) IDs

func (tq *ThoughtQuery) IDs(ctx context.Context) ([]int, error)

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

func (*ThoughtQuery) IDsX

func (tq *ThoughtQuery) IDsX(ctx context.Context) []int

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

func (*ThoughtQuery) Limit

func (tq *ThoughtQuery) Limit(limit int) *ThoughtQuery

Limit adds a limit step to the query.

func (*ThoughtQuery) Offset

func (tq *ThoughtQuery) Offset(offset int) *ThoughtQuery

Offset adds an offset step to the query.

func (*ThoughtQuery) Only

func (tq *ThoughtQuery) Only(ctx context.Context) (*Thought, error)

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

func (*ThoughtQuery) OnlyID

func (tq *ThoughtQuery) OnlyID(ctx context.Context) (id int, err error)

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

func (*ThoughtQuery) OnlyIDX

func (tq *ThoughtQuery) OnlyIDX(ctx context.Context) int

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

func (*ThoughtQuery) OnlyX

func (tq *ThoughtQuery) OnlyX(ctx context.Context) *Thought

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

func (*ThoughtQuery) Order

func (tq *ThoughtQuery) Order(o ...OrderFunc) *ThoughtQuery

Order adds an order step to the query.

func (*ThoughtQuery) Select

func (tq *ThoughtQuery) Select(field string, fields ...string) *ThoughtSelect

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

func (*ThoughtQuery) Where

func (tq *ThoughtQuery) Where(ps ...predicate.Thought) *ThoughtQuery

Where adds a new predicate for the ThoughtQuery builder.

type ThoughtSelect

type ThoughtSelect struct {
	*ThoughtQuery
	// contains filtered or unexported fields
}

ThoughtSelect is the builder for selecting fields of Thought entities.

func (*ThoughtSelect) Bool

func (ts *ThoughtSelect) Bool(ctx context.Context) (_ bool, err error)

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

func (*ThoughtSelect) BoolX

func (ts *ThoughtSelect) BoolX(ctx context.Context) bool

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

func (*ThoughtSelect) Bools

func (ts *ThoughtSelect) Bools(ctx context.Context) ([]bool, error)

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

func (*ThoughtSelect) BoolsX

func (ts *ThoughtSelect) BoolsX(ctx context.Context) []bool

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

func (*ThoughtSelect) Float64

func (ts *ThoughtSelect) Float64(ctx context.Context) (_ float64, err error)

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

func (*ThoughtSelect) Float64X

func (ts *ThoughtSelect) Float64X(ctx context.Context) float64

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

func (*ThoughtSelect) Float64s

func (ts *ThoughtSelect) Float64s(ctx context.Context) ([]float64, error)

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

func (*ThoughtSelect) Float64sX

func (ts *ThoughtSelect) Float64sX(ctx context.Context) []float64

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

func (*ThoughtSelect) Int

func (ts *ThoughtSelect) Int(ctx context.Context) (_ int, err error)

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

func (*ThoughtSelect) IntX

func (ts *ThoughtSelect) IntX(ctx context.Context) int

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

func (*ThoughtSelect) Ints

func (ts *ThoughtSelect) Ints(ctx context.Context) ([]int, error)

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

func (*ThoughtSelect) IntsX

func (ts *ThoughtSelect) IntsX(ctx context.Context) []int

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

func (*ThoughtSelect) Scan

func (ts *ThoughtSelect) Scan(ctx context.Context, v interface{}) error

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

func (*ThoughtSelect) ScanX

func (ts *ThoughtSelect) ScanX(ctx context.Context, v interface{})

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

func (*ThoughtSelect) String

func (ts *ThoughtSelect) String(ctx context.Context) (_ string, err error)

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

func (*ThoughtSelect) StringX

func (ts *ThoughtSelect) StringX(ctx context.Context) string

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

func (*ThoughtSelect) Strings

func (ts *ThoughtSelect) Strings(ctx context.Context) ([]string, error)

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

func (*ThoughtSelect) StringsX

func (ts *ThoughtSelect) StringsX(ctx context.Context) []string

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

type ThoughtUpdate

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

ThoughtUpdate is the builder for updating Thought entities.

func (*ThoughtUpdate) AddUserId

func (tu *ThoughtUpdate) AddUserId(i int64) *ThoughtUpdate

AddUserId adds i to the "userId" field.

func (*ThoughtUpdate) Exec

func (tu *ThoughtUpdate) Exec(ctx context.Context) error

Exec executes the query.

func (*ThoughtUpdate) ExecX

func (tu *ThoughtUpdate) ExecX(ctx context.Context)

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

func (*ThoughtUpdate) Mutation

func (tu *ThoughtUpdate) Mutation() *ThoughtMutation

Mutation returns the ThoughtMutation object of the builder.

func (*ThoughtUpdate) Save

func (tu *ThoughtUpdate) Save(ctx context.Context) (int, error)

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

func (*ThoughtUpdate) SaveX

func (tu *ThoughtUpdate) SaveX(ctx context.Context) int

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

func (*ThoughtUpdate) SetBody

func (tu *ThoughtUpdate) SetBody(s string) *ThoughtUpdate

SetBody sets the "body" field.

func (*ThoughtUpdate) SetImageURL

func (tu *ThoughtUpdate) SetImageURL(s string) *ThoughtUpdate

SetImageURL sets the "imageURL" field.

func (*ThoughtUpdate) SetNillableBody

func (tu *ThoughtUpdate) SetNillableBody(s *string) *ThoughtUpdate

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

func (*ThoughtUpdate) SetTitle

func (tu *ThoughtUpdate) SetTitle(s string) *ThoughtUpdate

SetTitle sets the "title" field.

func (*ThoughtUpdate) SetUserId

func (tu *ThoughtUpdate) SetUserId(i int64) *ThoughtUpdate

SetUserId sets the "userId" field.

func (*ThoughtUpdate) Where

func (tu *ThoughtUpdate) Where(ps ...predicate.Thought) *ThoughtUpdate

Where adds a new predicate for the ThoughtUpdate builder.

type ThoughtUpdateOne

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

ThoughtUpdateOne is the builder for updating a single Thought entity.

func (*ThoughtUpdateOne) AddUserId

func (tuo *ThoughtUpdateOne) AddUserId(i int64) *ThoughtUpdateOne

AddUserId adds i to the "userId" field.

func (*ThoughtUpdateOne) Exec

func (tuo *ThoughtUpdateOne) Exec(ctx context.Context) error

Exec executes the query on the entity.

func (*ThoughtUpdateOne) ExecX

func (tuo *ThoughtUpdateOne) ExecX(ctx context.Context)

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

func (*ThoughtUpdateOne) Mutation

func (tuo *ThoughtUpdateOne) Mutation() *ThoughtMutation

Mutation returns the ThoughtMutation object of the builder.

func (*ThoughtUpdateOne) Save

func (tuo *ThoughtUpdateOne) Save(ctx context.Context) (*Thought, error)

Save executes the query and returns the updated Thought entity.

func (*ThoughtUpdateOne) SaveX

func (tuo *ThoughtUpdateOne) SaveX(ctx context.Context) *Thought

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

func (*ThoughtUpdateOne) SetBody

func (tuo *ThoughtUpdateOne) SetBody(s string) *ThoughtUpdateOne

SetBody sets the "body" field.

func (*ThoughtUpdateOne) SetImageURL

func (tuo *ThoughtUpdateOne) SetImageURL(s string) *ThoughtUpdateOne

SetImageURL sets the "imageURL" field.

func (*ThoughtUpdateOne) SetNillableBody

func (tuo *ThoughtUpdateOne) SetNillableBody(s *string) *ThoughtUpdateOne

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

func (*ThoughtUpdateOne) SetTitle

func (tuo *ThoughtUpdateOne) SetTitle(s string) *ThoughtUpdateOne

SetTitle sets the "title" field.

func (*ThoughtUpdateOne) SetUserId

func (tuo *ThoughtUpdateOne) SetUserId(i int64) *ThoughtUpdateOne

SetUserId sets the "userId" field.

type Thoughts

type Thoughts []*Thought

Thoughts is a parsable slice of Thought.

type ThoughtsArray

type ThoughtsArray []*Thought

Method Injection

func (ThoughtsArray) ToGraphQLs

func (arr ThoughtsArray) ToGraphQLs() []*model.Thought

Convert all to GraphQL Schema

type Tx

type Tx struct {

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