ent

package
v0.0.0-...-1136dd0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Operation types.
	OpCreate    = ent.OpCreate
	OpDelete    = ent.OpDelete
	OpDeleteOne = ent.OpDeleteOne
	OpUpdate    = ent.OpUpdate
	OpUpdateOne = ent.OpUpdateOne

	// Node types.
	TypeManufacturer = "Manufacturer"
	TypeModel        = "Model"
)

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 MaskNotFound

func MaskNotFound(err error) error

MaskNotFound masks nor 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 Client attached.

Types

type Aggregate

type Aggregate func(*sql.Selector) string

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

func As

func As(fn Aggregate, end string) Aggregate

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() Aggregate

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

func Max

func Max(field string) Aggregate

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

func Mean

func Mean(field string) Aggregate

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

func Min

func Min(field string) Aggregate

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

func Sum

func Sum(field string) Aggregate

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
	// Manufacturer is the client for interacting with the Manufacturer builders.
	Manufacturer *ManufacturerClient
	// Model is the client for interacting with the Model builders.
	Model *ModelClient
	// contains filtered or unexported fields
}

Client is the client that holds all ent builders.

func FromContext

func FromContext(ctx context.Context) *Client

FromContext returns the Client stored in 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 connection to the database specified by the driver name and a driver-specific 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 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().
	Manufacturer.
	Query().
	Count(ctx)

func (*Client) Tx

func (c *Client) Tx(ctx context.Context) (*Tx, error)

Tx returns a new transactional client.

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 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 conflict in user's code.

type Manufacturer

