Documentation ¶
Index ¶
- func IsConstraintError(err error) bool
- func IsNotFound(err error) bool
- func IsNotLoaded(err error) bool
- func IsNotSingular(err error) bool
- func MaskNotFound(err error) error
- func NewContext(parent context.Context, c *Client) context.Context
- type Aggregate
- type Cities
- type City
- type CityClient
- func (c *CityClient) Create() *CityCreate
- func (c *CityClient) Delete() *CityDelete
- func (c *CityClient) DeleteOne(ci *City) *CityDeleteOne
- func (c *CityClient) DeleteOneID(id int) *CityDeleteOne
- func (c *CityClient) Get(ctx context.Context, id int) (*City, error)
- func (c *CityClient) GetX(ctx context.Context, id int) *City
- func (c *CityClient) Query() *CityQuery
- func (c *CityClient) QueryStreets(ci *City) *StreetQuery
- func (c *CityClient) Update() *CityUpdate
- func (c *CityClient) UpdateOne(ci *City) *CityUpdateOne
- func (c *CityClient) UpdateOneID(id int) *CityUpdateOne
- type CityCreate
- type CityDelete
- type CityDeleteOne
- type CityEdges
- type CityGroupBy
- func (cgb *CityGroupBy) Aggregate(fns ...Aggregate) *CityGroupBy
- func (cgb *CityGroupBy) Bools(ctx context.Context) ([]bool, error)
- func (cgb *CityGroupBy) BoolsX(ctx context.Context) []bool
- func (cgb *CityGroupBy) Float64s(ctx context.Context) ([]float64, error)
- func (cgb *CityGroupBy) Float64sX(ctx context.Context) []float64
- func (cgb *CityGroupBy) Ints(ctx context.Context) ([]int, error)
- func (cgb *CityGroupBy) IntsX(ctx context.Context) []int
- func (cgb *CityGroupBy) Scan(ctx context.Context, v interface{}) error
- func (cgb *CityGroupBy) ScanX(ctx context.Context, v interface{})
- func (cgb *CityGroupBy) Strings(ctx context.Context) ([]string, error)
- func (cgb *CityGroupBy) StringsX(ctx context.Context) []string
- type CityQuery
- func (cq *CityQuery) All(ctx context.Context) ([]*City, error)
- func (cq *CityQuery) AllX(ctx context.Context) []*City
- func (cq *CityQuery) Clone() *CityQuery
- func (cq *CityQuery) Count(ctx context.Context) (int, error)
- func (cq *CityQuery) CountX(ctx context.Context) int
- func (cq *CityQuery) Exist(ctx context.Context) (bool, error)
- func (cq *CityQuery) ExistX(ctx context.Context) bool
- func (cq *CityQuery) First(ctx context.Context) (*City, error)
- func (cq *CityQuery) FirstID(ctx context.Context) (id int, err error)
- func (cq *CityQuery) FirstX(ctx context.Context) *City
- func (cq *CityQuery) FirstXID(ctx context.Context) int
- func (cq *CityQuery) GroupBy(field string, fields ...string) *CityGroupBy
- func (cq *CityQuery) IDs(ctx context.Context) ([]int, error)
- func (cq *CityQuery) IDsX(ctx context.Context) []int
- func (cq *CityQuery) Limit(limit int) *CityQuery
- func (cq *CityQuery) Offset(offset int) *CityQuery
- func (cq *CityQuery) Only(ctx context.Context) (*City, error)
- func (cq *CityQuery) OnlyID(ctx context.Context) (id int, err error)
- func (cq *CityQuery) OnlyX(ctx context.Context) *City
- func (cq *CityQuery) OnlyXID(ctx context.Context) int
- func (cq *CityQuery) Order(o ...Order) *CityQuery
- func (cq *CityQuery) QueryStreets() *StreetQuery
- func (cq *CityQuery) Select(field string, fields ...string) *CitySelect
- func (cq *CityQuery) Where(ps ...predicate.City) *CityQuery
- func (cq *CityQuery) WithStreets(opts ...func(*StreetQuery)) *CityQuery
- type CitySelect
- func (cs *CitySelect) Bools(ctx context.Context) ([]bool, error)
- func (cs *CitySelect) BoolsX(ctx context.Context) []bool
- func (cs *CitySelect) Float64s(ctx context.Context) ([]float64, error)
- func (cs *CitySelect) Float64sX(ctx context.Context) []float64
- func (cs *CitySelect) Ints(ctx context.Context) ([]int, error)
- func (cs *CitySelect) IntsX(ctx context.Context) []int
- func (cs *CitySelect) Scan(ctx context.Context, v interface{}) error
- func (cs *CitySelect) ScanX(ctx context.Context, v interface{})
- func (cs *CitySelect) Strings(ctx context.Context) ([]string, error)
- func (cs *CitySelect) StringsX(ctx context.Context) []string
- type CityUpdate
- func (cu *CityUpdate) AddStreetIDs(ids ...int) *CityUpdate
- func (cu *CityUpdate) AddStreets(s ...*Street) *CityUpdate
- func (cu *CityUpdate) Exec(ctx context.Context) error
- func (cu *CityUpdate) ExecX(ctx context.Context)
- func (cu *CityUpdate) RemoveStreetIDs(ids ...int) *CityUpdate
- func (cu *CityUpdate) RemoveStreets(s ...*Street) *CityUpdate
- func (cu *CityUpdate) Save(ctx context.Context) (int, error)
- func (cu *CityUpdate) SaveX(ctx context.Context) int
- func (cu *CityUpdate) SetName(s string) *CityUpdate
- func (cu *CityUpdate) Where(ps ...predicate.City) *CityUpdate
- type CityUpdateOne
- func (cuo *CityUpdateOne) AddStreetIDs(ids ...int) *CityUpdateOne
- func (cuo *CityUpdateOne) AddStreets(s ...*Street) *CityUpdateOne
- func (cuo *CityUpdateOne) Exec(ctx context.Context) error
- func (cuo *CityUpdateOne) ExecX(ctx context.Context)
- func (cuo *CityUpdateOne) RemoveStreetIDs(ids ...int) *CityUpdateOne
- func (cuo *CityUpdateOne) RemoveStreets(s ...*Street) *CityUpdateOne
- func (cuo *CityUpdateOne) Save(ctx context.Context) (*City, error)
- func (cuo *CityUpdateOne) SaveX(ctx context.Context) *City
- func (cuo *CityUpdateOne) SetName(s string) *CityUpdateOne
- type Client
- type ConstraintError
- type NotFoundError
- type NotLoadedError
- type NotSingularError
- type Option
- type Order
- type Street
- type StreetClient
- func (c *StreetClient) Create() *StreetCreate
- func (c *StreetClient) Delete() *StreetDelete
- func (c *StreetClient) DeleteOne(s *Street) *StreetDeleteOne
- func (c *StreetClient) DeleteOneID(id int) *StreetDeleteOne
- func (c *StreetClient) Get(ctx context.Context, id int) (*Street, error)
- func (c *StreetClient) GetX(ctx context.Context, id int) *Street
- func (c *StreetClient) Query() *StreetQuery
- func (c *StreetClient) QueryCity(s *Street) *CityQuery
- func (c *StreetClient) Update() *StreetUpdate
- func (c *StreetClient) UpdateOne(s *Street) *StreetUpdateOne
- func (c *StreetClient) UpdateOneID(id int) *StreetUpdateOne
- type StreetCreate
- func (sc *StreetCreate) Save(ctx context.Context) (*Street, error)
- func (sc *StreetCreate) SaveX(ctx context.Context) *Street
- func (sc *StreetCreate) SetCity(c *City) *StreetCreate
- func (sc *StreetCreate) SetCityID(id int) *StreetCreate
- func (sc *StreetCreate) SetName(s string) *StreetCreate
- func (sc *StreetCreate) SetNillableCityID(id *int) *StreetCreate
- type StreetDelete
- type StreetDeleteOne
- type StreetEdges
- type StreetGroupBy
- func (sgb *StreetGroupBy) Aggregate(fns ...Aggregate) *StreetGroupBy
- func (sgb *StreetGroupBy) Bools(ctx context.Context) ([]bool, error)
- func (sgb *StreetGroupBy) BoolsX(ctx context.Context) []bool
- func (sgb *StreetGroupBy) Float64s(ctx context.Context) ([]float64, error)
- func (sgb *StreetGroupBy) Float64sX(ctx context.Context) []float64
- func (sgb *StreetGroupBy) Ints(ctx context.Context) ([]int, error)
- func (sgb *StreetGroupBy) IntsX(ctx context.Context) []int
- func (sgb *StreetGroupBy) Scan(ctx context.Context, v interface{}) error
- func (sgb *StreetGroupBy) ScanX(ctx context.Context, v interface{})
- func (sgb *StreetGroupBy) Strings(ctx context.Context) ([]string, error)
- func (sgb *StreetGroupBy) StringsX(ctx context.Context) []string
- type StreetQuery
- func (sq *StreetQuery) All(ctx context.Context) ([]*Street, error)
- func (sq *StreetQuery) AllX(ctx context.Context) []*Street
- func (sq *StreetQuery) Clone() *StreetQuery
- func (sq *StreetQuery) Count(ctx context.Context) (int, error)
- func (sq *StreetQuery) CountX(ctx context.Context) int
- func (sq *StreetQuery) Exist(ctx context.Context) (bool, error)
- func (sq *StreetQuery) ExistX(ctx context.Context) bool
- func (sq *StreetQuery) First(ctx context.Context) (*Street, error)
- func (sq *StreetQuery) FirstID(ctx context.Context) (id int, err error)
- func (sq *StreetQuery) FirstX(ctx context.Context) *Street
- func (sq *StreetQuery) FirstXID(ctx context.Context) int
- func (sq *StreetQuery) GroupBy(field string, fields ...string) *StreetGroupBy
- func (sq *StreetQuery) IDs(ctx context.Context) ([]int, error)
- func (sq *StreetQuery) IDsX(ctx context.Context) []int
- func (sq *StreetQuery) Limit(limit int) *StreetQuery
- func (sq *StreetQuery) Offset(offset int) *StreetQuery
- func (sq *StreetQuery) Only(ctx context.Context) (*Street, error)
- func (sq *StreetQuery) OnlyID(ctx context.Context) (id int, err error)
- func (sq *StreetQuery) OnlyX(ctx context.Context) *Street
- func (sq *StreetQuery) OnlyXID(ctx context.Context) int
- func (sq *StreetQuery) Order(o ...Order) *StreetQuery
- func (sq *StreetQuery) QueryCity() *CityQuery
- func (sq *StreetQuery) Select(field string, fields ...string) *StreetSelect
- func (sq *StreetQuery) Where(ps ...predicate.Street) *StreetQuery
- func (sq *StreetQuery) WithCity(opts ...func(*CityQuery)) *StreetQuery
- type StreetSelect
- func (ss *StreetSelect) Bools(ctx context.Context) ([]bool, error)
- func (ss *StreetSelect) BoolsX(ctx context.Context) []bool
- func (ss *StreetSelect) Float64s(ctx context.Context) ([]float64, error)
- func (ss *StreetSelect) Float64sX(ctx context.Context) []float64
- func (ss *StreetSelect) Ints(ctx context.Context) ([]int, error)
- func (ss *StreetSelect) IntsX(ctx context.Context) []int
- func (ss *StreetSelect) Scan(ctx context.Context, v interface{}) error
- func (ss *StreetSelect) ScanX(ctx context.Context, v interface{})
- func (ss *StreetSelect) Strings(ctx context.Context) ([]string, error)
- func (ss *StreetSelect) StringsX(ctx context.Context) []string
- type StreetUpdate
- func (su *StreetUpdate) ClearCity() *StreetUpdate
- func (su *StreetUpdate) Exec(ctx context.Context) error
- func (su *StreetUpdate) ExecX(ctx context.Context)
- func (su *StreetUpdate) Save(ctx context.Context) (int, error)
- func (su *StreetUpdate) SaveX(ctx context.Context) int
- func (su *StreetUpdate) SetCity(c *City) *StreetUpdate
- func (su *StreetUpdate) SetCityID(id int) *StreetUpdate
- func (su *StreetUpdate) SetName(s string) *StreetUpdate
- func (su *StreetUpdate) SetNillableCityID(id *int) *StreetUpdate
- func (su *StreetUpdate) Where(ps ...predicate.Street) *StreetUpdate
- type StreetUpdateOne
- func (suo *StreetUpdateOne) ClearCity() *StreetUpdateOne
- func (suo *StreetUpdateOne) Exec(ctx context.Context) error
- func (suo *StreetUpdateOne) ExecX(ctx context.Context)
- func (suo *StreetUpdateOne) Save(ctx context.Context) (*Street, error)
- func (suo *StreetUpdateOne) SaveX(ctx context.Context) *Street
- func (suo *StreetUpdateOne) SetCity(c *City) *StreetUpdateOne
- func (suo *StreetUpdateOne) SetCityID(id int) *StreetUpdateOne
- func (suo *StreetUpdateOne) SetName(s string) *StreetUpdateOne
- func (suo *StreetUpdateOne) SetNillableCityID(id *int) *StreetUpdateOne
- type Streets
- type Tx
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsConstraintError ¶
IsConstraintError returns a boolean indicating whether the error is a constraint failure.
func IsNotFound ¶
IsNotFound returns a boolean indicating whether the error is a not found error.
func IsNotLoaded ¶
IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
func IsNotSingular ¶
IsNotSingular returns a boolean indicating whether the error is a not singular error.
Types ¶
type Aggregate ¶
Aggregate 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)
type City ¶
type City struct { // ID of the ent. ID int `json:"id,omitempty"` // Name holds the value of the "name" field. Name string `json:"name,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the CityQuery when eager-loading is set. Edges CityEdges `json:"edges"` // contains filtered or unexported fields }
City is the model entity for the City schema.
Example ¶
if dsn == "" { return } ctx := context.Background() drv, err := sql.Open("mysql", dsn) if err != nil { log.Fatalf("failed creating database client: %v", err) } defer drv.Close() client := NewClient(Driver(drv)) // creating vertices for the city's edges. s0 := client.Street. Create(). SetName("string"). SaveX(ctx) log.Println("street created:", s0) // create city vertex with its edges. c := client.City. Create(). SetName("string"). AddStreets(s0). SaveX(ctx) log.Println("city created:", c) // query edges. s0, err = c.QueryStreets().First(ctx) if err != nil { log.Fatalf("failed querying streets: %v", err) } log.Println("streets found:", s0)
Output:
func (*City) QueryStreets ¶
func (c *City) QueryStreets() *StreetQuery
QueryStreets queries the streets edge of the City.
func (*City) Unwrap ¶
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 (*City) Update ¶
func (c *City) Update() *CityUpdateOne
Update returns a builder for updating this City. Note that, you need to call City.Unwrap() before calling this method, if this City was returned from a transaction, and the transaction was committed or rolled back.
type CityClient ¶
type CityClient struct {
// contains filtered or unexported fields
}
CityClient is a client for the City schema.
func NewCityClient ¶
func NewCityClient(c config) *CityClient
NewCityClient returns a client for the City from the given config.
func (*CityClient) Create ¶
func (c *CityClient) Create() *CityCreate
Create returns a create builder for City.
func (*CityClient) Delete ¶
func (c *CityClient) Delete() *CityDelete
Delete returns a delete builder for City.
func (*CityClient) DeleteOne ¶
func (c *CityClient) DeleteOne(ci *City) *CityDeleteOne
DeleteOne returns a delete builder for the given entity.
func (*CityClient) DeleteOneID ¶
func (c *CityClient) DeleteOneID(id int) *CityDeleteOne
DeleteOneID returns a delete builder for the given id.
func (*CityClient) GetX ¶
func (c *CityClient) GetX(ctx context.Context, id int) *City
GetX is like Get, but panics if an error occurs.
func (*CityClient) Query ¶
func (c *CityClient) Query() *CityQuery
Create returns a query builder for City.
func (*CityClient) QueryStreets ¶
func (c *CityClient) QueryStreets(ci *City) *StreetQuery
QueryStreets queries the streets edge of a City.
func (*CityClient) Update ¶
func (c *CityClient) Update() *CityUpdate
Update returns an update builder for City.
func (*CityClient) UpdateOne ¶
func (c *CityClient) UpdateOne(ci *City) *CityUpdateOne
UpdateOne returns an update builder for the given entity.
func (*CityClient) UpdateOneID ¶
func (c *CityClient) UpdateOneID(id int) *CityUpdateOne
UpdateOneID returns an update builder for the given id.
type CityCreate ¶
type CityCreate struct {
// contains filtered or unexported fields
}
CityCreate is the builder for creating a City entity.
func (*CityCreate) AddStreetIDs ¶
func (cc *CityCreate) AddStreetIDs(ids ...int) *CityCreate
AddStreetIDs adds the streets edge to Street by ids.
func (*CityCreate) AddStreets ¶
func (cc *CityCreate) AddStreets(s ...*Street) *CityCreate
AddStreets adds the streets edges to Street.
func (*CityCreate) Save ¶
func (cc *CityCreate) Save(ctx context.Context) (*City, error)
Save creates the City in the database.
func (*CityCreate) SaveX ¶
func (cc *CityCreate) SaveX(ctx context.Context) *City
SaveX calls Save and panics if Save returns an error.
func (*CityCreate) SetName ¶
func (cc *CityCreate) SetName(s string) *CityCreate
SetName sets the name field.
type CityDelete ¶
type CityDelete struct {
// contains filtered or unexported fields
}
CityDelete is the builder for deleting a City entity.
func (*CityDelete) Exec ¶
func (cd *CityDelete) Exec(ctx context.Context) (int, error)
Exec executes the deletion query and returns how many vertices were deleted.
func (*CityDelete) ExecX ¶
func (cd *CityDelete) ExecX(ctx context.Context) int
ExecX is like Exec, but panics if an error occurs.
func (*CityDelete) Where ¶
func (cd *CityDelete) Where(ps ...predicate.City) *CityDelete
Where adds a new predicate to the delete builder.
type CityDeleteOne ¶
type CityDeleteOne struct {
// contains filtered or unexported fields
}
CityDeleteOne is the builder for deleting a single City entity.
func (*CityDeleteOne) Exec ¶
func (cdo *CityDeleteOne) Exec(ctx context.Context) error
Exec executes the deletion query.
func (*CityDeleteOne) ExecX ¶
func (cdo *CityDeleteOne) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
type CityEdges ¶
type CityEdges struct { // Streets holds the value of the streets edge. Streets []*Street // contains filtered or unexported fields }
CityEdges holds the relations/edges for other nodes in the graph.
func (CityEdges) StreetsOrErr ¶
StreetsOrErr returns the Streets value or an error if the edge was not loaded in eager-loading.
type CityGroupBy ¶
type CityGroupBy struct {
// contains filtered or unexported fields
}
CityGroupBy is the builder for group-by City entities.
func (*CityGroupBy) Aggregate ¶
func (cgb *CityGroupBy) Aggregate(fns ...Aggregate) *CityGroupBy
Aggregate adds the given aggregation functions to the group-by query.
func (*CityGroupBy) Bools ¶
func (cgb *CityGroupBy) 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 (*CityGroupBy) BoolsX ¶
func (cgb *CityGroupBy) BoolsX(ctx context.Context) []bool
BoolsX is like Bools, but panics if an error occurs.
func (*CityGroupBy) Float64s ¶
func (cgb *CityGroupBy) 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 (*CityGroupBy) Float64sX ¶
func (cgb *CityGroupBy) Float64sX(ctx context.Context) []float64
Float64sX is like Float64s, but panics if an error occurs.
func (*CityGroupBy) Ints ¶
func (cgb *CityGroupBy) 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 (*CityGroupBy) IntsX ¶
func (cgb *CityGroupBy) IntsX(ctx context.Context) []int
IntsX is like Ints, but panics if an error occurs.
func (*CityGroupBy) Scan ¶
func (cgb *CityGroupBy) Scan(ctx context.Context, v interface{}) error
Scan applies the group-by query and scan the result into the given value.
func (*CityGroupBy) ScanX ¶
func (cgb *CityGroupBy) ScanX(ctx context.Context, v interface{})
ScanX is like Scan, but panics if an error occurs.
type CityQuery ¶
type CityQuery struct {
// contains filtered or unexported fields
}
CityQuery is the builder for querying City entities.
func (*CityQuery) Clone ¶
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 (*CityQuery) First ¶
First returns the first City entity in the query. Returns *NotFoundError when no city was found.
func (*CityQuery) FirstID ¶
FirstID returns the first City id in the query. Returns *NotFoundError when no id was found.
func (*CityQuery) GroupBy ¶
func (cq *CityQuery) GroupBy(field string, fields ...string) *CityGroupBy
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.City.Query(). GroupBy(city.FieldName). Aggregate(ent.Count()). Scan(ctx, &v)
func (*CityQuery) Only ¶
Only returns the only City entity in the query, returns an error if not exactly one entity was returned.
func (*CityQuery) OnlyID ¶
OnlyID returns the only City id in the query, returns an error if not exactly one id was returned.
func (*CityQuery) QueryStreets ¶
func (cq *CityQuery) QueryStreets() *StreetQuery
QueryStreets chains the current query on the streets edge.
func (*CityQuery) Select ¶
func (cq *CityQuery) Select(field string, fields ...string) *CitySelect
Select one or more fields from the given query.
Example:
var v []struct { Name string `json:"name,omitempty"` } client.City.Query(). Select(city.FieldName). Scan(ctx, &v)
func (*CityQuery) WithStreets ¶
func (cq *CityQuery) WithStreets(opts ...func(*StreetQuery)) *CityQuery
WithStreets tells the query-builder to eager-loads the nodes that are connected to
the "streets" edge. The optional arguments used to configure the query builder of the edge.
type CitySelect ¶
type CitySelect struct {
// contains filtered or unexported fields
}
CitySelect is the builder for select fields of City entities.
func (*CitySelect) Bools ¶
func (cs *CitySelect) Bools(ctx context.Context) ([]bool, error)
Bools returns list of bools from selector. It is only allowed when selecting one field.
func (*CitySelect) BoolsX ¶
func (cs *CitySelect) BoolsX(ctx context.Context) []bool
BoolsX is like Bools, but panics if an error occurs.
func (*CitySelect) Float64s ¶
func (cs *CitySelect) Float64s(ctx context.Context) ([]float64, error)
Float64s returns list of float64s from selector. It is only allowed when selecting one field.
func (*CitySelect) Float64sX ¶
func (cs *CitySelect) Float64sX(ctx context.Context) []float64
Float64sX is like Float64s, but panics if an error occurs.
func (*CitySelect) Ints ¶
func (cs *CitySelect) Ints(ctx context.Context) ([]int, error)
Ints returns list of ints from selector. It is only allowed when selecting one field.
func (*CitySelect) IntsX ¶
func (cs *CitySelect) IntsX(ctx context.Context) []int
IntsX is like Ints, but panics if an error occurs.
func (*CitySelect) Scan ¶
func (cs *CitySelect) Scan(ctx context.Context, v interface{}) error
Scan applies the selector query and scan the result into the given value.
func (*CitySelect) ScanX ¶
func (cs *CitySelect) ScanX(ctx context.Context, v interface{})
ScanX is like Scan, but panics if an error occurs.
type CityUpdate ¶
type CityUpdate struct {
// contains filtered or unexported fields
}
CityUpdate is the builder for updating City entities.
func (*CityUpdate) AddStreetIDs ¶
func (cu *CityUpdate) AddStreetIDs(ids ...int) *CityUpdate
AddStreetIDs adds the streets edge to Street by ids.
func (*CityUpdate) AddStreets ¶
func (cu *CityUpdate) AddStreets(s ...*Street) *CityUpdate
AddStreets adds the streets edges to Street.
func (*CityUpdate) Exec ¶
func (cu *CityUpdate) Exec(ctx context.Context) error
Exec executes the query.
func (*CityUpdate) ExecX ¶
func (cu *CityUpdate) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
func (*CityUpdate) RemoveStreetIDs ¶
func (cu *CityUpdate) RemoveStreetIDs(ids ...int) *CityUpdate
RemoveStreetIDs removes the streets edge to Street by ids.
func (*CityUpdate) RemoveStreets ¶
func (cu *CityUpdate) RemoveStreets(s ...*Street) *CityUpdate
RemoveStreets removes streets edges to Street.
func (*CityUpdate) Save ¶
func (cu *CityUpdate) Save(ctx context.Context) (int, error)
Save executes the query and returns the number of rows/vertices matched by this operation.
func (*CityUpdate) SaveX ¶
func (cu *CityUpdate) SaveX(ctx context.Context) int
SaveX is like Save, but panics if an error occurs.
func (*CityUpdate) SetName ¶
func (cu *CityUpdate) SetName(s string) *CityUpdate
SetName sets the name field.
func (*CityUpdate) Where ¶
func (cu *CityUpdate) Where(ps ...predicate.City) *CityUpdate
Where adds a new predicate for the builder.
type CityUpdateOne ¶
type CityUpdateOne struct {
// contains filtered or unexported fields
}
CityUpdateOne is the builder for updating a single City entity.
func (*CityUpdateOne) AddStreetIDs ¶
func (cuo *CityUpdateOne) AddStreetIDs(ids ...int) *CityUpdateOne
AddStreetIDs adds the streets edge to Street by ids.
func (*CityUpdateOne) AddStreets ¶
func (cuo *CityUpdateOne) AddStreets(s ...*Street) *CityUpdateOne
AddStreets adds the streets edges to Street.
func (*CityUpdateOne) Exec ¶
func (cuo *CityUpdateOne) Exec(ctx context.Context) error
Exec executes the query on the entity.
func (*CityUpdateOne) ExecX ¶
func (cuo *CityUpdateOne) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
func (*CityUpdateOne) RemoveStreetIDs ¶
func (cuo *CityUpdateOne) RemoveStreetIDs(ids ...int) *CityUpdateOne
RemoveStreetIDs removes the streets edge to Street by ids.
func (*CityUpdateOne) RemoveStreets ¶
func (cuo *CityUpdateOne) RemoveStreets(s ...*Street) *CityUpdateOne
RemoveStreets removes streets edges to Street.
func (*CityUpdateOne) Save ¶
func (cuo *CityUpdateOne) Save(ctx context.Context) (*City, error)
Save executes the query and returns the updated entity.
func (*CityUpdateOne) SaveX ¶
func (cuo *CityUpdateOne) SaveX(ctx context.Context) *City
SaveX is like Save, but panics if an error occurs.
func (*CityUpdateOne) SetName ¶
func (cuo *CityUpdateOne) SetName(s string) *CityUpdateOne
SetName sets the name field.
type Client ¶
type Client struct { // Schema is the client for creating, migrating and dropping schema. Schema *migrate.Schema // City is the client for interacting with the City builders. City *CityClient // Street is the client for interacting with the Street builders. Street *StreetClient // contains filtered or unexported fields }
Client is the client that holds all ent builders.
func FromContext ¶
FromContext returns the Client stored in a context, or nil if there isn't one.
func Open ¶
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.
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 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 Street ¶
type Street struct { // ID of the ent. ID int `json:"id,omitempty"` // Name holds the value of the "name" field. Name string `json:"name,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the StreetQuery when eager-loading is set. Edges StreetEdges `json:"edges"` // contains filtered or unexported fields }
Street is the model entity for the Street schema.
Example ¶
if dsn == "" { return } ctx := context.Background() drv, err := sql.Open("mysql", dsn) if err != nil { log.Fatalf("failed creating database client: %v", err) } defer drv.Close() client := NewClient(Driver(drv)) // creating vertices for the street's edges. // create street vertex with its edges. s := client.Street. Create(). SetName("string"). SaveX(ctx) log.Println("street created:", s) // query edges.
Output:
func (*Street) Unwrap ¶
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 (*Street) Update ¶
func (s *Street) Update() *StreetUpdateOne
Update returns a builder for updating this Street. Note that, you need to call Street.Unwrap() before calling this method, if this Street was returned from a transaction, and the transaction was committed or rolled back.
type StreetClient ¶
type StreetClient struct {
// contains filtered or unexported fields
}
StreetClient is a client for the Street schema.
func NewStreetClient ¶
func NewStreetClient(c config) *StreetClient
NewStreetClient returns a client for the Street from the given config.
func (*StreetClient) Create ¶
func (c *StreetClient) Create() *StreetCreate
Create returns a create builder for Street.
func (*StreetClient) Delete ¶
func (c *StreetClient) Delete() *StreetDelete
Delete returns a delete builder for Street.
func (*StreetClient) DeleteOne ¶
func (c *StreetClient) DeleteOne(s *Street) *StreetDeleteOne
DeleteOne returns a delete builder for the given entity.
func (*StreetClient) DeleteOneID ¶
func (c *StreetClient) DeleteOneID(id int) *StreetDeleteOne
DeleteOneID returns a delete builder for the given id.
func (*StreetClient) GetX ¶
func (c *StreetClient) GetX(ctx context.Context, id int) *Street
GetX is like Get, but panics if an error occurs.
func (*StreetClient) Query ¶
func (c *StreetClient) Query() *StreetQuery
Create returns a query builder for Street.
func (*StreetClient) QueryCity ¶
func (c *StreetClient) QueryCity(s *Street) *CityQuery
QueryCity queries the city edge of a Street.
func (*StreetClient) Update ¶
func (c *StreetClient) Update() *StreetUpdate
Update returns an update builder for Street.
func (*StreetClient) UpdateOne ¶
func (c *StreetClient) UpdateOne(s *Street) *StreetUpdateOne
UpdateOne returns an update builder for the given entity.
func (*StreetClient) UpdateOneID ¶
func (c *StreetClient) UpdateOneID(id int) *StreetUpdateOne
UpdateOneID returns an update builder for the given id.
type StreetCreate ¶
type StreetCreate struct {
// contains filtered or unexported fields
}
StreetCreate is the builder for creating a Street entity.
func (*StreetCreate) Save ¶
func (sc *StreetCreate) Save(ctx context.Context) (*Street, error)
Save creates the Street in the database.
func (*StreetCreate) SaveX ¶
func (sc *StreetCreate) SaveX(ctx context.Context) *Street
SaveX calls Save and panics if Save returns an error.
func (*StreetCreate) SetCity ¶
func (sc *StreetCreate) SetCity(c *City) *StreetCreate
SetCity sets the city edge to City.
func (*StreetCreate) SetCityID ¶
func (sc *StreetCreate) SetCityID(id int) *StreetCreate
SetCityID sets the city edge to City by id.
func (*StreetCreate) SetName ¶
func (sc *StreetCreate) SetName(s string) *StreetCreate
SetName sets the name field.
func (*StreetCreate) SetNillableCityID ¶
func (sc *StreetCreate) SetNillableCityID(id *int) *StreetCreate
SetNillableCityID sets the city edge to City by id if the given value is not nil.
type StreetDelete ¶
type StreetDelete struct {
// contains filtered or unexported fields
}
StreetDelete is the builder for deleting a Street entity.
func (*StreetDelete) Exec ¶
func (sd *StreetDelete) Exec(ctx context.Context) (int, error)
Exec executes the deletion query and returns how many vertices were deleted.
func (*StreetDelete) ExecX ¶
func (sd *StreetDelete) ExecX(ctx context.Context) int
ExecX is like Exec, but panics if an error occurs.
func (*StreetDelete) Where ¶
func (sd *StreetDelete) Where(ps ...predicate.Street) *StreetDelete
Where adds a new predicate to the delete builder.
type StreetDeleteOne ¶
type StreetDeleteOne struct {
// contains filtered or unexported fields
}
StreetDeleteOne is the builder for deleting a single Street entity.
func (*StreetDeleteOne) Exec ¶
func (sdo *StreetDeleteOne) Exec(ctx context.Context) error
Exec executes the deletion query.
func (*StreetDeleteOne) ExecX ¶
func (sdo *StreetDeleteOne) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
type StreetEdges ¶
type StreetEdges struct { // City holds the value of the city edge. City *City // contains filtered or unexported fields }
StreetEdges holds the relations/edges for other nodes in the graph.
func (StreetEdges) CityOrErr ¶
func (e StreetEdges) CityOrErr() (*City, error)
CityOrErr returns the City value or an error if the edge was not loaded in eager-loading, or loaded but was not found.
type StreetGroupBy ¶
type StreetGroupBy struct {
// contains filtered or unexported fields
}
StreetGroupBy is the builder for group-by Street entities.
func (*StreetGroupBy) Aggregate ¶
func (sgb *StreetGroupBy) Aggregate(fns ...Aggregate) *StreetGroupBy
Aggregate adds the given aggregation functions to the group-by query.
func (*StreetGroupBy) Bools ¶
func (sgb *StreetGroupBy) 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 (*StreetGroupBy) BoolsX ¶
func (sgb *StreetGroupBy) BoolsX(ctx context.Context) []bool
BoolsX is like Bools, but panics if an error occurs.
func (*StreetGroupBy) Float64s ¶
func (sgb *StreetGroupBy) 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 (*StreetGroupBy) Float64sX ¶
func (sgb *StreetGroupBy) Float64sX(ctx context.Context) []float64
Float64sX is like Float64s, but panics if an error occurs.
func (*StreetGroupBy) Ints ¶
func (sgb *StreetGroupBy) 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 (*StreetGroupBy) IntsX ¶
func (sgb *StreetGroupBy) IntsX(ctx context.Context) []int
IntsX is like Ints, but panics if an error occurs.
func (*StreetGroupBy) Scan ¶
func (sgb *StreetGroupBy) Scan(ctx context.Context, v interface{}) error
Scan applies the group-by query and scan the result into the given value.
func (*StreetGroupBy) ScanX ¶
func (sgb *StreetGroupBy) ScanX(ctx context.Context, v interface{})
ScanX is like Scan, but panics if an error occurs.
type StreetQuery ¶
type StreetQuery struct {
// contains filtered or unexported fields
}
StreetQuery is the builder for querying Street entities.
func (*StreetQuery) All ¶
func (sq *StreetQuery) All(ctx context.Context) ([]*Street, error)
All executes the query and returns a list of Streets.
func (*StreetQuery) AllX ¶
func (sq *StreetQuery) AllX(ctx context.Context) []*Street
AllX is like All, but panics if an error occurs.
func (*StreetQuery) Clone ¶
func (sq *StreetQuery) Clone() *StreetQuery
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 (*StreetQuery) Count ¶
func (sq *StreetQuery) Count(ctx context.Context) (int, error)
Count returns the count of the given query.
func (*StreetQuery) CountX ¶
func (sq *StreetQuery) CountX(ctx context.Context) int
CountX is like Count, but panics if an error occurs.
func (*StreetQuery) Exist ¶
func (sq *StreetQuery) Exist(ctx context.Context) (bool, error)
Exist returns true if the query has elements in the graph.
func (*StreetQuery) ExistX ¶
func (sq *StreetQuery) ExistX(ctx context.Context) bool
ExistX is like Exist, but panics if an error occurs.
func (*StreetQuery) First ¶
func (sq *StreetQuery) First(ctx context.Context) (*Street, error)
First returns the first Street entity in the query. Returns *NotFoundError when no street was found.
func (*StreetQuery) FirstID ¶
func (sq *StreetQuery) FirstID(ctx context.Context) (id int, err error)
FirstID returns the first Street id in the query. Returns *NotFoundError when no id was found.
func (*StreetQuery) FirstX ¶
func (sq *StreetQuery) FirstX(ctx context.Context) *Street
FirstX is like First, but panics if an error occurs.
func (*StreetQuery) FirstXID ¶
func (sq *StreetQuery) FirstXID(ctx context.Context) int
FirstXID is like FirstID, but panics if an error occurs.
func (*StreetQuery) GroupBy ¶
func (sq *StreetQuery) GroupBy(field string, fields ...string) *StreetGroupBy
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.Street.Query(). GroupBy(street.FieldName). Aggregate(ent.Count()). Scan(ctx, &v)
func (*StreetQuery) IDs ¶
func (sq *StreetQuery) IDs(ctx context.Context) ([]int, error)
IDs executes the query and returns a list of Street ids.
func (*StreetQuery) IDsX ¶
func (sq *StreetQuery) IDsX(ctx context.Context) []int
IDsX is like IDs, but panics if an error occurs.
func (*StreetQuery) Limit ¶
func (sq *StreetQuery) Limit(limit int) *StreetQuery
Limit adds a limit step to the query.
func (*StreetQuery) Offset ¶
func (sq *StreetQuery) Offset(offset int) *StreetQuery
Offset adds an offset step to the query.
func (*StreetQuery) Only ¶
func (sq *StreetQuery) Only(ctx context.Context) (*Street, error)
Only returns the only Street entity in the query, returns an error if not exactly one entity was returned.
func (*StreetQuery) OnlyID ¶
func (sq *StreetQuery) OnlyID(ctx context.Context) (id int, err error)
OnlyID returns the only Street id in the query, returns an error if not exactly one id was returned.
func (*StreetQuery) OnlyX ¶
func (sq *StreetQuery) OnlyX(ctx context.Context) *Street
OnlyX is like Only, but panics if an error occurs.
func (*StreetQuery) OnlyXID ¶
func (sq *StreetQuery) OnlyXID(ctx context.Context) int
OnlyXID is like OnlyID, but panics if an error occurs.
func (*StreetQuery) Order ¶
func (sq *StreetQuery) Order(o ...Order) *StreetQuery
Order adds an order step to the query.
func (*StreetQuery) QueryCity ¶
func (sq *StreetQuery) QueryCity() *CityQuery
QueryCity chains the current query on the city edge.
func (*StreetQuery) Select ¶
func (sq *StreetQuery) Select(field string, fields ...string) *StreetSelect
Select one or more fields from the given query.
Example:
var v []struct { Name string `json:"name,omitempty"` } client.Street.Query(). Select(street.FieldName). Scan(ctx, &v)
func (*StreetQuery) Where ¶
func (sq *StreetQuery) Where(ps ...predicate.Street) *StreetQuery
Where adds a new predicate for the builder.
func (*StreetQuery) WithCity ¶
func (sq *StreetQuery) WithCity(opts ...func(*CityQuery)) *StreetQuery
WithCity tells the query-builder to eager-loads the nodes that are connected to
the "city" edge. The optional arguments used to configure the query builder of the edge.
type StreetSelect ¶
type StreetSelect struct {
// contains filtered or unexported fields
}
StreetSelect is the builder for select fields of Street entities.
func (*StreetSelect) Bools ¶
func (ss *StreetSelect) Bools(ctx context.Context) ([]bool, error)
Bools returns list of bools from selector. It is only allowed when selecting one field.
func (*StreetSelect) BoolsX ¶
func (ss *StreetSelect) BoolsX(ctx context.Context) []bool
BoolsX is like Bools, but panics if an error occurs.
func (*StreetSelect) Float64s ¶
func (ss *StreetSelect) Float64s(ctx context.Context) ([]float64, error)
Float64s returns list of float64s from selector. It is only allowed when selecting one field.
func (*StreetSelect) Float64sX ¶
func (ss *StreetSelect) Float64sX(ctx context.Context) []float64
Float64sX is like Float64s, but panics if an error occurs.
func (*StreetSelect) Ints ¶
func (ss *StreetSelect) Ints(ctx context.Context) ([]int, error)
Ints returns list of ints from selector. It is only allowed when selecting one field.
func (*StreetSelect) IntsX ¶
func (ss *StreetSelect) IntsX(ctx context.Context) []int
IntsX is like Ints, but panics if an error occurs.
func (*StreetSelect) Scan ¶
func (ss *StreetSelect) Scan(ctx context.Context, v interface{}) error
Scan applies the selector query and scan the result into the given value.
func (*StreetSelect) ScanX ¶
func (ss *StreetSelect) ScanX(ctx context.Context, v interface{})
ScanX is like Scan, but panics if an error occurs.
type StreetUpdate ¶
type StreetUpdate struct {
// contains filtered or unexported fields
}
StreetUpdate is the builder for updating Street entities.
func (*StreetUpdate) ClearCity ¶
func (su *StreetUpdate) ClearCity() *StreetUpdate
ClearCity clears the city edge to City.
func (*StreetUpdate) Exec ¶
func (su *StreetUpdate) Exec(ctx context.Context) error
Exec executes the query.
func (*StreetUpdate) ExecX ¶
func (su *StreetUpdate) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
func (*StreetUpdate) Save ¶
func (su *StreetUpdate) Save(ctx context.Context) (int, error)
Save executes the query and returns the number of rows/vertices matched by this operation.
func (*StreetUpdate) SaveX ¶
func (su *StreetUpdate) SaveX(ctx context.Context) int
SaveX is like Save, but panics if an error occurs.
func (*StreetUpdate) SetCity ¶
func (su *StreetUpdate) SetCity(c *City) *StreetUpdate
SetCity sets the city edge to City.
func (*StreetUpdate) SetCityID ¶
func (su *StreetUpdate) SetCityID(id int) *StreetUpdate
SetCityID sets the city edge to City by id.
func (*StreetUpdate) SetName ¶
func (su *StreetUpdate) SetName(s string) *StreetUpdate
SetName sets the name field.
func (*StreetUpdate) SetNillableCityID ¶
func (su *StreetUpdate) SetNillableCityID(id *int) *StreetUpdate
SetNillableCityID sets the city edge to City by id if the given value is not nil.
func (*StreetUpdate) Where ¶
func (su *StreetUpdate) Where(ps ...predicate.Street) *StreetUpdate
Where adds a new predicate for the builder.
type StreetUpdateOne ¶
type StreetUpdateOne struct {
// contains filtered or unexported fields
}
StreetUpdateOne is the builder for updating a single Street entity.
func (*StreetUpdateOne) ClearCity ¶
func (suo *StreetUpdateOne) ClearCity() *StreetUpdateOne
ClearCity clears the city edge to City.
func (*StreetUpdateOne) Exec ¶
func (suo *StreetUpdateOne) Exec(ctx context.Context) error
Exec executes the query on the entity.
func (*StreetUpdateOne) ExecX ¶
func (suo *StreetUpdateOne) ExecX(ctx context.Context)
ExecX is like Exec, but panics if an error occurs.
func (*StreetUpdateOne) Save ¶
func (suo *StreetUpdateOne) Save(ctx context.Context) (*Street, error)
Save executes the query and returns the updated entity.
func (*StreetUpdateOne) SaveX ¶
func (suo *StreetUpdateOne) SaveX(ctx context.Context) *Street
SaveX is like Save, but panics if an error occurs.
func (*StreetUpdateOne) SetCity ¶
func (suo *StreetUpdateOne) SetCity(c *City) *StreetUpdateOne
SetCity sets the city edge to City.
func (*StreetUpdateOne) SetCityID ¶
func (suo *StreetUpdateOne) SetCityID(id int) *StreetUpdateOne
SetCityID sets the city edge to City by id.
func (*StreetUpdateOne) SetName ¶
func (suo *StreetUpdateOne) SetName(s string) *StreetUpdateOne
SetName sets the name field.
func (*StreetUpdateOne) SetNillableCityID ¶
func (suo *StreetUpdateOne) SetNillableCityID(id *int) *StreetUpdateOne
SetNillableCityID sets the city edge to City by id if the given value is not nil.
type Tx ¶
type Tx struct { // City is the client for interacting with the City builders. City *CityClient // Street is the client for interacting with the Street builders. Street *StreetClient // contains filtered or unexported fields }
Tx is a transactional client that is created by calling Client.Tx().