mirror of
https://github.com/ent/ent.git
synced 2026-05-28 09:49:08 +03:00
entc/gen: change receivers to static one (#4355)
* entc/gen: change receivers to static one * entc/integration: codegen * examples: codegen * chore: fixed spacing
This commit is contained in:
@@ -64,7 +64,7 @@ func (*City) scanValues(columns []string) ([]any, error) {
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the City fields.
|
||||
func (c *City) assignValues(columns []string, values []any) error {
|
||||
func (_m *City) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
@@ -75,15 +75,15 @@ func (c *City) assignValues(columns []string, values []any) error {
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
c.ID = int(value.Int64)
|
||||
_m.ID = int(value.Int64)
|
||||
case city.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
c.Name = value.String
|
||||
_m.Name = value.String
|
||||
}
|
||||
default:
|
||||
c.selectValues.Set(columns[i], values[i])
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -91,40 +91,40 @@ func (c *City) assignValues(columns []string, values []any) error {
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the City.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (c *City) Value(name string) (ent.Value, error) {
|
||||
return c.selectValues.Get(name)
|
||||
func (_m *City) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryStreets queries the "streets" edge of the City entity.
|
||||
func (c *City) QueryStreets() *StreetQuery {
|
||||
return NewCityClient(c.config).QueryStreets(c)
|
||||
func (_m *City) QueryStreets() *StreetQuery {
|
||||
return NewCityClient(_m.config).QueryStreets(_m)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (c *City) Update() *CityUpdateOne {
|
||||
return NewCityClient(c.config).UpdateOne(c)
|
||||
func (_m *City) Update() *CityUpdateOne {
|
||||
return NewCityClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the City 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 (c *City) Unwrap() *City {
|
||||
_tx, ok := c.config.driver.(*txDriver)
|
||||
func (_m *City) Unwrap() *City {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: City is not a transactional entity")
|
||||
}
|
||||
c.config.driver = _tx.drv
|
||||
return c
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (c *City) String() string {
|
||||
func (_m *City) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("City(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", c.ID))
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(c.Name)
|
||||
builder.WriteString(_m.Name)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -25,39 +25,39 @@ type CityCreate struct {
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (cc *CityCreate) SetName(s string) *CityCreate {
|
||||
cc.mutation.SetName(s)
|
||||
return cc
|
||||
func (_c *CityCreate) SetName(s string) *CityCreate {
|
||||
_c.mutation.SetName(s)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddStreetIDs adds the "streets" edge to the Street entity by IDs.
|
||||
func (cc *CityCreate) AddStreetIDs(ids ...int) *CityCreate {
|
||||
cc.mutation.AddStreetIDs(ids...)
|
||||
return cc
|
||||
func (_c *CityCreate) AddStreetIDs(ids ...int) *CityCreate {
|
||||
_c.mutation.AddStreetIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddStreets adds the "streets" edges to the Street entity.
|
||||
func (cc *CityCreate) AddStreets(s ...*Street) *CityCreate {
|
||||
func (_c *CityCreate) AddStreets(s ...*Street) *CityCreate {
|
||||
ids := make([]int, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
}
|
||||
return cc.AddStreetIDs(ids...)
|
||||
return _c.AddStreetIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the CityMutation object of the builder.
|
||||
func (cc *CityCreate) Mutation() *CityMutation {
|
||||
return cc.mutation
|
||||
func (_c *CityCreate) Mutation() *CityMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the City in the database.
|
||||
func (cc *CityCreate) Save(ctx context.Context) (*City, error) {
|
||||
return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks)
|
||||
func (_c *CityCreate) Save(ctx context.Context) (*City, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (cc *CityCreate) SaveX(ctx context.Context) *City {
|
||||
v, err := cc.Save(ctx)
|
||||
func (_c *CityCreate) SaveX(ctx context.Context) *City {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -65,32 +65,32 @@ func (cc *CityCreate) SaveX(ctx context.Context) *City {
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (cc *CityCreate) Exec(ctx context.Context) error {
|
||||
_, err := cc.Save(ctx)
|
||||
func (_c *CityCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cc *CityCreate) ExecX(ctx context.Context) {
|
||||
if err := cc.Exec(ctx); err != nil {
|
||||
func (_c *CityCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (cc *CityCreate) check() error {
|
||||
if _, ok := cc.mutation.Name(); !ok {
|
||||
func (_c *CityCreate) check() error {
|
||||
if _, ok := _c.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "City.name"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cc *CityCreate) sqlSave(ctx context.Context) (*City, error) {
|
||||
if err := cc.check(); err != nil {
|
||||
func (_c *CityCreate) sqlSave(ctx context.Context) (*City, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := cc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, cc.driver, _spec); err != nil {
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
@@ -98,21 +98,21 @@ func (cc *CityCreate) sqlSave(ctx context.Context) (*City, error) {
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
cc.mutation.id = &_node.ID
|
||||
cc.mutation.done = true
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (cc *CityCreate) createSpec() (*City, *sqlgraph.CreateSpec) {
|
||||
func (_c *CityCreate) createSpec() (*City, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &City{config: cc.config}
|
||||
_node = &City{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(city.Table, sqlgraph.NewFieldSpec(city.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := cc.mutation.Name(); ok {
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(city.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if nodes := cc.mutation.StreetsIDs(); len(nodes) > 0 {
|
||||
if nodes := _c.mutation.StreetsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
@@ -139,16 +139,16 @@ type CityCreateBulk struct {
|
||||
}
|
||||
|
||||
// Save creates the City entities in the database.
|
||||
func (ccb *CityCreateBulk) Save(ctx context.Context) ([]*City, error) {
|
||||
if ccb.err != nil {
|
||||
return nil, ccb.err
|
||||
func (_c *CityCreateBulk) Save(ctx context.Context) ([]*City, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(ccb.builders))
|
||||
nodes := make([]*City, len(ccb.builders))
|
||||
mutators := make([]Mutator, len(ccb.builders))
|
||||
for i := range ccb.builders {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*City, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := ccb.builders[i]
|
||||
builder := _c.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*CityMutation)
|
||||
if !ok {
|
||||
@@ -161,11 +161,11 @@ func (ccb *CityCreateBulk) Save(ctx context.Context) ([]*City, error) {
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, ccb.builders[i+1].mutation)
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, ccb.driver, spec); err != nil {
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
@@ -189,7 +189,7 @@ func (ccb *CityCreateBulk) Save(ctx context.Context) ([]*City, error) {
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, ccb.builders[0].mutation); err != nil {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -197,8 +197,8 @@ func (ccb *CityCreateBulk) Save(ctx context.Context) ([]*City, error) {
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (ccb *CityCreateBulk) SaveX(ctx context.Context) []*City {
|
||||
v, err := ccb.Save(ctx)
|
||||
func (_c *CityCreateBulk) SaveX(ctx context.Context) []*City {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -206,14 +206,14 @@ func (ccb *CityCreateBulk) SaveX(ctx context.Context) []*City {
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (ccb *CityCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := ccb.Save(ctx)
|
||||
func (_c *CityCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (ccb *CityCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := ccb.Exec(ctx); err != nil {
|
||||
func (_c *CityCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,56 +24,56 @@ type CityDelete struct {
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CityDelete builder.
|
||||
func (cd *CityDelete) Where(ps ...predicate.City) *CityDelete {
|
||||
cd.mutation.Where(ps...)
|
||||
return cd
|
||||
func (_d *CityDelete) Where(ps ...predicate.City) *CityDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (cd *CityDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, cd.sqlExec, cd.mutation, cd.hooks)
|
||||
func (_d *CityDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cd *CityDelete) ExecX(ctx context.Context) int {
|
||||
n, err := cd.Exec(ctx)
|
||||
func (_d *CityDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (cd *CityDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
func (_d *CityDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(city.Table, sqlgraph.NewFieldSpec(city.FieldID, field.TypeInt))
|
||||
if ps := cd.mutation.predicates; len(ps) > 0 {
|
||||
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, cd.driver, _spec)
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
cd.mutation.done = true
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// CityDeleteOne is the builder for deleting a single City entity.
|
||||
type CityDeleteOne struct {
|
||||
cd *CityDelete
|
||||
_d *CityDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CityDelete builder.
|
||||
func (cdo *CityDeleteOne) Where(ps ...predicate.City) *CityDeleteOne {
|
||||
cdo.cd.mutation.Where(ps...)
|
||||
return cdo
|
||||
func (_d *CityDeleteOne) Where(ps ...predicate.City) *CityDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (cdo *CityDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := cdo.cd.Exec(ctx)
|
||||
func (_d *CityDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
@@ -85,8 +85,8 @@ func (cdo *CityDeleteOne) Exec(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cdo *CityDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := cdo.Exec(ctx); err != nil {
|
||||
func (_d *CityDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,44 +35,44 @@ type CityQuery struct {
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the CityQuery builder.
|
||||
func (cq *CityQuery) Where(ps ...predicate.City) *CityQuery {
|
||||
cq.predicates = append(cq.predicates, ps...)
|
||||
return cq
|
||||
func (_q *CityQuery) Where(ps ...predicate.City) *CityQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (cq *CityQuery) Limit(limit int) *CityQuery {
|
||||
cq.ctx.Limit = &limit
|
||||
return cq
|
||||
func (_q *CityQuery) Limit(limit int) *CityQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (cq *CityQuery) Offset(offset int) *CityQuery {
|
||||
cq.ctx.Offset = &offset
|
||||
return cq
|
||||
func (_q *CityQuery) Offset(offset int) *CityQuery {
|
||||
_q.ctx.Offset = &offset
|
||||
return _q
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (cq *CityQuery) Unique(unique bool) *CityQuery {
|
||||
cq.ctx.Unique = &unique
|
||||
return cq
|
||||
func (_q *CityQuery) Unique(unique bool) *CityQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (cq *CityQuery) Order(o ...city.OrderOption) *CityQuery {
|
||||
cq.order = append(cq.order, o...)
|
||||
return cq
|
||||
func (_q *CityQuery) Order(o ...city.OrderOption) *CityQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryStreets chains the current query on the "streets" edge.
|
||||
func (cq *CityQuery) QueryStreets() *StreetQuery {
|
||||
query := (&StreetClient{config: cq.config}).Query()
|
||||
func (_q *CityQuery) QueryStreets() *StreetQuery {
|
||||
query := (&StreetClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := cq.sqlQuery(ctx)
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -81,7 +81,7 @@ func (cq *CityQuery) QueryStreets() *StreetQuery {
|
||||
sqlgraph.To(street.Table, street.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, city.StreetsTable, city.StreetsColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(cq.driver.Dialect(), step)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
@@ -89,8 +89,8 @@ func (cq *CityQuery) QueryStreets() *StreetQuery {
|
||||
|
||||
// First returns the first City entity from the query.
|
||||
// Returns a *NotFoundError when no City was found.
|
||||
func (cq *CityQuery) First(ctx context.Context) (*City, error) {
|
||||
nodes, err := cq.Limit(1).All(setContextOp(ctx, cq.ctx, ent.OpQueryFirst))
|
||||
func (_q *CityQuery) First(ctx context.Context) (*City, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -101,8 +101,8 @@ func (cq *CityQuery) First(ctx context.Context) (*City, error) {
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (cq *CityQuery) FirstX(ctx context.Context) *City {
|
||||
node, err := cq.First(ctx)
|
||||
func (_q *CityQuery) FirstX(ctx context.Context) *City {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
@@ -111,9 +111,9 @@ func (cq *CityQuery) FirstX(ctx context.Context) *City {
|
||||
|
||||
// FirstID returns the first City ID from the query.
|
||||
// Returns a *NotFoundError when no City ID was found.
|
||||
func (cq *CityQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
func (_q *CityQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = cq.Limit(1).IDs(setContextOp(ctx, cq.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
@@ -124,8 +124,8 @@ func (cq *CityQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (cq *CityQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := cq.FirstID(ctx)
|
||||
func (_q *CityQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
@@ -135,8 +135,8 @@ func (cq *CityQuery) FirstIDX(ctx context.Context) int {
|
||||
// Only returns a single City entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one City entity is found.
|
||||
// Returns a *NotFoundError when no City entities are found.
|
||||
func (cq *CityQuery) Only(ctx context.Context) (*City, error) {
|
||||
nodes, err := cq.Limit(2).All(setContextOp(ctx, cq.ctx, ent.OpQueryOnly))
|
||||
func (_q *CityQuery) Only(ctx context.Context) (*City, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -151,8 +151,8 @@ func (cq *CityQuery) Only(ctx context.Context) (*City, error) {
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (cq *CityQuery) OnlyX(ctx context.Context) *City {
|
||||
node, err := cq.Only(ctx)
|
||||
func (_q *CityQuery) OnlyX(ctx context.Context) *City {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -162,9 +162,9 @@ func (cq *CityQuery) OnlyX(ctx context.Context) *City {
|
||||
// OnlyID is like Only, but returns the only City ID in the query.
|
||||
// Returns a *NotSingularError when more than one City ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (cq *CityQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
func (_q *CityQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = cq.Limit(2).IDs(setContextOp(ctx, cq.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
@@ -179,8 +179,8 @@ func (cq *CityQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (cq *CityQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := cq.OnlyID(ctx)
|
||||
func (_q *CityQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -188,18 +188,18 @@ func (cq *CityQuery) OnlyIDX(ctx context.Context) int {
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Cities.
|
||||
func (cq *CityQuery) All(ctx context.Context) ([]*City, error) {
|
||||
ctx = setContextOp(ctx, cq.ctx, ent.OpQueryAll)
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
func (_q *CityQuery) All(ctx context.Context) ([]*City, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*City, *CityQuery]()
|
||||
return withInterceptors[[]*City](ctx, cq, qr, cq.inters)
|
||||
return withInterceptors[[]*City](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (cq *CityQuery) AllX(ctx context.Context) []*City {
|
||||
nodes, err := cq.All(ctx)
|
||||
func (_q *CityQuery) AllX(ctx context.Context) []*City {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -207,20 +207,20 @@ func (cq *CityQuery) AllX(ctx context.Context) []*City {
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of City IDs.
|
||||
func (cq *CityQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if cq.ctx.Unique == nil && cq.path != nil {
|
||||
cq.Unique(true)
|
||||
func (_q *CityQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, cq.ctx, ent.OpQueryIDs)
|
||||
if err = cq.Select(city.FieldID).Scan(ctx, &ids); err != nil {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(city.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (cq *CityQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := cq.IDs(ctx)
|
||||
func (_q *CityQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -228,17 +228,17 @@ func (cq *CityQuery) IDsX(ctx context.Context) []int {
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (cq *CityQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, cq.ctx, ent.OpQueryCount)
|
||||
if err := cq.prepareQuery(ctx); err != nil {
|
||||
func (_q *CityQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, cq, querierCount[*CityQuery](), cq.inters)
|
||||
return withInterceptors[int](ctx, _q, querierCount[*CityQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (cq *CityQuery) CountX(ctx context.Context) int {
|
||||
count, err := cq.Count(ctx)
|
||||
func (_q *CityQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -246,9 +246,9 @@ func (cq *CityQuery) CountX(ctx context.Context) int {
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (cq *CityQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, cq.ctx, ent.OpQueryExist)
|
||||
switch _, err := cq.FirstID(ctx); {
|
||||
func (_q *CityQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||
switch _, err := _q.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
@@ -259,8 +259,8 @@ func (cq *CityQuery) Exist(ctx context.Context) (bool, error) {
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (cq *CityQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := cq.Exist(ctx)
|
||||
func (_q *CityQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -269,32 +269,32 @@ func (cq *CityQuery) ExistX(ctx context.Context) bool {
|
||||
|
||||
// Clone returns a duplicate of the CityQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (cq *CityQuery) Clone() *CityQuery {
|
||||
if cq == nil {
|
||||
func (_q *CityQuery) Clone() *CityQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &CityQuery{
|
||||
config: cq.config,
|
||||
ctx: cq.ctx.Clone(),
|
||||
order: append([]city.OrderOption{}, cq.order...),
|
||||
inters: append([]Interceptor{}, cq.inters...),
|
||||
predicates: append([]predicate.City{}, cq.predicates...),
|
||||
withStreets: cq.withStreets.Clone(),
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]city.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.City{}, _q.predicates...),
|
||||
withStreets: _q.withStreets.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: cq.sql.Clone(),
|
||||
path: cq.path,
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithStreets tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "streets" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (cq *CityQuery) WithStreets(opts ...func(*StreetQuery)) *CityQuery {
|
||||
query := (&StreetClient{config: cq.config}).Query()
|
||||
func (_q *CityQuery) WithStreets(opts ...func(*StreetQuery)) *CityQuery {
|
||||
query := (&StreetClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
cq.withStreets = query
|
||||
return cq
|
||||
_q.withStreets = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
@@ -311,10 +311,10 @@ func (cq *CityQuery) WithStreets(opts ...func(*StreetQuery)) *CityQuery {
|
||||
// GroupBy(city.FieldName).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (cq *CityQuery) GroupBy(field string, fields ...string) *CityGroupBy {
|
||||
cq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &CityGroupBy{build: cq}
|
||||
grbuild.flds = &cq.ctx.Fields
|
||||
func (_q *CityQuery) GroupBy(field string, fields ...string) *CityGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &CityGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = city.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
@@ -332,58 +332,58 @@ func (cq *CityQuery) GroupBy(field string, fields ...string) *CityGroupBy {
|
||||
// client.City.Query().
|
||||
// Select(city.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
func (cq *CityQuery) Select(fields ...string) *CitySelect {
|
||||
cq.ctx.Fields = append(cq.ctx.Fields, fields...)
|
||||
sbuild := &CitySelect{CityQuery: cq}
|
||||
func (_q *CityQuery) Select(fields ...string) *CitySelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &CitySelect{CityQuery: _q}
|
||||
sbuild.label = city.Label
|
||||
sbuild.flds, sbuild.scan = &cq.ctx.Fields, sbuild.Scan
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a CitySelect configured with the given aggregations.
|
||||
func (cq *CityQuery) Aggregate(fns ...AggregateFunc) *CitySelect {
|
||||
return cq.Select().Aggregate(fns...)
|
||||
func (_q *CityQuery) Aggregate(fns ...AggregateFunc) *CitySelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (cq *CityQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range cq.inters {
|
||||
func (_q *CityQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, cq); err != nil {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range cq.ctx.Fields {
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !city.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if cq.path != nil {
|
||||
prev, err := cq.path(ctx)
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cq.sql = prev
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cq *CityQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*City, error) {
|
||||
func (_q *CityQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*City, error) {
|
||||
var (
|
||||
nodes = []*City{}
|
||||
_spec = cq.querySpec()
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
cq.withStreets != nil,
|
||||
_q.withStreets != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*City).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &City{config: cq.config}
|
||||
node := &City{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
@@ -391,14 +391,14 @@ func (cq *CityQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*City, e
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, cq.driver, _spec); err != nil {
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := cq.withStreets; query != nil {
|
||||
if err := cq.loadStreets(ctx, query, nodes,
|
||||
if query := _q.withStreets; query != nil {
|
||||
if err := _q.loadStreets(ctx, query, nodes,
|
||||
func(n *City) { n.Edges.Streets = []*Street{} },
|
||||
func(n *City, e *Street) { n.Edges.Streets = append(n.Edges.Streets, e) }); err != nil {
|
||||
return nil, err
|
||||
@@ -407,7 +407,7 @@ func (cq *CityQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*City, e
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (cq *CityQuery) loadStreets(ctx context.Context, query *StreetQuery, nodes []*City, init func(*City), assign func(*City, *Street)) error {
|
||||
func (_q *CityQuery) loadStreets(ctx context.Context, query *StreetQuery, nodes []*City, init func(*City), assign func(*City, *Street)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*City)
|
||||
for i := range nodes {
|
||||
@@ -439,24 +439,24 @@ func (cq *CityQuery) loadStreets(ctx context.Context, query *StreetQuery, nodes
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cq *CityQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := cq.querySpec()
|
||||
_spec.Node.Columns = cq.ctx.Fields
|
||||
if len(cq.ctx.Fields) > 0 {
|
||||
_spec.Unique = cq.ctx.Unique != nil && *cq.ctx.Unique
|
||||
func (_q *CityQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Columns = _q.ctx.Fields
|
||||
if len(_q.ctx.Fields) > 0 {
|
||||
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, cq.driver, _spec)
|
||||
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (cq *CityQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
func (_q *CityQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(city.Table, city.Columns, sqlgraph.NewFieldSpec(city.FieldID, field.TypeInt))
|
||||
_spec.From = cq.sql
|
||||
if unique := cq.ctx.Unique; unique != nil {
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if cq.path != nil {
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := cq.ctx.Fields; len(fields) > 0 {
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, city.FieldID)
|
||||
for i := range fields {
|
||||
@@ -465,20 +465,20 @@ func (cq *CityQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := cq.predicates; len(ps) > 0 {
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := cq.ctx.Limit; limit != nil {
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := cq.ctx.Offset; offset != nil {
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := cq.order; len(ps) > 0 {
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
@@ -488,33 +488,33 @@ func (cq *CityQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (cq *CityQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(cq.driver.Dialect())
|
||||
func (_q *CityQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(city.Table)
|
||||
columns := cq.ctx.Fields
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = city.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if cq.sql != nil {
|
||||
selector = cq.sql
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if cq.ctx.Unique != nil && *cq.ctx.Unique {
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range cq.predicates {
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range cq.order {
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := cq.ctx.Offset; offset != nil {
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := cq.ctx.Limit; limit != nil {
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
|
||||
@@ -27,74 +27,74 @@ type CityUpdate struct {
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CityUpdate builder.
|
||||
func (cu *CityUpdate) Where(ps ...predicate.City) *CityUpdate {
|
||||
cu.mutation.Where(ps...)
|
||||
return cu
|
||||
func (_u *CityUpdate) Where(ps ...predicate.City) *CityUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (cu *CityUpdate) SetName(s string) *CityUpdate {
|
||||
cu.mutation.SetName(s)
|
||||
return cu
|
||||
func (_u *CityUpdate) SetName(s string) *CityUpdate {
|
||||
_u.mutation.SetName(s)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (cu *CityUpdate) SetNillableName(s *string) *CityUpdate {
|
||||
func (_u *CityUpdate) SetNillableName(s *string) *CityUpdate {
|
||||
if s != nil {
|
||||
cu.SetName(*s)
|
||||
_u.SetName(*s)
|
||||
}
|
||||
return cu
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddStreetIDs adds the "streets" edge to the Street entity by IDs.
|
||||
func (cu *CityUpdate) AddStreetIDs(ids ...int) *CityUpdate {
|
||||
cu.mutation.AddStreetIDs(ids...)
|
||||
return cu
|
||||
func (_u *CityUpdate) AddStreetIDs(ids ...int) *CityUpdate {
|
||||
_u.mutation.AddStreetIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddStreets adds the "streets" edges to the Street entity.
|
||||
func (cu *CityUpdate) AddStreets(s ...*Street) *CityUpdate {
|
||||
func (_u *CityUpdate) AddStreets(s ...*Street) *CityUpdate {
|
||||
ids := make([]int, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
}
|
||||
return cu.AddStreetIDs(ids...)
|
||||
return _u.AddStreetIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the CityMutation object of the builder.
|
||||
func (cu *CityUpdate) Mutation() *CityMutation {
|
||||
return cu.mutation
|
||||
func (_u *CityUpdate) Mutation() *CityMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearStreets clears all "streets" edges to the Street entity.
|
||||
func (cu *CityUpdate) ClearStreets() *CityUpdate {
|
||||
cu.mutation.ClearStreets()
|
||||
return cu
|
||||
func (_u *CityUpdate) ClearStreets() *CityUpdate {
|
||||
_u.mutation.ClearStreets()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveStreetIDs removes the "streets" edge to Street entities by IDs.
|
||||
func (cu *CityUpdate) RemoveStreetIDs(ids ...int) *CityUpdate {
|
||||
cu.mutation.RemoveStreetIDs(ids...)
|
||||
return cu
|
||||
func (_u *CityUpdate) RemoveStreetIDs(ids ...int) *CityUpdate {
|
||||
_u.mutation.RemoveStreetIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveStreets removes "streets" edges to Street entities.
|
||||
func (cu *CityUpdate) RemoveStreets(s ...*Street) *CityUpdate {
|
||||
func (_u *CityUpdate) RemoveStreets(s ...*Street) *CityUpdate {
|
||||
ids := make([]int, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
}
|
||||
return cu.RemoveStreetIDs(ids...)
|
||||
return _u.RemoveStreetIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (cu *CityUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks)
|
||||
func (_u *CityUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (cu *CityUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := cu.Save(ctx)
|
||||
func (_u *CityUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -102,31 +102,31 @@ func (cu *CityUpdate) SaveX(ctx context.Context) int {
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (cu *CityUpdate) Exec(ctx context.Context) error {
|
||||
_, err := cu.Save(ctx)
|
||||
func (_u *CityUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cu *CityUpdate) ExecX(ctx context.Context) {
|
||||
if err := cu.Exec(ctx); err != nil {
|
||||
func (_u *CityUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (cu *CityUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
func (_u *CityUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(city.Table, city.Columns, sqlgraph.NewFieldSpec(city.FieldID, field.TypeInt))
|
||||
if ps := cu.mutation.predicates; len(ps) > 0 {
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := cu.mutation.Name(); ok {
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(city.FieldName, field.TypeString, value)
|
||||
}
|
||||
if cu.mutation.StreetsCleared() {
|
||||
if _u.mutation.StreetsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
@@ -139,7 +139,7 @@ func (cu *CityUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := cu.mutation.RemovedStreetsIDs(); len(nodes) > 0 && !cu.mutation.StreetsCleared() {
|
||||
if nodes := _u.mutation.RemovedStreetsIDs(); len(nodes) > 0 && !_u.mutation.StreetsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
@@ -155,7 +155,7 @@ func (cu *CityUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := cu.mutation.StreetsIDs(); len(nodes) > 0 {
|
||||
if nodes := _u.mutation.StreetsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
@@ -171,7 +171,7 @@ func (cu *CityUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, cu.driver, _spec); err != nil {
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{city.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
@@ -179,7 +179,7 @@ func (cu *CityUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
cu.mutation.done = true
|
||||
_u.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
@@ -192,81 +192,81 @@ type CityUpdateOne struct {
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (cuo *CityUpdateOne) SetName(s string) *CityUpdateOne {
|
||||
cuo.mutation.SetName(s)
|
||||
return cuo
|
||||
func (_u *CityUpdateOne) SetName(s string) *CityUpdateOne {
|
||||
_u.mutation.SetName(s)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (cuo *CityUpdateOne) SetNillableName(s *string) *CityUpdateOne {
|
||||
func (_u *CityUpdateOne) SetNillableName(s *string) *CityUpdateOne {
|
||||
if s != nil {
|
||||
cuo.SetName(*s)
|
||||
_u.SetName(*s)
|
||||
}
|
||||
return cuo
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddStreetIDs adds the "streets" edge to the Street entity by IDs.
|
||||
func (cuo *CityUpdateOne) AddStreetIDs(ids ...int) *CityUpdateOne {
|
||||
cuo.mutation.AddStreetIDs(ids...)
|
||||
return cuo
|
||||
func (_u *CityUpdateOne) AddStreetIDs(ids ...int) *CityUpdateOne {
|
||||
_u.mutation.AddStreetIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddStreets adds the "streets" edges to the Street entity.
|
||||
func (cuo *CityUpdateOne) AddStreets(s ...*Street) *CityUpdateOne {
|
||||
func (_u *CityUpdateOne) AddStreets(s ...*Street) *CityUpdateOne {
|
||||
ids := make([]int, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
}
|
||||
return cuo.AddStreetIDs(ids...)
|
||||
return _u.AddStreetIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the CityMutation object of the builder.
|
||||
func (cuo *CityUpdateOne) Mutation() *CityMutation {
|
||||
return cuo.mutation
|
||||
func (_u *CityUpdateOne) Mutation() *CityMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearStreets clears all "streets" edges to the Street entity.
|
||||
func (cuo *CityUpdateOne) ClearStreets() *CityUpdateOne {
|
||||
cuo.mutation.ClearStreets()
|
||||
return cuo
|
||||
func (_u *CityUpdateOne) ClearStreets() *CityUpdateOne {
|
||||
_u.mutation.ClearStreets()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveStreetIDs removes the "streets" edge to Street entities by IDs.
|
||||
func (cuo *CityUpdateOne) RemoveStreetIDs(ids ...int) *CityUpdateOne {
|
||||
cuo.mutation.RemoveStreetIDs(ids...)
|
||||
return cuo
|
||||
func (_u *CityUpdateOne) RemoveStreetIDs(ids ...int) *CityUpdateOne {
|
||||
_u.mutation.RemoveStreetIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveStreets removes "streets" edges to Street entities.
|
||||
func (cuo *CityUpdateOne) RemoveStreets(s ...*Street) *CityUpdateOne {
|
||||
func (_u *CityUpdateOne) RemoveStreets(s ...*Street) *CityUpdateOne {
|
||||
ids := make([]int, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
}
|
||||
return cuo.RemoveStreetIDs(ids...)
|
||||
return _u.RemoveStreetIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CityUpdate builder.
|
||||
func (cuo *CityUpdateOne) Where(ps ...predicate.City) *CityUpdateOne {
|
||||
cuo.mutation.Where(ps...)
|
||||
return cuo
|
||||
func (_u *CityUpdateOne) Where(ps ...predicate.City) *CityUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (cuo *CityUpdateOne) Select(field string, fields ...string) *CityUpdateOne {
|
||||
cuo.fields = append([]string{field}, fields...)
|
||||
return cuo
|
||||
func (_u *CityUpdateOne) Select(field string, fields ...string) *CityUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated City entity.
|
||||
func (cuo *CityUpdateOne) Save(ctx context.Context) (*City, error) {
|
||||
return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks)
|
||||
func (_u *CityUpdateOne) Save(ctx context.Context) (*City, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (cuo *CityUpdateOne) SaveX(ctx context.Context) *City {
|
||||
node, err := cuo.Save(ctx)
|
||||
func (_u *CityUpdateOne) SaveX(ctx context.Context) *City {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -274,26 +274,26 @@ func (cuo *CityUpdateOne) SaveX(ctx context.Context) *City {
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (cuo *CityUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := cuo.Save(ctx)
|
||||
func (_u *CityUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (cuo *CityUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := cuo.Exec(ctx); err != nil {
|
||||
func (_u *CityUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (cuo *CityUpdateOne) sqlSave(ctx context.Context) (_node *City, err error) {
|
||||
func (_u *CityUpdateOne) sqlSave(ctx context.Context) (_node *City, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(city.Table, city.Columns, sqlgraph.NewFieldSpec(city.FieldID, field.TypeInt))
|
||||
id, ok := cuo.mutation.ID()
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "City.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := cuo.fields; len(fields) > 0 {
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, city.FieldID)
|
||||
for _, f := range fields {
|
||||
@@ -305,17 +305,17 @@ func (cuo *CityUpdateOne) sqlSave(ctx context.Context) (_node *City, err error)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := cuo.mutation.predicates; len(ps) > 0 {
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := cuo.mutation.Name(); ok {
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(city.FieldName, field.TypeString, value)
|
||||
}
|
||||
if cuo.mutation.StreetsCleared() {
|
||||
if _u.mutation.StreetsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
@@ -328,7 +328,7 @@ func (cuo *CityUpdateOne) sqlSave(ctx context.Context) (_node *City, err error)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := cuo.mutation.RemovedStreetsIDs(); len(nodes) > 0 && !cuo.mutation.StreetsCleared() {
|
||||
if nodes := _u.mutation.RemovedStreetsIDs(); len(nodes) > 0 && !_u.mutation.StreetsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
@@ -344,7 +344,7 @@ func (cuo *CityUpdateOne) sqlSave(ctx context.Context) (_node *City, err error)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := cuo.mutation.StreetsIDs(); len(nodes) > 0 {
|
||||
if nodes := _u.mutation.StreetsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
@@ -360,10 +360,10 @@ func (cuo *CityUpdateOne) sqlSave(ctx context.Context) (_node *City, err error)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &City{config: cuo.config}
|
||||
_node = &City{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, cuo.driver, _spec); err != nil {
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{city.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
@@ -371,6 +371,6 @@ func (cuo *CityUpdateOne) sqlSave(ctx context.Context) (_node *City, err error)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
cuo.mutation.done = true
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
@@ -266,8 +266,8 @@ func (c *CityClient) Update() *CityUpdate {
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *CityClient) UpdateOne(ci *City) *CityUpdateOne {
|
||||
mutation := newCityMutation(c.config, OpUpdateOne, withCity(ci))
|
||||
func (c *CityClient) UpdateOne(_m *City) *CityUpdateOne {
|
||||
mutation := newCityMutation(c.config, OpUpdateOne, withCity(_m))
|
||||
return &CityUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
@@ -284,8 +284,8 @@ func (c *CityClient) Delete() *CityDelete {
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *CityClient) DeleteOne(ci *City) *CityDeleteOne {
|
||||
return c.DeleteOneID(ci.ID)
|
||||
func (c *CityClient) DeleteOne(_m *City) *CityDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
@@ -320,16 +320,16 @@ func (c *CityClient) GetX(ctx context.Context, id int) *City {
|
||||
}
|
||||
|
||||
// QueryStreets queries the streets edge of a City.
|
||||
func (c *CityClient) QueryStreets(ci *City) *StreetQuery {
|
||||
func (c *CityClient) QueryStreets(_m *City) *StreetQuery {
|
||||
query := (&StreetClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := ci.ID
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(city.Table, city.FieldID, id),
|
||||
sqlgraph.To(street.Table, street.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, city.StreetsTable, city.StreetsColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(ci.driver.Dialect(), step)
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
@@ -415,8 +415,8 @@ func (c *StreetClient) Update() *StreetUpdate {
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *StreetClient) UpdateOne(s *Street) *StreetUpdateOne {
|
||||
mutation := newStreetMutation(c.config, OpUpdateOne, withStreet(s))
|
||||
func (c *StreetClient) UpdateOne(_m *Street) *StreetUpdateOne {
|
||||
mutation := newStreetMutation(c.config, OpUpdateOne, withStreet(_m))
|
||||
return &StreetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
@@ -433,8 +433,8 @@ func (c *StreetClient) Delete() *StreetDelete {
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *StreetClient) DeleteOne(s *Street) *StreetDeleteOne {
|
||||
return c.DeleteOneID(s.ID)
|
||||
func (c *StreetClient) DeleteOne(_m *Street) *StreetDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
@@ -469,16 +469,16 @@ func (c *StreetClient) GetX(ctx context.Context, id int) *Street {
|
||||
}
|
||||
|
||||
// QueryCity queries the city edge of a Street.
|
||||
func (c *StreetClient) QueryCity(s *Street) *CityQuery {
|
||||
func (c *StreetClient) QueryCity(_m *Street) *CityQuery {
|
||||
query := (&CityClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := s.ID
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(street.Table, street.FieldID, id),
|
||||
sqlgraph.To(city.Table, city.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, street.CityTable, street.CityColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
|
||||
@@ -70,7 +70,7 @@ func (*Street) scanValues(columns []string) ([]any, error) {
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Street fields.
|
||||
func (s *Street) assignValues(columns []string, values []any) error {
|
||||
func (_m *Street) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
@@ -81,22 +81,22 @@ func (s *Street) assignValues(columns []string, values []any) error {
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
s.ID = int(value.Int64)
|
||||
_m.ID = int(value.Int64)
|
||||
case street.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
s.Name = value.String
|
||||
_m.Name = value.String
|
||||
}
|
||||
case street.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field city_streets", value)
|
||||
} else if value.Valid {
|
||||
s.city_streets = new(int)
|
||||
*s.city_streets = int(value.Int64)
|
||||
_m.city_streets = new(int)
|
||||
*_m.city_streets = int(value.Int64)
|
||||
}
|
||||
default:
|
||||
s.selectValues.Set(columns[i], values[i])
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -104,40 +104,40 @@ func (s *Street) assignValues(columns []string, values []any) error {
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Street.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (s *Street) Value(name string) (ent.Value, error) {
|
||||
return s.selectValues.Get(name)
|
||||
func (_m *Street) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryCity queries the "city" edge of the Street entity.
|
||||
func (s *Street) QueryCity() *CityQuery {
|
||||
return NewStreetClient(s.config).QueryCity(s)
|
||||
func (_m *Street) QueryCity() *CityQuery {
|
||||
return NewStreetClient(_m.config).QueryCity(_m)
|
||||
}
|
||||
|
||||
// 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.
|
||||
func (s *Street) Update() *StreetUpdateOne {
|
||||
return NewStreetClient(s.config).UpdateOne(s)
|
||||
func (_m *Street) Update() *StreetUpdateOne {
|
||||
return NewStreetClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Street 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 (s *Street) Unwrap() *Street {
|
||||
_tx, ok := s.config.driver.(*txDriver)
|
||||
func (_m *Street) Unwrap() *Street {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Street is not a transactional entity")
|
||||
}
|
||||
s.config.driver = _tx.drv
|
||||
return s
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (s *Street) String() string {
|
||||
func (_m *Street) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Street(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", s.ID))
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(s.Name)
|
||||
builder.WriteString(_m.Name)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -25,43 +25,43 @@ type StreetCreate struct {
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (sc *StreetCreate) SetName(s string) *StreetCreate {
|
||||
sc.mutation.SetName(s)
|
||||
return sc
|
||||
func (_c *StreetCreate) SetName(s string) *StreetCreate {
|
||||
_c.mutation.SetName(s)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCityID sets the "city" edge to the City entity by ID.
|
||||
func (sc *StreetCreate) SetCityID(id int) *StreetCreate {
|
||||
sc.mutation.SetCityID(id)
|
||||
return sc
|
||||
func (_c *StreetCreate) SetCityID(id int) *StreetCreate {
|
||||
_c.mutation.SetCityID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCityID sets the "city" edge to the City entity by ID if the given value is not nil.
|
||||
func (sc *StreetCreate) SetNillableCityID(id *int) *StreetCreate {
|
||||
func (_c *StreetCreate) SetNillableCityID(id *int) *StreetCreate {
|
||||
if id != nil {
|
||||
sc = sc.SetCityID(*id)
|
||||
_c = _c.SetCityID(*id)
|
||||
}
|
||||
return sc
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCity sets the "city" edge to the City entity.
|
||||
func (sc *StreetCreate) SetCity(c *City) *StreetCreate {
|
||||
return sc.SetCityID(c.ID)
|
||||
func (_c *StreetCreate) SetCity(c *City) *StreetCreate {
|
||||
return _c.SetCityID(c.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the StreetMutation object of the builder.
|
||||
func (sc *StreetCreate) Mutation() *StreetMutation {
|
||||
return sc.mutation
|
||||
func (_c *StreetCreate) Mutation() *StreetMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Street in the database.
|
||||
func (sc *StreetCreate) Save(ctx context.Context) (*Street, error) {
|
||||
return withHooks(ctx, sc.sqlSave, sc.mutation, sc.hooks)
|
||||
func (_c *StreetCreate) Save(ctx context.Context) (*Street, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (sc *StreetCreate) SaveX(ctx context.Context) *Street {
|
||||
v, err := sc.Save(ctx)
|
||||
func (_c *StreetCreate) SaveX(ctx context.Context) *Street {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -69,32 +69,32 @@ func (sc *StreetCreate) SaveX(ctx context.Context) *Street {
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (sc *StreetCreate) Exec(ctx context.Context) error {
|
||||
_, err := sc.Save(ctx)
|
||||
func (_c *StreetCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sc *StreetCreate) ExecX(ctx context.Context) {
|
||||
if err := sc.Exec(ctx); err != nil {
|
||||
func (_c *StreetCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (sc *StreetCreate) check() error {
|
||||
if _, ok := sc.mutation.Name(); !ok {
|
||||
func (_c *StreetCreate) check() error {
|
||||
if _, ok := _c.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Street.name"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sc *StreetCreate) sqlSave(ctx context.Context) (*Street, error) {
|
||||
if err := sc.check(); err != nil {
|
||||
func (_c *StreetCreate) sqlSave(ctx context.Context) (*Street, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := sc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, sc.driver, _spec); err != nil {
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
@@ -102,21 +102,21 @@ func (sc *StreetCreate) sqlSave(ctx context.Context) (*Street, error) {
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
sc.mutation.id = &_node.ID
|
||||
sc.mutation.done = true
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (sc *StreetCreate) createSpec() (*Street, *sqlgraph.CreateSpec) {
|
||||
func (_c *StreetCreate) createSpec() (*Street, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Street{config: sc.config}
|
||||
_node = &Street{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(street.Table, sqlgraph.NewFieldSpec(street.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := sc.mutation.Name(); ok {
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(street.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if nodes := sc.mutation.CityIDs(); len(nodes) > 0 {
|
||||
if nodes := _c.mutation.CityIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
@@ -144,16 +144,16 @@ type StreetCreateBulk struct {
|
||||
}
|
||||
|
||||
// Save creates the Street entities in the database.
|
||||
func (scb *StreetCreateBulk) Save(ctx context.Context) ([]*Street, error) {
|
||||
if scb.err != nil {
|
||||
return nil, scb.err
|
||||
func (_c *StreetCreateBulk) Save(ctx context.Context) ([]*Street, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(scb.builders))
|
||||
nodes := make([]*Street, len(scb.builders))
|
||||
mutators := make([]Mutator, len(scb.builders))
|
||||
for i := range scb.builders {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Street, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := scb.builders[i]
|
||||
builder := _c.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*StreetMutation)
|
||||
if !ok {
|
||||
@@ -166,11 +166,11 @@ func (scb *StreetCreateBulk) Save(ctx context.Context) ([]*Street, error) {
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, scb.builders[i+1].mutation)
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, scb.driver, spec); err != nil {
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
@@ -194,7 +194,7 @@ func (scb *StreetCreateBulk) Save(ctx context.Context) ([]*Street, error) {
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, scb.builders[0].mutation); err != nil {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@@ -202,8 +202,8 @@ func (scb *StreetCreateBulk) Save(ctx context.Context) ([]*Street, error) {
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (scb *StreetCreateBulk) SaveX(ctx context.Context) []*Street {
|
||||
v, err := scb.Save(ctx)
|
||||
func (_c *StreetCreateBulk) SaveX(ctx context.Context) []*Street {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -211,14 +211,14 @@ func (scb *StreetCreateBulk) SaveX(ctx context.Context) []*Street {
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (scb *StreetCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := scb.Save(ctx)
|
||||
func (_c *StreetCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (scb *StreetCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := scb.Exec(ctx); err != nil {
|
||||
func (_c *StreetCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,56 +24,56 @@ type StreetDelete struct {
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the StreetDelete builder.
|
||||
func (sd *StreetDelete) Where(ps ...predicate.Street) *StreetDelete {
|
||||
sd.mutation.Where(ps...)
|
||||
return sd
|
||||
func (_d *StreetDelete) Where(ps ...predicate.Street) *StreetDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (sd *StreetDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, sd.sqlExec, sd.mutation, sd.hooks)
|
||||
func (_d *StreetDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sd *StreetDelete) ExecX(ctx context.Context) int {
|
||||
n, err := sd.Exec(ctx)
|
||||
func (_d *StreetDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (sd *StreetDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
func (_d *StreetDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(street.Table, sqlgraph.NewFieldSpec(street.FieldID, field.TypeInt))
|
||||
if ps := sd.mutation.predicates; len(ps) > 0 {
|
||||
if ps := _d.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, sd.driver, _spec)
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
sd.mutation.done = true
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// StreetDeleteOne is the builder for deleting a single Street entity.
|
||||
type StreetDeleteOne struct {
|
||||
sd *StreetDelete
|
||||
_d *StreetDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the StreetDelete builder.
|
||||
func (sdo *StreetDeleteOne) Where(ps ...predicate.Street) *StreetDeleteOne {
|
||||
sdo.sd.mutation.Where(ps...)
|
||||
return sdo
|
||||
func (_d *StreetDeleteOne) Where(ps ...predicate.Street) *StreetDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (sdo *StreetDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := sdo.sd.Exec(ctx)
|
||||
func (_d *StreetDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
@@ -85,8 +85,8 @@ func (sdo *StreetDeleteOne) Exec(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sdo *StreetDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := sdo.Exec(ctx); err != nil {
|
||||
func (_d *StreetDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,44 +35,44 @@ type StreetQuery struct {
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the StreetQuery builder.
|
||||
func (sq *StreetQuery) Where(ps ...predicate.Street) *StreetQuery {
|
||||
sq.predicates = append(sq.predicates, ps...)
|
||||
return sq
|
||||
func (_q *StreetQuery) Where(ps ...predicate.Street) *StreetQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (sq *StreetQuery) Limit(limit int) *StreetQuery {
|
||||
sq.ctx.Limit = &limit
|
||||
return sq
|
||||
func (_q *StreetQuery) Limit(limit int) *StreetQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (sq *StreetQuery) Offset(offset int) *StreetQuery {
|
||||
sq.ctx.Offset = &offset
|
||||
return sq
|
||||
func (_q *StreetQuery) Offset(offset int) *StreetQuery {
|
||||
_q.ctx.Offset = &offset
|
||||
return _q
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (sq *StreetQuery) Unique(unique bool) *StreetQuery {
|
||||
sq.ctx.Unique = &unique
|
||||
return sq
|
||||
func (_q *StreetQuery) Unique(unique bool) *StreetQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (sq *StreetQuery) Order(o ...street.OrderOption) *StreetQuery {
|
||||
sq.order = append(sq.order, o...)
|
||||
return sq
|
||||
func (_q *StreetQuery) Order(o ...street.OrderOption) *StreetQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryCity chains the current query on the "city" edge.
|
||||
func (sq *StreetQuery) QueryCity() *CityQuery {
|
||||
query := (&CityClient{config: sq.config}).Query()
|
||||
func (_q *StreetQuery) QueryCity() *CityQuery {
|
||||
query := (&CityClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := sq.prepareQuery(ctx); err != nil {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := sq.sqlQuery(ctx)
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -81,7 +81,7 @@ func (sq *StreetQuery) QueryCity() *CityQuery {
|
||||
sqlgraph.To(city.Table, city.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, street.CityTable, street.CityColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(sq.driver.Dialect(), step)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
@@ -89,8 +89,8 @@ func (sq *StreetQuery) QueryCity() *CityQuery {
|
||||
|
||||
// First returns the first Street entity from the query.
|
||||
// Returns a *NotFoundError when no Street was found.
|
||||
func (sq *StreetQuery) First(ctx context.Context) (*Street, error) {
|
||||
nodes, err := sq.Limit(1).All(setContextOp(ctx, sq.ctx, ent.OpQueryFirst))
|
||||
func (_q *StreetQuery) First(ctx context.Context) (*Street, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -101,8 +101,8 @@ func (sq *StreetQuery) First(ctx context.Context) (*Street, error) {
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (sq *StreetQuery) FirstX(ctx context.Context) *Street {
|
||||
node, err := sq.First(ctx)
|
||||
func (_q *StreetQuery) FirstX(ctx context.Context) *Street {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
@@ -111,9 +111,9 @@ func (sq *StreetQuery) FirstX(ctx context.Context) *Street {
|
||||
|
||||
// FirstID returns the first Street ID from the query.
|
||||
// Returns a *NotFoundError when no Street ID was found.
|
||||
func (sq *StreetQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
func (_q *StreetQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = sq.Limit(1).IDs(setContextOp(ctx, sq.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
@@ -124,8 +124,8 @@ func (sq *StreetQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (sq *StreetQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := sq.FirstID(ctx)
|
||||
func (_q *StreetQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
@@ -135,8 +135,8 @@ func (sq *StreetQuery) FirstIDX(ctx context.Context) int {
|
||||
// Only returns a single Street entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Street entity is found.
|
||||
// Returns a *NotFoundError when no Street entities are found.
|
||||
func (sq *StreetQuery) Only(ctx context.Context) (*Street, error) {
|
||||
nodes, err := sq.Limit(2).All(setContextOp(ctx, sq.ctx, ent.OpQueryOnly))
|
||||
func (_q *StreetQuery) Only(ctx context.Context) (*Street, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -151,8 +151,8 @@ func (sq *StreetQuery) Only(ctx context.Context) (*Street, error) {
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (sq *StreetQuery) OnlyX(ctx context.Context) *Street {
|
||||
node, err := sq.Only(ctx)
|
||||
func (_q *StreetQuery) OnlyX(ctx context.Context) *Street {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -162,9 +162,9 @@ func (sq *StreetQuery) OnlyX(ctx context.Context) *Street {
|
||||
// OnlyID is like Only, but returns the only Street ID in the query.
|
||||
// Returns a *NotSingularError when more than one Street ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (sq *StreetQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
func (_q *StreetQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = sq.Limit(2).IDs(setContextOp(ctx, sq.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
@@ -179,8 +179,8 @@ func (sq *StreetQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (sq *StreetQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := sq.OnlyID(ctx)
|
||||
func (_q *StreetQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -188,18 +188,18 @@ func (sq *StreetQuery) OnlyIDX(ctx context.Context) int {
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Streets.
|
||||
func (sq *StreetQuery) All(ctx context.Context) ([]*Street, error) {
|
||||
ctx = setContextOp(ctx, sq.ctx, ent.OpQueryAll)
|
||||
if err := sq.prepareQuery(ctx); err != nil {
|
||||
func (_q *StreetQuery) All(ctx context.Context) ([]*Street, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Street, *StreetQuery]()
|
||||
return withInterceptors[[]*Street](ctx, sq, qr, sq.inters)
|
||||
return withInterceptors[[]*Street](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (sq *StreetQuery) AllX(ctx context.Context) []*Street {
|
||||
nodes, err := sq.All(ctx)
|
||||
func (_q *StreetQuery) AllX(ctx context.Context) []*Street {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -207,20 +207,20 @@ func (sq *StreetQuery) AllX(ctx context.Context) []*Street {
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Street IDs.
|
||||
func (sq *StreetQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if sq.ctx.Unique == nil && sq.path != nil {
|
||||
sq.Unique(true)
|
||||
func (_q *StreetQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, sq.ctx, ent.OpQueryIDs)
|
||||
if err = sq.Select(street.FieldID).Scan(ctx, &ids); err != nil {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(street.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (sq *StreetQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := sq.IDs(ctx)
|
||||
func (_q *StreetQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -228,17 +228,17 @@ func (sq *StreetQuery) IDsX(ctx context.Context) []int {
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (sq *StreetQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, sq.ctx, ent.OpQueryCount)
|
||||
if err := sq.prepareQuery(ctx); err != nil {
|
||||
func (_q *StreetQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, sq, querierCount[*StreetQuery](), sq.inters)
|
||||
return withInterceptors[int](ctx, _q, querierCount[*StreetQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (sq *StreetQuery) CountX(ctx context.Context) int {
|
||||
count, err := sq.Count(ctx)
|
||||
func (_q *StreetQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -246,9 +246,9 @@ func (sq *StreetQuery) CountX(ctx context.Context) int {
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (sq *StreetQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, sq.ctx, ent.OpQueryExist)
|
||||
switch _, err := sq.FirstID(ctx); {
|
||||
func (_q *StreetQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||
switch _, err := _q.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
@@ -259,8 +259,8 @@ func (sq *StreetQuery) Exist(ctx context.Context) (bool, error) {
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (sq *StreetQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := sq.Exist(ctx)
|
||||
func (_q *StreetQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -269,32 +269,32 @@ func (sq *StreetQuery) ExistX(ctx context.Context) bool {
|
||||
|
||||
// Clone returns a duplicate of the StreetQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (sq *StreetQuery) Clone() *StreetQuery {
|
||||
if sq == nil {
|
||||
func (_q *StreetQuery) Clone() *StreetQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &StreetQuery{
|
||||
config: sq.config,
|
||||
ctx: sq.ctx.Clone(),
|
||||
order: append([]street.OrderOption{}, sq.order...),
|
||||
inters: append([]Interceptor{}, sq.inters...),
|
||||
predicates: append([]predicate.Street{}, sq.predicates...),
|
||||
withCity: sq.withCity.Clone(),
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]street.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Street{}, _q.predicates...),
|
||||
withCity: _q.withCity.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: sq.sql.Clone(),
|
||||
path: sq.path,
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithCity tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "city" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (sq *StreetQuery) WithCity(opts ...func(*CityQuery)) *StreetQuery {
|
||||
query := (&CityClient{config: sq.config}).Query()
|
||||
func (_q *StreetQuery) WithCity(opts ...func(*CityQuery)) *StreetQuery {
|
||||
query := (&CityClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
sq.withCity = query
|
||||
return sq
|
||||
_q.withCity = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
@@ -311,10 +311,10 @@ func (sq *StreetQuery) WithCity(opts ...func(*CityQuery)) *StreetQuery {
|
||||
// GroupBy(street.FieldName).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (sq *StreetQuery) GroupBy(field string, fields ...string) *StreetGroupBy {
|
||||
sq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &StreetGroupBy{build: sq}
|
||||
grbuild.flds = &sq.ctx.Fields
|
||||
func (_q *StreetQuery) GroupBy(field string, fields ...string) *StreetGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &StreetGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = street.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
@@ -332,55 +332,55 @@ func (sq *StreetQuery) GroupBy(field string, fields ...string) *StreetGroupBy {
|
||||
// client.Street.Query().
|
||||
// Select(street.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
func (sq *StreetQuery) Select(fields ...string) *StreetSelect {
|
||||
sq.ctx.Fields = append(sq.ctx.Fields, fields...)
|
||||
sbuild := &StreetSelect{StreetQuery: sq}
|
||||
func (_q *StreetQuery) Select(fields ...string) *StreetSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &StreetSelect{StreetQuery: _q}
|
||||
sbuild.label = street.Label
|
||||
sbuild.flds, sbuild.scan = &sq.ctx.Fields, sbuild.Scan
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a StreetSelect configured with the given aggregations.
|
||||
func (sq *StreetQuery) Aggregate(fns ...AggregateFunc) *StreetSelect {
|
||||
return sq.Select().Aggregate(fns...)
|
||||
func (_q *StreetQuery) Aggregate(fns ...AggregateFunc) *StreetSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (sq *StreetQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range sq.inters {
|
||||
func (_q *StreetQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, sq); err != nil {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range sq.ctx.Fields {
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !street.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if sq.path != nil {
|
||||
prev, err := sq.path(ctx)
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sq.sql = prev
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sq *StreetQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Street, error) {
|
||||
func (_q *StreetQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Street, error) {
|
||||
var (
|
||||
nodes = []*Street{}
|
||||
withFKs = sq.withFKs
|
||||
_spec = sq.querySpec()
|
||||
withFKs = _q.withFKs
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
sq.withCity != nil,
|
||||
_q.withCity != nil,
|
||||
}
|
||||
)
|
||||
if sq.withCity != nil {
|
||||
if _q.withCity != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
@@ -390,7 +390,7 @@ func (sq *StreetQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Stree
|
||||
return (*Street).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Street{config: sq.config}
|
||||
node := &Street{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
@@ -398,14 +398,14 @@ func (sq *StreetQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Stree
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, sq.driver, _spec); err != nil {
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := sq.withCity; query != nil {
|
||||
if err := sq.loadCity(ctx, query, nodes, nil,
|
||||
if query := _q.withCity; query != nil {
|
||||
if err := _q.loadCity(ctx, query, nodes, nil,
|
||||
func(n *Street, e *City) { n.Edges.City = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -413,7 +413,7 @@ func (sq *StreetQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Stree
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (sq *StreetQuery) loadCity(ctx context.Context, query *CityQuery, nodes []*Street, init func(*Street), assign func(*Street, *City)) error {
|
||||
func (_q *StreetQuery) loadCity(ctx context.Context, query *CityQuery, nodes []*Street, init func(*Street), assign func(*Street, *City)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Street)
|
||||
for i := range nodes {
|
||||
@@ -446,24 +446,24 @@ func (sq *StreetQuery) loadCity(ctx context.Context, query *CityQuery, nodes []*
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sq *StreetQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := sq.querySpec()
|
||||
_spec.Node.Columns = sq.ctx.Fields
|
||||
if len(sq.ctx.Fields) > 0 {
|
||||
_spec.Unique = sq.ctx.Unique != nil && *sq.ctx.Unique
|
||||
func (_q *StreetQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Columns = _q.ctx.Fields
|
||||
if len(_q.ctx.Fields) > 0 {
|
||||
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, sq.driver, _spec)
|
||||
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (sq *StreetQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
func (_q *StreetQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(street.Table, street.Columns, sqlgraph.NewFieldSpec(street.FieldID, field.TypeInt))
|
||||
_spec.From = sq.sql
|
||||
if unique := sq.ctx.Unique; unique != nil {
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if sq.path != nil {
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := sq.ctx.Fields; len(fields) > 0 {
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, street.FieldID)
|
||||
for i := range fields {
|
||||
@@ -472,20 +472,20 @@ func (sq *StreetQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := sq.predicates; len(ps) > 0 {
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := sq.ctx.Limit; limit != nil {
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := sq.ctx.Offset; offset != nil {
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := sq.order; len(ps) > 0 {
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
@@ -495,33 +495,33 @@ func (sq *StreetQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (sq *StreetQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(sq.driver.Dialect())
|
||||
func (_q *StreetQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(street.Table)
|
||||
columns := sq.ctx.Fields
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = street.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if sq.sql != nil {
|
||||
selector = sq.sql
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if sq.ctx.Unique != nil && *sq.ctx.Unique {
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range sq.predicates {
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range sq.order {
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := sq.ctx.Offset; offset != nil {
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := sq.ctx.Limit; limit != nil {
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
|
||||
@@ -27,63 +27,63 @@ type StreetUpdate struct {
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the StreetUpdate builder.
|
||||
func (su *StreetUpdate) Where(ps ...predicate.Street) *StreetUpdate {
|
||||
su.mutation.Where(ps...)
|
||||
return su
|
||||
func (_u *StreetUpdate) Where(ps ...predicate.Street) *StreetUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (su *StreetUpdate) SetName(s string) *StreetUpdate {
|
||||
su.mutation.SetName(s)
|
||||
return su
|
||||
func (_u *StreetUpdate) SetName(s string) *StreetUpdate {
|
||||
_u.mutation.SetName(s)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (su *StreetUpdate) SetNillableName(s *string) *StreetUpdate {
|
||||
func (_u *StreetUpdate) SetNillableName(s *string) *StreetUpdate {
|
||||
if s != nil {
|
||||
su.SetName(*s)
|
||||
_u.SetName(*s)
|
||||
}
|
||||
return su
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCityID sets the "city" edge to the City entity by ID.
|
||||
func (su *StreetUpdate) SetCityID(id int) *StreetUpdate {
|
||||
su.mutation.SetCityID(id)
|
||||
return su
|
||||
func (_u *StreetUpdate) SetCityID(id int) *StreetUpdate {
|
||||
_u.mutation.SetCityID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCityID sets the "city" edge to the City entity by ID if the given value is not nil.
|
||||
func (su *StreetUpdate) SetNillableCityID(id *int) *StreetUpdate {
|
||||
func (_u *StreetUpdate) SetNillableCityID(id *int) *StreetUpdate {
|
||||
if id != nil {
|
||||
su = su.SetCityID(*id)
|
||||
_u = _u.SetCityID(*id)
|
||||
}
|
||||
return su
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCity sets the "city" edge to the City entity.
|
||||
func (su *StreetUpdate) SetCity(c *City) *StreetUpdate {
|
||||
return su.SetCityID(c.ID)
|
||||
func (_u *StreetUpdate) SetCity(c *City) *StreetUpdate {
|
||||
return _u.SetCityID(c.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the StreetMutation object of the builder.
|
||||
func (su *StreetUpdate) Mutation() *StreetMutation {
|
||||
return su.mutation
|
||||
func (_u *StreetUpdate) Mutation() *StreetMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearCity clears the "city" edge to the City entity.
|
||||
func (su *StreetUpdate) ClearCity() *StreetUpdate {
|
||||
su.mutation.ClearCity()
|
||||
return su
|
||||
func (_u *StreetUpdate) ClearCity() *StreetUpdate {
|
||||
_u.mutation.ClearCity()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (su *StreetUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, su.sqlSave, su.mutation, su.hooks)
|
||||
func (_u *StreetUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (su *StreetUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := su.Save(ctx)
|
||||
func (_u *StreetUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -91,31 +91,31 @@ func (su *StreetUpdate) SaveX(ctx context.Context) int {
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (su *StreetUpdate) Exec(ctx context.Context) error {
|
||||
_, err := su.Save(ctx)
|
||||
func (_u *StreetUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (su *StreetUpdate) ExecX(ctx context.Context) {
|
||||
if err := su.Exec(ctx); err != nil {
|
||||
func (_u *StreetUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (su *StreetUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
func (_u *StreetUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(street.Table, street.Columns, sqlgraph.NewFieldSpec(street.FieldID, field.TypeInt))
|
||||
if ps := su.mutation.predicates; len(ps) > 0 {
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := su.mutation.Name(); ok {
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(street.FieldName, field.TypeString, value)
|
||||
}
|
||||
if su.mutation.CityCleared() {
|
||||
if _u.mutation.CityCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
@@ -128,7 +128,7 @@ func (su *StreetUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := su.mutation.CityIDs(); len(nodes) > 0 {
|
||||
if nodes := _u.mutation.CityIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
@@ -144,7 +144,7 @@ func (su *StreetUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{street.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
@@ -152,7 +152,7 @@ func (su *StreetUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
su.mutation.done = true
|
||||
_u.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
@@ -165,70 +165,70 @@ type StreetUpdateOne struct {
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (suo *StreetUpdateOne) SetName(s string) *StreetUpdateOne {
|
||||
suo.mutation.SetName(s)
|
||||
return suo
|
||||
func (_u *StreetUpdateOne) SetName(s string) *StreetUpdateOne {
|
||||
_u.mutation.SetName(s)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (suo *StreetUpdateOne) SetNillableName(s *string) *StreetUpdateOne {
|
||||
func (_u *StreetUpdateOne) SetNillableName(s *string) *StreetUpdateOne {
|
||||
if s != nil {
|
||||
suo.SetName(*s)
|
||||
_u.SetName(*s)
|
||||
}
|
||||
return suo
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCityID sets the "city" edge to the City entity by ID.
|
||||
func (suo *StreetUpdateOne) SetCityID(id int) *StreetUpdateOne {
|
||||
suo.mutation.SetCityID(id)
|
||||
return suo
|
||||
func (_u *StreetUpdateOne) SetCityID(id int) *StreetUpdateOne {
|
||||
_u.mutation.SetCityID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCityID sets the "city" edge to the City entity by ID if the given value is not nil.
|
||||
func (suo *StreetUpdateOne) SetNillableCityID(id *int) *StreetUpdateOne {
|
||||
func (_u *StreetUpdateOne) SetNillableCityID(id *int) *StreetUpdateOne {
|
||||
if id != nil {
|
||||
suo = suo.SetCityID(*id)
|
||||
_u = _u.SetCityID(*id)
|
||||
}
|
||||
return suo
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCity sets the "city" edge to the City entity.
|
||||
func (suo *StreetUpdateOne) SetCity(c *City) *StreetUpdateOne {
|
||||
return suo.SetCityID(c.ID)
|
||||
func (_u *StreetUpdateOne) SetCity(c *City) *StreetUpdateOne {
|
||||
return _u.SetCityID(c.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the StreetMutation object of the builder.
|
||||
func (suo *StreetUpdateOne) Mutation() *StreetMutation {
|
||||
return suo.mutation
|
||||
func (_u *StreetUpdateOne) Mutation() *StreetMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearCity clears the "city" edge to the City entity.
|
||||
func (suo *StreetUpdateOne) ClearCity() *StreetUpdateOne {
|
||||
suo.mutation.ClearCity()
|
||||
return suo
|
||||
func (_u *StreetUpdateOne) ClearCity() *StreetUpdateOne {
|
||||
_u.mutation.ClearCity()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the StreetUpdate builder.
|
||||
func (suo *StreetUpdateOne) Where(ps ...predicate.Street) *StreetUpdateOne {
|
||||
suo.mutation.Where(ps...)
|
||||
return suo
|
||||
func (_u *StreetUpdateOne) Where(ps ...predicate.Street) *StreetUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (suo *StreetUpdateOne) Select(field string, fields ...string) *StreetUpdateOne {
|
||||
suo.fields = append([]string{field}, fields...)
|
||||
return suo
|
||||
func (_u *StreetUpdateOne) Select(field string, fields ...string) *StreetUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Street entity.
|
||||
func (suo *StreetUpdateOne) Save(ctx context.Context) (*Street, error) {
|
||||
return withHooks(ctx, suo.sqlSave, suo.mutation, suo.hooks)
|
||||
func (_u *StreetUpdateOne) Save(ctx context.Context) (*Street, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (suo *StreetUpdateOne) SaveX(ctx context.Context) *Street {
|
||||
node, err := suo.Save(ctx)
|
||||
func (_u *StreetUpdateOne) SaveX(ctx context.Context) *Street {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -236,26 +236,26 @@ func (suo *StreetUpdateOne) SaveX(ctx context.Context) *Street {
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (suo *StreetUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := suo.Save(ctx)
|
||||
func (_u *StreetUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (suo *StreetUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := suo.Exec(ctx); err != nil {
|
||||
func (_u *StreetUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (suo *StreetUpdateOne) sqlSave(ctx context.Context) (_node *Street, err error) {
|
||||
func (_u *StreetUpdateOne) sqlSave(ctx context.Context) (_node *Street, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(street.Table, street.Columns, sqlgraph.NewFieldSpec(street.FieldID, field.TypeInt))
|
||||
id, ok := suo.mutation.ID()
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Street.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := suo.fields; len(fields) > 0 {
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, street.FieldID)
|
||||
for _, f := range fields {
|
||||
@@ -267,17 +267,17 @@ func (suo *StreetUpdateOne) sqlSave(ctx context.Context) (_node *Street, err err
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := suo.mutation.predicates; len(ps) > 0 {
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := suo.mutation.Name(); ok {
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(street.FieldName, field.TypeString, value)
|
||||
}
|
||||
if suo.mutation.CityCleared() {
|
||||
if _u.mutation.CityCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
@@ -290,7 +290,7 @@ func (suo *StreetUpdateOne) sqlSave(ctx context.Context) (_node *Street, err err
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := suo.mutation.CityIDs(); len(nodes) > 0 {
|
||||
if nodes := _u.mutation.CityIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
@@ -306,10 +306,10 @@ func (suo *StreetUpdateOne) sqlSave(ctx context.Context) (_node *Street, err err
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Street{config: suo.config}
|
||||
_node = &Street{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, suo.driver, _spec); err != nil {
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{street.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
@@ -317,6 +317,6 @@ func (suo *StreetUpdateOne) sqlSave(ctx context.Context) (_node *Street, err err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
suo.mutation.done = true
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user