type Manufacturer struct {

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

Manufacturer is the model entity for the Manufacturer schema.

func (*Manufacturer) String

func (m *Manufacturer) String() string

String implements the fmt.Stringer.

func (*Manufacturer) Unwrap

func (m *Manufacturer) Unwrap() *Manufacturer

Unwrap unwraps the entity that was returned from a transaction after it was closed, so that all next queries will be executed through the driver which created the transaction.

func (*Manufacturer) Update

func (m *Manufacturer) Update() *ManufacturerUpdateOne

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

type ManufacturerClient

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

ManufacturerClient is a client for the Manufacturer schema.

func NewManufacturerClient

func NewManufacturerClient(c config) *ManufacturerClient

NewManufacturerClient returns a client for the Manufacturer from the given config.

func (*ManufacturerClient) Create

Create returns a create builder for Manufacturer.

func (*ManufacturerClient) Delete

Delete returns a delete builder for Manufacturer.

func (*ManufacturerClient) DeleteOne

DeleteOne returns a delete builder for the given entity.

func (*ManufacturerClient) DeleteOneID

func (c *ManufacturerClient) DeleteOneID(id int) *ManufacturerDeleteOne

DeleteOneID returns a delete builder for the given id.

func (*ManufacturerClient) Get

Get returns a Manufacturer entity by its id.

func (*ManufacturerClient) GetX

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

func (*ManufacturerClient) Hooks

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

Hooks returns the client hooks.

func (*ManufacturerClient) Query

Create returns a query builder for Manufacturer.

func (*ManufacturerClient) Update

Update returns an update builder for Manufacturer.

func (*ManufacturerClient) UpdateOne

UpdateOne returns an update builder for the given entity.

func (*ManufacturerClient) UpdateOneID

func (c *ManufacturerClient) UpdateOneID(id int) *ManufacturerUpdateOne

UpdateOneID returns an update builder for the given id.

func (*ManufacturerClient) Use

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

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

type ManufacturerCreate

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

ManufacturerCreate is the builder for creating a Manufacturer entity.

func (*ManufacturerCreate) Save

Save creates the Manufacturer in the database.

func (*ManufacturerCreate) SaveX

SaveX calls Save and panics if Save returns an error.

func (*ManufacturerCreate) SetName

SetName sets the name field.

func (*ManufacturerCreate) SetNillableName

func (mc *ManufacturerCreate) SetNillableName(s *string) *ManufacturerCreate

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

type ManufacturerDelete

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

ManufacturerDelete is the builder for deleting a Manufacturer entity.

func (*ManufacturerDelete) Exec

func (md *ManufacturerDelete) Exec(ctx context.Context) (int, error)

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

func (*ManufacturerDelete) ExecX

func (md *ManufacturerDelete) ExecX(ctx context.Context) int

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

func (*ManufacturerDelete) Where

Where adds a new predicate to the delete builder.

type ManufacturerDeleteOne

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

ManufacturerDeleteOne is the builder for deleting a single Manufacturer entity.

func (*ManufacturerDeleteOne) Exec

func (mdo *ManufacturerDeleteOne) Exec(ctx context.Context) error

Exec executes the deletion query.

func (*ManufacturerDeleteOne) ExecX

func (mdo *ManufacturerDeleteOne) ExecX(ctx context.Context)

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

type ManufacturerGroupBy

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

ManufacturerGroupBy is the builder for group-by Manufacturer entities.

func (*ManufacturerGroupBy) Aggregate

func (mgb *ManufacturerGroupBy) Aggregate(fns ...Aggregate) *ManufacturerGroupBy

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

func (*ManufacturerGroupBy) Bools

func (mgb *ManufacturerGroupBy) Bools(ctx context.Context) ([]bool, error)

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

func (*ManufacturerGroupBy) BoolsX

func (mgb *ManufacturerGroupBy) BoolsX(ctx context.Context) []bool

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

func (*ManufacturerGroupBy) Float64s

func (mgb *ManufacturerGroupBy) Float64s(ctx context.Context) ([]float64, error)

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

func (*ManufacturerGroupBy) Float64sX

func (mgb *ManufacturerGroupBy) Float64sX(ctx context.Context) []float64

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

func (*ManufacturerGroupBy) Ints

func (mgb *ManufacturerGroupBy) Ints(ctx context.Context) ([]int, error)

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

func (*ManufacturerGroupBy) IntsX

func (mgb *ManufacturerGroupBy) IntsX(ctx context.Context) []int

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

func (*ManufacturerGroupBy) Scan

func (mgb *ManufacturerGroupBy) Scan(ctx context.Context, v interface{}) error

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

func (*ManufacturerGroupBy) ScanX

func (mgb *ManufacturerGroupBy) ScanX(ctx context.Context, v interface{})

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

func (*ManufacturerGroupBy) Strings

func (mgb *ManufacturerGroupBy) Strings(ctx context.Context) ([]string, error)

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

func (*ManufacturerGroupBy) StringsX

func (mgb *ManufacturerGroupBy) StringsX(ctx context.Context) []string

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

type ManufacturerMutation

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

ManufacturerMutation represents an operation that mutate the Manufacturers nodes in the graph.

func (*ManufacturerMutation) AddField

func (m *ManufacturerMutation) AddField(name string, value ent.Value) error

AddField adds the value for the given name. It returns an error if the field is not defined in the schema, or if the type mismatch the field type.

func (*ManufacturerMutation) AddedEdges

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

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

func (*ManufacturerMutation) AddedField

func (m *ManufacturerMutation) AddedField(name string) (ent.Value, bool)

AddedField returns the numeric value that was in/decremented from a field with the given name. The second value indicates that this field was not set, or was not define in the schema.

func (*ManufacturerMutation) AddedFields

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

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

func (*ManufacturerMutation) AddedIDs

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

AddedIDs returns all ids (to other nodes) that were added for the given edge name.

func (*ManufacturerMutation) ClearEdge

func (m *ManufacturerMutation) ClearEdge(name string) error

ClearEdge clears the value for the given name. It returns an error if the edge name is not defined in the schema.

func (*ManufacturerMutation) ClearField

func (m *ManufacturerMutation) ClearField(name string) error

ClearField clears the value for the given name. It returns an error if the field is not defined in the schema.

func (*ManufacturerMutation) ClearedEdges

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

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

func (*ManufacturerMutation) ClearedFields

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

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

func (ManufacturerMutation) Client

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

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

EdgeCleared returns a boolean indicates if this edge was cleared in this mutation.

func (*ManufacturerMutation) Field

func (m *ManufacturerMutation) Field(name string) (ent.Value, bool)

Field returns the value of a field with the given name. The second boolean value indicates that this field was not set, or was not define in the schema.

func (*ManufacturerMutation) FieldCleared

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

FieldCleared returns a boolean indicates if this field was cleared in this mutation.

func (*ManufacturerMutation) Fields

func (m *ManufacturerMutation) Fields() []string

Fields returns all fields that were changed during this mutation. Note that, in order to get all numeric fields that were in/decremented, call AddedFields().

func (*ManufacturerMutation) ID

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

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

func (*ManufacturerMutation) Name

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

Name returns the name value in the mutation.

func (*ManufacturerMutation) Op

func (m *ManufacturerMutation) Op() Op

Op returns the operation name.

func (*ManufacturerMutation) RemovedEdges

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

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

func (*ManufacturerMutation) RemovedIDs

func (m *ManufacturerMutation) RemovedIDs(name string) []ent.Value

RemovedIDs returns all ids (to other nodes) that were removed for the given edge name.

func (*ManufacturerMutation) ResetEdge

func (m *ManufacturerMutation) ResetEdge(name string) error

ResetEdge resets all changes in the mutation regarding the given edge name. It returns an error if the edge is not defined in the schema.

func (*ManufacturerMutation) ResetField

func (m *ManufacturerMutation) ResetField(name string) error

ResetField resets all changes in the mutation regarding the given field name. It returns an error if the field is not defined in the schema.

func (*ManufacturerMutation) ResetName

func (m *ManufacturerMutation) ResetName()

ResetName reset all changes of the name field.

func (*ManufacturerMutation) SetField

func (m *ManufacturerMutation) SetField(name string, value ent.Value) error

SetField sets the value for the given name. It returns an error if the field is not defined in the schema, or if the type mismatch the field type.

func (*ManufacturerMutation) SetName

func (m *ManufacturerMutation) SetName(s string)

SetName sets the name field.

func (ManufacturerMutation) Tx

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

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

func (*ManufacturerMutation) Type

func (m *ManufacturerMutation) Type() string

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

type ManufacturerQuery

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

ManufacturerQuery is the builder for querying Manufacturer entities.

func (*ManufacturerQuery) All

func (mq *ManufacturerQuery) All(ctx context.Context) ([]*Manufacturer, error)

All executes the query and returns a list of Manufacturers.

func (*ManufacturerQuery) AllX

func (mq *ManufacturerQuery) AllX(ctx context.Context) []*Manufacturer

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

func (*ManufacturerQuery) Clone

func (mq *ManufacturerQuery) Clone() *ManufacturerQuery

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

func (*ManufacturerQuery) Count

func (mq *ManufacturerQuery) Count(ctx context.Context) (int, error)

Count returns the count of the given query.

func (*ManufacturerQuery) CountX

func (mq *ManufacturerQuery) CountX(ctx context.Context) int

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

func (*ManufacturerQuery) Exist

func (mq *ManufacturerQuery) Exist(ctx context.Context) (bool, error)

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

func (*ManufacturerQuery) ExistX

func (mq *ManufacturerQuery) ExistX(ctx context.Context) bool

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

func (*ManufacturerQuery) First

func (mq *ManufacturerQuery) First(ctx context.Context) (*Manufacturer, error)

First returns the first Manufacturer entity in the query. Returns *NotFoundError when no manufacturer was found.

func (*ManufacturerQuery) FirstID

func (mq *ManufacturerQuery) FirstID(ctx context.Context) (id int, err error)

FirstID returns the first Manufacturer id in the query. Returns *NotFoundError when no id was found.

func (*ManufacturerQuery) FirstX

func (mq *ManufacturerQuery) FirstX(ctx context.Context) *Manufacturer

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

func (*ManufacturerQuery) FirstXID

func (mq *ManufacturerQuery) FirstXID(ctx context.Context) int

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

func (*ManufacturerQuery) GroupBy

func (mq *ManufacturerQuery) GroupBy(field string, fields ...string) *ManufacturerGroupBy

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

func (*ManufacturerQuery) IDs

func (mq *ManufacturerQuery) IDs(ctx context.Context) ([]int, error)

IDs executes the query and returns a list of Manufacturer ids.

func (*ManufacturerQuery) IDsX

func (mq *ManufacturerQuery) IDsX(ctx context.Context) []int

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

func (*ManufacturerQuery) Limit

func (mq *ManufacturerQuery) Limit(limit int) *ManufacturerQuery

Limit adds a limit step to the query.

func (*ManufacturerQuery) Offset

func (mq *ManufacturerQuery) Offset(offset int) *ManufacturerQuery

Offset adds an offset step to the query.

func (*ManufacturerQuery) Only

Only returns the only Manufacturer entity in the query, returns an error if not exactly one entity was returned.

func (*ManufacturerQuery) OnlyID

func (mq *ManufacturerQuery) OnlyID(ctx context.Context) (id int, err error)

OnlyID returns the only Manufacturer id in the query, returns an error if not exactly one id was returned.

func (*ManufacturerQuery) OnlyX

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

func (*ManufacturerQuery) OnlyXID

func (mq *ManufacturerQuery) OnlyXID(ctx context.Context) int

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

func (*ManufacturerQuery) Order

func (mq *ManufacturerQuery) Order(o ...Order) *ManufacturerQuery

Order adds an order step to the query.

func (*ManufacturerQuery) Select

func (mq *ManufacturerQuery) Select(field string, fields ...string) *ManufacturerSelect

Select one or more fields from the given query.

Example:

var v []struct {
	Name string `json:"name,omitempty"`
}

client.Manufacturer.Query().
	Select(manufacturer.FieldName).
	Scan(ctx, &v)

func (*ManufacturerQuery) Where

Where adds a new predicate for the builder.

type ManufacturerSelect

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

ManufacturerSelect is the builder for select fields of Manufacturer entities.

func (*ManufacturerSelect) Bools

func (ms *ManufacturerSelect) Bools(ctx context.Context) ([]bool, error)

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

func (*ManufacturerSelect) BoolsX

func (ms *ManufacturerSelect) BoolsX(ctx context.Context) []bool

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

func (*ManufacturerSelect) Float64s

func (ms *ManufacturerSelect) Float64s(ctx context.Context) ([]float64, error)

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

func (*ManufacturerSelect) Float64sX

func (ms *ManufacturerSelect) Float64sX(ctx context.Context) []float64

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

func (*ManufacturerSelect) Ints

func (ms *ManufacturerSelect) Ints(ctx context.Context) ([]int, error)

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

func (*ManufacturerSelect) IntsX

func (ms *ManufacturerSelect) IntsX(ctx context.Context) []int

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

func (*ManufacturerSelect) Scan

func (ms *ManufacturerSelect) Scan(ctx context.Context, v interface{}) error

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

func (*ManufacturerSelect) ScanX

func (ms *ManufacturerSelect) ScanX(ctx context.Context, v interface{})

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

func (*ManufacturerSelect) Strings

func (ms *ManufacturerSelect) Strings(ctx context.Context) ([]string, error)

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

func (*ManufacturerSelect) StringsX

func (ms *ManufacturerSelect) StringsX(ctx context.Context) []string

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

type ManufacturerUpdate

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

ManufacturerUpdate is the builder for updating Manufacturer entities.

func (*ManufacturerUpdate) Exec

func (mu *ManufacturerUpdate) Exec(ctx context.Context) error

Exec executes the query.

func (*ManufacturerUpdate) ExecX

func (mu *ManufacturerUpdate) ExecX(ctx context.Context)

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

func (*ManufacturerUpdate) Save

func (mu *ManufacturerUpdate) Save(ctx context.Context) (int, error)

Save executes the query and returns the number of rows/vertices matched by this operation.

func (*ManufacturerUpdate) SaveX

func (mu *ManufacturerUpdate) SaveX(ctx context.Context) int

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

func (*ManufacturerUpdate) SetName

SetName sets the name field.

func (*ManufacturerUpdate) SetNillableName

func (mu *ManufacturerUpdate) SetNillableName(s *string) *ManufacturerUpdate

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

func (*ManufacturerUpdate) Where

Where adds a new predicate for the builder.

type ManufacturerUpdateOne

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

ManufacturerUpdateOne is the builder for updating a single Manufacturer entity.

func (*ManufacturerUpdateOne) Exec

func (muo *ManufacturerUpdateOne) Exec(ctx context.Context) error

Exec executes the query on the entity.

func (*ManufacturerUpdateOne) ExecX

func (muo *ManufacturerUpdateOne) ExecX(ctx context.Context)

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

func (*ManufacturerUpdateOne) Save

Save executes the query and returns the updated entity.

func (*ManufacturerUpdateOne) SaveX

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

func (*ManufacturerUpdateOne) SetName

SetName sets the name field.

func (*ManufacturerUpdateOne) SetNillableName

func (muo *ManufacturerUpdateOne) SetNillableName(s *string) *ManufacturerUpdateOne

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

type Manufacturers

type Manufacturers []*Manufacturer

Manufacturers is a parsable slice of Manufacturer.

type Model

type Model struct {

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

Model is the model entity for the Model schema.

func (*Model) String

func (m *Model) String() string

String implements the fmt.Stringer.

func (*Model) Unwrap

func (m *Model) Unwrap() *Model

Unwrap unwraps the entity that was returned from a transaction after it was closed, so that all next queries will be executed through the driver which created the transaction.

func (*Model) Update

func (m *Model) Update() *ModelUpdateOne

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

type ModelClient

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

ModelClient is a client for the Model schema.

func NewModelClient

func NewModelClient(c config) *ModelClient

NewModelClient returns a client for the Model from the given config.

func (*ModelClient) Create

func (c *ModelClient) Create() *ModelCreate

Create returns a create builder for Model.

func (*ModelClient) Delete

func (c *ModelClient) Delete() *ModelDelete

Delete returns a delete builder for Model.

func (*ModelClient) DeleteOne

func (c *ModelClient) DeleteOne(m *Model) *ModelDeleteOne

DeleteOne returns a delete builder for the given entity.

func (*ModelClient) DeleteOneID

func (c *ModelClient) DeleteOneID(id int) *ModelDeleteOne

DeleteOneID returns a delete builder for the given id.

func (*ModelClient) Get

func (c *ModelClient) Get(ctx context.Context, id int) (*Model, error)

Get returns a Model entity by its id.

func (*ModelClient) GetX

func (c *ModelClient) GetX(ctx context.Context, id int) *Model

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

func (*ModelClient) Hooks

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

Hooks returns the client hooks.

func (*ModelClient) Query

func (c *ModelClient) Query() *ModelQuery

Create returns a query builder for Model.

func (*ModelClient) Update

func (c *ModelClient) Update() *ModelUpdate

Update returns an update builder for Model.

func (*ModelClient) UpdateOne

func (c *ModelClient) UpdateOne(m *Model) *ModelUpdateOne

UpdateOne returns an update builder for the given entity.

func (*ModelClient) UpdateOneID

func (c *ModelClient) UpdateOneID(id int) *ModelUpdateOne

UpdateOneID returns an update builder for the given id.

func (*ModelClient) Use

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

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

type ModelCreate

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

ModelCreate is the builder for creating a Model entity.

func (*ModelCreate) Save

func (mc *ModelCreate) Save(ctx context.Context) (*Model, error)

Save creates the Model in the database.

func (*ModelCreate) SaveX

func (mc *ModelCreate) SaveX(ctx context.Context) *Model

SaveX calls Save and panics if Save returns an error.

func (*ModelCreate) SetName

func (mc *ModelCreate) SetName(s string) *ModelCreate

SetName sets the name field.

func (*ModelCreate) SetNillableName

func (mc *ModelCreate) SetNillableName(s *string) *ModelCreate

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

type ModelDelete

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

ModelDelete is the builder for deleting a Model entity.

func (*ModelDelete) Exec

func (md *ModelDelete) Exec(ctx context.Context) (int, error)

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

func (*ModelDelete) ExecX

func (md *ModelDelete) ExecX(ctx context.Context) int

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

func (*ModelDelete) Where

func (md *ModelDelete) Where(ps ...predicate.Model) *ModelDelete

Where adds a new predicate to the delete builder.

type ModelDeleteOne

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

ModelDeleteOne is the builder for deleting a single Model entity.

func (*ModelDeleteOne) Exec

func (mdo *ModelDeleteOne) Exec(ctx context.Context) error

Exec executes the deletion query.

func (*ModelDeleteOne) ExecX

func (mdo *ModelDeleteOne) ExecX(ctx context.Context)

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

type ModelGroupBy

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

ModelGroupBy is the builder for group-by Model entities.

func (*ModelGroupBy) Aggregate

func (mgb *ModelGroupBy) Aggregate(fns ...Aggregate) *ModelGroupBy

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

func (*ModelGroupBy) Bools

func (mgb *ModelGroupBy) Bools(ctx context.Context) ([]bool, error)

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

func (*ModelGroupBy) BoolsX

func (mgb *ModelGroupBy) BoolsX(ctx context.Context) []bool

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

func (*ModelGroupBy) Float64s

func (mgb *ModelGroupBy) Float64s(ctx context.Context) ([]float64, error)

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

func (*ModelGroupBy) Float64sX

func (mgb *ModelGroupBy) Float64sX(ctx context.Context) []float64

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

func (*ModelGroupBy) Ints

func (mgb *ModelGroupBy) Ints(ctx context.Context) ([]int, error)

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

func (*ModelGroupBy) IntsX

func (mgb *ModelGroupBy) IntsX(ctx context.Context) []int

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

func (*ModelGroupBy) Scan

func (mgb *ModelGroupBy) Scan(ctx context.Context, v interface{}) error

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

func (*ModelGroupBy) ScanX

func (mgb *ModelGroupBy) ScanX(ctx context.Context, v interface{})

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

func (*ModelGroupBy) Strings

func (mgb *ModelGroupBy) Strings(ctx context.Context) ([]string, error)

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

func (*ModelGroupBy) StringsX

func (mgb *ModelGroupBy) StringsX(ctx context.Context) []string

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

type ModelMutation

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

ModelMutation represents an operation that mutate the Models nodes in the graph.

func (*ModelMutation) AddField

func (m *ModelMutation) AddField(name string, value ent.Value) error

AddField adds the value for the given name. It returns an error if the field is not defined in the schema, or if the type mismatch the field type.

func (*ModelMutation) AddedEdges

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

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

func (*ModelMutation) AddedField

func (m *ModelMutation) AddedField(name string) (ent.Value, bool)

AddedField returns the numeric value that was in/decremented from a field with the given name. The second value indicates that this field was not set, or was not define in the schema.

func (*ModelMutation) AddedFields

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

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

func (*ModelMutation) AddedIDs

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

AddedIDs returns all ids (to other nodes) that were added for the given edge name.

func (*ModelMutation) ClearEdge

func (m *ModelMutation) ClearEdge(name string) error

ClearEdge clears the value for the given name. It returns an error if the edge name is not defined in the schema.

func (*ModelMutation) ClearField

func (m *ModelMutation) ClearField(name string) error

ClearField clears the value for the given name. It returns an error if the field is not defined in the schema.

func (*ModelMutation) ClearedEdges

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

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

func (*ModelMutation) ClearedFields

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

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

func (ModelMutation) Client

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

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

EdgeCleared returns a boolean indicates if this edge was cleared in this mutation.

func (*ModelMutation) Field

func (m *ModelMutation) Field(name string) (ent.Value, bool)

Field returns the value of a field with the given name. The second boolean value indicates that this field was not set, or was not define in the schema.

func (*ModelMutation) FieldCleared

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

FieldCleared returns a boolean indicates if this field was cleared in this mutation.

func (*ModelMutation) Fields

func (m *ModelMutation) Fields() []string

Fields returns all fields that were changed during this mutation. Note that, in order to get all numeric fields that were in/decremented, call AddedFields().

func (*ModelMutation) ID

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

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

func (*ModelMutation) Name

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

Name returns the name value in the mutation.

func (*ModelMutation) Op

func (m *ModelMutation) Op() Op

Op returns the operation name.

func (*ModelMutation) RemovedEdges

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

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

func (*ModelMutation) RemovedIDs

func (m *ModelMutation) RemovedIDs(name string) []ent.Value

RemovedIDs returns all ids (to other nodes) that were removed for the given edge name.

func (*ModelMutation) ResetEdge

func (m *ModelMutation) ResetEdge(name string) error

ResetEdge resets all changes in the mutation regarding the given edge name. It returns an error if the edge is not defined in the schema.

func (*ModelMutation) ResetField

func (m *ModelMutation) ResetField(name string) error

ResetField resets all changes in the mutation regarding the given field name. It returns an error if the field is not defined in the schema.

func (*ModelMutation) ResetName

func (m *ModelMutation) ResetName()

ResetName reset all changes of the name field.

func (*ModelMutation) SetField

func (m *ModelMutation) SetField(name string, value ent.Value) error

SetField sets the value for the given name. It returns an error if the field is not defined in the schema, or if the type mismatch the field type.

func (*ModelMutation) SetName

func (m *ModelMutation) SetName(s string)

SetName sets the name field.

func (ModelMutation) Tx

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

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

func (*ModelMutation) Type

func (m *ModelMutation) Type() string

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

type ModelQuery

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

ModelQuery is the builder for querying Model entities.

func (*ModelQuery) All

func (mq *ModelQuery) All(ctx context.Context) ([]*Model, error)

All executes the query and returns a list of Models.

func (*ModelQuery) AllX

func (mq *ModelQuery) AllX(ctx context.Context) []*Model

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

func (*ModelQuery) Clone

func (mq *ModelQuery) Clone() *ModelQuery

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

func (*ModelQuery) Count

func (mq *ModelQuery) Count(ctx context.Context) (int, error)

Count returns the count of the given query.

func (*ModelQuery) CountX

func (mq *ModelQuery) CountX(ctx context.Context) int

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

func (*ModelQuery) Exist

func (mq *ModelQuery) Exist(ctx context.Context) (bool, error)

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

func (*ModelQuery) ExistX

func (mq *ModelQuery) ExistX(ctx context.Context) bool

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

func (*ModelQuery) First

func (mq *ModelQuery) First(ctx context.Context) (*Model, error)

First returns the first Model entity in the query. Returns *NotFoundError when no model was found.

func (*ModelQuery) FirstID

func (mq *ModelQuery) FirstID(ctx context.Context) (id int, err error)

FirstID returns the first Model id in the query. Returns *NotFoundError when no id was found.

func (*ModelQuery) FirstX

func (mq *ModelQuery) FirstX(ctx context.Context) *Model

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

func (*ModelQuery) FirstXID

func (mq *ModelQuery) FirstXID(ctx context.Context) int

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

func (*ModelQuery) GroupBy

func (mq *ModelQuery) GroupBy(field string, fields ...string) *ModelGroupBy

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

func (*ModelQuery) IDs

func (mq *ModelQuery) IDs(ctx context.Context) ([]int, error)

IDs executes the query and returns a list of Model ids.

func (*ModelQuery) IDsX

func (mq *ModelQuery) IDsX(ctx context.Context) []int

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

func (*ModelQuery) Limit

func (mq *ModelQuery) Limit(limit int) *ModelQuery

Limit adds a limit step to the query.

func (*ModelQuery) Offset

func (mq *ModelQuery) Offset(offset int) *ModelQuery

Offset adds an offset step to the query.

func (*ModelQuery) Only

func (mq *ModelQuery) Only(ctx context.Context) (*Model, error)

Only returns the only Model entity in the query, returns an error if not exactly one entity was returned.

func (*ModelQuery) OnlyID

func (mq *ModelQuery) OnlyID(ctx context.Context) (id int, err error)

OnlyID returns the only Model id in the query, returns an error if not exactly one id was returned.

func (*ModelQuery) OnlyX

func (mq *ModelQuery) OnlyX(ctx context.Context) *Model

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

func (*ModelQuery) OnlyXID

func (mq *ModelQuery) OnlyXID(ctx context.Context) int

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

func (*ModelQuery) Order

func (mq *ModelQuery) Order(o ...Order) *ModelQuery

Order adds an order step to the query.

func (*ModelQuery) Select

func (mq *ModelQuery) Select(field string, fields ...string) *ModelSelect

Select one or more fields from the given query.

Example:

var v []struct {
	Name string `json:"name,omitempty"`
}

client.Model.Query().
	Select(model.FieldName).
	Scan(ctx, &v)

func (*ModelQuery) Where

func (mq *ModelQuery) Where(ps ...predicate.Model) *ModelQuery

Where adds a new predicate for the builder.

type ModelSelect

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

ModelSelect is the builder for select fields of Model entities.

func (*ModelSelect) Bools

func (ms *ModelSelect) Bools(ctx context.Context) ([]bool, error)

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

func (*ModelSelect) BoolsX

func (ms *ModelSelect) BoolsX(ctx context.Context) []bool

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

func (*ModelSelect) Float64s

func (ms *ModelSelect) Float64s(ctx context.Context) ([]float64, error)

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

func (*ModelSelect) Float64sX

func (ms *ModelSelect) Float64sX(ctx context.Context) []float64

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

func (*ModelSelect) Ints

func (ms *ModelSelect) Ints(ctx context.Context) ([]int, error)

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

func (*ModelSelect) IntsX

func (ms *ModelSelect) IntsX(ctx context.Context) []int

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

func (*ModelSelect) Scan

func (ms *ModelSelect) Scan(ctx context.Context, v interface{}) error

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

func (*ModelSelect) ScanX

func (ms *ModelSelect) ScanX(ctx context.Context, v interface{})

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

func (*ModelSelect) Strings

func (ms *ModelSelect) Strings(ctx context.Context) ([]string, error)

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

func (*ModelSelect) StringsX

func (ms *ModelSelect) StringsX(ctx context.Context) []string

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

type ModelUpdate

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

ModelUpdate is the builder for updating Model entities.

func (*ModelUpdate) Exec

func (mu *ModelUpdate) Exec(ctx context.Context) error

Exec executes the query.

func (*ModelUpdate) ExecX

func (mu *ModelUpdate) ExecX(ctx context.Context)

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

func (*ModelUpdate) Save

func (mu *ModelUpdate) Save(ctx context.Context) (int, error)

Save executes the query and returns the number of rows/vertices matched by this operation.

func (*ModelUpdate) SaveX

func (mu *ModelUpdate) SaveX(ctx context.Context) int

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

func (*ModelUpdate) SetName

func (mu *ModelUpdate) SetName(s string) *ModelUpdate

SetName sets the name field.

func (*ModelUpdate) SetNillableName

func (mu *ModelUpdate) SetNillableName(s *string) *ModelUpdate

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

func (*ModelUpdate) Where

func (mu *ModelUpdate) Where(ps ...predicate.Model) *ModelUpdate

Where adds a new predicate for the builder.

type ModelUpdateOne

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

ModelUpdateOne is the builder for updating a single Model entity.

func (*ModelUpdateOne) Exec

func (muo *ModelUpdateOne) Exec(ctx context.Context) error

Exec executes the query on the entity.

func (*ModelUpdateOne) ExecX

func (muo *ModelUpdateOne) ExecX(ctx context.Context)

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

func (*ModelUpdateOne) Save

func (muo *ModelUpdateOne) Save(ctx context.Context) (*Model, error)

Save executes the query and returns the updated entity.

func (*ModelUpdateOne) SaveX

func (muo *ModelUpdateOne) SaveX(ctx context.Context) *Model

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

func (*ModelUpdateOne) SetName

func (muo *ModelUpdateOne) SetName(s string) *ModelUpdateOne

SetName sets the name field.

func (*ModelUpdateOne) SetNillableName

func (muo *ModelUpdateOne) SetNillableName(s *string) *ModelUpdateOne

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

type Models

type Models []*Model

Models is a parsable slice of Model.

type MutateFunc

type MutateFunc = ent.MutateFunc

ent aliases to avoid import conflict in user's code.

type Mutation

type Mutation = ent.Mutation

ent aliases to avoid import conflict in user's code.

type Mutator

type Mutator = ent.Mutator

ent aliases to avoid import conflict 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 conflict 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 Order

type Order func(*sql.Selector)

Order applies an ordering on either graph traversal or sql selector.

func Asc

func Asc(fields ...string) Order

Asc applies the given fields in ASC order.

func Desc

func Desc(fields ...string) Order

Desc applies the given fields in DESC order.

type Policy

type Policy = ent.Policy

ent aliases to avoid import conflict in user's code.

type Query

type Query = ent.Query

ent aliases to avoid import conflict in user's code.

type Tx

type Tx struct {

	// Manufacturer is the client for interacting with the Manufacturer builders.
	Manufacturer *ManufacturerClient
	// Model is the client for interacting with the Model builders.
	Model *ModelClient
	// 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 the Tx stored in 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 func(error))

OnCommit adds a function to call on commit.

func (*Tx) OnRollback

func (tx *Tx) OnRollback(f func(error))

OnRollback adds a function to call on rollback.

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Rollback rollbacks the transaction.

type Value

type Value = ent.Value

ent aliases to avoid import conflict 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