snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
134
entc/integration/migrate/entv1/car.go
Normal file
134
entc/integration/migrate/entv1/car.go
Normal file
@@ -0,0 +1,134 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/user"
|
||||
)
|
||||
|
||||
// Car is the model entity for the Car schema.
|
||||
type Car struct {
|
||||
config
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the CarQuery when eager-loading is set.
|
||||
Edges CarEdges `json:"edges"`
|
||||
user_car *int
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// CarEdges holds the relations/edges for other nodes in the graph.
|
||||
type CarEdges struct {
|
||||
// Owner holds the value of the owner edge.
|
||||
Owner *User `json:"owner,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// OwnerOrErr returns the Owner value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e CarEdges) OwnerOrErr() (*User, error) {
|
||||
if e.Owner != nil {
|
||||
return e.Owner, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "owner"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Car) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case car.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case car.ForeignKeys[0]: // user_car
|
||||
values[i] = new(sql.NullInt64)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Car fields.
|
||||
func (_m *Car) 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)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case car.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int(value.Int64)
|
||||
case car.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field user_car", value)
|
||||
} else if value.Valid {
|
||||
_m.user_car = new(int)
|
||||
*_m.user_car = int(value.Int64)
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Car.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Car) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryOwner queries the "owner" edge of the Car entity.
|
||||
func (_m *Car) QueryOwner() *UserQuery {
|
||||
return NewCarClient(_m.config).QueryOwner(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Car.
|
||||
// Note that you need to call Car.Unwrap() before calling this method if this Car
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Car) Update() *CarUpdateOne {
|
||||
return NewCarClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Car 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 (_m *Car) Unwrap() *Car {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("entv1: Car is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Car) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Car(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v", _m.ID))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Cars is a parsable slice of Car.
|
||||
type Cars []*Car
|
||||
80
entc/integration/migrate/entv1/car/car.go
Normal file
80
entc/integration/migrate/entv1/car/car.go
Normal file
@@ -0,0 +1,80 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package car
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the car type in the database.
|
||||
Label = "car"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// EdgeOwner holds the string denoting the owner edge name in mutations.
|
||||
EdgeOwner = "owner"
|
||||
// UserFieldID holds the string denoting the ID field of the User.
|
||||
UserFieldID = "oid"
|
||||
// Table holds the table name of the car in the database.
|
||||
Table = "Car"
|
||||
// OwnerTable is the table that holds the owner relation/edge.
|
||||
OwnerTable = "Car"
|
||||
// OwnerInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
OwnerInverseTable = "users"
|
||||
// OwnerColumn is the table column denoting the owner relation/edge.
|
||||
OwnerColumn = "user_car"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for car fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "Car"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"user_car",
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for i := range ForeignKeys {
|
||||
if column == ForeignKeys[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the Car queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByOwnerField orders the results by owner field.
|
||||
func ByOwnerField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newOwnerStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newOwnerStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(OwnerInverseTable, UserFieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, OwnerTable, OwnerColumn),
|
||||
)
|
||||
}
|
||||
259
entc/integration/migrate/entv1/car/mutation.go
Normal file
259
entc/integration/migrate/entv1/car/mutation.go
Normal file
@@ -0,0 +1,259 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package car
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Car nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
clearedFields map[string]struct{}
|
||||
owner *int
|
||||
clearedowner bool
|
||||
predicates []predicate.Car
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Car entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Car",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Car {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner" edge to the User entity by id.
|
||||
func (m *Mutation) SetOwnerID(id int) {
|
||||
m.owner = &id
|
||||
}
|
||||
|
||||
// ClearOwner clears the "owner" edge to the User entity.
|
||||
func (m *Mutation) ClearOwner() {
|
||||
m.clearedowner = true
|
||||
}
|
||||
|
||||
// OwnerCleared reports if the "owner" edge to the User entity was cleared.
|
||||
func (m *Mutation) OwnerCleared() bool {
|
||||
return m.clearedowner
|
||||
}
|
||||
|
||||
// OwnerID returns the "owner" edge ID in the mutation.
|
||||
func (m *Mutation) OwnerID() (id int, exists bool) {
|
||||
if m.owner != nil {
|
||||
return *m.owner, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OwnerIDs returns the "owner" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// OwnerID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) OwnerIDs() (ids []int) {
|
||||
if id := m.owner; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetOwner resets all changes to the "owner" edge.
|
||||
func (m *Mutation) ResetOwner() {
|
||||
m.owner = nil
|
||||
m.clearedowner = false
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.Car) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the Mutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *Mutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.Car, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *Mutation) Op() ent.Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *Mutation) SetOp(op ent.Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (Car).
|
||||
func (m *Mutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *Mutation) Fields() []string {
|
||||
fields := make([]string, 0, 0)
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *Mutation) Field(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *Mutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("unknown Car field %s", name)
|
||||
}
|
||||
|
||||
// SetField sets the value of a field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *Mutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
}
|
||||
return fmt.Errorf("unknown Car field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *Mutation) AddedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||
// with the given name. The second boolean return value indicates that this field
|
||||
// was not set, or was not defined in the schema.
|
||||
func (m *Mutation) AddedField(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// AddField adds the value to the field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *Mutation) AddField(name string, value ent.Value) error {
|
||||
return fmt.Errorf("unknown Car numeric field %s", name)
|
||||
}
|
||||
|
||||
// ClearedFields returns all nullable fields that were cleared during this
|
||||
// mutation.
|
||||
func (m *Mutation) ClearedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
// cleared in this mutation.
|
||||
func (m *Mutation) FieldCleared(name string) bool {
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *Mutation) ClearField(name string) error {
|
||||
return fmt.Errorf("unknown Car nullable field %s", name)
|
||||
}
|
||||
|
||||
// ResetField resets all changes in the mutation for the field with the given name.
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *Mutation) ResetField(name string) error {
|
||||
return fmt.Errorf("unknown Car field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *Mutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
if m.owner != nil {
|
||||
edges = append(edges, EdgeOwner)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *Mutation) AddedIDs(name string) []ent.Value {
|
||||
switch name {
|
||||
case EdgeOwner:
|
||||
if id := m.owner; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *Mutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *Mutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *Mutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
if m.clearedowner {
|
||||
edges = append(edges, EdgeOwner)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *Mutation) EdgeCleared(name string) bool {
|
||||
switch name {
|
||||
case EdgeOwner:
|
||||
return m.clearedowner
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *Mutation) ClearEdge(name string) error {
|
||||
switch name {
|
||||
case EdgeOwner:
|
||||
m.ClearOwner()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Car unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *Mutation) ResetEdge(name string) error {
|
||||
switch name {
|
||||
case EdgeOwner:
|
||||
m.ResetOwner()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Car edge %s", name)
|
||||
}
|
||||
96
entc/integration/migrate/entv1/car/where.go
Normal file
96
entc/integration/migrate/entv1/car/where.go
Normal file
@@ -0,0 +1,96 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package car
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Car {
|
||||
return predicate.Car(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Car {
|
||||
return predicate.Car(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Car {
|
||||
return predicate.Car(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Car {
|
||||
return predicate.Car(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Car {
|
||||
return predicate.Car(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Car {
|
||||
return predicate.Car(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Car {
|
||||
return predicate.Car(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Car {
|
||||
return predicate.Car(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Car {
|
||||
return predicate.Car(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// HasOwner applies the HasEdge predicate on the "owner" edge.
|
||||
func HasOwner() predicate.Car {
|
||||
return predicate.Car(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, OwnerTable, OwnerColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasOwnerWith applies the HasEdge predicate on the "owner" edge with a given conditions (other predicates).
|
||||
func HasOwnerWith(preds ...predicate.User) predicate.Car {
|
||||
return predicate.Car(func(s *sql.Selector) {
|
||||
step := newOwnerStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Car) predicate.Car {
|
||||
return predicate.Car(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Car) predicate.Car {
|
||||
return predicate.Car(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Car) predicate.Car {
|
||||
return predicate.Car(sql.NotPredicates(p))
|
||||
}
|
||||
210
entc/integration/migrate/entv1/car_create.go
Normal file
210
entc/integration/migrate/entv1/car_create.go
Normal file
@@ -0,0 +1,210 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CarCreate is the builder for creating a Car entity.
|
||||
type CarCreate struct {
|
||||
config
|
||||
mutation *CarMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner" edge to the User entity by ID.
|
||||
func (_c *CarCreate) SetOwnerID(id int) *CarCreate {
|
||||
_c.mutation.SetOwnerID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableOwnerID sets the "owner" edge to the User entity by ID if the given value is not nil.
|
||||
func (_c *CarCreate) SetNillableOwnerID(id *int) *CarCreate {
|
||||
if id != nil {
|
||||
_c = _c.SetOwnerID(*id)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" edge to the User entity.
|
||||
func (_c *CarCreate) SetOwner(v *User) *CarCreate {
|
||||
return _c.SetOwnerID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CarMutation object of the builder.
|
||||
func (_c *CarCreate) Mutation() *CarMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Car in the database.
|
||||
func (_c *CarCreate) Save(ctx context.Context) (*Car, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *CarCreate) SaveX(ctx context.Context) *Car {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *CarCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *CarCreate) 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 (_c *CarCreate) check() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *CarCreate) sqlSave(ctx context.Context) (*Car, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_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}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *CarCreate) createSpec() (*Car, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Car{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(car.Table, sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt))
|
||||
)
|
||||
if nodes := _c.mutation.OwnerIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: car.OwnerTable,
|
||||
Columns: []string{car.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.user_car = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// CarCreateBulk is the builder for creating many Car entities in bulk.
|
||||
type CarCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*CarCreate
|
||||
}
|
||||
|
||||
// Save creates the Car entities in the database.
|
||||
func (_c *CarCreateBulk) Save(ctx context.Context) ([]*Car, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Car, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*CarMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, 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, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *CarCreateBulk) SaveX(ctx context.Context) []*Car {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *CarCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *CarCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/migrate/entv1/car_delete.go
Normal file
92
entc/integration/migrate/entv1/car_delete.go
Normal file
@@ -0,0 +1,92 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CarDelete is the builder for deleting a Car entity.
|
||||
type CarDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CarMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CarDelete builder.
|
||||
func (_d *CarDelete) Where(ps ...predicate.Car) *CarDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *CarDelete) 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 (_d *CarDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *CarDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(car.Table, sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt))
|
||||
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, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// CarDeleteOne is the builder for deleting a single Car entity.
|
||||
type CarDeleteOne struct {
|
||||
_d *CarDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CarDelete builder.
|
||||
func (_d *CarDeleteOne) Where(ps ...predicate.Car) *CarDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *CarDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{car.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *CarDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
596
entc/integration/migrate/entv1/car_query.go
Normal file
596
entc/integration/migrate/entv1/car_query.go
Normal file
@@ -0,0 +1,596 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CarQuery is the builder for querying Car entities.
|
||||
type CarQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []car.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Car
|
||||
withOwner *UserQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the CarQuery builder.
|
||||
func (_q *CarQuery) Where(ps ...predicate.Car) *CarQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *CarQuery) Limit(limit int) *CarQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *CarQuery) Offset(offset int) *CarQuery {
|
||||
_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 (_q *CarQuery) Unique(unique bool) *CarQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *CarQuery) Order(o ...car.OrderOption) *CarQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryOwner chains the current query on the "owner" edge.
|
||||
func (_q *CarQuery) QueryOwner() *UserQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(car.Table, car.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, car.OwnerTable, car.OwnerColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Car entity from the query.
|
||||
// Returns a *NotFoundError when no Car was found.
|
||||
func (_q *CarQuery) First(ctx context.Context) (*Car, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{car.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *CarQuery) FirstX(ctx context.Context) *Car {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Car ID from the query.
|
||||
// Returns a *NotFoundError when no Car ID was found.
|
||||
func (_q *CarQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{car.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *CarQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Car entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Car entity is found.
|
||||
// Returns a *NotFoundError when no Car entities are found.
|
||||
func (_q *CarQuery) Only(ctx context.Context) (*Car, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{car.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{car.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *CarQuery) OnlyX(ctx context.Context) *Car {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Car ID in the query.
|
||||
// Returns a *NotSingularError when more than one Car ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *CarQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{car.Label}
|
||||
default:
|
||||
err = &NotSingularError{car.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *CarQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Cars.
|
||||
func (_q *CarQuery) All(ctx context.Context) ([]*Car, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Car, *CarQuery]()
|
||||
return withInterceptors[[]*Car](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *CarQuery) AllX(ctx context.Context) []*Car {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Car IDs.
|
||||
func (_q *CarQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(car.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *CarQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *CarQuery) 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, _q, querierCount[*CarQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *CarQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *CarQuery) 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:
|
||||
return false, fmt.Errorf("entv1: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *CarQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the CarQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *CarQuery) Clone() *CarQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &CarQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]car.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Car{}, _q.predicates...),
|
||||
withOwner: _q.withOwner.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithOwner tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "owner" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *CarQuery) WithOwner(opts ...func(*UserQuery)) *CarQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withOwner = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
func (_q *CarQuery) GroupBy(field string, fields ...string) *CarGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &CarGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = car.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
func (_q *CarQuery) Select(fields ...string) *CarSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &CarSelect{CarQuery: _q}
|
||||
sbuild.label = car.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a CarSelect configured with the given aggregations.
|
||||
func (_q *CarQuery) Aggregate(fns ...AggregateFunc) *CarSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *CarQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("entv1: uninitialized interceptor (forgotten import entv1/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !car.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("entv1: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *CarQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Car, error) {
|
||||
var (
|
||||
nodes = []*Car{}
|
||||
withFKs = _q.withFKs
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
_q.withOwner != nil,
|
||||
}
|
||||
)
|
||||
if _q.withOwner != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, car.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Car).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Car{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := _q.withOwner; query != nil {
|
||||
if err := _q.loadOwner(ctx, query, nodes, nil,
|
||||
func(n *Car, e *User) { n.Edges.Owner = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *CarQuery) loadOwner(ctx context.Context, query *UserQuery, nodes []*Car, init func(*Car), assign func(*Car, *User)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Car)
|
||||
for i := range nodes {
|
||||
if nodes[i].user_car == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].user_car
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "user_car" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *CarQuery) 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, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *CarQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(car.Table, car.Columns, sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, car.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != car.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *CarQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(car.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = car.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
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 := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// CarGroupBy is the group-by builder for Car entities.
|
||||
type CarGroupBy struct {
|
||||
selector
|
||||
build *CarQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *CarGroupBy) Aggregate(fns ...AggregateFunc) *CarGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *CarGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*CarQuery, *CarGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *CarGroupBy) sqlScan(ctx context.Context, root *CarQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// CarSelect is the builder for selecting fields of Car entities.
|
||||
type CarSelect struct {
|
||||
*CarQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *CarSelect) Aggregate(fns ...AggregateFunc) *CarSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *CarSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*CarQuery, *CarSelect](ctx, _s.CarQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *CarSelect) sqlScan(ctx context.Context, root *CarQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
288
entc/integration/migrate/entv1/car_update.go
Normal file
288
entc/integration/migrate/entv1/car_update.go
Normal file
@@ -0,0 +1,288 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CarUpdate is the builder for updating Car entities.
|
||||
type CarUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CarMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CarUpdate builder.
|
||||
func (_u *CarUpdate) Where(ps ...predicate.Car) *CarUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner" edge to the User entity by ID.
|
||||
func (_u *CarUpdate) SetOwnerID(id int) *CarUpdate {
|
||||
_u.mutation.SetOwnerID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableOwnerID sets the "owner" edge to the User entity by ID if the given value is not nil.
|
||||
func (_u *CarUpdate) SetNillableOwnerID(id *int) *CarUpdate {
|
||||
if id != nil {
|
||||
_u = _u.SetOwnerID(*id)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" edge to the User entity.
|
||||
func (_u *CarUpdate) SetOwner(v *User) *CarUpdate {
|
||||
return _u.SetOwnerID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CarMutation object of the builder.
|
||||
func (_u *CarUpdate) Mutation() *CarMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearOwner clears the "owner" edge to the User entity.
|
||||
func (_u *CarUpdate) ClearOwner() *CarUpdate {
|
||||
_u.mutation.ClearOwner()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *CarUpdate) 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 (_u *CarUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *CarUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *CarUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *CarUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(car.Table, car.Columns, sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if _u.mutation.OwnerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: car.OwnerTable,
|
||||
Columns: []string{car.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.OwnerIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: car.OwnerTable,
|
||||
Columns: []string{car.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{car.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// CarUpdateOne is the builder for updating a single Car entity.
|
||||
type CarUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *CarMutation
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner" edge to the User entity by ID.
|
||||
func (_u *CarUpdateOne) SetOwnerID(id int) *CarUpdateOne {
|
||||
_u.mutation.SetOwnerID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableOwnerID sets the "owner" edge to the User entity by ID if the given value is not nil.
|
||||
func (_u *CarUpdateOne) SetNillableOwnerID(id *int) *CarUpdateOne {
|
||||
if id != nil {
|
||||
_u = _u.SetOwnerID(*id)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" edge to the User entity.
|
||||
func (_u *CarUpdateOne) SetOwner(v *User) *CarUpdateOne {
|
||||
return _u.SetOwnerID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CarMutation object of the builder.
|
||||
func (_u *CarUpdateOne) Mutation() *CarMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearOwner clears the "owner" edge to the User entity.
|
||||
func (_u *CarUpdateOne) ClearOwner() *CarUpdateOne {
|
||||
_u.mutation.ClearOwner()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CarUpdate builder.
|
||||
func (_u *CarUpdateOne) Where(ps ...predicate.Car) *CarUpdateOne {
|
||||
_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 (_u *CarUpdateOne) Select(field string, fields ...string) *CarUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Car entity.
|
||||
func (_u *CarUpdateOne) Save(ctx context.Context) (*Car, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *CarUpdateOne) SaveX(ctx context.Context) *Car {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *CarUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *CarUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *CarUpdateOne) sqlSave(ctx context.Context) (_node *Car, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(car.Table, car.Columns, sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`entv1: missing "Car.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, car.FieldID)
|
||||
for _, f := range fields {
|
||||
if !car.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("entv1: invalid field %q for query", f)}
|
||||
}
|
||||
if f != car.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if _u.mutation.OwnerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: car.OwnerTable,
|
||||
Columns: []string{car.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.OwnerIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: car.OwnerTable,
|
||||
Columns: []string{car.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Car{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{car.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
854
entc/integration/migrate/entv1/client.go
Normal file
854
entc/integration/migrate/entv1/client.go
Normal file
@@ -0,0 +1,854 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/migrate"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/conversion"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/customtype"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/user"
|
||||
)
|
||||
|
||||
// Client is the client that holds all ent builders.
|
||||
type Client struct {
|
||||
config
|
||||
// Schema is the client for creating, migrating and dropping schema.
|
||||
Schema *migrate.Schema
|
||||
// Car is the client for interacting with the Car builders.
|
||||
Car *CarClient
|
||||
// Conversion is the client for interacting with the Conversion builders.
|
||||
Conversion *ConversionClient
|
||||
// CustomType is the client for interacting with the CustomType builders.
|
||||
CustomType *CustomTypeClient
|
||||
// User is the client for interacting with the User builders.
|
||||
User *UserClient
|
||||
}
|
||||
|
||||
// NewClient creates a new client configured with the given options.
|
||||
func NewClient(opts ...Option) *Client {
|
||||
client := &Client{config: newConfig(opts...)}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.Car = NewCarClient(c.config)
|
||||
c.Conversion = NewConversionClient(c.config)
|
||||
c.CustomType = NewCustomTypeClient(c.config)
|
||||
c.User = NewUserClient(c.config)
|
||||
}
|
||||
|
||||
type (
|
||||
// config is the configuration for the client and its builder.
|
||||
config struct {
|
||||
// driver used for executing database requests.
|
||||
driver dialect.Driver
|
||||
// debug enable a debug logging.
|
||||
debug bool
|
||||
// log used for logging on debug mode.
|
||||
log func(...any)
|
||||
// hooks to execute on mutations.
|
||||
hooks *hooks
|
||||
// interceptors to execute on queries.
|
||||
inters *inters
|
||||
}
|
||||
// Option function to configure the client.
|
||||
Option func(*config)
|
||||
)
|
||||
|
||||
// newConfig creates a new config for the client.
|
||||
func newConfig(opts ...Option) config {
|
||||
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
|
||||
cfg.options(opts...)
|
||||
return cfg
|
||||
}
|
||||
|
||||
// options applies the options on the config object.
|
||||
func (c *config) options(opts ...Option) {
|
||||
for _, opt := range opts {
|
||||
opt(c)
|
||||
}
|
||||
if c.debug {
|
||||
c.driver = dialect.Debug(c.driver, c.log)
|
||||
}
|
||||
}
|
||||
|
||||
// Debug enables debug logging on the ent.Driver.
|
||||
func Debug() Option {
|
||||
return func(c *config) {
|
||||
c.debug = true
|
||||
}
|
||||
}
|
||||
|
||||
// Log sets the logging function for debug mode.
|
||||
func Log(fn func(...any)) Option {
|
||||
return func(c *config) {
|
||||
c.log = fn
|
||||
}
|
||||
}
|
||||
|
||||
// Driver configures the client driver.
|
||||
func Driver(driver dialect.Driver) Option {
|
||||
return func(c *config) {
|
||||
c.driver = driver
|
||||
}
|
||||
}
|
||||
|
||||
// Open opens a database/sql.DB specified by the driver name and
|
||||
// the data source name, and returns a new client attached to it.
|
||||
// Optional parameters can be added for configuring the client.
|
||||
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
|
||||
switch driverName {
|
||||
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
|
||||
drv, err := sql.Open(driverName, dataSourceName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewClient(append(options, Driver(drv))...), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported driver: %q", driverName)
|
||||
}
|
||||
}
|
||||
|
||||
// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
|
||||
var ErrTxStarted = errors.New("entv1: cannot start a transaction within a transaction")
|
||||
|
||||
// Tx returns a new transactional client. The provided context
|
||||
// is used until the transaction is committed or rolled back.
|
||||
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
if _, ok := c.driver.(*txDriver); ok {
|
||||
return nil, ErrTxStarted
|
||||
}
|
||||
tx, err := newTx(ctx, c.driver)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("entv1: starting a transaction: %w", err)
|
||||
}
|
||||
cfg := c.config
|
||||
cfg.driver = tx
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Car: NewCarClient(cfg),
|
||||
Conversion: NewConversionClient(cfg),
|
||||
CustomType: NewCustomTypeClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// BeginTx returns a transactional client with specified options.
|
||||
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
|
||||
if _, ok := c.driver.(*txDriver); ok {
|
||||
return nil, errors.New("ent: cannot start a transaction within a transaction")
|
||||
}
|
||||
tx, err := c.driver.(interface {
|
||||
BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
|
||||
}).BeginTx(ctx, opts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
|
||||
}
|
||||
cfg := c.config
|
||||
cfg.driver = &txDriver{tx: tx, drv: c.driver}
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Car: NewCarClient(cfg),
|
||||
Conversion: NewConversionClient(cfg),
|
||||
CustomType: NewCustomTypeClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// Car.
|
||||
// Query().
|
||||
// Count(ctx)
|
||||
func (c *Client) Debug() *Client {
|
||||
if c.debug {
|
||||
return c
|
||||
}
|
||||
cfg := c.config
|
||||
cfg.driver = dialect.Debug(c.driver, c.log)
|
||||
client := &Client{config: cfg}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
// Close closes the database connection and prevents new queries from starting.
|
||||
func (c *Client) Close() error {
|
||||
return c.driver.Close()
|
||||
}
|
||||
|
||||
// Use adds the mutation hooks to all the entity clients.
|
||||
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||
func (c *Client) Use(hooks ...Hook) {
|
||||
c.Car.Use(hooks...)
|
||||
c.Conversion.Use(hooks...)
|
||||
c.CustomType.Use(hooks...)
|
||||
c.User.Use(hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds the query interceptors to all the entity clients.
|
||||
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
c.Car.Intercept(interceptors...)
|
||||
c.Conversion.Intercept(interceptors...)
|
||||
c.CustomType.Intercept(interceptors...)
|
||||
c.User.Intercept(interceptors...)
|
||||
}
|
||||
|
||||
// Mutate implements the ent.Mutator interface.
|
||||
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
switch m := m.(type) {
|
||||
case *CarMutation:
|
||||
return c.Car.mutate(ctx, m)
|
||||
case *ConversionMutation:
|
||||
return c.Conversion.mutate(ctx, m)
|
||||
case *CustomTypeMutation:
|
||||
return c.CustomType.mutate(ctx, m)
|
||||
case *UserMutation:
|
||||
return c.User.mutate(ctx, m)
|
||||
default:
|
||||
return nil, fmt.Errorf("entv1: unknown mutation type %T", m)
|
||||
}
|
||||
}
|
||||
|
||||
// CarClient is a client for the Car schema.
|
||||
type CarClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewCarClient returns a client for the Car from the given config.
|
||||
func NewCarClient(c config) *CarClient {
|
||||
return &CarClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `car.Hooks(f(g(h())))`.
|
||||
func (c *CarClient) Use(hooks ...Hook) {
|
||||
c.hooks.Car = append(c.hooks.Car, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `car.Intercept(f(g(h())))`.
|
||||
func (c *CarClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Car = append(c.inters.Car, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Car entity.
|
||||
func (c *CarClient) Create() *CarCreate {
|
||||
mutation := newCarMutation(c.config, OpCreate)
|
||||
return &CarCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Car entities.
|
||||
func (c *CarClient) CreateBulk(builders ...*CarCreate) *CarCreateBulk {
|
||||
return &CarCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *CarClient) MapCreateBulk(slice any, setFunc func(*CarCreate, int)) *CarCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &CarCreateBulk{err: fmt.Errorf("calling to CarClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*CarCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &CarCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Car.
|
||||
func (c *CarClient) Update() *CarUpdate {
|
||||
mutation := newCarMutation(c.config, OpUpdate)
|
||||
return &CarUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *CarClient) UpdateOne(_m *Car) *CarUpdateOne {
|
||||
mutation := newCarMutation(c.config, OpUpdateOne, withCar(_m))
|
||||
return &CarUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *CarClient) UpdateOneID(id int) *CarUpdateOne {
|
||||
mutation := newCarMutation(c.config, OpUpdateOne, withCarID(id))
|
||||
return &CarUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Car.
|
||||
func (c *CarClient) Delete() *CarDelete {
|
||||
mutation := newCarMutation(c.config, OpDelete)
|
||||
return &CarDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *CarClient) DeleteOne(_m *Car) *CarDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *CarClient) DeleteOneID(id int) *CarDeleteOne {
|
||||
builder := c.Delete().Where(car.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.SetOp(OpDeleteOne)
|
||||
return &CarDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Car.
|
||||
func (c *CarClient) Query() *CarQuery {
|
||||
return &CarQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeCar},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Car entity by its id.
|
||||
func (c *CarClient) Get(ctx context.Context, id int) (*Car, error) {
|
||||
return c.Query().Where(car.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *CarClient) GetX(ctx context.Context, id int) *Car {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryOwner queries the owner edge of a Car.
|
||||
func (c *CarClient) QueryOwner(_m *Car) *UserQuery {
|
||||
query := (&UserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(car.Table, car.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, car.OwnerTable, car.OwnerColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *CarClient) Hooks() []Hook {
|
||||
return c.hooks.Car
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *CarClient) Interceptors() []Interceptor {
|
||||
return c.inters.Car
|
||||
}
|
||||
|
||||
func (c *CarClient) mutate(ctx context.Context, m *CarMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&CarCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&CarUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&CarUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&CarDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("entv1: unknown Car mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// ConversionClient is a client for the Conversion schema.
|
||||
type ConversionClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewConversionClient returns a client for the Conversion from the given config.
|
||||
func NewConversionClient(c config) *ConversionClient {
|
||||
return &ConversionClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `conversion.Hooks(f(g(h())))`.
|
||||
func (c *ConversionClient) Use(hooks ...Hook) {
|
||||
c.hooks.Conversion = append(c.hooks.Conversion, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `conversion.Intercept(f(g(h())))`.
|
||||
func (c *ConversionClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Conversion = append(c.inters.Conversion, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Conversion entity.
|
||||
func (c *ConversionClient) Create() *ConversionCreate {
|
||||
mutation := newConversionMutation(c.config, OpCreate)
|
||||
return &ConversionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Conversion entities.
|
||||
func (c *ConversionClient) CreateBulk(builders ...*ConversionCreate) *ConversionCreateBulk {
|
||||
return &ConversionCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *ConversionClient) MapCreateBulk(slice any, setFunc func(*ConversionCreate, int)) *ConversionCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &ConversionCreateBulk{err: fmt.Errorf("calling to ConversionClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*ConversionCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &ConversionCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Conversion.
|
||||
func (c *ConversionClient) Update() *ConversionUpdate {
|
||||
mutation := newConversionMutation(c.config, OpUpdate)
|
||||
return &ConversionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *ConversionClient) UpdateOne(_m *Conversion) *ConversionUpdateOne {
|
||||
mutation := newConversionMutation(c.config, OpUpdateOne, withConversion(_m))
|
||||
return &ConversionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *ConversionClient) UpdateOneID(id int) *ConversionUpdateOne {
|
||||
mutation := newConversionMutation(c.config, OpUpdateOne, withConversionID(id))
|
||||
return &ConversionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Conversion.
|
||||
func (c *ConversionClient) Delete() *ConversionDelete {
|
||||
mutation := newConversionMutation(c.config, OpDelete)
|
||||
return &ConversionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *ConversionClient) DeleteOne(_m *Conversion) *ConversionDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *ConversionClient) DeleteOneID(id int) *ConversionDeleteOne {
|
||||
builder := c.Delete().Where(conversion.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.SetOp(OpDeleteOne)
|
||||
return &ConversionDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Conversion.
|
||||
func (c *ConversionClient) Query() *ConversionQuery {
|
||||
return &ConversionQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeConversion},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Conversion entity by its id.
|
||||
func (c *ConversionClient) Get(ctx context.Context, id int) (*Conversion, error) {
|
||||
return c.Query().Where(conversion.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *ConversionClient) GetX(ctx context.Context, id int) *Conversion {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *ConversionClient) Hooks() []Hook {
|
||||
return c.hooks.Conversion
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *ConversionClient) Interceptors() []Interceptor {
|
||||
return c.inters.Conversion
|
||||
}
|
||||
|
||||
func (c *ConversionClient) mutate(ctx context.Context, m *ConversionMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&ConversionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&ConversionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&ConversionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&ConversionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("entv1: unknown Conversion mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// CustomTypeClient is a client for the CustomType schema.
|
||||
type CustomTypeClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewCustomTypeClient returns a client for the CustomType from the given config.
|
||||
func NewCustomTypeClient(c config) *CustomTypeClient {
|
||||
return &CustomTypeClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `customtype.Hooks(f(g(h())))`.
|
||||
func (c *CustomTypeClient) Use(hooks ...Hook) {
|
||||
c.hooks.CustomType = append(c.hooks.CustomType, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `customtype.Intercept(f(g(h())))`.
|
||||
func (c *CustomTypeClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.CustomType = append(c.inters.CustomType, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a CustomType entity.
|
||||
func (c *CustomTypeClient) Create() *CustomTypeCreate {
|
||||
mutation := newCustomTypeMutation(c.config, OpCreate)
|
||||
return &CustomTypeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of CustomType entities.
|
||||
func (c *CustomTypeClient) CreateBulk(builders ...*CustomTypeCreate) *CustomTypeCreateBulk {
|
||||
return &CustomTypeCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *CustomTypeClient) MapCreateBulk(slice any, setFunc func(*CustomTypeCreate, int)) *CustomTypeCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &CustomTypeCreateBulk{err: fmt.Errorf("calling to CustomTypeClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*CustomTypeCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &CustomTypeCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for CustomType.
|
||||
func (c *CustomTypeClient) Update() *CustomTypeUpdate {
|
||||
mutation := newCustomTypeMutation(c.config, OpUpdate)
|
||||
return &CustomTypeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *CustomTypeClient) UpdateOne(_m *CustomType) *CustomTypeUpdateOne {
|
||||
mutation := newCustomTypeMutation(c.config, OpUpdateOne, withCustomType(_m))
|
||||
return &CustomTypeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *CustomTypeClient) UpdateOneID(id int) *CustomTypeUpdateOne {
|
||||
mutation := newCustomTypeMutation(c.config, OpUpdateOne, withCustomTypeID(id))
|
||||
return &CustomTypeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for CustomType.
|
||||
func (c *CustomTypeClient) Delete() *CustomTypeDelete {
|
||||
mutation := newCustomTypeMutation(c.config, OpDelete)
|
||||
return &CustomTypeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *CustomTypeClient) DeleteOne(_m *CustomType) *CustomTypeDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *CustomTypeClient) DeleteOneID(id int) *CustomTypeDeleteOne {
|
||||
builder := c.Delete().Where(customtype.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.SetOp(OpDeleteOne)
|
||||
return &CustomTypeDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for CustomType.
|
||||
func (c *CustomTypeClient) Query() *CustomTypeQuery {
|
||||
return &CustomTypeQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeCustomType},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a CustomType entity by its id.
|
||||
func (c *CustomTypeClient) Get(ctx context.Context, id int) (*CustomType, error) {
|
||||
return c.Query().Where(customtype.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *CustomTypeClient) GetX(ctx context.Context, id int) *CustomType {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *CustomTypeClient) Hooks() []Hook {
|
||||
return c.hooks.CustomType
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *CustomTypeClient) Interceptors() []Interceptor {
|
||||
return c.inters.CustomType
|
||||
}
|
||||
|
||||
func (c *CustomTypeClient) mutate(ctx context.Context, m *CustomTypeMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&CustomTypeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&CustomTypeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&CustomTypeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&CustomTypeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("entv1: unknown CustomType mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// UserClient is a client for the User schema.
|
||||
type UserClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewUserClient returns a client for the User from the given config.
|
||||
func NewUserClient(c config) *UserClient {
|
||||
return &UserClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `user.Hooks(f(g(h())))`.
|
||||
func (c *UserClient) Use(hooks ...Hook) {
|
||||
c.hooks.User = append(c.hooks.User, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `user.Intercept(f(g(h())))`.
|
||||
func (c *UserClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.User = append(c.inters.User, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a User entity.
|
||||
func (c *UserClient) Create() *UserCreate {
|
||||
mutation := newUserMutation(c.config, OpCreate)
|
||||
return &UserCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of User entities.
|
||||
func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk {
|
||||
return &UserCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*UserCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &UserCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for User.
|
||||
func (c *UserClient) Update() *UserUpdate {
|
||||
mutation := newUserMutation(c.config, OpUpdate)
|
||||
return &UserUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *UserClient) UpdateOne(_m *User) *UserUpdateOne {
|
||||
mutation := newUserMutation(c.config, OpUpdateOne, withUser(_m))
|
||||
return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *UserClient) UpdateOneID(id int) *UserUpdateOne {
|
||||
mutation := newUserMutation(c.config, OpUpdateOne, withUserID(id))
|
||||
return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for User.
|
||||
func (c *UserClient) Delete() *UserDelete {
|
||||
mutation := newUserMutation(c.config, OpDelete)
|
||||
return &UserDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *UserClient) DeleteOne(_m *User) *UserDeleteOne {
|
||||
return c.DeleteOneID(_m.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *UserClient) DeleteOneID(id int) *UserDeleteOne {
|
||||
builder := c.Delete().Where(user.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.SetOp(OpDeleteOne)
|
||||
return &UserDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for User.
|
||||
func (c *UserClient) Query() *UserQuery {
|
||||
return &UserQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeUser},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a User entity by its id.
|
||||
func (c *UserClient) Get(ctx context.Context, id int) (*User, error) {
|
||||
return c.Query().Where(user.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *UserClient) GetX(ctx context.Context, id int) *User {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryParent queries the parent edge of a User.
|
||||
func (c *UserClient) QueryParent(_m *User) *UserQuery {
|
||||
query := (&UserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, user.ParentTable, user.ParentColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryChildren queries the children edge of a User.
|
||||
func (c *UserClient) QueryChildren(_m *User) *UserQuery {
|
||||
query := (&UserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.ChildrenTable, user.ChildrenColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QuerySpouse queries the spouse edge of a User.
|
||||
func (c *UserClient) QuerySpouse(_m *User) *UserQuery {
|
||||
query := (&UserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.SpouseTable, user.SpouseColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryCar queries the car edge of a User.
|
||||
func (c *UserClient) QueryCar(_m *User) *CarQuery {
|
||||
query := (&CarClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := _m.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(car.Table, car.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.CarTable, user.CarColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *UserClient) Hooks() []Hook {
|
||||
return c.hooks.User
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *UserClient) Interceptors() []Interceptor {
|
||||
return c.inters.User
|
||||
}
|
||||
|
||||
func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("entv1: unknown User mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
Car, Conversion, CustomType, User []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
Car, Conversion, CustomType, User []ent.Interceptor
|
||||
}
|
||||
)
|
||||
195
entc/integration/migrate/entv1/conversion.go
Normal file
195
entc/integration/migrate/entv1/conversion.go
Normal file
@@ -0,0 +1,195 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/conversion"
|
||||
)
|
||||
|
||||
// Conversion is the model entity for the Conversion schema.
|
||||
type Conversion struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Int8ToString holds the value of the "int8_to_string" field.
|
||||
Int8ToString int8 `json:"int8_to_string,omitempty"`
|
||||
// Uint8ToString holds the value of the "uint8_to_string" field.
|
||||
Uint8ToString uint8 `json:"uint8_to_string,omitempty"`
|
||||
// Int16ToString holds the value of the "int16_to_string" field.
|
||||
Int16ToString int16 `json:"int16_to_string,omitempty"`
|
||||
// Uint16ToString holds the value of the "uint16_to_string" field.
|
||||
Uint16ToString uint16 `json:"uint16_to_string,omitempty"`
|
||||
// Int32ToString holds the value of the "int32_to_string" field.
|
||||
Int32ToString int32 `json:"int32_to_string,omitempty"`
|
||||
// Uint32ToString holds the value of the "uint32_to_string" field.
|
||||
Uint32ToString uint32 `json:"uint32_to_string,omitempty"`
|
||||
// Int64ToString holds the value of the "int64_to_string" field.
|
||||
Int64ToString int64 `json:"int64_to_string,omitempty"`
|
||||
// Uint64ToString holds the value of the "uint64_to_string" field.
|
||||
Uint64ToString uint64 `json:"uint64_to_string,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Conversion) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case conversion.FieldID, conversion.FieldInt8ToString, conversion.FieldUint8ToString, conversion.FieldInt16ToString, conversion.FieldUint16ToString, conversion.FieldInt32ToString, conversion.FieldUint32ToString, conversion.FieldInt64ToString, conversion.FieldUint64ToString:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case conversion.FieldName:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Conversion fields.
|
||||
func (_m *Conversion) 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)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case conversion.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int(value.Int64)
|
||||
case conversion.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Name = value.String
|
||||
}
|
||||
case conversion.FieldInt8ToString:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field int8_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Int8ToString = int8(value.Int64)
|
||||
}
|
||||
case conversion.FieldUint8ToString:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field uint8_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Uint8ToString = uint8(value.Int64)
|
||||
}
|
||||
case conversion.FieldInt16ToString:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field int16_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Int16ToString = int16(value.Int64)
|
||||
}
|
||||
case conversion.FieldUint16ToString:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field uint16_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Uint16ToString = uint16(value.Int64)
|
||||
}
|
||||
case conversion.FieldInt32ToString:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field int32_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Int32ToString = int32(value.Int64)
|
||||
}
|
||||
case conversion.FieldUint32ToString:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field uint32_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Uint32ToString = uint32(value.Int64)
|
||||
}
|
||||
case conversion.FieldInt64ToString:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field int64_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Int64ToString = value.Int64
|
||||
}
|
||||
case conversion.FieldUint64ToString:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field uint64_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Uint64ToString = uint64(value.Int64)
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Conversion.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Conversion) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Conversion.
|
||||
// Note that you need to call Conversion.Unwrap() before calling this method if this Conversion
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Conversion) Update() *ConversionUpdateOne {
|
||||
return NewConversionClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Conversion 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 (_m *Conversion) Unwrap() *Conversion {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("entv1: Conversion is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Conversion) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Conversion(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(_m.Name)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("int8_to_string=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Int8ToString))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("uint8_to_string=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Uint8ToString))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("int16_to_string=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Int16ToString))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("uint16_to_string=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Uint16ToString))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("int32_to_string=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Int32ToString))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("uint32_to_string=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Uint32ToString))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("int64_to_string=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Int64ToString))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("uint64_to_string=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Uint64ToString))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Conversions is a parsable slice of Conversion.
|
||||
type Conversions []*Conversion
|
||||
115
entc/integration/migrate/entv1/conversion/conversion.go
Normal file
115
entc/integration/migrate/entv1/conversion/conversion.go
Normal file
@@ -0,0 +1,115 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package conversion
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the conversion type in the database.
|
||||
Label = "conversion"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// FieldInt8ToString holds the string denoting the int8_to_string field in the database.
|
||||
FieldInt8ToString = "int8_to_string"
|
||||
// FieldUint8ToString holds the string denoting the uint8_to_string field in the database.
|
||||
FieldUint8ToString = "uint8_to_string"
|
||||
// FieldInt16ToString holds the string denoting the int16_to_string field in the database.
|
||||
FieldInt16ToString = "int16_to_string"
|
||||
// FieldUint16ToString holds the string denoting the uint16_to_string field in the database.
|
||||
FieldUint16ToString = "uint16_to_string"
|
||||
// FieldInt32ToString holds the string denoting the int32_to_string field in the database.
|
||||
FieldInt32ToString = "int32_to_string"
|
||||
// FieldUint32ToString holds the string denoting the uint32_to_string field in the database.
|
||||
FieldUint32ToString = "uint32_to_string"
|
||||
// FieldInt64ToString holds the string denoting the int64_to_string field in the database.
|
||||
FieldInt64ToString = "int64_to_string"
|
||||
// FieldUint64ToString holds the string denoting the uint64_to_string field in the database.
|
||||
FieldUint64ToString = "uint64_to_string"
|
||||
// Table holds the table name of the conversion in the database.
|
||||
Table = "conversions"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for conversion fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldName,
|
||||
FieldInt8ToString,
|
||||
FieldUint8ToString,
|
||||
FieldInt16ToString,
|
||||
FieldUint16ToString,
|
||||
FieldInt32ToString,
|
||||
FieldUint32ToString,
|
||||
FieldInt64ToString,
|
||||
FieldUint64ToString,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the Conversion queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByInt8ToString orders the results by the int8_to_string field.
|
||||
func ByInt8ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldInt8ToString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUint8ToString orders the results by the uint8_to_string field.
|
||||
func ByUint8ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUint8ToString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByInt16ToString orders the results by the int16_to_string field.
|
||||
func ByInt16ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldInt16ToString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUint16ToString orders the results by the uint16_to_string field.
|
||||
func ByUint16ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUint16ToString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByInt32ToString orders the results by the int32_to_string field.
|
||||
func ByInt32ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldInt32ToString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUint32ToString orders the results by the uint32_to_string field.
|
||||
func ByUint32ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUint32ToString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByInt64ToString orders the results by the int64_to_string field.
|
||||
func ByInt64ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldInt64ToString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUint64ToString orders the results by the uint64_to_string field.
|
||||
func ByUint64ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUint64ToString, opts...).ToFunc()
|
||||
}
|
||||
962
entc/integration/migrate/entv1/conversion/mutation.go
Normal file
962
entc/integration/migrate/entv1/conversion/mutation.go
Normal file
@@ -0,0 +1,962 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package conversion
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Conversion nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
name *string
|
||||
int8_to_string *int8
|
||||
addint8_to_string *int8
|
||||
uint8_to_string *uint8
|
||||
adduint8_to_string *int8
|
||||
int16_to_string *int16
|
||||
addint16_to_string *int16
|
||||
uint16_to_string *uint16
|
||||
adduint16_to_string *int16
|
||||
int32_to_string *int32
|
||||
addint32_to_string *int32
|
||||
uint32_to_string *uint32
|
||||
adduint32_to_string *int32
|
||||
int64_to_string *int64
|
||||
addint64_to_string *int64
|
||||
uint64_to_string *uint64
|
||||
adduint64_to_string *int64
|
||||
clearedFields map[string]struct{}
|
||||
predicates []predicate.Conversion
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Conversion entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Conversion",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Conversion {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (m *Mutation) SetName(s string) {
|
||||
m.name = &s
|
||||
}
|
||||
|
||||
// Name returns the value of the "name" field in the mutation.
|
||||
func (m *Mutation) Name() (r string, exists bool) {
|
||||
v := m.name
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearName clears the value of the "name" field.
|
||||
func (m *Mutation) ClearName() {
|
||||
m.name = nil
|
||||
m.clearedFields[FieldName] = struct{}{}
|
||||
}
|
||||
|
||||
// NameCleared returns if the "name" field was cleared in this mutation.
|
||||
func (m *Mutation) NameCleared() bool {
|
||||
_, ok := m.clearedFields[FieldName]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetName resets all changes to the "name" field.
|
||||
func (m *Mutation) ResetName() {
|
||||
m.name = nil
|
||||
delete(m.clearedFields, FieldName)
|
||||
}
|
||||
|
||||
// SetInt8ToString sets the "int8_to_string" field.
|
||||
func (m *Mutation) SetInt8ToString(i int8) {
|
||||
m.int8_to_string = &i
|
||||
m.addint8_to_string = nil
|
||||
}
|
||||
|
||||
// Int8ToString returns the value of the "int8_to_string" field in the mutation.
|
||||
func (m *Mutation) Int8ToString() (r int8, exists bool) {
|
||||
v := m.int8_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// AddInt8ToString adds i to the "int8_to_string" field.
|
||||
func (m *Mutation) AddInt8ToString(i int8) {
|
||||
if m.addint8_to_string != nil {
|
||||
*m.addint8_to_string += i
|
||||
} else {
|
||||
m.addint8_to_string = &i
|
||||
}
|
||||
}
|
||||
|
||||
// AddedInt8ToString returns the value that was added to the "int8_to_string" field in this mutation.
|
||||
func (m *Mutation) AddedInt8ToString() (r int8, exists bool) {
|
||||
v := m.addint8_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearInt8ToString clears the value of the "int8_to_string" field.
|
||||
func (m *Mutation) ClearInt8ToString() {
|
||||
m.int8_to_string = nil
|
||||
m.addint8_to_string = nil
|
||||
m.clearedFields[FieldInt8ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Int8ToStringCleared returns if the "int8_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Int8ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldInt8ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetInt8ToString resets all changes to the "int8_to_string" field.
|
||||
func (m *Mutation) ResetInt8ToString() {
|
||||
m.int8_to_string = nil
|
||||
m.addint8_to_string = nil
|
||||
delete(m.clearedFields, FieldInt8ToString)
|
||||
}
|
||||
|
||||
// SetUint8ToString sets the "uint8_to_string" field.
|
||||
func (m *Mutation) SetUint8ToString(u uint8) {
|
||||
m.uint8_to_string = &u
|
||||
m.adduint8_to_string = nil
|
||||
}
|
||||
|
||||
// Uint8ToString returns the value of the "uint8_to_string" field in the mutation.
|
||||
func (m *Mutation) Uint8ToString() (r uint8, exists bool) {
|
||||
v := m.uint8_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// AddUint8ToString adds u to the "uint8_to_string" field.
|
||||
func (m *Mutation) AddUint8ToString(u int8) {
|
||||
if m.adduint8_to_string != nil {
|
||||
*m.adduint8_to_string += u
|
||||
} else {
|
||||
m.adduint8_to_string = &u
|
||||
}
|
||||
}
|
||||
|
||||
// AddedUint8ToString returns the value that was added to the "uint8_to_string" field in this mutation.
|
||||
func (m *Mutation) AddedUint8ToString() (r int8, exists bool) {
|
||||
v := m.adduint8_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearUint8ToString clears the value of the "uint8_to_string" field.
|
||||
func (m *Mutation) ClearUint8ToString() {
|
||||
m.uint8_to_string = nil
|
||||
m.adduint8_to_string = nil
|
||||
m.clearedFields[FieldUint8ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Uint8ToStringCleared returns if the "uint8_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Uint8ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldUint8ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetUint8ToString resets all changes to the "uint8_to_string" field.
|
||||
func (m *Mutation) ResetUint8ToString() {
|
||||
m.uint8_to_string = nil
|
||||
m.adduint8_to_string = nil
|
||||
delete(m.clearedFields, FieldUint8ToString)
|
||||
}
|
||||
|
||||
// SetInt16ToString sets the "int16_to_string" field.
|
||||
func (m *Mutation) SetInt16ToString(i int16) {
|
||||
m.int16_to_string = &i
|
||||
m.addint16_to_string = nil
|
||||
}
|
||||
|
||||
// Int16ToString returns the value of the "int16_to_string" field in the mutation.
|
||||
func (m *Mutation) Int16ToString() (r int16, exists bool) {
|
||||
v := m.int16_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// AddInt16ToString adds i to the "int16_to_string" field.
|
||||
func (m *Mutation) AddInt16ToString(i int16) {
|
||||
if m.addint16_to_string != nil {
|
||||
*m.addint16_to_string += i
|
||||
} else {
|
||||
m.addint16_to_string = &i
|
||||
}
|
||||
}
|
||||
|
||||
// AddedInt16ToString returns the value that was added to the "int16_to_string" field in this mutation.
|
||||
func (m *Mutation) AddedInt16ToString() (r int16, exists bool) {
|
||||
v := m.addint16_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearInt16ToString clears the value of the "int16_to_string" field.
|
||||
func (m *Mutation) ClearInt16ToString() {
|
||||
m.int16_to_string = nil
|
||||
m.addint16_to_string = nil
|
||||
m.clearedFields[FieldInt16ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Int16ToStringCleared returns if the "int16_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Int16ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldInt16ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetInt16ToString resets all changes to the "int16_to_string" field.
|
||||
func (m *Mutation) ResetInt16ToString() {
|
||||
m.int16_to_string = nil
|
||||
m.addint16_to_string = nil
|
||||
delete(m.clearedFields, FieldInt16ToString)
|
||||
}
|
||||
|
||||
// SetUint16ToString sets the "uint16_to_string" field.
|
||||
func (m *Mutation) SetUint16ToString(u uint16) {
|
||||
m.uint16_to_string = &u
|
||||
m.adduint16_to_string = nil
|
||||
}
|
||||
|
||||
// Uint16ToString returns the value of the "uint16_to_string" field in the mutation.
|
||||
func (m *Mutation) Uint16ToString() (r uint16, exists bool) {
|
||||
v := m.uint16_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// AddUint16ToString adds u to the "uint16_to_string" field.
|
||||
func (m *Mutation) AddUint16ToString(u int16) {
|
||||
if m.adduint16_to_string != nil {
|
||||
*m.adduint16_to_string += u
|
||||
} else {
|
||||
m.adduint16_to_string = &u
|
||||
}
|
||||
}
|
||||
|
||||
// AddedUint16ToString returns the value that was added to the "uint16_to_string" field in this mutation.
|
||||
func (m *Mutation) AddedUint16ToString() (r int16, exists bool) {
|
||||
v := m.adduint16_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearUint16ToString clears the value of the "uint16_to_string" field.
|
||||
func (m *Mutation) ClearUint16ToString() {
|
||||
m.uint16_to_string = nil
|
||||
m.adduint16_to_string = nil
|
||||
m.clearedFields[FieldUint16ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Uint16ToStringCleared returns if the "uint16_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Uint16ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldUint16ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetUint16ToString resets all changes to the "uint16_to_string" field.
|
||||
func (m *Mutation) ResetUint16ToString() {
|
||||
m.uint16_to_string = nil
|
||||
m.adduint16_to_string = nil
|
||||
delete(m.clearedFields, FieldUint16ToString)
|
||||
}
|
||||
|
||||
// SetInt32ToString sets the "int32_to_string" field.
|
||||
func (m *Mutation) SetInt32ToString(i int32) {
|
||||
m.int32_to_string = &i
|
||||
m.addint32_to_string = nil
|
||||
}
|
||||
|
||||
// Int32ToString returns the value of the "int32_to_string" field in the mutation.
|
||||
func (m *Mutation) Int32ToString() (r int32, exists bool) {
|
||||
v := m.int32_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// AddInt32ToString adds i to the "int32_to_string" field.
|
||||
func (m *Mutation) AddInt32ToString(i int32) {
|
||||
if m.addint32_to_string != nil {
|
||||
*m.addint32_to_string += i
|
||||
} else {
|
||||
m.addint32_to_string = &i
|
||||
}
|
||||
}
|
||||
|
||||
// AddedInt32ToString returns the value that was added to the "int32_to_string" field in this mutation.
|
||||
func (m *Mutation) AddedInt32ToString() (r int32, exists bool) {
|
||||
v := m.addint32_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearInt32ToString clears the value of the "int32_to_string" field.
|
||||
func (m *Mutation) ClearInt32ToString() {
|
||||
m.int32_to_string = nil
|
||||
m.addint32_to_string = nil
|
||||
m.clearedFields[FieldInt32ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Int32ToStringCleared returns if the "int32_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Int32ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldInt32ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetInt32ToString resets all changes to the "int32_to_string" field.
|
||||
func (m *Mutation) ResetInt32ToString() {
|
||||
m.int32_to_string = nil
|
||||
m.addint32_to_string = nil
|
||||
delete(m.clearedFields, FieldInt32ToString)
|
||||
}
|
||||
|
||||
// SetUint32ToString sets the "uint32_to_string" field.
|
||||
func (m *Mutation) SetUint32ToString(u uint32) {
|
||||
m.uint32_to_string = &u
|
||||
m.adduint32_to_string = nil
|
||||
}
|
||||
|
||||
// Uint32ToString returns the value of the "uint32_to_string" field in the mutation.
|
||||
func (m *Mutation) Uint32ToString() (r uint32, exists bool) {
|
||||
v := m.uint32_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// AddUint32ToString adds u to the "uint32_to_string" field.
|
||||
func (m *Mutation) AddUint32ToString(u int32) {
|
||||
if m.adduint32_to_string != nil {
|
||||
*m.adduint32_to_string += u
|
||||
} else {
|
||||
m.adduint32_to_string = &u
|
||||
}
|
||||
}
|
||||
|
||||
// AddedUint32ToString returns the value that was added to the "uint32_to_string" field in this mutation.
|
||||
func (m *Mutation) AddedUint32ToString() (r int32, exists bool) {
|
||||
v := m.adduint32_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearUint32ToString clears the value of the "uint32_to_string" field.
|
||||
func (m *Mutation) ClearUint32ToString() {
|
||||
m.uint32_to_string = nil
|
||||
m.adduint32_to_string = nil
|
||||
m.clearedFields[FieldUint32ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Uint32ToStringCleared returns if the "uint32_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Uint32ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldUint32ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetUint32ToString resets all changes to the "uint32_to_string" field.
|
||||
func (m *Mutation) ResetUint32ToString() {
|
||||
m.uint32_to_string = nil
|
||||
m.adduint32_to_string = nil
|
||||
delete(m.clearedFields, FieldUint32ToString)
|
||||
}
|
||||
|
||||
// SetInt64ToString sets the "int64_to_string" field.
|
||||
func (m *Mutation) SetInt64ToString(i int64) {
|
||||
m.int64_to_string = &i
|
||||
m.addint64_to_string = nil
|
||||
}
|
||||
|
||||
// Int64ToString returns the value of the "int64_to_string" field in the mutation.
|
||||
func (m *Mutation) Int64ToString() (r int64, exists bool) {
|
||||
v := m.int64_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// AddInt64ToString adds i to the "int64_to_string" field.
|
||||
func (m *Mutation) AddInt64ToString(i int64) {
|
||||
if m.addint64_to_string != nil {
|
||||
*m.addint64_to_string += i
|
||||
} else {
|
||||
m.addint64_to_string = &i
|
||||
}
|
||||
}
|
||||
|
||||
// AddedInt64ToString returns the value that was added to the "int64_to_string" field in this mutation.
|
||||
func (m *Mutation) AddedInt64ToString() (r int64, exists bool) {
|
||||
v := m.addint64_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearInt64ToString clears the value of the "int64_to_string" field.
|
||||
func (m *Mutation) ClearInt64ToString() {
|
||||
m.int64_to_string = nil
|
||||
m.addint64_to_string = nil
|
||||
m.clearedFields[FieldInt64ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Int64ToStringCleared returns if the "int64_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Int64ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldInt64ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetInt64ToString resets all changes to the "int64_to_string" field.
|
||||
func (m *Mutation) ResetInt64ToString() {
|
||||
m.int64_to_string = nil
|
||||
m.addint64_to_string = nil
|
||||
delete(m.clearedFields, FieldInt64ToString)
|
||||
}
|
||||
|
||||
// SetUint64ToString sets the "uint64_to_string" field.
|
||||
func (m *Mutation) SetUint64ToString(u uint64) {
|
||||
m.uint64_to_string = &u
|
||||
m.adduint64_to_string = nil
|
||||
}
|
||||
|
||||
// Uint64ToString returns the value of the "uint64_to_string" field in the mutation.
|
||||
func (m *Mutation) Uint64ToString() (r uint64, exists bool) {
|
||||
v := m.uint64_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// AddUint64ToString adds u to the "uint64_to_string" field.
|
||||
func (m *Mutation) AddUint64ToString(u int64) {
|
||||
if m.adduint64_to_string != nil {
|
||||
*m.adduint64_to_string += u
|
||||
} else {
|
||||
m.adduint64_to_string = &u
|
||||
}
|
||||
}
|
||||
|
||||
// AddedUint64ToString returns the value that was added to the "uint64_to_string" field in this mutation.
|
||||
func (m *Mutation) AddedUint64ToString() (r int64, exists bool) {
|
||||
v := m.adduint64_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearUint64ToString clears the value of the "uint64_to_string" field.
|
||||
func (m *Mutation) ClearUint64ToString() {
|
||||
m.uint64_to_string = nil
|
||||
m.adduint64_to_string = nil
|
||||
m.clearedFields[FieldUint64ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Uint64ToStringCleared returns if the "uint64_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Uint64ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldUint64ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetUint64ToString resets all changes to the "uint64_to_string" field.
|
||||
func (m *Mutation) ResetUint64ToString() {
|
||||
m.uint64_to_string = nil
|
||||
m.adduint64_to_string = nil
|
||||
delete(m.clearedFields, FieldUint64ToString)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.Conversion) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the Mutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *Mutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.Conversion, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *Mutation) Op() ent.Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *Mutation) SetOp(op ent.Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (Conversion).
|
||||
func (m *Mutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *Mutation) Fields() []string {
|
||||
fields := make([]string, 0, 9)
|
||||
if m.name != nil {
|
||||
fields = append(fields, FieldName)
|
||||
}
|
||||
if m.int8_to_string != nil {
|
||||
fields = append(fields, FieldInt8ToString)
|
||||
}
|
||||
if m.uint8_to_string != nil {
|
||||
fields = append(fields, FieldUint8ToString)
|
||||
}
|
||||
if m.int16_to_string != nil {
|
||||
fields = append(fields, FieldInt16ToString)
|
||||
}
|
||||
if m.uint16_to_string != nil {
|
||||
fields = append(fields, FieldUint16ToString)
|
||||
}
|
||||
if m.int32_to_string != nil {
|
||||
fields = append(fields, FieldInt32ToString)
|
||||
}
|
||||
if m.uint32_to_string != nil {
|
||||
fields = append(fields, FieldUint32ToString)
|
||||
}
|
||||
if m.int64_to_string != nil {
|
||||
fields = append(fields, FieldInt64ToString)
|
||||
}
|
||||
if m.uint64_to_string != nil {
|
||||
fields = append(fields, FieldUint64ToString)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *Mutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case FieldName:
|
||||
return m.Name()
|
||||
case FieldInt8ToString:
|
||||
return m.Int8ToString()
|
||||
case FieldUint8ToString:
|
||||
return m.Uint8ToString()
|
||||
case FieldInt16ToString:
|
||||
return m.Int16ToString()
|
||||
case FieldUint16ToString:
|
||||
return m.Uint16ToString()
|
||||
case FieldInt32ToString:
|
||||
return m.Int32ToString()
|
||||
case FieldUint32ToString:
|
||||
return m.Uint32ToString()
|
||||
case FieldInt64ToString:
|
||||
return m.Int64ToString()
|
||||
case FieldUint64ToString:
|
||||
return m.Uint64ToString()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *Mutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("unknown Conversion field %s", name)
|
||||
}
|
||||
|
||||
// SetField sets the value of a field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *Mutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case FieldName:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetName(v)
|
||||
return nil
|
||||
case FieldInt8ToString:
|
||||
v, ok := value.(int8)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetInt8ToString(v)
|
||||
return nil
|
||||
case FieldUint8ToString:
|
||||
v, ok := value.(uint8)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUint8ToString(v)
|
||||
return nil
|
||||
case FieldInt16ToString:
|
||||
v, ok := value.(int16)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetInt16ToString(v)
|
||||
return nil
|
||||
case FieldUint16ToString:
|
||||
v, ok := value.(uint16)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUint16ToString(v)
|
||||
return nil
|
||||
case FieldInt32ToString:
|
||||
v, ok := value.(int32)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetInt32ToString(v)
|
||||
return nil
|
||||
case FieldUint32ToString:
|
||||
v, ok := value.(uint32)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUint32ToString(v)
|
||||
return nil
|
||||
case FieldInt64ToString:
|
||||
v, ok := value.(int64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetInt64ToString(v)
|
||||
return nil
|
||||
case FieldUint64ToString:
|
||||
v, ok := value.(uint64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUint64ToString(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Conversion field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *Mutation) AddedFields() []string {
|
||||
var fields []string
|
||||
if m.addint8_to_string != nil {
|
||||
fields = append(fields, FieldInt8ToString)
|
||||
}
|
||||
if m.adduint8_to_string != nil {
|
||||
fields = append(fields, FieldUint8ToString)
|
||||
}
|
||||
if m.addint16_to_string != nil {
|
||||
fields = append(fields, FieldInt16ToString)
|
||||
}
|
||||
if m.adduint16_to_string != nil {
|
||||
fields = append(fields, FieldUint16ToString)
|
||||
}
|
||||
if m.addint32_to_string != nil {
|
||||
fields = append(fields, FieldInt32ToString)
|
||||
}
|
||||
if m.adduint32_to_string != nil {
|
||||
fields = append(fields, FieldUint32ToString)
|
||||
}
|
||||
if m.addint64_to_string != nil {
|
||||
fields = append(fields, FieldInt64ToString)
|
||||
}
|
||||
if m.adduint64_to_string != nil {
|
||||
fields = append(fields, FieldUint64ToString)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||
// with the given name. The second boolean return value indicates that this field
|
||||
// was not set, or was not defined in the schema.
|
||||
func (m *Mutation) AddedField(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case FieldInt8ToString:
|
||||
return m.AddedInt8ToString()
|
||||
case FieldUint8ToString:
|
||||
return m.AddedUint8ToString()
|
||||
case FieldInt16ToString:
|
||||
return m.AddedInt16ToString()
|
||||
case FieldUint16ToString:
|
||||
return m.AddedUint16ToString()
|
||||
case FieldInt32ToString:
|
||||
return m.AddedInt32ToString()
|
||||
case FieldUint32ToString:
|
||||
return m.AddedUint32ToString()
|
||||
case FieldInt64ToString:
|
||||
return m.AddedInt64ToString()
|
||||
case FieldUint64ToString:
|
||||
return m.AddedUint64ToString()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// AddField adds the value to the field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *Mutation) AddField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case FieldInt8ToString:
|
||||
v, ok := value.(int8)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.AddInt8ToString(v)
|
||||
return nil
|
||||
case FieldUint8ToString:
|
||||
v, ok := value.(int8)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.AddUint8ToString(v)
|
||||
return nil
|
||||
case FieldInt16ToString:
|
||||
v, ok := value.(int16)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.AddInt16ToString(v)
|
||||
return nil
|
||||
case FieldUint16ToString:
|
||||
v, ok := value.(int16)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.AddUint16ToString(v)
|
||||
return nil
|
||||
case FieldInt32ToString:
|
||||
v, ok := value.(int32)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.AddInt32ToString(v)
|
||||
return nil
|
||||
case FieldUint32ToString:
|
||||
v, ok := value.(int32)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.AddUint32ToString(v)
|
||||
return nil
|
||||
case FieldInt64ToString:
|
||||
v, ok := value.(int64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.AddInt64ToString(v)
|
||||
return nil
|
||||
case FieldUint64ToString:
|
||||
v, ok := value.(int64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.AddUint64ToString(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Conversion numeric field %s", name)
|
||||
}
|
||||
|
||||
// ClearedFields returns all nullable fields that were cleared during this
|
||||
// mutation.
|
||||
func (m *Mutation) ClearedFields() []string {
|
||||
var fields []string
|
||||
if m.FieldCleared(FieldName) {
|
||||
fields = append(fields, FieldName)
|
||||
}
|
||||
if m.FieldCleared(FieldInt8ToString) {
|
||||
fields = append(fields, FieldInt8ToString)
|
||||
}
|
||||
if m.FieldCleared(FieldUint8ToString) {
|
||||
fields = append(fields, FieldUint8ToString)
|
||||
}
|
||||
if m.FieldCleared(FieldInt16ToString) {
|
||||
fields = append(fields, FieldInt16ToString)
|
||||
}
|
||||
if m.FieldCleared(FieldUint16ToString) {
|
||||
fields = append(fields, FieldUint16ToString)
|
||||
}
|
||||
if m.FieldCleared(FieldInt32ToString) {
|
||||
fields = append(fields, FieldInt32ToString)
|
||||
}
|
||||
if m.FieldCleared(FieldUint32ToString) {
|
||||
fields = append(fields, FieldUint32ToString)
|
||||
}
|
||||
if m.FieldCleared(FieldInt64ToString) {
|
||||
fields = append(fields, FieldInt64ToString)
|
||||
}
|
||||
if m.FieldCleared(FieldUint64ToString) {
|
||||
fields = append(fields, FieldUint64ToString)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
// cleared in this mutation.
|
||||
func (m *Mutation) FieldCleared(name string) bool {
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *Mutation) ClearField(name string) error {
|
||||
switch name {
|
||||
case FieldName:
|
||||
m.ClearName()
|
||||
return nil
|
||||
case FieldInt8ToString:
|
||||
m.ClearInt8ToString()
|
||||
return nil
|
||||
case FieldUint8ToString:
|
||||
m.ClearUint8ToString()
|
||||
return nil
|
||||
case FieldInt16ToString:
|
||||
m.ClearInt16ToString()
|
||||
return nil
|
||||
case FieldUint16ToString:
|
||||
m.ClearUint16ToString()
|
||||
return nil
|
||||
case FieldInt32ToString:
|
||||
m.ClearInt32ToString()
|
||||
return nil
|
||||
case FieldUint32ToString:
|
||||
m.ClearUint32ToString()
|
||||
return nil
|
||||
case FieldInt64ToString:
|
||||
m.ClearInt64ToString()
|
||||
return nil
|
||||
case FieldUint64ToString:
|
||||
m.ClearUint64ToString()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Conversion nullable field %s", name)
|
||||
}
|
||||
|
||||
// ResetField resets all changes in the mutation for the field with the given name.
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *Mutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case FieldName:
|
||||
m.ResetName()
|
||||
return nil
|
||||
case FieldInt8ToString:
|
||||
m.ResetInt8ToString()
|
||||
return nil
|
||||
case FieldUint8ToString:
|
||||
m.ResetUint8ToString()
|
||||
return nil
|
||||
case FieldInt16ToString:
|
||||
m.ResetInt16ToString()
|
||||
return nil
|
||||
case FieldUint16ToString:
|
||||
m.ResetUint16ToString()
|
||||
return nil
|
||||
case FieldInt32ToString:
|
||||
m.ResetInt32ToString()
|
||||
return nil
|
||||
case FieldUint32ToString:
|
||||
m.ResetUint32ToString()
|
||||
return nil
|
||||
case FieldInt64ToString:
|
||||
m.ResetInt64ToString()
|
||||
return nil
|
||||
case FieldUint64ToString:
|
||||
m.ResetUint64ToString()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Conversion field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *Mutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *Mutation) AddedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *Mutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *Mutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *Mutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *Mutation) EdgeCleared(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *Mutation) ClearEdge(name string) error {
|
||||
return fmt.Errorf("unknown Conversion unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *Mutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown Conversion edge %s", name)
|
||||
}
|
||||
592
entc/integration/migrate/entv1/conversion/where.go
Normal file
592
entc/integration/migrate/entv1/conversion/where.go
Normal file
@@ -0,0 +1,592 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package conversion
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// Int8ToString applies equality check predicate on the "int8_to_string" field. It's identical to Int8ToStringEQ.
|
||||
func Int8ToString(v int8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToString applies equality check predicate on the "uint8_to_string" field. It's identical to Uint8ToStringEQ.
|
||||
func Uint8ToString(v uint8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToString applies equality check predicate on the "int16_to_string" field. It's identical to Int16ToStringEQ.
|
||||
func Int16ToString(v int16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToString applies equality check predicate on the "uint16_to_string" field. It's identical to Uint16ToStringEQ.
|
||||
func Uint16ToString(v uint16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToString applies equality check predicate on the "int32_to_string" field. It's identical to Int32ToStringEQ.
|
||||
func Int32ToString(v int32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToString applies equality check predicate on the "uint32_to_string" field. It's identical to Uint32ToStringEQ.
|
||||
func Uint32ToString(v uint32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToString applies equality check predicate on the "int64_to_string" field. It's identical to Int64ToStringEQ.
|
||||
func Int64ToString(v int64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToString applies equality check predicate on the "uint64_to_string" field. It's identical to Uint64ToStringEQ.
|
||||
func Uint64ToString(v uint64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIsNil applies the IsNil predicate on the "name" field.
|
||||
func NameIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldName))
|
||||
}
|
||||
|
||||
// NameNotNil applies the NotNil predicate on the "name" field.
|
||||
func NameNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldName))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// Int8ToStringEQ applies the EQ predicate on the "int8_to_string" field.
|
||||
func Int8ToStringEQ(v int8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringNEQ applies the NEQ predicate on the "int8_to_string" field.
|
||||
func Int8ToStringNEQ(v int8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringIn applies the In predicate on the "int8_to_string" field.
|
||||
func Int8ToStringIn(vs ...int8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldInt8ToString, vs...))
|
||||
}
|
||||
|
||||
// Int8ToStringNotIn applies the NotIn predicate on the "int8_to_string" field.
|
||||
func Int8ToStringNotIn(vs ...int8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldInt8ToString, vs...))
|
||||
}
|
||||
|
||||
// Int8ToStringGT applies the GT predicate on the "int8_to_string" field.
|
||||
func Int8ToStringGT(v int8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringGTE applies the GTE predicate on the "int8_to_string" field.
|
||||
func Int8ToStringGTE(v int8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringLT applies the LT predicate on the "int8_to_string" field.
|
||||
func Int8ToStringLT(v int8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringLTE applies the LTE predicate on the "int8_to_string" field.
|
||||
func Int8ToStringLTE(v int8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringIsNil applies the IsNil predicate on the "int8_to_string" field.
|
||||
func Int8ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldInt8ToString))
|
||||
}
|
||||
|
||||
// Int8ToStringNotNil applies the NotNil predicate on the "int8_to_string" field.
|
||||
func Int8ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldInt8ToString))
|
||||
}
|
||||
|
||||
// Uint8ToStringEQ applies the EQ predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringEQ(v uint8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringNEQ applies the NEQ predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringNEQ(v uint8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringIn applies the In predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringIn(vs ...uint8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldUint8ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint8ToStringNotIn applies the NotIn predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringNotIn(vs ...uint8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldUint8ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint8ToStringGT applies the GT predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringGT(v uint8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringGTE applies the GTE predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringGTE(v uint8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringLT applies the LT predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringLT(v uint8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringLTE applies the LTE predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringLTE(v uint8) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringIsNil applies the IsNil predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldUint8ToString))
|
||||
}
|
||||
|
||||
// Uint8ToStringNotNil applies the NotNil predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldUint8ToString))
|
||||
}
|
||||
|
||||
// Int16ToStringEQ applies the EQ predicate on the "int16_to_string" field.
|
||||
func Int16ToStringEQ(v int16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringNEQ applies the NEQ predicate on the "int16_to_string" field.
|
||||
func Int16ToStringNEQ(v int16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringIn applies the In predicate on the "int16_to_string" field.
|
||||
func Int16ToStringIn(vs ...int16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldInt16ToString, vs...))
|
||||
}
|
||||
|
||||
// Int16ToStringNotIn applies the NotIn predicate on the "int16_to_string" field.
|
||||
func Int16ToStringNotIn(vs ...int16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldInt16ToString, vs...))
|
||||
}
|
||||
|
||||
// Int16ToStringGT applies the GT predicate on the "int16_to_string" field.
|
||||
func Int16ToStringGT(v int16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringGTE applies the GTE predicate on the "int16_to_string" field.
|
||||
func Int16ToStringGTE(v int16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringLT applies the LT predicate on the "int16_to_string" field.
|
||||
func Int16ToStringLT(v int16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringLTE applies the LTE predicate on the "int16_to_string" field.
|
||||
func Int16ToStringLTE(v int16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringIsNil applies the IsNil predicate on the "int16_to_string" field.
|
||||
func Int16ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldInt16ToString))
|
||||
}
|
||||
|
||||
// Int16ToStringNotNil applies the NotNil predicate on the "int16_to_string" field.
|
||||
func Int16ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldInt16ToString))
|
||||
}
|
||||
|
||||
// Uint16ToStringEQ applies the EQ predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringEQ(v uint16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringNEQ applies the NEQ predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringNEQ(v uint16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringIn applies the In predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringIn(vs ...uint16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldUint16ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint16ToStringNotIn applies the NotIn predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringNotIn(vs ...uint16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldUint16ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint16ToStringGT applies the GT predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringGT(v uint16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringGTE applies the GTE predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringGTE(v uint16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringLT applies the LT predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringLT(v uint16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringLTE applies the LTE predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringLTE(v uint16) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringIsNil applies the IsNil predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldUint16ToString))
|
||||
}
|
||||
|
||||
// Uint16ToStringNotNil applies the NotNil predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldUint16ToString))
|
||||
}
|
||||
|
||||
// Int32ToStringEQ applies the EQ predicate on the "int32_to_string" field.
|
||||
func Int32ToStringEQ(v int32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringNEQ applies the NEQ predicate on the "int32_to_string" field.
|
||||
func Int32ToStringNEQ(v int32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringIn applies the In predicate on the "int32_to_string" field.
|
||||
func Int32ToStringIn(vs ...int32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldInt32ToString, vs...))
|
||||
}
|
||||
|
||||
// Int32ToStringNotIn applies the NotIn predicate on the "int32_to_string" field.
|
||||
func Int32ToStringNotIn(vs ...int32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldInt32ToString, vs...))
|
||||
}
|
||||
|
||||
// Int32ToStringGT applies the GT predicate on the "int32_to_string" field.
|
||||
func Int32ToStringGT(v int32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringGTE applies the GTE predicate on the "int32_to_string" field.
|
||||
func Int32ToStringGTE(v int32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringLT applies the LT predicate on the "int32_to_string" field.
|
||||
func Int32ToStringLT(v int32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringLTE applies the LTE predicate on the "int32_to_string" field.
|
||||
func Int32ToStringLTE(v int32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringIsNil applies the IsNil predicate on the "int32_to_string" field.
|
||||
func Int32ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldInt32ToString))
|
||||
}
|
||||
|
||||
// Int32ToStringNotNil applies the NotNil predicate on the "int32_to_string" field.
|
||||
func Int32ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldInt32ToString))
|
||||
}
|
||||
|
||||
// Uint32ToStringEQ applies the EQ predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringEQ(v uint32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringNEQ applies the NEQ predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringNEQ(v uint32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringIn applies the In predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringIn(vs ...uint32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldUint32ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint32ToStringNotIn applies the NotIn predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringNotIn(vs ...uint32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldUint32ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint32ToStringGT applies the GT predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringGT(v uint32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringGTE applies the GTE predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringGTE(v uint32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringLT applies the LT predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringLT(v uint32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringLTE applies the LTE predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringLTE(v uint32) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringIsNil applies the IsNil predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldUint32ToString))
|
||||
}
|
||||
|
||||
// Uint32ToStringNotNil applies the NotNil predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldUint32ToString))
|
||||
}
|
||||
|
||||
// Int64ToStringEQ applies the EQ predicate on the "int64_to_string" field.
|
||||
func Int64ToStringEQ(v int64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringNEQ applies the NEQ predicate on the "int64_to_string" field.
|
||||
func Int64ToStringNEQ(v int64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringIn applies the In predicate on the "int64_to_string" field.
|
||||
func Int64ToStringIn(vs ...int64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldInt64ToString, vs...))
|
||||
}
|
||||
|
||||
// Int64ToStringNotIn applies the NotIn predicate on the "int64_to_string" field.
|
||||
func Int64ToStringNotIn(vs ...int64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldInt64ToString, vs...))
|
||||
}
|
||||
|
||||
// Int64ToStringGT applies the GT predicate on the "int64_to_string" field.
|
||||
func Int64ToStringGT(v int64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringGTE applies the GTE predicate on the "int64_to_string" field.
|
||||
func Int64ToStringGTE(v int64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringLT applies the LT predicate on the "int64_to_string" field.
|
||||
func Int64ToStringLT(v int64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringLTE applies the LTE predicate on the "int64_to_string" field.
|
||||
func Int64ToStringLTE(v int64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringIsNil applies the IsNil predicate on the "int64_to_string" field.
|
||||
func Int64ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldInt64ToString))
|
||||
}
|
||||
|
||||
// Int64ToStringNotNil applies the NotNil predicate on the "int64_to_string" field.
|
||||
func Int64ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldInt64ToString))
|
||||
}
|
||||
|
||||
// Uint64ToStringEQ applies the EQ predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringEQ(v uint64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringNEQ applies the NEQ predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringNEQ(v uint64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringIn applies the In predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringIn(vs ...uint64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldUint64ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint64ToStringNotIn applies the NotIn predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringNotIn(vs ...uint64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldUint64ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint64ToStringGT applies the GT predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringGT(v uint64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringGTE applies the GTE predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringGTE(v uint64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringLT applies the LT predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringLT(v uint64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringLTE applies the LTE predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringLTE(v uint64) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringIsNil applies the IsNil predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldUint64ToString))
|
||||
}
|
||||
|
||||
// Uint64ToStringNotNil applies the NotNil predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldUint64ToString))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Conversion) predicate.Conversion {
|
||||
return predicate.Conversion(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Conversion) predicate.Conversion {
|
||||
return predicate.Conversion(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Conversion) predicate.Conversion {
|
||||
return predicate.Conversion(sql.NotPredicates(p))
|
||||
}
|
||||
335
entc/integration/migrate/entv1/conversion_create.go
Normal file
335
entc/integration/migrate/entv1/conversion_create.go
Normal file
@@ -0,0 +1,335 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/conversion"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ConversionCreate is the builder for creating a Conversion entity.
|
||||
type ConversionCreate struct {
|
||||
config
|
||||
mutation *ConversionMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *ConversionCreate) SetName(v string) *ConversionCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableName(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetName(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetInt8ToString sets the "int8_to_string" field.
|
||||
func (_c *ConversionCreate) SetInt8ToString(v int8) *ConversionCreate {
|
||||
_c.mutation.SetInt8ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableInt8ToString sets the "int8_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableInt8ToString(v *int8) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetInt8ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUint8ToString sets the "uint8_to_string" field.
|
||||
func (_c *ConversionCreate) SetUint8ToString(v uint8) *ConversionCreate {
|
||||
_c.mutation.SetUint8ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUint8ToString sets the "uint8_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableUint8ToString(v *uint8) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetUint8ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetInt16ToString sets the "int16_to_string" field.
|
||||
func (_c *ConversionCreate) SetInt16ToString(v int16) *ConversionCreate {
|
||||
_c.mutation.SetInt16ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableInt16ToString sets the "int16_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableInt16ToString(v *int16) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetInt16ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUint16ToString sets the "uint16_to_string" field.
|
||||
func (_c *ConversionCreate) SetUint16ToString(v uint16) *ConversionCreate {
|
||||
_c.mutation.SetUint16ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUint16ToString sets the "uint16_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableUint16ToString(v *uint16) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetUint16ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetInt32ToString sets the "int32_to_string" field.
|
||||
func (_c *ConversionCreate) SetInt32ToString(v int32) *ConversionCreate {
|
||||
_c.mutation.SetInt32ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableInt32ToString sets the "int32_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableInt32ToString(v *int32) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetInt32ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUint32ToString sets the "uint32_to_string" field.
|
||||
func (_c *ConversionCreate) SetUint32ToString(v uint32) *ConversionCreate {
|
||||
_c.mutation.SetUint32ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUint32ToString sets the "uint32_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableUint32ToString(v *uint32) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetUint32ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetInt64ToString sets the "int64_to_string" field.
|
||||
func (_c *ConversionCreate) SetInt64ToString(v int64) *ConversionCreate {
|
||||
_c.mutation.SetInt64ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableInt64ToString sets the "int64_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableInt64ToString(v *int64) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetInt64ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUint64ToString sets the "uint64_to_string" field.
|
||||
func (_c *ConversionCreate) SetUint64ToString(v uint64) *ConversionCreate {
|
||||
_c.mutation.SetUint64ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUint64ToString sets the "uint64_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableUint64ToString(v *uint64) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetUint64ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the ConversionMutation object of the builder.
|
||||
func (_c *ConversionCreate) Mutation() *ConversionMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Conversion in the database.
|
||||
func (_c *ConversionCreate) Save(ctx context.Context) (*Conversion, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *ConversionCreate) SaveX(ctx context.Context) *Conversion {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *ConversionCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *ConversionCreate) 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 (_c *ConversionCreate) check() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *ConversionCreate) sqlSave(ctx context.Context) (*Conversion, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_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}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *ConversionCreate) createSpec() (*Conversion, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Conversion{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(conversion.Table, sqlgraph.NewFieldSpec(conversion.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(conversion.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := _c.mutation.Int8ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt8ToString, field.TypeInt8, value)
|
||||
_node.Int8ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Uint8ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint8ToString, field.TypeUint8, value)
|
||||
_node.Uint8ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Int16ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt16ToString, field.TypeInt16, value)
|
||||
_node.Int16ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Uint16ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint16ToString, field.TypeUint16, value)
|
||||
_node.Uint16ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Int32ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt32ToString, field.TypeInt32, value)
|
||||
_node.Int32ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Uint32ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint32ToString, field.TypeUint32, value)
|
||||
_node.Uint32ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Int64ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt64ToString, field.TypeInt64, value)
|
||||
_node.Int64ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Uint64ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint64ToString, field.TypeUint64, value)
|
||||
_node.Uint64ToString = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// ConversionCreateBulk is the builder for creating many Conversion entities in bulk.
|
||||
type ConversionCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*ConversionCreate
|
||||
}
|
||||
|
||||
// Save creates the Conversion entities in the database.
|
||||
func (_c *ConversionCreateBulk) Save(ctx context.Context) ([]*Conversion, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Conversion, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*ConversionMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, 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, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *ConversionCreateBulk) SaveX(ctx context.Context) []*Conversion {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *ConversionCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *ConversionCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/migrate/entv1/conversion_delete.go
Normal file
92
entc/integration/migrate/entv1/conversion_delete.go
Normal file
@@ -0,0 +1,92 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/conversion"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ConversionDelete is the builder for deleting a Conversion entity.
|
||||
type ConversionDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ConversionMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ConversionDelete builder.
|
||||
func (_d *ConversionDelete) Where(ps ...predicate.Conversion) *ConversionDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *ConversionDelete) 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 (_d *ConversionDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *ConversionDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(conversion.Table, sqlgraph.NewFieldSpec(conversion.FieldID, field.TypeInt))
|
||||
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, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// ConversionDeleteOne is the builder for deleting a single Conversion entity.
|
||||
type ConversionDeleteOne struct {
|
||||
_d *ConversionDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ConversionDelete builder.
|
||||
func (_d *ConversionDeleteOne) Where(ps ...predicate.Conversion) *ConversionDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *ConversionDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{conversion.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *ConversionDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
531
entc/integration/migrate/entv1/conversion_query.go
Normal file
531
entc/integration/migrate/entv1/conversion_query.go
Normal file
@@ -0,0 +1,531 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/conversion"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ConversionQuery is the builder for querying Conversion entities.
|
||||
type ConversionQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []conversion.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Conversion
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the ConversionQuery builder.
|
||||
func (_q *ConversionQuery) Where(ps ...predicate.Conversion) *ConversionQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *ConversionQuery) Limit(limit int) *ConversionQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *ConversionQuery) Offset(offset int) *ConversionQuery {
|
||||
_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 (_q *ConversionQuery) Unique(unique bool) *ConversionQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *ConversionQuery) Order(o ...conversion.OrderOption) *ConversionQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// First returns the first Conversion entity from the query.
|
||||
// Returns a *NotFoundError when no Conversion was found.
|
||||
func (_q *ConversionQuery) First(ctx context.Context) (*Conversion, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{conversion.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) FirstX(ctx context.Context) *Conversion {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Conversion ID from the query.
|
||||
// Returns a *NotFoundError when no Conversion ID was found.
|
||||
func (_q *ConversionQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{conversion.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Conversion entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Conversion entity is found.
|
||||
// Returns a *NotFoundError when no Conversion entities are found.
|
||||
func (_q *ConversionQuery) Only(ctx context.Context) (*Conversion, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{conversion.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{conversion.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) OnlyX(ctx context.Context) *Conversion {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Conversion ID in the query.
|
||||
// Returns a *NotSingularError when more than one Conversion ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *ConversionQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{conversion.Label}
|
||||
default:
|
||||
err = &NotSingularError{conversion.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Conversions.
|
||||
func (_q *ConversionQuery) All(ctx context.Context) ([]*Conversion, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Conversion, *ConversionQuery]()
|
||||
return withInterceptors[[]*Conversion](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) AllX(ctx context.Context) []*Conversion {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Conversion IDs.
|
||||
func (_q *ConversionQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(conversion.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *ConversionQuery) 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, _q, querierCount[*ConversionQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *ConversionQuery) 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:
|
||||
return false, fmt.Errorf("entv1: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the ConversionQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *ConversionQuery) Clone() *ConversionQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &ConversionQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]conversion.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Conversion{}, _q.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Conversion.Query().
|
||||
// GroupBy(conversion.FieldName).
|
||||
// Aggregate(entv1.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *ConversionQuery) GroupBy(field string, fields ...string) *ConversionGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &ConversionGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = conversion.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Conversion.Query().
|
||||
// Select(conversion.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *ConversionQuery) Select(fields ...string) *ConversionSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &ConversionSelect{ConversionQuery: _q}
|
||||
sbuild.label = conversion.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a ConversionSelect configured with the given aggregations.
|
||||
func (_q *ConversionQuery) Aggregate(fns ...AggregateFunc) *ConversionSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *ConversionQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("entv1: uninitialized interceptor (forgotten import entv1/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !conversion.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("entv1: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *ConversionQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Conversion, error) {
|
||||
var (
|
||||
nodes = []*Conversion{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Conversion).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Conversion{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *ConversionQuery) 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, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *ConversionQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(conversion.Table, conversion.Columns, sqlgraph.NewFieldSpec(conversion.FieldID, field.TypeInt))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, conversion.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != conversion.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *ConversionQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(conversion.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = conversion.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
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 := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// ConversionGroupBy is the group-by builder for Conversion entities.
|
||||
type ConversionGroupBy struct {
|
||||
selector
|
||||
build *ConversionQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *ConversionGroupBy) Aggregate(fns ...AggregateFunc) *ConversionGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *ConversionGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*ConversionQuery, *ConversionGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *ConversionGroupBy) sqlScan(ctx context.Context, root *ConversionQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// ConversionSelect is the builder for selecting fields of Conversion entities.
|
||||
type ConversionSelect struct {
|
||||
*ConversionQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *ConversionSelect) Aggregate(fns ...AggregateFunc) *ConversionSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *ConversionSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*ConversionQuery, *ConversionSelect](ctx, _s.ConversionQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *ConversionSelect) sqlScan(ctx context.Context, root *ConversionQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
807
entc/integration/migrate/entv1/conversion_update.go
Normal file
807
entc/integration/migrate/entv1/conversion_update.go
Normal file
@@ -0,0 +1,807 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/conversion"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ConversionUpdate is the builder for updating Conversion entities.
|
||||
type ConversionUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ConversionMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ConversionUpdate builder.
|
||||
func (_u *ConversionUpdate) Where(ps ...predicate.Conversion) *ConversionUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *ConversionUpdate) SetName(v string) *ConversionUpdate {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableName(v *string) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearName clears the value of the "name" field.
|
||||
func (_u *ConversionUpdate) ClearName() *ConversionUpdate {
|
||||
_u.mutation.ClearName()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt8ToString sets the "int8_to_string" field.
|
||||
func (_u *ConversionUpdate) SetInt8ToString(v int8) *ConversionUpdate {
|
||||
_u.mutation.ResetInt8ToString()
|
||||
_u.mutation.SetInt8ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt8ToString sets the "int8_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableInt8ToString(v *int8) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetInt8ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddInt8ToString adds value to the "int8_to_string" field.
|
||||
func (_u *ConversionUpdate) AddInt8ToString(v int8) *ConversionUpdate {
|
||||
_u.mutation.AddInt8ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt8ToString clears the value of the "int8_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearInt8ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearInt8ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint8ToString sets the "uint8_to_string" field.
|
||||
func (_u *ConversionUpdate) SetUint8ToString(v uint8) *ConversionUpdate {
|
||||
_u.mutation.ResetUint8ToString()
|
||||
_u.mutation.SetUint8ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint8ToString sets the "uint8_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableUint8ToString(v *uint8) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetUint8ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddUint8ToString adds value to the "uint8_to_string" field.
|
||||
func (_u *ConversionUpdate) AddUint8ToString(v int8) *ConversionUpdate {
|
||||
_u.mutation.AddUint8ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint8ToString clears the value of the "uint8_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearUint8ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearUint8ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt16ToString sets the "int16_to_string" field.
|
||||
func (_u *ConversionUpdate) SetInt16ToString(v int16) *ConversionUpdate {
|
||||
_u.mutation.ResetInt16ToString()
|
||||
_u.mutation.SetInt16ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt16ToString sets the "int16_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableInt16ToString(v *int16) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetInt16ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddInt16ToString adds value to the "int16_to_string" field.
|
||||
func (_u *ConversionUpdate) AddInt16ToString(v int16) *ConversionUpdate {
|
||||
_u.mutation.AddInt16ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt16ToString clears the value of the "int16_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearInt16ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearInt16ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint16ToString sets the "uint16_to_string" field.
|
||||
func (_u *ConversionUpdate) SetUint16ToString(v uint16) *ConversionUpdate {
|
||||
_u.mutation.ResetUint16ToString()
|
||||
_u.mutation.SetUint16ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint16ToString sets the "uint16_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableUint16ToString(v *uint16) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetUint16ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddUint16ToString adds value to the "uint16_to_string" field.
|
||||
func (_u *ConversionUpdate) AddUint16ToString(v int16) *ConversionUpdate {
|
||||
_u.mutation.AddUint16ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint16ToString clears the value of the "uint16_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearUint16ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearUint16ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt32ToString sets the "int32_to_string" field.
|
||||
func (_u *ConversionUpdate) SetInt32ToString(v int32) *ConversionUpdate {
|
||||
_u.mutation.ResetInt32ToString()
|
||||
_u.mutation.SetInt32ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt32ToString sets the "int32_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableInt32ToString(v *int32) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetInt32ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddInt32ToString adds value to the "int32_to_string" field.
|
||||
func (_u *ConversionUpdate) AddInt32ToString(v int32) *ConversionUpdate {
|
||||
_u.mutation.AddInt32ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt32ToString clears the value of the "int32_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearInt32ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearInt32ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint32ToString sets the "uint32_to_string" field.
|
||||
func (_u *ConversionUpdate) SetUint32ToString(v uint32) *ConversionUpdate {
|
||||
_u.mutation.ResetUint32ToString()
|
||||
_u.mutation.SetUint32ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint32ToString sets the "uint32_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableUint32ToString(v *uint32) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetUint32ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddUint32ToString adds value to the "uint32_to_string" field.
|
||||
func (_u *ConversionUpdate) AddUint32ToString(v int32) *ConversionUpdate {
|
||||
_u.mutation.AddUint32ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint32ToString clears the value of the "uint32_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearUint32ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearUint32ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt64ToString sets the "int64_to_string" field.
|
||||
func (_u *ConversionUpdate) SetInt64ToString(v int64) *ConversionUpdate {
|
||||
_u.mutation.ResetInt64ToString()
|
||||
_u.mutation.SetInt64ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt64ToString sets the "int64_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableInt64ToString(v *int64) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetInt64ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddInt64ToString adds value to the "int64_to_string" field.
|
||||
func (_u *ConversionUpdate) AddInt64ToString(v int64) *ConversionUpdate {
|
||||
_u.mutation.AddInt64ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt64ToString clears the value of the "int64_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearInt64ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearInt64ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint64ToString sets the "uint64_to_string" field.
|
||||
func (_u *ConversionUpdate) SetUint64ToString(v uint64) *ConversionUpdate {
|
||||
_u.mutation.ResetUint64ToString()
|
||||
_u.mutation.SetUint64ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint64ToString sets the "uint64_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableUint64ToString(v *uint64) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetUint64ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddUint64ToString adds value to the "uint64_to_string" field.
|
||||
func (_u *ConversionUpdate) AddUint64ToString(v int64) *ConversionUpdate {
|
||||
_u.mutation.AddUint64ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint64ToString clears the value of the "uint64_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearUint64ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearUint64ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the ConversionMutation object of the builder.
|
||||
func (_u *ConversionUpdate) Mutation() *ConversionMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *ConversionUpdate) 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 (_u *ConversionUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *ConversionUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *ConversionUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *ConversionUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(conversion.Table, conversion.Columns, sqlgraph.NewFieldSpec(conversion.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(conversion.FieldName, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.NameCleared() {
|
||||
_spec.ClearField(conversion.FieldName, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Int8ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt8ToString, field.TypeInt8, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedInt8ToString(); ok {
|
||||
_spec.AddField(conversion.FieldInt8ToString, field.TypeInt8, value)
|
||||
}
|
||||
if _u.mutation.Int8ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt8ToString, field.TypeInt8)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint8ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint8ToString, field.TypeUint8, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedUint8ToString(); ok {
|
||||
_spec.AddField(conversion.FieldUint8ToString, field.TypeUint8, value)
|
||||
}
|
||||
if _u.mutation.Uint8ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint8ToString, field.TypeUint8)
|
||||
}
|
||||
if value, ok := _u.mutation.Int16ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt16ToString, field.TypeInt16, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedInt16ToString(); ok {
|
||||
_spec.AddField(conversion.FieldInt16ToString, field.TypeInt16, value)
|
||||
}
|
||||
if _u.mutation.Int16ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt16ToString, field.TypeInt16)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint16ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint16ToString, field.TypeUint16, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedUint16ToString(); ok {
|
||||
_spec.AddField(conversion.FieldUint16ToString, field.TypeUint16, value)
|
||||
}
|
||||
if _u.mutation.Uint16ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint16ToString, field.TypeUint16)
|
||||
}
|
||||
if value, ok := _u.mutation.Int32ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt32ToString, field.TypeInt32, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedInt32ToString(); ok {
|
||||
_spec.AddField(conversion.FieldInt32ToString, field.TypeInt32, value)
|
||||
}
|
||||
if _u.mutation.Int32ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt32ToString, field.TypeInt32)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint32ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint32ToString, field.TypeUint32, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedUint32ToString(); ok {
|
||||
_spec.AddField(conversion.FieldUint32ToString, field.TypeUint32, value)
|
||||
}
|
||||
if _u.mutation.Uint32ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint32ToString, field.TypeUint32)
|
||||
}
|
||||
if value, ok := _u.mutation.Int64ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt64ToString, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedInt64ToString(); ok {
|
||||
_spec.AddField(conversion.FieldInt64ToString, field.TypeInt64, value)
|
||||
}
|
||||
if _u.mutation.Int64ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt64ToString, field.TypeInt64)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint64ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint64ToString, field.TypeUint64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedUint64ToString(); ok {
|
||||
_spec.AddField(conversion.FieldUint64ToString, field.TypeUint64, value)
|
||||
}
|
||||
if _u.mutation.Uint64ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint64ToString, field.TypeUint64)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{conversion.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// ConversionUpdateOne is the builder for updating a single Conversion entity.
|
||||
type ConversionUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *ConversionMutation
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *ConversionUpdateOne) SetName(v string) *ConversionUpdateOne {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableName(v *string) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearName clears the value of the "name" field.
|
||||
func (_u *ConversionUpdateOne) ClearName() *ConversionUpdateOne {
|
||||
_u.mutation.ClearName()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt8ToString sets the "int8_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetInt8ToString(v int8) *ConversionUpdateOne {
|
||||
_u.mutation.ResetInt8ToString()
|
||||
_u.mutation.SetInt8ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt8ToString sets the "int8_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableInt8ToString(v *int8) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetInt8ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddInt8ToString adds value to the "int8_to_string" field.
|
||||
func (_u *ConversionUpdateOne) AddInt8ToString(v int8) *ConversionUpdateOne {
|
||||
_u.mutation.AddInt8ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt8ToString clears the value of the "int8_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearInt8ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearInt8ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint8ToString sets the "uint8_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetUint8ToString(v uint8) *ConversionUpdateOne {
|
||||
_u.mutation.ResetUint8ToString()
|
||||
_u.mutation.SetUint8ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint8ToString sets the "uint8_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableUint8ToString(v *uint8) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUint8ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddUint8ToString adds value to the "uint8_to_string" field.
|
||||
func (_u *ConversionUpdateOne) AddUint8ToString(v int8) *ConversionUpdateOne {
|
||||
_u.mutation.AddUint8ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint8ToString clears the value of the "uint8_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearUint8ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearUint8ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt16ToString sets the "int16_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetInt16ToString(v int16) *ConversionUpdateOne {
|
||||
_u.mutation.ResetInt16ToString()
|
||||
_u.mutation.SetInt16ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt16ToString sets the "int16_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableInt16ToString(v *int16) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetInt16ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddInt16ToString adds value to the "int16_to_string" field.
|
||||
func (_u *ConversionUpdateOne) AddInt16ToString(v int16) *ConversionUpdateOne {
|
||||
_u.mutation.AddInt16ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt16ToString clears the value of the "int16_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearInt16ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearInt16ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint16ToString sets the "uint16_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetUint16ToString(v uint16) *ConversionUpdateOne {
|
||||
_u.mutation.ResetUint16ToString()
|
||||
_u.mutation.SetUint16ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint16ToString sets the "uint16_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableUint16ToString(v *uint16) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUint16ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddUint16ToString adds value to the "uint16_to_string" field.
|
||||
func (_u *ConversionUpdateOne) AddUint16ToString(v int16) *ConversionUpdateOne {
|
||||
_u.mutation.AddUint16ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint16ToString clears the value of the "uint16_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearUint16ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearUint16ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt32ToString sets the "int32_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetInt32ToString(v int32) *ConversionUpdateOne {
|
||||
_u.mutation.ResetInt32ToString()
|
||||
_u.mutation.SetInt32ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt32ToString sets the "int32_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableInt32ToString(v *int32) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetInt32ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddInt32ToString adds value to the "int32_to_string" field.
|
||||
func (_u *ConversionUpdateOne) AddInt32ToString(v int32) *ConversionUpdateOne {
|
||||
_u.mutation.AddInt32ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt32ToString clears the value of the "int32_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearInt32ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearInt32ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint32ToString sets the "uint32_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetUint32ToString(v uint32) *ConversionUpdateOne {
|
||||
_u.mutation.ResetUint32ToString()
|
||||
_u.mutation.SetUint32ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint32ToString sets the "uint32_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableUint32ToString(v *uint32) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUint32ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddUint32ToString adds value to the "uint32_to_string" field.
|
||||
func (_u *ConversionUpdateOne) AddUint32ToString(v int32) *ConversionUpdateOne {
|
||||
_u.mutation.AddUint32ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint32ToString clears the value of the "uint32_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearUint32ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearUint32ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt64ToString sets the "int64_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetInt64ToString(v int64) *ConversionUpdateOne {
|
||||
_u.mutation.ResetInt64ToString()
|
||||
_u.mutation.SetInt64ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt64ToString sets the "int64_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableInt64ToString(v *int64) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetInt64ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddInt64ToString adds value to the "int64_to_string" field.
|
||||
func (_u *ConversionUpdateOne) AddInt64ToString(v int64) *ConversionUpdateOne {
|
||||
_u.mutation.AddInt64ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt64ToString clears the value of the "int64_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearInt64ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearInt64ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint64ToString sets the "uint64_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetUint64ToString(v uint64) *ConversionUpdateOne {
|
||||
_u.mutation.ResetUint64ToString()
|
||||
_u.mutation.SetUint64ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint64ToString sets the "uint64_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableUint64ToString(v *uint64) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUint64ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddUint64ToString adds value to the "uint64_to_string" field.
|
||||
func (_u *ConversionUpdateOne) AddUint64ToString(v int64) *ConversionUpdateOne {
|
||||
_u.mutation.AddUint64ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint64ToString clears the value of the "uint64_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearUint64ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearUint64ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the ConversionMutation object of the builder.
|
||||
func (_u *ConversionUpdateOne) Mutation() *ConversionMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ConversionUpdate builder.
|
||||
func (_u *ConversionUpdateOne) Where(ps ...predicate.Conversion) *ConversionUpdateOne {
|
||||
_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 (_u *ConversionUpdateOne) Select(field string, fields ...string) *ConversionUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Conversion entity.
|
||||
func (_u *ConversionUpdateOne) Save(ctx context.Context) (*Conversion, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *ConversionUpdateOne) SaveX(ctx context.Context) *Conversion {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *ConversionUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *ConversionUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *ConversionUpdateOne) sqlSave(ctx context.Context) (_node *Conversion, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(conversion.Table, conversion.Columns, sqlgraph.NewFieldSpec(conversion.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`entv1: missing "Conversion.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, conversion.FieldID)
|
||||
for _, f := range fields {
|
||||
if !conversion.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("entv1: invalid field %q for query", f)}
|
||||
}
|
||||
if f != conversion.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(conversion.FieldName, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.NameCleared() {
|
||||
_spec.ClearField(conversion.FieldName, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Int8ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt8ToString, field.TypeInt8, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedInt8ToString(); ok {
|
||||
_spec.AddField(conversion.FieldInt8ToString, field.TypeInt8, value)
|
||||
}
|
||||
if _u.mutation.Int8ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt8ToString, field.TypeInt8)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint8ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint8ToString, field.TypeUint8, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedUint8ToString(); ok {
|
||||
_spec.AddField(conversion.FieldUint8ToString, field.TypeUint8, value)
|
||||
}
|
||||
if _u.mutation.Uint8ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint8ToString, field.TypeUint8)
|
||||
}
|
||||
if value, ok := _u.mutation.Int16ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt16ToString, field.TypeInt16, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedInt16ToString(); ok {
|
||||
_spec.AddField(conversion.FieldInt16ToString, field.TypeInt16, value)
|
||||
}
|
||||
if _u.mutation.Int16ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt16ToString, field.TypeInt16)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint16ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint16ToString, field.TypeUint16, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedUint16ToString(); ok {
|
||||
_spec.AddField(conversion.FieldUint16ToString, field.TypeUint16, value)
|
||||
}
|
||||
if _u.mutation.Uint16ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint16ToString, field.TypeUint16)
|
||||
}
|
||||
if value, ok := _u.mutation.Int32ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt32ToString, field.TypeInt32, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedInt32ToString(); ok {
|
||||
_spec.AddField(conversion.FieldInt32ToString, field.TypeInt32, value)
|
||||
}
|
||||
if _u.mutation.Int32ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt32ToString, field.TypeInt32)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint32ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint32ToString, field.TypeUint32, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedUint32ToString(); ok {
|
||||
_spec.AddField(conversion.FieldUint32ToString, field.TypeUint32, value)
|
||||
}
|
||||
if _u.mutation.Uint32ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint32ToString, field.TypeUint32)
|
||||
}
|
||||
if value, ok := _u.mutation.Int64ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt64ToString, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedInt64ToString(); ok {
|
||||
_spec.AddField(conversion.FieldInt64ToString, field.TypeInt64, value)
|
||||
}
|
||||
if _u.mutation.Int64ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt64ToString, field.TypeInt64)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint64ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint64ToString, field.TypeUint64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedUint64ToString(); ok {
|
||||
_spec.AddField(conversion.FieldUint64ToString, field.TypeUint64, value)
|
||||
}
|
||||
if _u.mutation.Uint64ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint64ToString, field.TypeUint64)
|
||||
}
|
||||
_node = &Conversion{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{conversion.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
107
entc/integration/migrate/entv1/customtype.go
Normal file
107
entc/integration/migrate/entv1/customtype.go
Normal file
@@ -0,0 +1,107 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/customtype"
|
||||
)
|
||||
|
||||
// CustomType is the model entity for the CustomType schema.
|
||||
type CustomType struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Custom holds the value of the "custom" field.
|
||||
Custom string `json:"custom,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*CustomType) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case customtype.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case customtype.FieldCustom:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the CustomType fields.
|
||||
func (_m *CustomType) 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)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case customtype.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int(value.Int64)
|
||||
case customtype.FieldCustom:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field custom", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Custom = value.String
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the CustomType.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *CustomType) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this CustomType.
|
||||
// Note that you need to call CustomType.Unwrap() before calling this method if this CustomType
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *CustomType) Update() *CustomTypeUpdateOne {
|
||||
return NewCustomTypeClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the CustomType 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 (_m *CustomType) Unwrap() *CustomType {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("entv1: CustomType is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *CustomType) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("CustomType(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("custom=")
|
||||
builder.WriteString(_m.Custom)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// CustomTypes is a parsable slice of CustomType.
|
||||
type CustomTypes []*CustomType
|
||||
51
entc/integration/migrate/entv1/customtype/customtype.go
Normal file
51
entc/integration/migrate/entv1/customtype/customtype.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package customtype
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the customtype type in the database.
|
||||
Label = "custom_type"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCustom holds the string denoting the custom field in the database.
|
||||
FieldCustom = "custom"
|
||||
// Table holds the table name of the customtype in the database.
|
||||
Table = "custom_types"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for customtype fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCustom,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the CustomType queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCustom orders the results by the custom field.
|
||||
func ByCustom(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCustom, opts...).ToFunc()
|
||||
}
|
||||
255
entc/integration/migrate/entv1/customtype/mutation.go
Normal file
255
entc/integration/migrate/entv1/customtype/mutation.go
Normal file
@@ -0,0 +1,255 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package customtype
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the CustomType nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
custom *string
|
||||
clearedFields map[string]struct{}
|
||||
predicates []predicate.CustomType
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the CustomType entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "CustomType",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.CustomType {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetCustom sets the "custom" field.
|
||||
func (m *Mutation) SetCustom(s string) {
|
||||
m.custom = &s
|
||||
}
|
||||
|
||||
// Custom returns the value of the "custom" field in the mutation.
|
||||
func (m *Mutation) Custom() (r string, exists bool) {
|
||||
v := m.custom
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearCustom clears the value of the "custom" field.
|
||||
func (m *Mutation) ClearCustom() {
|
||||
m.custom = nil
|
||||
m.clearedFields[FieldCustom] = struct{}{}
|
||||
}
|
||||
|
||||
// CustomCleared returns if the "custom" field was cleared in this mutation.
|
||||
func (m *Mutation) CustomCleared() bool {
|
||||
_, ok := m.clearedFields[FieldCustom]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetCustom resets all changes to the "custom" field.
|
||||
func (m *Mutation) ResetCustom() {
|
||||
m.custom = nil
|
||||
delete(m.clearedFields, FieldCustom)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.CustomType) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the Mutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *Mutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.CustomType, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *Mutation) Op() ent.Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *Mutation) SetOp(op ent.Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (CustomType).
|
||||
func (m *Mutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *Mutation) Fields() []string {
|
||||
fields := make([]string, 0, 1)
|
||||
if m.custom != nil {
|
||||
fields = append(fields, FieldCustom)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *Mutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case FieldCustom:
|
||||
return m.Custom()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *Mutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("unknown CustomType field %s", name)
|
||||
}
|
||||
|
||||
// SetField sets the value of a field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *Mutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case FieldCustom:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetCustom(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown CustomType field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *Mutation) AddedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||
// with the given name. The second boolean return value indicates that this field
|
||||
// was not set, or was not defined in the schema.
|
||||
func (m *Mutation) AddedField(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// AddField adds the value to the field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *Mutation) AddField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
}
|
||||
return fmt.Errorf("unknown CustomType numeric field %s", name)
|
||||
}
|
||||
|
||||
// ClearedFields returns all nullable fields that were cleared during this
|
||||
// mutation.
|
||||
func (m *Mutation) ClearedFields() []string {
|
||||
var fields []string
|
||||
if m.FieldCleared(FieldCustom) {
|
||||
fields = append(fields, FieldCustom)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
// cleared in this mutation.
|
||||
func (m *Mutation) FieldCleared(name string) bool {
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *Mutation) ClearField(name string) error {
|
||||
switch name {
|
||||
case FieldCustom:
|
||||
m.ClearCustom()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown CustomType nullable field %s", name)
|
||||
}
|
||||
|
||||
// ResetField resets all changes in the mutation for the field with the given name.
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *Mutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case FieldCustom:
|
||||
m.ResetCustom()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown CustomType field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *Mutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *Mutation) AddedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *Mutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *Mutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *Mutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *Mutation) EdgeCleared(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *Mutation) ClearEdge(name string) error {
|
||||
return fmt.Errorf("unknown CustomType unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *Mutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown CustomType edge %s", name)
|
||||
}
|
||||
152
entc/integration/migrate/entv1/customtype/where.go
Normal file
152
entc/integration/migrate/entv1/customtype/where.go
Normal file
@@ -0,0 +1,152 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package customtype
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Custom applies equality check predicate on the "custom" field. It's identical to CustomEQ.
|
||||
func Custom(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldEQ(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomEQ applies the EQ predicate on the "custom" field.
|
||||
func CustomEQ(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldEQ(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomNEQ applies the NEQ predicate on the "custom" field.
|
||||
func CustomNEQ(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNEQ(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomIn applies the In predicate on the "custom" field.
|
||||
func CustomIn(vs ...string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldIn(FieldCustom, vs...))
|
||||
}
|
||||
|
||||
// CustomNotIn applies the NotIn predicate on the "custom" field.
|
||||
func CustomNotIn(vs ...string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNotIn(FieldCustom, vs...))
|
||||
}
|
||||
|
||||
// CustomGT applies the GT predicate on the "custom" field.
|
||||
func CustomGT(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldGT(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomGTE applies the GTE predicate on the "custom" field.
|
||||
func CustomGTE(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldGTE(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomLT applies the LT predicate on the "custom" field.
|
||||
func CustomLT(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldLT(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomLTE applies the LTE predicate on the "custom" field.
|
||||
func CustomLTE(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldLTE(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomContains applies the Contains predicate on the "custom" field.
|
||||
func CustomContains(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldContains(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomHasPrefix applies the HasPrefix predicate on the "custom" field.
|
||||
func CustomHasPrefix(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldHasPrefix(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomHasSuffix applies the HasSuffix predicate on the "custom" field.
|
||||
func CustomHasSuffix(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldHasSuffix(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomIsNil applies the IsNil predicate on the "custom" field.
|
||||
func CustomIsNil() predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldIsNull(FieldCustom))
|
||||
}
|
||||
|
||||
// CustomNotNil applies the NotNil predicate on the "custom" field.
|
||||
func CustomNotNil() predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNotNull(FieldCustom))
|
||||
}
|
||||
|
||||
// CustomEqualFold applies the EqualFold predicate on the "custom" field.
|
||||
func CustomEqualFold(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldEqualFold(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomContainsFold applies the ContainsFold predicate on the "custom" field.
|
||||
func CustomContainsFold(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldContainsFold(FieldCustom, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.CustomType) predicate.CustomType {
|
||||
return predicate.CustomType(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.CustomType) predicate.CustomType {
|
||||
return predicate.CustomType(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.CustomType) predicate.CustomType {
|
||||
return predicate.CustomType(sql.NotPredicates(p))
|
||||
}
|
||||
191
entc/integration/migrate/entv1/customtype_create.go
Normal file
191
entc/integration/migrate/entv1/customtype_create.go
Normal file
@@ -0,0 +1,191 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/customtype"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CustomTypeCreate is the builder for creating a CustomType entity.
|
||||
type CustomTypeCreate struct {
|
||||
config
|
||||
mutation *CustomTypeMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetCustom sets the "custom" field.
|
||||
func (_c *CustomTypeCreate) SetCustom(v string) *CustomTypeCreate {
|
||||
_c.mutation.SetCustom(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCustom sets the "custom" field if the given value is not nil.
|
||||
func (_c *CustomTypeCreate) SetNillableCustom(v *string) *CustomTypeCreate {
|
||||
if v != nil {
|
||||
_c.SetCustom(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the CustomTypeMutation object of the builder.
|
||||
func (_c *CustomTypeCreate) Mutation() *CustomTypeMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the CustomType in the database.
|
||||
func (_c *CustomTypeCreate) Save(ctx context.Context) (*CustomType, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *CustomTypeCreate) SaveX(ctx context.Context) *CustomType {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *CustomTypeCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *CustomTypeCreate) 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 (_c *CustomTypeCreate) check() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *CustomTypeCreate) sqlSave(ctx context.Context) (*CustomType, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_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}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *CustomTypeCreate) createSpec() (*CustomType, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &CustomType{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(customtype.Table, sqlgraph.NewFieldSpec(customtype.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.Custom(); ok {
|
||||
_spec.SetField(customtype.FieldCustom, field.TypeString, value)
|
||||
_node.Custom = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// CustomTypeCreateBulk is the builder for creating many CustomType entities in bulk.
|
||||
type CustomTypeCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*CustomTypeCreate
|
||||
}
|
||||
|
||||
// Save creates the CustomType entities in the database.
|
||||
func (_c *CustomTypeCreateBulk) Save(ctx context.Context) ([]*CustomType, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*CustomType, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*CustomTypeMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, 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, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *CustomTypeCreateBulk) SaveX(ctx context.Context) []*CustomType {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *CustomTypeCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *CustomTypeCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/migrate/entv1/customtype_delete.go
Normal file
92
entc/integration/migrate/entv1/customtype_delete.go
Normal file
@@ -0,0 +1,92 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/customtype"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CustomTypeDelete is the builder for deleting a CustomType entity.
|
||||
type CustomTypeDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CustomTypeMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CustomTypeDelete builder.
|
||||
func (_d *CustomTypeDelete) Where(ps ...predicate.CustomType) *CustomTypeDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *CustomTypeDelete) 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 (_d *CustomTypeDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *CustomTypeDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(customtype.Table, sqlgraph.NewFieldSpec(customtype.FieldID, field.TypeInt))
|
||||
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, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// CustomTypeDeleteOne is the builder for deleting a single CustomType entity.
|
||||
type CustomTypeDeleteOne struct {
|
||||
_d *CustomTypeDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CustomTypeDelete builder.
|
||||
func (_d *CustomTypeDeleteOne) Where(ps ...predicate.CustomType) *CustomTypeDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *CustomTypeDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{customtype.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *CustomTypeDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
531
entc/integration/migrate/entv1/customtype_query.go
Normal file
531
entc/integration/migrate/entv1/customtype_query.go
Normal file
@@ -0,0 +1,531 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/customtype"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CustomTypeQuery is the builder for querying CustomType entities.
|
||||
type CustomTypeQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []customtype.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.CustomType
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the CustomTypeQuery builder.
|
||||
func (_q *CustomTypeQuery) Where(ps ...predicate.CustomType) *CustomTypeQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *CustomTypeQuery) Limit(limit int) *CustomTypeQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *CustomTypeQuery) Offset(offset int) *CustomTypeQuery {
|
||||
_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 (_q *CustomTypeQuery) Unique(unique bool) *CustomTypeQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *CustomTypeQuery) Order(o ...customtype.OrderOption) *CustomTypeQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// First returns the first CustomType entity from the query.
|
||||
// Returns a *NotFoundError when no CustomType was found.
|
||||
func (_q *CustomTypeQuery) First(ctx context.Context) (*CustomType, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{customtype.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) FirstX(ctx context.Context) *CustomType {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first CustomType ID from the query.
|
||||
// Returns a *NotFoundError when no CustomType ID was found.
|
||||
func (_q *CustomTypeQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{customtype.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single CustomType entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one CustomType entity is found.
|
||||
// Returns a *NotFoundError when no CustomType entities are found.
|
||||
func (_q *CustomTypeQuery) Only(ctx context.Context) (*CustomType, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{customtype.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{customtype.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) OnlyX(ctx context.Context) *CustomType {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only CustomType ID in the query.
|
||||
// Returns a *NotSingularError when more than one CustomType ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *CustomTypeQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{customtype.Label}
|
||||
default:
|
||||
err = &NotSingularError{customtype.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of CustomTypes.
|
||||
func (_q *CustomTypeQuery) All(ctx context.Context) ([]*CustomType, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*CustomType, *CustomTypeQuery]()
|
||||
return withInterceptors[[]*CustomType](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) AllX(ctx context.Context) []*CustomType {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of CustomType IDs.
|
||||
func (_q *CustomTypeQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(customtype.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *CustomTypeQuery) 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, _q, querierCount[*CustomTypeQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *CustomTypeQuery) 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:
|
||||
return false, fmt.Errorf("entv1: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the CustomTypeQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *CustomTypeQuery) Clone() *CustomTypeQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &CustomTypeQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]customtype.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.CustomType{}, _q.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Custom string `json:"custom,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.CustomType.Query().
|
||||
// GroupBy(customtype.FieldCustom).
|
||||
// Aggregate(entv1.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *CustomTypeQuery) GroupBy(field string, fields ...string) *CustomTypeGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &CustomTypeGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = customtype.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Custom string `json:"custom,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.CustomType.Query().
|
||||
// Select(customtype.FieldCustom).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *CustomTypeQuery) Select(fields ...string) *CustomTypeSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &CustomTypeSelect{CustomTypeQuery: _q}
|
||||
sbuild.label = customtype.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a CustomTypeSelect configured with the given aggregations.
|
||||
func (_q *CustomTypeQuery) Aggregate(fns ...AggregateFunc) *CustomTypeSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *CustomTypeQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("entv1: uninitialized interceptor (forgotten import entv1/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !customtype.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("entv1: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *CustomTypeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CustomType, error) {
|
||||
var (
|
||||
nodes = []*CustomType{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*CustomType).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &CustomType{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *CustomTypeQuery) 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, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *CustomTypeQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(customtype.Table, customtype.Columns, sqlgraph.NewFieldSpec(customtype.FieldID, field.TypeInt))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, customtype.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != customtype.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *CustomTypeQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(customtype.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = customtype.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
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 := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// CustomTypeGroupBy is the group-by builder for CustomType entities.
|
||||
type CustomTypeGroupBy struct {
|
||||
selector
|
||||
build *CustomTypeQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *CustomTypeGroupBy) Aggregate(fns ...AggregateFunc) *CustomTypeGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *CustomTypeGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*CustomTypeQuery, *CustomTypeGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *CustomTypeGroupBy) sqlScan(ctx context.Context, root *CustomTypeQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// CustomTypeSelect is the builder for selecting fields of CustomType entities.
|
||||
type CustomTypeSelect struct {
|
||||
*CustomTypeQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *CustomTypeSelect) Aggregate(fns ...AggregateFunc) *CustomTypeSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *CustomTypeSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*CustomTypeQuery, *CustomTypeSelect](ctx, _s.CustomTypeQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *CustomTypeSelect) sqlScan(ctx context.Context, root *CustomTypeQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
231
entc/integration/migrate/entv1/customtype_update.go
Normal file
231
entc/integration/migrate/entv1/customtype_update.go
Normal file
@@ -0,0 +1,231 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/customtype"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CustomTypeUpdate is the builder for updating CustomType entities.
|
||||
type CustomTypeUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CustomTypeMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CustomTypeUpdate builder.
|
||||
func (_u *CustomTypeUpdate) Where(ps ...predicate.CustomType) *CustomTypeUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCustom sets the "custom" field.
|
||||
func (_u *CustomTypeUpdate) SetCustom(v string) *CustomTypeUpdate {
|
||||
_u.mutation.SetCustom(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCustom sets the "custom" field if the given value is not nil.
|
||||
func (_u *CustomTypeUpdate) SetNillableCustom(v *string) *CustomTypeUpdate {
|
||||
if v != nil {
|
||||
_u.SetCustom(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearCustom clears the value of the "custom" field.
|
||||
func (_u *CustomTypeUpdate) ClearCustom() *CustomTypeUpdate {
|
||||
_u.mutation.ClearCustom()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the CustomTypeMutation object of the builder.
|
||||
func (_u *CustomTypeUpdate) Mutation() *CustomTypeMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *CustomTypeUpdate) 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 (_u *CustomTypeUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *CustomTypeUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *CustomTypeUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *CustomTypeUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(customtype.Table, customtype.Columns, sqlgraph.NewFieldSpec(customtype.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.Custom(); ok {
|
||||
_spec.SetField(customtype.FieldCustom, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.CustomCleared() {
|
||||
_spec.ClearField(customtype.FieldCustom, field.TypeString)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{customtype.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// CustomTypeUpdateOne is the builder for updating a single CustomType entity.
|
||||
type CustomTypeUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *CustomTypeMutation
|
||||
}
|
||||
|
||||
// SetCustom sets the "custom" field.
|
||||
func (_u *CustomTypeUpdateOne) SetCustom(v string) *CustomTypeUpdateOne {
|
||||
_u.mutation.SetCustom(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCustom sets the "custom" field if the given value is not nil.
|
||||
func (_u *CustomTypeUpdateOne) SetNillableCustom(v *string) *CustomTypeUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetCustom(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearCustom clears the value of the "custom" field.
|
||||
func (_u *CustomTypeUpdateOne) ClearCustom() *CustomTypeUpdateOne {
|
||||
_u.mutation.ClearCustom()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the CustomTypeMutation object of the builder.
|
||||
func (_u *CustomTypeUpdateOne) Mutation() *CustomTypeMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CustomTypeUpdate builder.
|
||||
func (_u *CustomTypeUpdateOne) Where(ps ...predicate.CustomType) *CustomTypeUpdateOne {
|
||||
_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 (_u *CustomTypeUpdateOne) Select(field string, fields ...string) *CustomTypeUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated CustomType entity.
|
||||
func (_u *CustomTypeUpdateOne) Save(ctx context.Context) (*CustomType, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *CustomTypeUpdateOne) SaveX(ctx context.Context) *CustomType {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *CustomTypeUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *CustomTypeUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *CustomTypeUpdateOne) sqlSave(ctx context.Context) (_node *CustomType, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(customtype.Table, customtype.Columns, sqlgraph.NewFieldSpec(customtype.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`entv1: missing "CustomType.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, customtype.FieldID)
|
||||
for _, f := range fields {
|
||||
if !customtype.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("entv1: invalid field %q for query", f)}
|
||||
}
|
||||
if f != customtype.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.Custom(); ok {
|
||||
_spec.SetField(customtype.FieldCustom, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.CustomCleared() {
|
||||
_spec.ClearField(customtype.FieldCustom, field.TypeString)
|
||||
}
|
||||
_node = &CustomType{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{customtype.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
618
entc/integration/migrate/entv1/ent.go
Normal file
618
entc/integration/migrate/entv1/ent.go
Normal file
@@ -0,0 +1,618 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/conversion"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/customtype"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/user"
|
||||
)
|
||||
|
||||
// ent aliases to avoid import conflicts in user's code.
|
||||
type (
|
||||
Op = ent.Op
|
||||
Hook = ent.Hook
|
||||
Value = ent.Value
|
||||
Query = ent.Query
|
||||
QueryContext = ent.QueryContext
|
||||
Querier = ent.Querier
|
||||
QuerierFunc = ent.QuerierFunc
|
||||
Interceptor = ent.Interceptor
|
||||
InterceptFunc = ent.InterceptFunc
|
||||
Traverser = ent.Traverser
|
||||
TraverseFunc = ent.TraverseFunc
|
||||
Policy = ent.Policy
|
||||
Mutator = ent.Mutator
|
||||
Mutation = ent.Mutation
|
||||
MutateFunc = ent.MutateFunc
|
||||
)
|
||||
|
||||
type clientCtxKey struct{}
|
||||
|
||||
// FromContext returns a Client stored inside a context, or nil if there isn't one.
|
||||
func FromContext(ctx context.Context) *Client {
|
||||
c, _ := ctx.Value(clientCtxKey{}).(*Client)
|
||||
return c
|
||||
}
|
||||
|
||||
// NewContext returns a new context with the given Client attached.
|
||||
func NewContext(parent context.Context, c *Client) context.Context {
|
||||
return context.WithValue(parent, clientCtxKey{}, c)
|
||||
}
|
||||
|
||||
type txCtxKey struct{}
|
||||
|
||||
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
|
||||
func TxFromContext(ctx context.Context) *Tx {
|
||||
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
|
||||
return tx
|
||||
}
|
||||
|
||||
// NewTxContext returns a new context with the given Tx attached.
|
||||
func NewTxContext(parent context.Context, tx *Tx) context.Context {
|
||||
return context.WithValue(parent, txCtxKey{}, tx)
|
||||
}
|
||||
|
||||
// OrderFunc applies an ordering on the sql selector.
|
||||
// Deprecated: Use Asc/Desc functions or the package builders instead.
|
||||
type OrderFunc func(*sql.Selector)
|
||||
|
||||
var (
|
||||
initCheck sync.Once
|
||||
columnCheck sql.ColumnCheck
|
||||
)
|
||||
|
||||
// checkColumn checks if the column exists in the given table.
|
||||
func checkColumn(t, c string) error {
|
||||
initCheck.Do(func() {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
car.Table: car.ValidColumn,
|
||||
conversion.Table: conversion.ValidColumn,
|
||||
customtype.Table: customtype.ValidColumn,
|
||||
user.Table: user.ValidColumn,
|
||||
})
|
||||
})
|
||||
return columnCheck(t, c)
|
||||
}
|
||||
|
||||
// Asc applies the given fields in ASC order.
|
||||
func Asc(fields ...string) func(*sql.Selector) {
|
||||
return func(s *sql.Selector) {
|
||||
for _, f := range fields {
|
||||
if err := checkColumn(s.TableName(), f); err != nil {
|
||||
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("entv1: %w", err)})
|
||||
}
|
||||
s.OrderBy(sql.Asc(s.C(f)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Desc applies the given fields in DESC order.
|
||||
func Desc(fields ...string) func(*sql.Selector) {
|
||||
return func(s *sql.Selector) {
|
||||
for _, f := range fields {
|
||||
if err := checkColumn(s.TableName(), f); err != nil {
|
||||
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("entv1: %w", err)})
|
||||
}
|
||||
s.OrderBy(sql.Desc(s.C(f)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
|
||||
type AggregateFunc func(*sql.Selector) string
|
||||
|
||||
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||
//
|
||||
// GroupBy(field1, field2).
|
||||
// Aggregate(entv1.As(entv1.Sum(field1), "sum_field1"), (entv1.As(entv1.Sum(field2), "sum_field2")).
|
||||
// Scan(ctx, &v)
|
||||
func As(fn AggregateFunc, end string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.As(fn(s), end)
|
||||
}
|
||||
}
|
||||
|
||||
// Count applies the "count" aggregation function on each group.
|
||||
func Count() AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
return sql.Count("*")
|
||||
}
|
||||
}
|
||||
|
||||
// Max applies the "max" aggregation function on the given field of each group.
|
||||
func Max(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("entv1: %w", err)})
|
||||
return ""
|
||||
}
|
||||
return sql.Max(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||
func Mean(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("entv1: %w", err)})
|
||||
return ""
|
||||
}
|
||||
return sql.Avg(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Min applies the "min" aggregation function on the given field of each group.
|
||||
func Min(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("entv1: %w", err)})
|
||||
return ""
|
||||
}
|
||||
return sql.Min(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||
func Sum(field string) AggregateFunc {
|
||||
return func(s *sql.Selector) string {
|
||||
if err := checkColumn(s.TableName(), field); err != nil {
|
||||
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("entv1: %w", err)})
|
||||
return ""
|
||||
}
|
||||
return sql.Sum(s.C(field))
|
||||
}
|
||||
}
|
||||
|
||||
// ValidationError returns when validating a field or edge fails.
|
||||
type ValidationError struct {
|
||||
Name string // Field or edge name.
|
||||
err error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *ValidationError) Error() string {
|
||||
return e.err.Error()
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ValidationError) Unwrap() error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
// IsValidationError returns a boolean indicating whether the error is a validation error.
|
||||
func IsValidationError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ValidationError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
|
||||
type NotFoundError struct {
|
||||
label string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotFoundError) Error() string {
|
||||
return "entv1: " + e.label + " not found"
|
||||
}
|
||||
|
||||
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// MaskNotFound masks not found error.
|
||||
func MaskNotFound(err error) error {
|
||||
if IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
|
||||
type NotSingularError struct {
|
||||
label string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotSingularError) Error() string {
|
||||
return "entv1: " + e.label + " not singular"
|
||||
}
|
||||
|
||||
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||
func IsNotSingular(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||
type NotLoadedError struct {
|
||||
edge string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *NotLoadedError) Error() string {
|
||||
return "entv1: " + e.edge + " edge was not loaded"
|
||||
}
|
||||
|
||||
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||
func IsNotLoaded(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
// one or more of their constraints failed. For example, violation of edge or
|
||||
// field uniqueness.
|
||||
type ConstraintError struct {
|
||||
msg string
|
||||
wrap error
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e ConstraintError) Error() string {
|
||||
return "entv1: constraint failed: " + e.msg
|
||||
}
|
||||
|
||||
// Unwrap implements the errors.Wrapper interface.
|
||||
func (e *ConstraintError) Unwrap() error {
|
||||
return e.wrap
|
||||
}
|
||||
|
||||
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||
func IsConstraintError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// selector embedded by the different Select/GroupBy builders.
|
||||
type selector struct {
|
||||
label string
|
||||
flds *[]string
|
||||
fns []AggregateFunc
|
||||
scan func(context.Context, any) error
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (s *selector) ScanX(ctx context.Context, v any) {
|
||||
if err := s.scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("entv1: Strings is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (s *selector) StringsX(ctx context.Context) []string {
|
||||
v, err := s.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = s.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("entv1: Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (s *selector) StringX(ctx context.Context) string {
|
||||
v, err := s.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("entv1: Ints is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (s *selector) IntsX(ctx context.Context) []int {
|
||||
v, err := s.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = s.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("entv1: Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (s *selector) IntX(ctx context.Context) int {
|
||||
v, err := s.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("entv1: Float64s is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (s *selector) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := s.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = s.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("entv1: Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (s *selector) Float64X(ctx context.Context) float64 {
|
||||
v, err := s.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(*s.flds) > 1 {
|
||||
return nil, errors.New("entv1: Bools is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := s.scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (s *selector) BoolsX(ctx context.Context) []bool {
|
||||
v, err := s.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||
func (s *selector) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = s.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{s.label}
|
||||
default:
|
||||
err = fmt.Errorf("entv1: Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (s *selector) BoolX(ctx context.Context) bool {
|
||||
v, err := s.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// withHooks invokes the builder operation with the given hooks, if any.
|
||||
func withHooks[V Value, M any, PM interface {
|
||||
*M
|
||||
Mutation
|
||||
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
|
||||
if len(hooks) == 0 {
|
||||
return exec(ctx)
|
||||
}
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutationT, ok := any(m).(PM)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
// Set the mutation to the builder.
|
||||
*mutation = *mutationT
|
||||
return exec(ctx)
|
||||
})
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
if hooks[i] == nil {
|
||||
return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = hooks[i](mut)
|
||||
}
|
||||
v, err := mut.Mutate(ctx, mutation)
|
||||
if err != nil {
|
||||
return value, err
|
||||
}
|
||||
nv, ok := v.(V)
|
||||
if !ok {
|
||||
return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
|
||||
}
|
||||
return nv, nil
|
||||
}
|
||||
|
||||
// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
|
||||
func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
|
||||
if ent.QueryFromContext(ctx) == nil {
|
||||
qc.Op = op
|
||||
ctx = ent.NewQueryContext(ctx, qc)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
func querierAll[V Value, Q interface {
|
||||
sqlAll(context.Context, ...queryHook) (V, error)
|
||||
}]() Querier {
|
||||
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
return query.sqlAll(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func querierCount[Q interface {
|
||||
sqlCount(context.Context) (int, error)
|
||||
}]() Querier {
|
||||
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
return query.sqlCount(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
|
||||
for i := len(inters) - 1; i >= 0; i-- {
|
||||
qr = inters[i].Intercept(qr)
|
||||
}
|
||||
rv, err := qr.Query(ctx, q)
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
vt, ok := rv.(V)
|
||||
if !ok {
|
||||
return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
|
||||
}
|
||||
return vt, nil
|
||||
}
|
||||
|
||||
func scanWithInterceptors[Q1 ent.Query, Q2 interface {
|
||||
sqlScan(context.Context, Q1, any) error
|
||||
}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
|
||||
rv := reflect.ValueOf(v)
|
||||
var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q1)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
|
||||
return rv.Elem().Interface(), nil
|
||||
}
|
||||
return v, nil
|
||||
})
|
||||
for i := len(inters) - 1; i >= 0; i-- {
|
||||
qr = inters[i].Intercept(qr)
|
||||
}
|
||||
vv, err := qr.Query(ctx, rootQuery)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch rv2 := reflect.ValueOf(vv); {
|
||||
case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
|
||||
case rv.Type() == rv2.Type():
|
||||
rv.Elem().Set(rv2.Elem())
|
||||
case rv.Elem().Type() == rv2.Type():
|
||||
rv.Elem().Set(rv2)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// queryHook describes an internal hook for the different sqlAll methods.
|
||||
type queryHook func(context.Context, *sqlgraph.QuerySpec)
|
||||
88
entc/integration/migrate/entv1/enttest/enttest.go
Normal file
88
entc/integration/migrate/entv1/enttest/enttest.go
Normal file
@@ -0,0 +1,88 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package enttest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/entc/integration/migrate/entv1"
|
||||
// required by schema hooks.
|
||||
_ "entgo.io/ent/entc/integration/migrate/entv1/runtime"
|
||||
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/migrate"
|
||||
)
|
||||
|
||||
type (
|
||||
// TestingT is the interface that is shared between
|
||||
// testing.T and testing.B and used by enttest.
|
||||
TestingT interface {
|
||||
FailNow()
|
||||
Error(...any)
|
||||
}
|
||||
|
||||
// Option configures client creation.
|
||||
Option func(*options)
|
||||
|
||||
options struct {
|
||||
opts []entv1.Option
|
||||
migrateOpts []schema.MigrateOption
|
||||
}
|
||||
)
|
||||
|
||||
// WithOptions forwards options to client creation.
|
||||
func WithOptions(opts ...entv1.Option) Option {
|
||||
return func(o *options) {
|
||||
o.opts = append(o.opts, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// WithMigrateOptions forwards options to auto migration.
|
||||
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
|
||||
return func(o *options) {
|
||||
o.migrateOpts = append(o.migrateOpts, opts...)
|
||||
}
|
||||
}
|
||||
|
||||
func newOptions(opts []Option) *options {
|
||||
o := &options{}
|
||||
for _, opt := range opts {
|
||||
opt(o)
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
// Open calls entv1.Open and auto-run migration.
|
||||
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *entv1.Client {
|
||||
o := newOptions(opts)
|
||||
c, err := entv1.Open(driverName, dataSourceName, o.opts...)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
migrateSchema(t, c, o)
|
||||
return c
|
||||
}
|
||||
|
||||
// NewClient calls entv1.NewClient and auto-run migration.
|
||||
func NewClient(t TestingT, opts ...Option) *entv1.Client {
|
||||
o := newOptions(opts)
|
||||
c := entv1.NewClient(o.opts...)
|
||||
migrateSchema(t, c, o)
|
||||
return c
|
||||
}
|
||||
func migrateSchema(t TestingT, c *entv1.Client, o *options) {
|
||||
tables, err := schema.CopyTables(migrate.Tables)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
7
entc/integration/migrate/entv1/generate.go
Normal file
7
entc/integration/migrate/entv1/generate.go
Normal file
@@ -0,0 +1,7 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
package entv1
|
||||
|
||||
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate --header "// Copyright 2019-present Facebook Inc. All rights reserved.\n// This source code is licensed under the Apache 2.0 license found\n// in the LICENSE file in the root directory of this source tree.\n\n// Code generated by ent, DO NOT EDIT." ./schema
|
||||
239
entc/integration/migrate/entv1/hook/hook.go
Normal file
239
entc/integration/migrate/entv1/hook/hook.go
Normal file
@@ -0,0 +1,239 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package hook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/entc/integration/migrate/entv1"
|
||||
)
|
||||
|
||||
// The CarFunc type is an adapter to allow the use of ordinary
|
||||
// function as Car mutator.
|
||||
type CarFunc func(context.Context, *entv1.CarMutation) (entv1.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f CarFunc) Mutate(ctx context.Context, m entv1.Mutation) (entv1.Value, error) {
|
||||
if mv, ok := m.(*entv1.CarMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *entv1.CarMutation", m)
|
||||
}
|
||||
|
||||
// The ConversionFunc type is an adapter to allow the use of ordinary
|
||||
// function as Conversion mutator.
|
||||
type ConversionFunc func(context.Context, *entv1.ConversionMutation) (entv1.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f ConversionFunc) Mutate(ctx context.Context, m entv1.Mutation) (entv1.Value, error) {
|
||||
if mv, ok := m.(*entv1.ConversionMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *entv1.ConversionMutation", m)
|
||||
}
|
||||
|
||||
// The CustomTypeFunc type is an adapter to allow the use of ordinary
|
||||
// function as CustomType mutator.
|
||||
type CustomTypeFunc func(context.Context, *entv1.CustomTypeMutation) (entv1.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f CustomTypeFunc) Mutate(ctx context.Context, m entv1.Mutation) (entv1.Value, error) {
|
||||
if mv, ok := m.(*entv1.CustomTypeMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *entv1.CustomTypeMutation", m)
|
||||
}
|
||||
|
||||
// The UserFunc type is an adapter to allow the use of ordinary
|
||||
// function as User mutator.
|
||||
type UserFunc func(context.Context, *entv1.UserMutation) (entv1.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f UserFunc) Mutate(ctx context.Context, m entv1.Mutation) (entv1.Value, error) {
|
||||
if mv, ok := m.(*entv1.UserMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *entv1.UserMutation", m)
|
||||
}
|
||||
|
||||
// Condition is a hook condition function.
|
||||
type Condition func(context.Context, entv1.Mutation) bool
|
||||
|
||||
// And groups conditions with the AND operator.
|
||||
func And(first, second Condition, rest ...Condition) Condition {
|
||||
return func(ctx context.Context, m entv1.Mutation) bool {
|
||||
if !first(ctx, m) || !second(ctx, m) {
|
||||
return false
|
||||
}
|
||||
for _, cond := range rest {
|
||||
if !cond(ctx, m) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// Or groups conditions with the OR operator.
|
||||
func Or(first, second Condition, rest ...Condition) Condition {
|
||||
return func(ctx context.Context, m entv1.Mutation) bool {
|
||||
if first(ctx, m) || second(ctx, m) {
|
||||
return true
|
||||
}
|
||||
for _, cond := range rest {
|
||||
if cond(ctx, m) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Not negates a given condition.
|
||||
func Not(cond Condition) Condition {
|
||||
return func(ctx context.Context, m entv1.Mutation) bool {
|
||||
return !cond(ctx, m)
|
||||
}
|
||||
}
|
||||
|
||||
// HasOp is a condition testing mutation operation.
|
||||
func HasOp(op entv1.Op) Condition {
|
||||
return func(_ context.Context, m entv1.Mutation) bool {
|
||||
return m.Op().Is(op)
|
||||
}
|
||||
}
|
||||
|
||||
// HasAddedFields is a condition validating `.AddedField` on fields.
|
||||
func HasAddedFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m entv1.Mutation) bool {
|
||||
if _, exists := m.AddedField(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if _, exists := m.AddedField(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// HasClearedFields is a condition validating `.FieldCleared` on fields.
|
||||
func HasClearedFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m entv1.Mutation) bool {
|
||||
if exists := m.FieldCleared(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if exists := m.FieldCleared(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// HasFields is a condition validating `.Field` on fields.
|
||||
func HasFields(field string, fields ...string) Condition {
|
||||
return func(_ context.Context, m entv1.Mutation) bool {
|
||||
if _, exists := m.Field(field); !exists {
|
||||
return false
|
||||
}
|
||||
for _, field := range fields {
|
||||
if _, exists := m.Field(field); !exists {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// If executes the given hook under condition.
|
||||
//
|
||||
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
|
||||
func If(hk entv1.Hook, cond Condition) entv1.Hook {
|
||||
return func(next entv1.Mutator) entv1.Mutator {
|
||||
return entv1.MutateFunc(func(ctx context.Context, m entv1.Mutation) (entv1.Value, error) {
|
||||
if cond(ctx, m) {
|
||||
return hk(next).Mutate(ctx, m)
|
||||
}
|
||||
return next.Mutate(ctx, m)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// On executes the given hook only for the given operation.
|
||||
//
|
||||
// hook.On(Log, entv1.Delete|entv1.Create)
|
||||
func On(hk entv1.Hook, op entv1.Op) entv1.Hook {
|
||||
return If(hk, HasOp(op))
|
||||
}
|
||||
|
||||
// Unless skips the given hook only for the given operation.
|
||||
//
|
||||
// hook.Unless(Log, entv1.Update|entv1.UpdateOne)
|
||||
func Unless(hk entv1.Hook, op entv1.Op) entv1.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) entv1.Hook {
|
||||
return func(entv1.Mutator) entv1.Mutator {
|
||||
return entv1.MutateFunc(func(context.Context, entv1.Mutation) (entv1.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []entv1.Hook {
|
||||
// return []entv1.Hook{
|
||||
// Reject(entv1.Delete|entv1.Update),
|
||||
// }
|
||||
// }
|
||||
func Reject(op entv1.Op) entv1.Hook {
|
||||
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||
return On(hk, op)
|
||||
}
|
||||
|
||||
// Chain acts as a list of hooks and is effectively immutable.
|
||||
// Once created, it will always hold the same set of hooks in the same order.
|
||||
type Chain struct {
|
||||
hooks []entv1.Hook
|
||||
}
|
||||
|
||||
// NewChain creates a new chain of hooks.
|
||||
func NewChain(hooks ...entv1.Hook) Chain {
|
||||
return Chain{append([]entv1.Hook(nil), hooks...)}
|
||||
}
|
||||
|
||||
// Hook chains the list of hooks and returns the final hook.
|
||||
func (c Chain) Hook() entv1.Hook {
|
||||
return func(mutator entv1.Mutator) entv1.Mutator {
|
||||
for i := len(c.hooks) - 1; i >= 0; i-- {
|
||||
mutator = c.hooks[i](mutator)
|
||||
}
|
||||
return mutator
|
||||
}
|
||||
}
|
||||
|
||||
// Append extends a chain, adding the specified hook
|
||||
// as the last ones in the mutation flow.
|
||||
func (c Chain) Append(hooks ...entv1.Hook) Chain {
|
||||
newHooks := make([]entv1.Hook, 0, len(c.hooks)+len(hooks))
|
||||
newHooks = append(newHooks, c.hooks...)
|
||||
newHooks = append(newHooks, hooks...)
|
||||
return Chain{newHooks}
|
||||
}
|
||||
|
||||
// Extend extends a chain, adding the specified chain
|
||||
// as the last ones in the mutation flow.
|
||||
func (c Chain) Extend(chain Chain) Chain {
|
||||
return c.Append(chain.hooks...)
|
||||
}
|
||||
68
entc/integration/migrate/entv1/migrate/migrate.go
Normal file
68
entc/integration/migrate/entv1/migrate/migrate.go
Normal file
@@ -0,0 +1,68 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
)
|
||||
|
||||
var (
|
||||
// WithGlobalUniqueID sets the universal ids options to the migration.
|
||||
// If this option is enabled, ent migration will allocate a 1<<32 range
|
||||
// for the ids of each entity (table).
|
||||
// Note that this option cannot be applied on tables that already exist.
|
||||
WithGlobalUniqueID = schema.WithGlobalUniqueID
|
||||
// WithDropColumn sets the drop column option to the migration.
|
||||
// If this option is enabled, ent migration will drop old columns
|
||||
// that were used for both fields and edges. This defaults to false.
|
||||
WithDropColumn = schema.WithDropColumn
|
||||
// WithDropIndex sets the drop index option to the migration.
|
||||
// If this option is enabled, ent migration will drop old indexes
|
||||
// that were defined in the schema. This defaults to false.
|
||||
// Note that unique constraints are defined using `UNIQUE INDEX`,
|
||||
// and therefore, it's recommended to enable this option to get more
|
||||
// flexibility in the schema changes.
|
||||
WithDropIndex = schema.WithDropIndex
|
||||
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
|
||||
WithForeignKeys = schema.WithForeignKeys
|
||||
)
|
||||
|
||||
// Schema is the API for creating, migrating and dropping a schema.
|
||||
type Schema struct {
|
||||
drv dialect.Driver
|
||||
}
|
||||
|
||||
// NewSchema creates a new schema client.
|
||||
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
|
||||
|
||||
// Create creates all schema resources.
|
||||
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||
return Create(ctx, s, Tables, opts...)
|
||||
}
|
||||
|
||||
// Create creates all table resources using the given schema driver.
|
||||
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
|
||||
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ent/migrate: %w", err)
|
||||
}
|
||||
return migrate.Create(ctx, tables...)
|
||||
}
|
||||
|
||||
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||
//
|
||||
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
|
||||
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
|
||||
}
|
||||
134
entc/integration/migrate/entv1/migrate/schema.go
Normal file
134
entc/integration/migrate/entv1/migrate/schema.go
Normal file
@@ -0,0 +1,134 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
var (
|
||||
// CarColumns holds the columns for the "Car" table.
|
||||
CarColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "user_car", Type: field.TypeInt, Unique: true, Nullable: true},
|
||||
}
|
||||
// CarTable holds the schema information for the "Car" table.
|
||||
CarTable = &schema.Table{
|
||||
Name: "Car",
|
||||
Columns: CarColumns,
|
||||
PrimaryKey: []*schema.Column{CarColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "Car_users_car",
|
||||
Columns: []*schema.Column{CarColumns[1]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
}
|
||||
// ConversionsColumns holds the columns for the "conversions" table.
|
||||
ConversionsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString, Nullable: true},
|
||||
{Name: "int8_to_string", Type: field.TypeInt8, Nullable: true},
|
||||
{Name: "uint8_to_string", Type: field.TypeUint8, Nullable: true},
|
||||
{Name: "int16_to_string", Type: field.TypeInt16, Nullable: true},
|
||||
{Name: "uint16_to_string", Type: field.TypeUint16, Nullable: true},
|
||||
{Name: "int32_to_string", Type: field.TypeInt32, Nullable: true},
|
||||
{Name: "uint32_to_string", Type: field.TypeUint32, Nullable: true},
|
||||
{Name: "int64_to_string", Type: field.TypeInt64, Nullable: true},
|
||||
{Name: "uint64_to_string", Type: field.TypeUint64, Nullable: true},
|
||||
}
|
||||
// ConversionsTable holds the schema information for the "conversions" table.
|
||||
ConversionsTable = &schema.Table{
|
||||
Name: "conversions",
|
||||
Columns: ConversionsColumns,
|
||||
PrimaryKey: []*schema.Column{ConversionsColumns[0]},
|
||||
}
|
||||
// CustomTypesColumns holds the columns for the "custom_types" table.
|
||||
CustomTypesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "custom", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "customtype"}},
|
||||
}
|
||||
// CustomTypesTable holds the schema information for the "custom_types" table.
|
||||
CustomTypesTable = &schema.Table{
|
||||
Name: "custom_types",
|
||||
Columns: CustomTypesColumns,
|
||||
PrimaryKey: []*schema.Column{CustomTypesColumns[0]},
|
||||
}
|
||||
// UsersColumns holds the columns for the "users" table.
|
||||
UsersColumns = []*schema.Column{
|
||||
{Name: "oid", Type: field.TypeInt, Increment: true},
|
||||
{Name: "age", Type: field.TypeInt32},
|
||||
{Name: "name", Type: field.TypeString, Size: 10},
|
||||
{Name: "description", Type: field.TypeString, Nullable: true, Size: 2147483647},
|
||||
{Name: "nickname", Type: field.TypeString, Unique: true},
|
||||
{Name: "address", Type: field.TypeString, Nullable: true},
|
||||
{Name: "renamed", Type: field.TypeString, Nullable: true},
|
||||
{Name: "old_token", Type: field.TypeString},
|
||||
{Name: "blob", Type: field.TypeBytes, Nullable: true, Size: 255},
|
||||
{Name: "state", Type: field.TypeEnum, Nullable: true, Enums: []string{"logged_in", "logged_out"}, Default: "logged_in"},
|
||||
{Name: "status", Type: field.TypeString, Nullable: true},
|
||||
{Name: "workplace", Type: field.TypeString, Nullable: true, Size: 30},
|
||||
{Name: "drop_optional", Type: field.TypeString, Nullable: true},
|
||||
{Name: "user_children", Type: field.TypeInt, Nullable: true},
|
||||
{Name: "user_spouse", Type: field.TypeInt, Unique: true, Nullable: true},
|
||||
}
|
||||
// UsersTable holds the schema information for the "users" table.
|
||||
UsersTable = &schema.Table{
|
||||
Name: "users",
|
||||
Columns: UsersColumns,
|
||||
PrimaryKey: []*schema.Column{UsersColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "users_users_children",
|
||||
Columns: []*schema.Column{UsersColumns[13]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "users_users_spouse",
|
||||
Columns: []*schema.Column{UsersColumns[14]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "user_description",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UsersColumns[3]},
|
||||
Annotation: &entsql.IndexAnnotation{
|
||||
Prefix: 50,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "user_name_address",
|
||||
Unique: true,
|
||||
Columns: []*schema.Column{UsersColumns[2], UsersColumns[5]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
CarTable,
|
||||
ConversionsTable,
|
||||
CustomTypesTable,
|
||||
UsersTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
CarTable.ForeignKeys[0].RefTable = UsersTable
|
||||
CarTable.Annotation = &entsql.Annotation{
|
||||
Table: "Car",
|
||||
}
|
||||
UsersTable.ForeignKeys[0].RefTable = UsersTable
|
||||
UsersTable.ForeignKeys[1].RefTable = UsersTable
|
||||
}
|
||||
913
entc/integration/migrate/entv1/mutation.go
Normal file
913
entc/integration/migrate/entv1/mutation.go
Normal file
@@ -0,0 +1,913 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/conversion"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/customtype"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/user"
|
||||
)
|
||||
|
||||
const (
|
||||
// Operation types.
|
||||
OpCreate = ent.OpCreate
|
||||
OpDelete = ent.OpDelete
|
||||
OpDeleteOne = ent.OpDeleteOne
|
||||
OpUpdate = ent.OpUpdate
|
||||
OpUpdateOne = ent.OpUpdateOne
|
||||
|
||||
// Node types.
|
||||
TypeCar = "Car"
|
||||
TypeConversion = "Conversion"
|
||||
TypeCustomType = "CustomType"
|
||||
TypeUser = "User"
|
||||
)
|
||||
|
||||
// CarMutation represents an operation that mutates the Car nodes in the graph.
|
||||
type CarMutation struct {
|
||||
car.Mutation
|
||||
config
|
||||
id *int
|
||||
done bool
|
||||
oldValue func(context.Context) (*Car, error)
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*CarMutation)(nil)
|
||||
|
||||
// carOption allows management of the mutation configuration using functional options.
|
||||
type carOption func(*CarMutation)
|
||||
|
||||
// newCarMutation creates new mutation for the Car entity.
|
||||
func newCarMutation(c config, op Op, opts ...carOption) *CarMutation {
|
||||
m := &CarMutation{
|
||||
Mutation: *car.NewMutation(op),
|
||||
config: c,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||
// if it was provided to the builder or after it was returned from the database.
|
||||
func (m *CarMutation) ID() (id int, exists bool) {
|
||||
if m.id == nil {
|
||||
return
|
||||
}
|
||||
return *m.id, true
|
||||
}
|
||||
|
||||
// withCarID sets the ID field of the mutation.
|
||||
func withCarID(id int) carOption {
|
||||
return func(m *CarMutation) {
|
||||
var (
|
||||
err error
|
||||
once sync.Once
|
||||
value *Car
|
||||
)
|
||||
m.oldValue = func(ctx context.Context) (*Car, error) {
|
||||
once.Do(func() {
|
||||
if m.done {
|
||||
err = errors.New("querying old values post mutation is not allowed")
|
||||
} else {
|
||||
value, err = m.Client().Car.Get(ctx, id)
|
||||
}
|
||||
})
|
||||
return value, err
|
||||
}
|
||||
m.id = &id
|
||||
}
|
||||
}
|
||||
|
||||
// withCar sets the old Car of the mutation.
|
||||
func withCar(node *Car) carOption {
|
||||
return func(m *CarMutation) {
|
||||
m.oldValue = func(context.Context) (*Car, error) {
|
||||
return node, nil
|
||||
}
|
||||
m.id = &node.ID
|
||||
}
|
||||
}
|
||||
|
||||
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||
func (m CarMutation) Client() *Client {
|
||||
client := &Client{config: m.config}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||
// it returns an error otherwise.
|
||||
func (m CarMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, errors.New("entv1: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||
// or updated by the mutation.
|
||||
func (m *CarMutation) IDs(ctx context.Context) ([]int, error) {
|
||||
switch {
|
||||
case m.Op().Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []int{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.Op().Is(OpUpdate | OpDelete):
|
||||
return m.Client().Car.Query().Where(m.Predicates()...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *CarMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("unknown Car field %s", name)
|
||||
}
|
||||
|
||||
// ConversionMutation represents an operation that mutates the Conversion nodes in the graph.
|
||||
type ConversionMutation struct {
|
||||
conversion.Mutation
|
||||
config
|
||||
id *int
|
||||
done bool
|
||||
oldValue func(context.Context) (*Conversion, error)
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*ConversionMutation)(nil)
|
||||
|
||||
// conversionOption allows management of the mutation configuration using functional options.
|
||||
type conversionOption func(*ConversionMutation)
|
||||
|
||||
// newConversionMutation creates new mutation for the Conversion entity.
|
||||
func newConversionMutation(c config, op Op, opts ...conversionOption) *ConversionMutation {
|
||||
m := &ConversionMutation{
|
||||
Mutation: *conversion.NewMutation(op),
|
||||
config: c,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||
// if it was provided to the builder or after it was returned from the database.
|
||||
func (m *ConversionMutation) ID() (id int, exists bool) {
|
||||
if m.id == nil {
|
||||
return
|
||||
}
|
||||
return *m.id, true
|
||||
}
|
||||
|
||||
// withConversionID sets the ID field of the mutation.
|
||||
func withConversionID(id int) conversionOption {
|
||||
return func(m *ConversionMutation) {
|
||||
var (
|
||||
err error
|
||||
once sync.Once
|
||||
value *Conversion
|
||||
)
|
||||
m.oldValue = func(ctx context.Context) (*Conversion, error) {
|
||||
once.Do(func() {
|
||||
if m.done {
|
||||
err = errors.New("querying old values post mutation is not allowed")
|
||||
} else {
|
||||
value, err = m.Client().Conversion.Get(ctx, id)
|
||||
}
|
||||
})
|
||||
return value, err
|
||||
}
|
||||
m.id = &id
|
||||
}
|
||||
}
|
||||
|
||||
// withConversion sets the old Conversion of the mutation.
|
||||
func withConversion(node *Conversion) conversionOption {
|
||||
return func(m *ConversionMutation) {
|
||||
m.oldValue = func(context.Context) (*Conversion, error) {
|
||||
return node, nil
|
||||
}
|
||||
m.id = &node.ID
|
||||
}
|
||||
}
|
||||
|
||||
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||
func (m ConversionMutation) Client() *Client {
|
||||
client := &Client{config: m.config}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||
// it returns an error otherwise.
|
||||
func (m ConversionMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, errors.New("entv1: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||
// or updated by the mutation.
|
||||
func (m *ConversionMutation) IDs(ctx context.Context) ([]int, error) {
|
||||
switch {
|
||||
case m.Op().Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []int{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.Op().Is(OpUpdate | OpDelete):
|
||||
return m.Client().Conversion.Query().Where(m.Predicates()...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// OldName returns the old "name" field's value of the Conversion entity.
|
||||
// If the Conversion object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *ConversionMutation) OldName(ctx context.Context) (v string, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldName is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldName requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldName: %w", err)
|
||||
}
|
||||
return oldValue.Name, nil
|
||||
}
|
||||
|
||||
// OldInt8ToString returns the old "int8_to_string" field's value of the Conversion entity.
|
||||
// If the Conversion object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *ConversionMutation) OldInt8ToString(ctx context.Context) (v int8, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldInt8ToString is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldInt8ToString requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldInt8ToString: %w", err)
|
||||
}
|
||||
return oldValue.Int8ToString, nil
|
||||
}
|
||||
|
||||
// OldUint8ToString returns the old "uint8_to_string" field's value of the Conversion entity.
|
||||
// If the Conversion object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *ConversionMutation) OldUint8ToString(ctx context.Context) (v uint8, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldUint8ToString is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldUint8ToString requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldUint8ToString: %w", err)
|
||||
}
|
||||
return oldValue.Uint8ToString, nil
|
||||
}
|
||||
|
||||
// OldInt16ToString returns the old "int16_to_string" field's value of the Conversion entity.
|
||||
// If the Conversion object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *ConversionMutation) OldInt16ToString(ctx context.Context) (v int16, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldInt16ToString is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldInt16ToString requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldInt16ToString: %w", err)
|
||||
}
|
||||
return oldValue.Int16ToString, nil
|
||||
}
|
||||
|
||||
// OldUint16ToString returns the old "uint16_to_string" field's value of the Conversion entity.
|
||||
// If the Conversion object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *ConversionMutation) OldUint16ToString(ctx context.Context) (v uint16, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldUint16ToString is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldUint16ToString requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldUint16ToString: %w", err)
|
||||
}
|
||||
return oldValue.Uint16ToString, nil
|
||||
}
|
||||
|
||||
// OldInt32ToString returns the old "int32_to_string" field's value of the Conversion entity.
|
||||
// If the Conversion object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *ConversionMutation) OldInt32ToString(ctx context.Context) (v int32, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldInt32ToString is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldInt32ToString requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldInt32ToString: %w", err)
|
||||
}
|
||||
return oldValue.Int32ToString, nil
|
||||
}
|
||||
|
||||
// OldUint32ToString returns the old "uint32_to_string" field's value of the Conversion entity.
|
||||
// If the Conversion object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *ConversionMutation) OldUint32ToString(ctx context.Context) (v uint32, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldUint32ToString is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldUint32ToString requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldUint32ToString: %w", err)
|
||||
}
|
||||
return oldValue.Uint32ToString, nil
|
||||
}
|
||||
|
||||
// OldInt64ToString returns the old "int64_to_string" field's value of the Conversion entity.
|
||||
// If the Conversion object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *ConversionMutation) OldInt64ToString(ctx context.Context) (v int64, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldInt64ToString is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldInt64ToString requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldInt64ToString: %w", err)
|
||||
}
|
||||
return oldValue.Int64ToString, nil
|
||||
}
|
||||
|
||||
// OldUint64ToString returns the old "uint64_to_string" field's value of the Conversion entity.
|
||||
// If the Conversion object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *ConversionMutation) OldUint64ToString(ctx context.Context) (v uint64, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldUint64ToString is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldUint64ToString requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldUint64ToString: %w", err)
|
||||
}
|
||||
return oldValue.Uint64ToString, nil
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *ConversionMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
switch name {
|
||||
case conversion.FieldName:
|
||||
return m.OldName(ctx)
|
||||
case conversion.FieldInt8ToString:
|
||||
return m.OldInt8ToString(ctx)
|
||||
case conversion.FieldUint8ToString:
|
||||
return m.OldUint8ToString(ctx)
|
||||
case conversion.FieldInt16ToString:
|
||||
return m.OldInt16ToString(ctx)
|
||||
case conversion.FieldUint16ToString:
|
||||
return m.OldUint16ToString(ctx)
|
||||
case conversion.FieldInt32ToString:
|
||||
return m.OldInt32ToString(ctx)
|
||||
case conversion.FieldUint32ToString:
|
||||
return m.OldUint32ToString(ctx)
|
||||
case conversion.FieldInt64ToString:
|
||||
return m.OldInt64ToString(ctx)
|
||||
case conversion.FieldUint64ToString:
|
||||
return m.OldUint64ToString(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown Conversion field %s", name)
|
||||
}
|
||||
|
||||
// CustomTypeMutation represents an operation that mutates the CustomType nodes in the graph.
|
||||
type CustomTypeMutation struct {
|
||||
customtype.Mutation
|
||||
config
|
||||
id *int
|
||||
done bool
|
||||
oldValue func(context.Context) (*CustomType, error)
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*CustomTypeMutation)(nil)
|
||||
|
||||
// customtypeOption allows management of the mutation configuration using functional options.
|
||||
type customtypeOption func(*CustomTypeMutation)
|
||||
|
||||
// newCustomTypeMutation creates new mutation for the CustomType entity.
|
||||
func newCustomTypeMutation(c config, op Op, opts ...customtypeOption) *CustomTypeMutation {
|
||||
m := &CustomTypeMutation{
|
||||
Mutation: *customtype.NewMutation(op),
|
||||
config: c,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||
// if it was provided to the builder or after it was returned from the database.
|
||||
func (m *CustomTypeMutation) ID() (id int, exists bool) {
|
||||
if m.id == nil {
|
||||
return
|
||||
}
|
||||
return *m.id, true
|
||||
}
|
||||
|
||||
// withCustomTypeID sets the ID field of the mutation.
|
||||
func withCustomTypeID(id int) customtypeOption {
|
||||
return func(m *CustomTypeMutation) {
|
||||
var (
|
||||
err error
|
||||
once sync.Once
|
||||
value *CustomType
|
||||
)
|
||||
m.oldValue = func(ctx context.Context) (*CustomType, error) {
|
||||
once.Do(func() {
|
||||
if m.done {
|
||||
err = errors.New("querying old values post mutation is not allowed")
|
||||
} else {
|
||||
value, err = m.Client().CustomType.Get(ctx, id)
|
||||
}
|
||||
})
|
||||
return value, err
|
||||
}
|
||||
m.id = &id
|
||||
}
|
||||
}
|
||||
|
||||
// withCustomType sets the old CustomType of the mutation.
|
||||
func withCustomType(node *CustomType) customtypeOption {
|
||||
return func(m *CustomTypeMutation) {
|
||||
m.oldValue = func(context.Context) (*CustomType, error) {
|
||||
return node, nil
|
||||
}
|
||||
m.id = &node.ID
|
||||
}
|
||||
}
|
||||
|
||||
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||
func (m CustomTypeMutation) Client() *Client {
|
||||
client := &Client{config: m.config}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||
// it returns an error otherwise.
|
||||
func (m CustomTypeMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, errors.New("entv1: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||
// or updated by the mutation.
|
||||
func (m *CustomTypeMutation) IDs(ctx context.Context) ([]int, error) {
|
||||
switch {
|
||||
case m.Op().Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []int{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.Op().Is(OpUpdate | OpDelete):
|
||||
return m.Client().CustomType.Query().Where(m.Predicates()...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// OldCustom returns the old "custom" field's value of the CustomType entity.
|
||||
// If the CustomType object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *CustomTypeMutation) OldCustom(ctx context.Context) (v string, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldCustom is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldCustom requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldCustom: %w", err)
|
||||
}
|
||||
return oldValue.Custom, nil
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *CustomTypeMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
switch name {
|
||||
case customtype.FieldCustom:
|
||||
return m.OldCustom(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown CustomType field %s", name)
|
||||
}
|
||||
|
||||
// UserMutation represents an operation that mutates the User nodes in the graph.
|
||||
type UserMutation struct {
|
||||
user.Mutation
|
||||
config
|
||||
id *int
|
||||
done bool
|
||||
oldValue func(context.Context) (*User, error)
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*UserMutation)(nil)
|
||||
|
||||
// userOption allows management of the mutation configuration using functional options.
|
||||
type userOption func(*UserMutation)
|
||||
|
||||
// newUserMutation creates new mutation for the User entity.
|
||||
func newUserMutation(c config, op Op, opts ...userOption) *UserMutation {
|
||||
m := &UserMutation{
|
||||
Mutation: *user.NewMutation(op),
|
||||
config: c,
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// SetID sets the value of the id field. Note that this
|
||||
// operation is only accepted on creation of User entities.
|
||||
func (m *UserMutation) SetID(id int) {
|
||||
m.id = &id
|
||||
}
|
||||
|
||||
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||
// if it was provided to the builder or after it was returned from the database.
|
||||
func (m *UserMutation) ID() (id int, exists bool) {
|
||||
if m.id == nil {
|
||||
return
|
||||
}
|
||||
return *m.id, true
|
||||
}
|
||||
|
||||
// withUserID sets the ID field of the mutation.
|
||||
func withUserID(id int) userOption {
|
||||
return func(m *UserMutation) {
|
||||
var (
|
||||
err error
|
||||
once sync.Once
|
||||
value *User
|
||||
)
|
||||
m.oldValue = func(ctx context.Context) (*User, error) {
|
||||
once.Do(func() {
|
||||
if m.done {
|
||||
err = errors.New("querying old values post mutation is not allowed")
|
||||
} else {
|
||||
value, err = m.Client().User.Get(ctx, id)
|
||||
}
|
||||
})
|
||||
return value, err
|
||||
}
|
||||
m.id = &id
|
||||
}
|
||||
}
|
||||
|
||||
// withUser sets the old User of the mutation.
|
||||
func withUser(node *User) userOption {
|
||||
return func(m *UserMutation) {
|
||||
m.oldValue = func(context.Context) (*User, error) {
|
||||
return node, nil
|
||||
}
|
||||
m.id = &node.ID
|
||||
}
|
||||
}
|
||||
|
||||
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||
func (m UserMutation) Client() *Client {
|
||||
client := &Client{config: m.config}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||
// it returns an error otherwise.
|
||||
func (m UserMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, errors.New("entv1: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||
// or updated by the mutation.
|
||||
func (m *UserMutation) IDs(ctx context.Context) ([]int, error) {
|
||||
switch {
|
||||
case m.Op().Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []int{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.Op().Is(OpUpdate | OpDelete):
|
||||
return m.Client().User.Query().Where(m.Predicates()...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// OldAge returns the old "age" field's value of the User entity.
|
||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *UserMutation) OldAge(ctx context.Context) (v int32, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldAge is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldAge requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldAge: %w", err)
|
||||
}
|
||||
return oldValue.Age, nil
|
||||
}
|
||||
|
||||
// OldName returns the old "name" field's value of the User entity.
|
||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *UserMutation) OldName(ctx context.Context) (v string, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldName is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldName requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldName: %w", err)
|
||||
}
|
||||
return oldValue.Name, nil
|
||||
}
|
||||
|
||||
// OldDescription returns the old "description" field's value of the User entity.
|
||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *UserMutation) OldDescription(ctx context.Context) (v string, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldDescription is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldDescription requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldDescription: %w", err)
|
||||
}
|
||||
return oldValue.Description, nil
|
||||
}
|
||||
|
||||
// OldNickname returns the old "nickname" field's value of the User entity.
|
||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *UserMutation) OldNickname(ctx context.Context) (v string, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldNickname is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldNickname requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldNickname: %w", err)
|
||||
}
|
||||
return oldValue.Nickname, nil
|
||||
}
|
||||
|
||||
// OldAddress returns the old "address" field's value of the User entity.
|
||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *UserMutation) OldAddress(ctx context.Context) (v string, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldAddress is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldAddress requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldAddress: %w", err)
|
||||
}
|
||||
return oldValue.Address, nil
|
||||
}
|
||||
|
||||
// OldRenamed returns the old "renamed" field's value of the User entity.
|
||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *UserMutation) OldRenamed(ctx context.Context) (v string, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldRenamed is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldRenamed requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldRenamed: %w", err)
|
||||
}
|
||||
return oldValue.Renamed, nil
|
||||
}
|
||||
|
||||
// OldOldToken returns the old "old_token" field's value of the User entity.
|
||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *UserMutation) OldOldToken(ctx context.Context) (v string, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldOldToken is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldOldToken requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldOldToken: %w", err)
|
||||
}
|
||||
return oldValue.OldToken, nil
|
||||
}
|
||||
|
||||
// OldBlob returns the old "blob" field's value of the User entity.
|
||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *UserMutation) OldBlob(ctx context.Context) (v []byte, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldBlob is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldBlob requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldBlob: %w", err)
|
||||
}
|
||||
return oldValue.Blob, nil
|
||||
}
|
||||
|
||||
// OldState returns the old "state" field's value of the User entity.
|
||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *UserMutation) OldState(ctx context.Context) (v user.State, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldState is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldState requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldState: %w", err)
|
||||
}
|
||||
return oldValue.State, nil
|
||||
}
|
||||
|
||||
// OldStatus returns the old "status" field's value of the User entity.
|
||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *UserMutation) OldStatus(ctx context.Context) (v string, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldStatus is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldStatus requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldStatus: %w", err)
|
||||
}
|
||||
return oldValue.Status, nil
|
||||
}
|
||||
|
||||
// OldWorkplace returns the old "workplace" field's value of the User entity.
|
||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *UserMutation) OldWorkplace(ctx context.Context) (v string, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldWorkplace is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldWorkplace requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldWorkplace: %w", err)
|
||||
}
|
||||
return oldValue.Workplace, nil
|
||||
}
|
||||
|
||||
// OldDropOptional returns the old "drop_optional" field's value of the User entity.
|
||||
// If the User object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *UserMutation) OldDropOptional(ctx context.Context) (v string, err error) {
|
||||
if !m.Op().Is(OpUpdateOne) {
|
||||
return v, errors.New("OldDropOptional is only allowed on UpdateOne operations")
|
||||
}
|
||||
if _, exists := m.ID(); !exists || m.oldValue == nil {
|
||||
return v, errors.New("OldDropOptional requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldDropOptional: %w", err)
|
||||
}
|
||||
return oldValue.DropOptional, nil
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
switch name {
|
||||
case user.FieldAge:
|
||||
return m.OldAge(ctx)
|
||||
case user.FieldName:
|
||||
return m.OldName(ctx)
|
||||
case user.FieldDescription:
|
||||
return m.OldDescription(ctx)
|
||||
case user.FieldNickname:
|
||||
return m.OldNickname(ctx)
|
||||
case user.FieldAddress:
|
||||
return m.OldAddress(ctx)
|
||||
case user.FieldRenamed:
|
||||
return m.OldRenamed(ctx)
|
||||
case user.FieldOldToken:
|
||||
return m.OldOldToken(ctx)
|
||||
case user.FieldBlob:
|
||||
return m.OldBlob(ctx)
|
||||
case user.FieldState:
|
||||
return m.OldState(ctx)
|
||||
case user.FieldStatus:
|
||||
return m.OldStatus(ctx)
|
||||
case user.FieldWorkplace:
|
||||
return m.OldWorkplace(ctx)
|
||||
case user.FieldDropOptional:
|
||||
return m.OldDropOptional(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown User field %s", name)
|
||||
}
|
||||
23
entc/integration/migrate/entv1/predicate/predicate.go
Normal file
23
entc/integration/migrate/entv1/predicate/predicate.go
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package predicate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Car is the predicate function for car builders.
|
||||
type Car func(*sql.Selector)
|
||||
|
||||
// Conversion is the predicate function for conversion builders.
|
||||
type Conversion func(*sql.Selector)
|
||||
|
||||
// CustomType is the predicate function for customtype builders.
|
||||
type CustomType func(*sql.Selector)
|
||||
|
||||
// User is the predicate function for user builders.
|
||||
type User func(*sql.Selector)
|
||||
36
entc/integration/migrate/entv1/runtime.go
Normal file
36
entc/integration/migrate/entv1/runtime.go
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/schema"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/user"
|
||||
)
|
||||
|
||||
// The init function reads all schema descriptors with runtime code
|
||||
// (default values, validators, hooks and policies) and stitches it
|
||||
// to their package variables.
|
||||
func init() {
|
||||
userFields := schema.User{}.Fields()
|
||||
_ = userFields
|
||||
// userDescName is the schema descriptor for name field.
|
||||
userDescName := userFields[2].Descriptor()
|
||||
// user.NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||
user.NameValidator = userDescName.Validators[0].(func(string) error)
|
||||
// userDescOldToken is the schema descriptor for old_token field.
|
||||
userDescOldToken := userFields[7].Descriptor()
|
||||
// user.DefaultOldToken holds the default value on creation for the old_token field.
|
||||
user.DefaultOldToken = userDescOldToken.Default.(func() string)
|
||||
// userDescBlob is the schema descriptor for blob field.
|
||||
userDescBlob := userFields[8].Descriptor()
|
||||
// user.BlobValidator is a validator for the "blob" field. It is called by the builders before save.
|
||||
user.BlobValidator = userDescBlob.Validators[0].(func([]byte) error)
|
||||
// userDescWorkplace is the schema descriptor for workplace field.
|
||||
userDescWorkplace := userFields[11].Descriptor()
|
||||
// user.WorkplaceValidator is a validator for the "workplace" field. It is called by the builders before save.
|
||||
user.WorkplaceValidator = userDescWorkplace.Validators[0].(func(string) error)
|
||||
}
|
||||
13
entc/integration/migrate/entv1/runtime/runtime.go
Normal file
13
entc/integration/migrate/entv1/runtime/runtime.go
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package runtime
|
||||
|
||||
// The schema-stitching logic is generated in entgo.io/ent/entc/integration/migrate/entv1/runtime.go
|
||||
|
||||
const (
|
||||
Version = "v0.0.0-00010101000000-000000000000" // Version of ent codegen.
|
||||
)
|
||||
39
entc/integration/migrate/entv1/schema/conversion.go
Normal file
39
entc/integration/migrate/entv1/schema/conversion.go
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Conversion holds the schema definition for the Conversion entity.
|
||||
type Conversion struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Conversion.
|
||||
func (Conversion) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name").
|
||||
Optional(),
|
||||
field.Int8("int8_to_string").
|
||||
Optional(),
|
||||
field.Uint8("uint8_to_string").
|
||||
Optional(),
|
||||
field.Int16("int16_to_string").
|
||||
Optional(),
|
||||
field.Uint16("uint16_to_string").
|
||||
Optional(),
|
||||
field.Int32("int32_to_string").
|
||||
Optional(),
|
||||
field.Uint32("uint32_to_string").
|
||||
Optional(),
|
||||
field.Int64("int64_to_string").
|
||||
Optional(),
|
||||
field.Uint64("uint64_to_string").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
27
entc/integration/migrate/entv1/schema/customtype.go
Normal file
27
entc/integration/migrate/entv1/schema/customtype.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CustomType holds the schema definition for the CustomType entity.
|
||||
type CustomType struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the CustomType.
|
||||
func (CustomType) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("custom").
|
||||
Optional().
|
||||
SchemaType(map[string]string{
|
||||
dialect.Postgres: "customtype",
|
||||
}),
|
||||
}
|
||||
}
|
||||
95
entc/integration/migrate/entv1/schema/user.go
Normal file
95
entc/integration/migrate/entv1/schema/user.go
Normal file
@@ -0,0 +1,95 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// User holds the schema definition for the User entity.
|
||||
type User struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the User.
|
||||
func (User) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").
|
||||
StorageKey("oid"),
|
||||
field.Int32("age"),
|
||||
field.String("name").
|
||||
MaxLen(10),
|
||||
field.Text("description").
|
||||
Optional(),
|
||||
field.String("nickname").
|
||||
Unique(),
|
||||
field.String("address").
|
||||
Optional(),
|
||||
field.String("renamed").
|
||||
Optional(),
|
||||
field.String("old_token").
|
||||
DefaultFunc(uuid.NewString),
|
||||
field.Bytes("blob").
|
||||
Optional().
|
||||
MaxLen(255),
|
||||
field.Enum("state").
|
||||
Optional().
|
||||
Values("logged_in", "logged_out").
|
||||
Default("logged_in"),
|
||||
field.String("status").
|
||||
Optional(),
|
||||
field.String("workplace").
|
||||
MaxLen(30).
|
||||
Optional(),
|
||||
field.String("drop_optional").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("children", User.Type).
|
||||
From("parent").
|
||||
Unique(),
|
||||
edge.To("spouse", User.Type).
|
||||
Unique(),
|
||||
edge.To("car", Car.Type).
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
func (User) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("description").
|
||||
Annotations(entsql.Prefix(50)),
|
||||
index.Fields("name", "address").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
type Car struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Annotations of the Car.
|
||||
func (Car) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Annotation{Table: "Car"},
|
||||
}
|
||||
}
|
||||
|
||||
func (Car) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("owner", User.Type).
|
||||
Ref("car").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
223
entc/integration/migrate/entv1/tx.go
Normal file
223
entc/integration/migrate/entv1/tx.go
Normal file
@@ -0,0 +1,223 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
)
|
||||
|
||||
// Tx is a transactional client that is created by calling Client.Tx().
|
||||
type Tx struct {
|
||||
config
|
||||
// Car is the client for interacting with the Car builders.
|
||||
Car *CarClient
|
||||
// Conversion is the client for interacting with the Conversion builders.
|
||||
Conversion *ConversionClient
|
||||
// CustomType is the client for interacting with the CustomType builders.
|
||||
CustomType *CustomTypeClient
|
||||
// User is the client for interacting with the User builders.
|
||||
User *UserClient
|
||||
|
||||
// lazily loaded.
|
||||
client *Client
|
||||
clientOnce sync.Once
|
||||
// ctx lives for the life of the transaction. It is
|
||||
// the same context used by the underlying connection.
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
type (
|
||||
// Committer is the interface that wraps the Commit method.
|
||||
Committer interface {
|
||||
Commit(context.Context, *Tx) error
|
||||
}
|
||||
|
||||
// The CommitFunc type is an adapter to allow the use of ordinary
|
||||
// function as a Committer. If f is a function with the appropriate
|
||||
// signature, CommitFunc(f) is a Committer that calls f.
|
||||
CommitFunc func(context.Context, *Tx) error
|
||||
|
||||
// CommitHook defines the "commit middleware". A function that gets a Committer
|
||||
// and returns a Committer. For example:
|
||||
//
|
||||
// hook := func(next ent.Committer) ent.Committer {
|
||||
// return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||
// // Do some stuff before.
|
||||
// if err := next.Commit(ctx, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // Do some stuff after.
|
||||
// return nil
|
||||
// })
|
||||
// }
|
||||
//
|
||||
CommitHook func(Committer) Committer
|
||||
)
|
||||
|
||||
// Commit calls f(ctx, m).
|
||||
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
|
||||
return f(ctx, tx)
|
||||
}
|
||||
|
||||
// Commit commits the transaction.
|
||||
func (tx *Tx) Commit() error {
|
||||
txDriver := tx.config.driver.(*txDriver)
|
||||
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
|
||||
return txDriver.tx.Commit()
|
||||
})
|
||||
txDriver.mu.Lock()
|
||||
hooks := append([]CommitHook(nil), txDriver.onCommit...)
|
||||
txDriver.mu.Unlock()
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
fn = hooks[i](fn)
|
||||
}
|
||||
return fn.Commit(tx.ctx, tx)
|
||||
}
|
||||
|
||||
// OnCommit adds a hook to call on commit.
|
||||
func (tx *Tx) OnCommit(f CommitHook) {
|
||||
txDriver := tx.config.driver.(*txDriver)
|
||||
txDriver.mu.Lock()
|
||||
txDriver.onCommit = append(txDriver.onCommit, f)
|
||||
txDriver.mu.Unlock()
|
||||
}
|
||||
|
||||
type (
|
||||
// Rollbacker is the interface that wraps the Rollback method.
|
||||
Rollbacker interface {
|
||||
Rollback(context.Context, *Tx) error
|
||||
}
|
||||
|
||||
// The RollbackFunc type is an adapter to allow the use of ordinary
|
||||
// function as a Rollbacker. If f is a function with the appropriate
|
||||
// signature, RollbackFunc(f) is a Rollbacker that calls f.
|
||||
RollbackFunc func(context.Context, *Tx) error
|
||||
|
||||
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
|
||||
// and returns a Rollbacker. For example:
|
||||
//
|
||||
// hook := func(next ent.Rollbacker) ent.Rollbacker {
|
||||
// return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||
// // Do some stuff before.
|
||||
// if err := next.Rollback(ctx, tx); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// // Do some stuff after.
|
||||
// return nil
|
||||
// })
|
||||
// }
|
||||
//
|
||||
RollbackHook func(Rollbacker) Rollbacker
|
||||
)
|
||||
|
||||
// Rollback calls f(ctx, m).
|
||||
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
|
||||
return f(ctx, tx)
|
||||
}
|
||||
|
||||
// Rollback rollbacks the transaction.
|
||||
func (tx *Tx) Rollback() error {
|
||||
txDriver := tx.config.driver.(*txDriver)
|
||||
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
|
||||
return txDriver.tx.Rollback()
|
||||
})
|
||||
txDriver.mu.Lock()
|
||||
hooks := append([]RollbackHook(nil), txDriver.onRollback...)
|
||||
txDriver.mu.Unlock()
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
fn = hooks[i](fn)
|
||||
}
|
||||
return fn.Rollback(tx.ctx, tx)
|
||||
}
|
||||
|
||||
// OnRollback adds a hook to call on rollback.
|
||||
func (tx *Tx) OnRollback(f RollbackHook) {
|
||||
txDriver := tx.config.driver.(*txDriver)
|
||||
txDriver.mu.Lock()
|
||||
txDriver.onRollback = append(txDriver.onRollback, f)
|
||||
txDriver.mu.Unlock()
|
||||
}
|
||||
|
||||
// Client returns a Client that binds to current transaction.
|
||||
func (tx *Tx) Client() *Client {
|
||||
tx.clientOnce.Do(func() {
|
||||
tx.client = &Client{config: tx.config}
|
||||
tx.client.init()
|
||||
})
|
||||
return tx.client
|
||||
}
|
||||
|
||||
func (tx *Tx) init() {
|
||||
tx.Car = NewCarClient(tx.config)
|
||||
tx.Conversion = NewConversionClient(tx.config)
|
||||
tx.CustomType = NewCustomTypeClient(tx.config)
|
||||
tx.User = NewUserClient(tx.config)
|
||||
}
|
||||
|
||||
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
|
||||
// The idea is to support transactions without adding any extra code to the builders.
|
||||
// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance.
|
||||
// Commit and Rollback are nop for the internal builders and the user must call one
|
||||
// of them in order to commit or rollback the transaction.
|
||||
//
|
||||
// If a closed transaction is embedded in one of the generated entities, and the entity
|
||||
// applies a query, for example: Car.QueryXXX(), the query will be executed
|
||||
// through the driver which created this transaction.
|
||||
//
|
||||
// Note that txDriver is not goroutine safe.
|
||||
type txDriver struct {
|
||||
// the driver we started the transaction from.
|
||||
drv dialect.Driver
|
||||
// tx is the underlying transaction.
|
||||
tx dialect.Tx
|
||||
// completion hooks.
|
||||
mu sync.Mutex
|
||||
onCommit []CommitHook
|
||||
onRollback []RollbackHook
|
||||
}
|
||||
|
||||
// newTx creates a new transactional driver.
|
||||
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) {
|
||||
tx, err := drv.Tx(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &txDriver{tx: tx, drv: drv}, nil
|
||||
}
|
||||
|
||||
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
|
||||
// from the internal builders. Should be called only by the internal builders.
|
||||
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil }
|
||||
|
||||
// Dialect returns the dialect of the driver we started the transaction from.
|
||||
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() }
|
||||
|
||||
// Close is a nop close.
|
||||
func (*txDriver) Close() error { return nil }
|
||||
|
||||
// Commit is a nop commit for the internal builders.
|
||||
// User must call `Tx.Commit` in order to commit the transaction.
|
||||
func (*txDriver) Commit() error { return nil }
|
||||
|
||||
// Rollback is a nop rollback for the internal builders.
|
||||
// User must call `Tx.Rollback` in order to rollback the transaction.
|
||||
func (*txDriver) Rollback() error { return nil }
|
||||
|
||||
// Exec calls tx.Exec.
|
||||
func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error {
|
||||
return tx.tx.Exec(ctx, query, args, v)
|
||||
}
|
||||
|
||||
// Query calls tx.Query.
|
||||
func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error {
|
||||
return tx.tx.Query(ctx, query, args, v)
|
||||
}
|
||||
|
||||
var _ dialect.Driver = (*txDriver)(nil)
|
||||
331
entc/integration/migrate/entv1/user.go
Normal file
331
entc/integration/migrate/entv1/user.go
Normal file
@@ -0,0 +1,331 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/user"
|
||||
)
|
||||
|
||||
// User is the model entity for the User schema.
|
||||
type User struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Age holds the value of the "age" field.
|
||||
Age int32 `json:"age,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Description holds the value of the "description" field.
|
||||
Description string `json:"description,omitempty"`
|
||||
// Nickname holds the value of the "nickname" field.
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
// Address holds the value of the "address" field.
|
||||
Address string `json:"address,omitempty"`
|
||||
// Renamed holds the value of the "renamed" field.
|
||||
Renamed string `json:"renamed,omitempty"`
|
||||
// OldToken holds the value of the "old_token" field.
|
||||
OldToken string `json:"old_token,omitempty"`
|
||||
// Blob holds the value of the "blob" field.
|
||||
Blob []byte `json:"blob,omitempty"`
|
||||
// State holds the value of the "state" field.
|
||||
State user.State `json:"state,omitempty"`
|
||||
// Status holds the value of the "status" field.
|
||||
Status string `json:"status,omitempty"`
|
||||
// Workplace holds the value of the "workplace" field.
|
||||
Workplace string `json:"workplace,omitempty"`
|
||||
// DropOptional holds the value of the "drop_optional" field.
|
||||
DropOptional string `json:"drop_optional,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the UserQuery when eager-loading is set.
|
||||
Edges UserEdges `json:"edges"`
|
||||
user_children *int
|
||||
user_spouse *int
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// UserEdges holds the relations/edges for other nodes in the graph.
|
||||
type UserEdges struct {
|
||||
// Parent holds the value of the parent edge.
|
||||
Parent *User `json:"parent,omitempty"`
|
||||
// Children holds the value of the children edge.
|
||||
Children []*User `json:"children,omitempty"`
|
||||
// Spouse holds the value of the spouse edge.
|
||||
Spouse *User `json:"spouse,omitempty"`
|
||||
// Car holds the value of the car edge.
|
||||
Car *Car `json:"car,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [4]bool
|
||||
}
|
||||
|
||||
// ParentOrErr returns the Parent value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e UserEdges) ParentOrErr() (*User, error) {
|
||||
if e.Parent != nil {
|
||||
return e.Parent, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "parent"}
|
||||
}
|
||||
|
||||
// ChildrenOrErr returns the Children value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e UserEdges) ChildrenOrErr() ([]*User, error) {
|
||||
if e.loadedTypes[1] {
|
||||
return e.Children, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "children"}
|
||||
}
|
||||
|
||||
// SpouseOrErr returns the Spouse value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e UserEdges) SpouseOrErr() (*User, error) {
|
||||
if e.Spouse != nil {
|
||||
return e.Spouse, nil
|
||||
} else if e.loadedTypes[2] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "spouse"}
|
||||
}
|
||||
|
||||
// CarOrErr returns the Car value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e UserEdges) CarOrErr() (*Car, error) {
|
||||
if e.Car != nil {
|
||||
return e.Car, nil
|
||||
} else if e.loadedTypes[3] {
|
||||
return nil, &NotFoundError{label: car.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "car"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*User) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case user.FieldBlob:
|
||||
values[i] = new([]byte)
|
||||
case user.FieldID, user.FieldAge:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case user.FieldName, user.FieldDescription, user.FieldNickname, user.FieldAddress, user.FieldRenamed, user.FieldOldToken, user.FieldState, user.FieldStatus, user.FieldWorkplace, user.FieldDropOptional:
|
||||
values[i] = new(sql.NullString)
|
||||
case user.ForeignKeys[0]: // user_children
|
||||
values[i] = new(sql.NullInt64)
|
||||
case user.ForeignKeys[1]: // user_spouse
|
||||
values[i] = new(sql.NullInt64)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the User fields.
|
||||
func (_m *User) 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)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case user.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int(value.Int64)
|
||||
case user.FieldAge:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field age", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Age = int32(value.Int64)
|
||||
}
|
||||
case user.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Name = value.String
|
||||
}
|
||||
case user.FieldDescription:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field description", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Description = value.String
|
||||
}
|
||||
case user.FieldNickname:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field nickname", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Nickname = value.String
|
||||
}
|
||||
case user.FieldAddress:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field address", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Address = value.String
|
||||
}
|
||||
case user.FieldRenamed:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field renamed", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Renamed = value.String
|
||||
}
|
||||
case user.FieldOldToken:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field old_token", values[i])
|
||||
} else if value.Valid {
|
||||
_m.OldToken = value.String
|
||||
}
|
||||
case user.FieldBlob:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field blob", values[i])
|
||||
} else if value != nil {
|
||||
_m.Blob = *value
|
||||
}
|
||||
case user.FieldState:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field state", values[i])
|
||||
} else if value.Valid {
|
||||
_m.State = user.State(value.String)
|
||||
}
|
||||
case user.FieldStatus:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field status", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Status = value.String
|
||||
}
|
||||
case user.FieldWorkplace:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field workplace", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Workplace = value.String
|
||||
}
|
||||
case user.FieldDropOptional:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field drop_optional", values[i])
|
||||
} else if value.Valid {
|
||||
_m.DropOptional = value.String
|
||||
}
|
||||
case user.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field user_children", value)
|
||||
} else if value.Valid {
|
||||
_m.user_children = new(int)
|
||||
*_m.user_children = int(value.Int64)
|
||||
}
|
||||
case user.ForeignKeys[1]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field user_spouse", value)
|
||||
} else if value.Valid {
|
||||
_m.user_spouse = new(int)
|
||||
*_m.user_spouse = int(value.Int64)
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the User.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *User) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryParent queries the "parent" edge of the User entity.
|
||||
func (_m *User) QueryParent() *UserQuery {
|
||||
return NewUserClient(_m.config).QueryParent(_m)
|
||||
}
|
||||
|
||||
// QueryChildren queries the "children" edge of the User entity.
|
||||
func (_m *User) QueryChildren() *UserQuery {
|
||||
return NewUserClient(_m.config).QueryChildren(_m)
|
||||
}
|
||||
|
||||
// QuerySpouse queries the "spouse" edge of the User entity.
|
||||
func (_m *User) QuerySpouse() *UserQuery {
|
||||
return NewUserClient(_m.config).QuerySpouse(_m)
|
||||
}
|
||||
|
||||
// QueryCar queries the "car" edge of the User entity.
|
||||
func (_m *User) QueryCar() *CarQuery {
|
||||
return NewUserClient(_m.config).QueryCar(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this User.
|
||||
// Note that you need to call User.Unwrap() before calling this method if this User
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *User) Update() *UserUpdateOne {
|
||||
return NewUserClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the User 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 (_m *User) Unwrap() *User {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("entv1: User is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *User) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("User(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("age=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Age))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(_m.Name)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("description=")
|
||||
builder.WriteString(_m.Description)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("nickname=")
|
||||
builder.WriteString(_m.Nickname)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("address=")
|
||||
builder.WriteString(_m.Address)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("renamed=")
|
||||
builder.WriteString(_m.Renamed)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("old_token=")
|
||||
builder.WriteString(_m.OldToken)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("blob=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Blob))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("state=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.State))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("status=")
|
||||
builder.WriteString(_m.Status)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("workplace=")
|
||||
builder.WriteString(_m.Workplace)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("drop_optional=")
|
||||
builder.WriteString(_m.DropOptional)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Users is a parsable slice of User.
|
||||
type Users []*User
|
||||
1079
entc/integration/migrate/entv1/user/mutation.go
Normal file
1079
entc/integration/migrate/entv1/user/mutation.go
Normal file
File diff suppressed because it is too large
Load Diff
278
entc/integration/migrate/entv1/user/user.go
Normal file
278
entc/integration/migrate/entv1/user/user.go
Normal file
@@ -0,0 +1,278 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the user type in the database.
|
||||
Label = "user"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "oid"
|
||||
// FieldAge holds the string denoting the age field in the database.
|
||||
FieldAge = "age"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// FieldDescription holds the string denoting the description field in the database.
|
||||
FieldDescription = "description"
|
||||
// FieldNickname holds the string denoting the nickname field in the database.
|
||||
FieldNickname = "nickname"
|
||||
// FieldAddress holds the string denoting the address field in the database.
|
||||
FieldAddress = "address"
|
||||
// FieldRenamed holds the string denoting the renamed field in the database.
|
||||
FieldRenamed = "renamed"
|
||||
// FieldOldToken holds the string denoting the old_token field in the database.
|
||||
FieldOldToken = "old_token"
|
||||
// FieldBlob holds the string denoting the blob field in the database.
|
||||
FieldBlob = "blob"
|
||||
// FieldState holds the string denoting the state field in the database.
|
||||
FieldState = "state"
|
||||
// FieldStatus holds the string denoting the status field in the database.
|
||||
FieldStatus = "status"
|
||||
// FieldWorkplace holds the string denoting the workplace field in the database.
|
||||
FieldWorkplace = "workplace"
|
||||
// FieldDropOptional holds the string denoting the drop_optional field in the database.
|
||||
FieldDropOptional = "drop_optional"
|
||||
// EdgeParent holds the string denoting the parent edge name in mutations.
|
||||
EdgeParent = "parent"
|
||||
// EdgeChildren holds the string denoting the children edge name in mutations.
|
||||
EdgeChildren = "children"
|
||||
// EdgeSpouse holds the string denoting the spouse edge name in mutations.
|
||||
EdgeSpouse = "spouse"
|
||||
// EdgeCar holds the string denoting the car edge name in mutations.
|
||||
EdgeCar = "car"
|
||||
// CarFieldID holds the string denoting the ID field of the Car.
|
||||
CarFieldID = "id"
|
||||
// Table holds the table name of the user in the database.
|
||||
Table = "users"
|
||||
// ParentTable is the table that holds the parent relation/edge.
|
||||
ParentTable = "users"
|
||||
// ParentColumn is the table column denoting the parent relation/edge.
|
||||
ParentColumn = "user_children"
|
||||
// ChildrenTable is the table that holds the children relation/edge.
|
||||
ChildrenTable = "users"
|
||||
// ChildrenColumn is the table column denoting the children relation/edge.
|
||||
ChildrenColumn = "user_children"
|
||||
// SpouseTable is the table that holds the spouse relation/edge.
|
||||
SpouseTable = "users"
|
||||
// SpouseColumn is the table column denoting the spouse relation/edge.
|
||||
SpouseColumn = "user_spouse"
|
||||
// CarTable is the table that holds the car relation/edge.
|
||||
CarTable = "Car"
|
||||
// CarInverseTable is the table name for the Car entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "car" package.
|
||||
CarInverseTable = "Car"
|
||||
// CarColumn is the table column denoting the car relation/edge.
|
||||
CarColumn = "user_car"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for user fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldAge,
|
||||
FieldName,
|
||||
FieldDescription,
|
||||
FieldNickname,
|
||||
FieldAddress,
|
||||
FieldRenamed,
|
||||
FieldOldToken,
|
||||
FieldBlob,
|
||||
FieldState,
|
||||
FieldStatus,
|
||||
FieldWorkplace,
|
||||
FieldDropOptional,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "users"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"user_children",
|
||||
"user_spouse",
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for i := range ForeignKeys {
|
||||
if column == ForeignKeys[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
// NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||
NameValidator func(string) error
|
||||
// DefaultOldToken holds the default value on creation for the "old_token" field.
|
||||
DefaultOldToken func() string
|
||||
// BlobValidator is a validator for the "blob" field. It is called by the builders before save.
|
||||
BlobValidator func([]byte) error
|
||||
// WorkplaceValidator is a validator for the "workplace" field. It is called by the builders before save.
|
||||
WorkplaceValidator func(string) error
|
||||
)
|
||||
|
||||
// State defines the type for the "state" enum field.
|
||||
type State string
|
||||
|
||||
// StateLoggedIn is the default value of the State enum.
|
||||
const DefaultState = StateLoggedIn
|
||||
|
||||
// State values.
|
||||
const (
|
||||
StateLoggedIn State = "logged_in"
|
||||
StateLoggedOut State = "logged_out"
|
||||
)
|
||||
|
||||
func (s State) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// StateValidator is a validator for the "state" field enum values. It is called by the builders before save.
|
||||
func StateValidator(s State) error {
|
||||
switch s {
|
||||
case StateLoggedIn, StateLoggedOut:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("user: invalid enum value for state field: %q", s)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the User queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAge orders the results by the age field.
|
||||
func ByAge(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldAge, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDescription orders the results by the description field.
|
||||
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDescription, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByNickname orders the results by the nickname field.
|
||||
func ByNickname(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldNickname, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAddress orders the results by the address field.
|
||||
func ByAddress(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldAddress, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByRenamed orders the results by the renamed field.
|
||||
func ByRenamed(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldRenamed, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByOldToken orders the results by the old_token field.
|
||||
func ByOldToken(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldOldToken, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByState orders the results by the state field.
|
||||
func ByState(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldState, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByStatus orders the results by the status field.
|
||||
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByWorkplace orders the results by the workplace field.
|
||||
func ByWorkplace(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldWorkplace, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDropOptional orders the results by the drop_optional field.
|
||||
func ByDropOptional(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDropOptional, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByParentField orders the results by parent field.
|
||||
func ByParentField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newParentStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByChildrenCount orders the results by children count.
|
||||
func ByChildrenCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newChildrenStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByChildren orders the results by children terms.
|
||||
func ByChildren(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newChildrenStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// BySpouseField orders the results by spouse field.
|
||||
func BySpouseField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newSpouseStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByCarField orders the results by car field.
|
||||
func ByCarField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newCarStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newParentStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, ParentTable, ParentColumn),
|
||||
)
|
||||
}
|
||||
func newChildrenStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, ChildrenTable, ChildrenColumn),
|
||||
)
|
||||
}
|
||||
func newSpouseStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, SpouseTable, SpouseColumn),
|
||||
)
|
||||
}
|
||||
func newCarStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(CarInverseTable, CarFieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, CarTable, CarColumn),
|
||||
)
|
||||
}
|
||||
985
entc/integration/migrate/entv1/user/where.go
Normal file
985
entc/integration/migrate/entv1/user/where.go
Normal file
@@ -0,0 +1,985 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Age applies equality check predicate on the "age" field. It's identical to AgeEQ.
|
||||
func Age(v int32) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldAge, v))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
|
||||
func Description(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// Nickname applies equality check predicate on the "nickname" field. It's identical to NicknameEQ.
|
||||
func Nickname(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldNickname, v))
|
||||
}
|
||||
|
||||
// Address applies equality check predicate on the "address" field. It's identical to AddressEQ.
|
||||
func Address(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldAddress, v))
|
||||
}
|
||||
|
||||
// Renamed applies equality check predicate on the "renamed" field. It's identical to RenamedEQ.
|
||||
func Renamed(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldRenamed, v))
|
||||
}
|
||||
|
||||
// OldToken applies equality check predicate on the "old_token" field. It's identical to OldTokenEQ.
|
||||
func OldToken(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldOldToken, v))
|
||||
}
|
||||
|
||||
// Blob applies equality check predicate on the "blob" field. It's identical to BlobEQ.
|
||||
func Blob(v []byte) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldBlob, v))
|
||||
}
|
||||
|
||||
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
|
||||
func Status(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldStatus, v))
|
||||
}
|
||||
|
||||
// Workplace applies equality check predicate on the "workplace" field. It's identical to WorkplaceEQ.
|
||||
func Workplace(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldWorkplace, v))
|
||||
}
|
||||
|
||||
// DropOptional applies equality check predicate on the "drop_optional" field. It's identical to DropOptionalEQ.
|
||||
func DropOptional(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldDropOptional, v))
|
||||
}
|
||||
|
||||
// AgeEQ applies the EQ predicate on the "age" field.
|
||||
func AgeEQ(v int32) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldAge, v))
|
||||
}
|
||||
|
||||
// AgeNEQ applies the NEQ predicate on the "age" field.
|
||||
func AgeNEQ(v int32) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldAge, v))
|
||||
}
|
||||
|
||||
// AgeIn applies the In predicate on the "age" field.
|
||||
func AgeIn(vs ...int32) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldAge, vs...))
|
||||
}
|
||||
|
||||
// AgeNotIn applies the NotIn predicate on the "age" field.
|
||||
func AgeNotIn(vs ...int32) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldAge, vs...))
|
||||
}
|
||||
|
||||
// AgeGT applies the GT predicate on the "age" field.
|
||||
func AgeGT(v int32) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldAge, v))
|
||||
}
|
||||
|
||||
// AgeGTE applies the GTE predicate on the "age" field.
|
||||
func AgeGTE(v int32) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldAge, v))
|
||||
}
|
||||
|
||||
// AgeLT applies the LT predicate on the "age" field.
|
||||
func AgeLT(v int32) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldAge, v))
|
||||
}
|
||||
|
||||
// AgeLTE applies the LTE predicate on the "age" field.
|
||||
func AgeLTE(v int32) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldAge, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// DescriptionEQ applies the EQ predicate on the "description" field.
|
||||
func DescriptionEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionNEQ applies the NEQ predicate on the "description" field.
|
||||
func DescriptionNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionIn applies the In predicate on the "description" field.
|
||||
func DescriptionIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldDescription, vs...))
|
||||
}
|
||||
|
||||
// DescriptionNotIn applies the NotIn predicate on the "description" field.
|
||||
func DescriptionNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldDescription, vs...))
|
||||
}
|
||||
|
||||
// DescriptionGT applies the GT predicate on the "description" field.
|
||||
func DescriptionGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionGTE applies the GTE predicate on the "description" field.
|
||||
func DescriptionGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionLT applies the LT predicate on the "description" field.
|
||||
func DescriptionLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionLTE applies the LTE predicate on the "description" field.
|
||||
func DescriptionLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionContains applies the Contains predicate on the "description" field.
|
||||
func DescriptionContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
|
||||
func DescriptionHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
|
||||
func DescriptionHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionIsNil applies the IsNil predicate on the "description" field.
|
||||
func DescriptionIsNil() predicate.User {
|
||||
return predicate.User(sql.FieldIsNull(FieldDescription))
|
||||
}
|
||||
|
||||
// DescriptionNotNil applies the NotNil predicate on the "description" field.
|
||||
func DescriptionNotNil() predicate.User {
|
||||
return predicate.User(sql.FieldNotNull(FieldDescription))
|
||||
}
|
||||
|
||||
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
|
||||
func DescriptionEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
|
||||
func DescriptionContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldDescription, v))
|
||||
}
|
||||
|
||||
// NicknameEQ applies the EQ predicate on the "nickname" field.
|
||||
func NicknameEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldNickname, v))
|
||||
}
|
||||
|
||||
// NicknameNEQ applies the NEQ predicate on the "nickname" field.
|
||||
func NicknameNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldNickname, v))
|
||||
}
|
||||
|
||||
// NicknameIn applies the In predicate on the "nickname" field.
|
||||
func NicknameIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldNickname, vs...))
|
||||
}
|
||||
|
||||
// NicknameNotIn applies the NotIn predicate on the "nickname" field.
|
||||
func NicknameNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldNickname, vs...))
|
||||
}
|
||||
|
||||
// NicknameGT applies the GT predicate on the "nickname" field.
|
||||
func NicknameGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldNickname, v))
|
||||
}
|
||||
|
||||
// NicknameGTE applies the GTE predicate on the "nickname" field.
|
||||
func NicknameGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldNickname, v))
|
||||
}
|
||||
|
||||
// NicknameLT applies the LT predicate on the "nickname" field.
|
||||
func NicknameLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldNickname, v))
|
||||
}
|
||||
|
||||
// NicknameLTE applies the LTE predicate on the "nickname" field.
|
||||
func NicknameLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldNickname, v))
|
||||
}
|
||||
|
||||
// NicknameContains applies the Contains predicate on the "nickname" field.
|
||||
func NicknameContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldNickname, v))
|
||||
}
|
||||
|
||||
// NicknameHasPrefix applies the HasPrefix predicate on the "nickname" field.
|
||||
func NicknameHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldNickname, v))
|
||||
}
|
||||
|
||||
// NicknameHasSuffix applies the HasSuffix predicate on the "nickname" field.
|
||||
func NicknameHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldNickname, v))
|
||||
}
|
||||
|
||||
// NicknameEqualFold applies the EqualFold predicate on the "nickname" field.
|
||||
func NicknameEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldNickname, v))
|
||||
}
|
||||
|
||||
// NicknameContainsFold applies the ContainsFold predicate on the "nickname" field.
|
||||
func NicknameContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldNickname, v))
|
||||
}
|
||||
|
||||
// AddressEQ applies the EQ predicate on the "address" field.
|
||||
func AddressEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldAddress, v))
|
||||
}
|
||||
|
||||
// AddressNEQ applies the NEQ predicate on the "address" field.
|
||||
func AddressNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldAddress, v))
|
||||
}
|
||||
|
||||
// AddressIn applies the In predicate on the "address" field.
|
||||
func AddressIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldAddress, vs...))
|
||||
}
|
||||
|
||||
// AddressNotIn applies the NotIn predicate on the "address" field.
|
||||
func AddressNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldAddress, vs...))
|
||||
}
|
||||
|
||||
// AddressGT applies the GT predicate on the "address" field.
|
||||
func AddressGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldAddress, v))
|
||||
}
|
||||
|
||||
// AddressGTE applies the GTE predicate on the "address" field.
|
||||
func AddressGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldAddress, v))
|
||||
}
|
||||
|
||||
// AddressLT applies the LT predicate on the "address" field.
|
||||
func AddressLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldAddress, v))
|
||||
}
|
||||
|
||||
// AddressLTE applies the LTE predicate on the "address" field.
|
||||
func AddressLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldAddress, v))
|
||||
}
|
||||
|
||||
// AddressContains applies the Contains predicate on the "address" field.
|
||||
func AddressContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldAddress, v))
|
||||
}
|
||||
|
||||
// AddressHasPrefix applies the HasPrefix predicate on the "address" field.
|
||||
func AddressHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldAddress, v))
|
||||
}
|
||||
|
||||
// AddressHasSuffix applies the HasSuffix predicate on the "address" field.
|
||||
func AddressHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldAddress, v))
|
||||
}
|
||||
|
||||
// AddressIsNil applies the IsNil predicate on the "address" field.
|
||||
func AddressIsNil() predicate.User {
|
||||
return predicate.User(sql.FieldIsNull(FieldAddress))
|
||||
}
|
||||
|
||||
// AddressNotNil applies the NotNil predicate on the "address" field.
|
||||
func AddressNotNil() predicate.User {
|
||||
return predicate.User(sql.FieldNotNull(FieldAddress))
|
||||
}
|
||||
|
||||
// AddressEqualFold applies the EqualFold predicate on the "address" field.
|
||||
func AddressEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldAddress, v))
|
||||
}
|
||||
|
||||
// AddressContainsFold applies the ContainsFold predicate on the "address" field.
|
||||
func AddressContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldAddress, v))
|
||||
}
|
||||
|
||||
// RenamedEQ applies the EQ predicate on the "renamed" field.
|
||||
func RenamedEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldRenamed, v))
|
||||
}
|
||||
|
||||
// RenamedNEQ applies the NEQ predicate on the "renamed" field.
|
||||
func RenamedNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldRenamed, v))
|
||||
}
|
||||
|
||||
// RenamedIn applies the In predicate on the "renamed" field.
|
||||
func RenamedIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldRenamed, vs...))
|
||||
}
|
||||
|
||||
// RenamedNotIn applies the NotIn predicate on the "renamed" field.
|
||||
func RenamedNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldRenamed, vs...))
|
||||
}
|
||||
|
||||
// RenamedGT applies the GT predicate on the "renamed" field.
|
||||
func RenamedGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldRenamed, v))
|
||||
}
|
||||
|
||||
// RenamedGTE applies the GTE predicate on the "renamed" field.
|
||||
func RenamedGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldRenamed, v))
|
||||
}
|
||||
|
||||
// RenamedLT applies the LT predicate on the "renamed" field.
|
||||
func RenamedLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldRenamed, v))
|
||||
}
|
||||
|
||||
// RenamedLTE applies the LTE predicate on the "renamed" field.
|
||||
func RenamedLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldRenamed, v))
|
||||
}
|
||||
|
||||
// RenamedContains applies the Contains predicate on the "renamed" field.
|
||||
func RenamedContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldRenamed, v))
|
||||
}
|
||||
|
||||
// RenamedHasPrefix applies the HasPrefix predicate on the "renamed" field.
|
||||
func RenamedHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldRenamed, v))
|
||||
}
|
||||
|
||||
// RenamedHasSuffix applies the HasSuffix predicate on the "renamed" field.
|
||||
func RenamedHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldRenamed, v))
|
||||
}
|
||||
|
||||
// RenamedIsNil applies the IsNil predicate on the "renamed" field.
|
||||
func RenamedIsNil() predicate.User {
|
||||
return predicate.User(sql.FieldIsNull(FieldRenamed))
|
||||
}
|
||||
|
||||
// RenamedNotNil applies the NotNil predicate on the "renamed" field.
|
||||
func RenamedNotNil() predicate.User {
|
||||
return predicate.User(sql.FieldNotNull(FieldRenamed))
|
||||
}
|
||||
|
||||
// RenamedEqualFold applies the EqualFold predicate on the "renamed" field.
|
||||
func RenamedEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldRenamed, v))
|
||||
}
|
||||
|
||||
// RenamedContainsFold applies the ContainsFold predicate on the "renamed" field.
|
||||
func RenamedContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldRenamed, v))
|
||||
}
|
||||
|
||||
// OldTokenEQ applies the EQ predicate on the "old_token" field.
|
||||
func OldTokenEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldOldToken, v))
|
||||
}
|
||||
|
||||
// OldTokenNEQ applies the NEQ predicate on the "old_token" field.
|
||||
func OldTokenNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldOldToken, v))
|
||||
}
|
||||
|
||||
// OldTokenIn applies the In predicate on the "old_token" field.
|
||||
func OldTokenIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldOldToken, vs...))
|
||||
}
|
||||
|
||||
// OldTokenNotIn applies the NotIn predicate on the "old_token" field.
|
||||
func OldTokenNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldOldToken, vs...))
|
||||
}
|
||||
|
||||
// OldTokenGT applies the GT predicate on the "old_token" field.
|
||||
func OldTokenGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldOldToken, v))
|
||||
}
|
||||
|
||||
// OldTokenGTE applies the GTE predicate on the "old_token" field.
|
||||
func OldTokenGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldOldToken, v))
|
||||
}
|
||||
|
||||
// OldTokenLT applies the LT predicate on the "old_token" field.
|
||||
func OldTokenLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldOldToken, v))
|
||||
}
|
||||
|
||||
// OldTokenLTE applies the LTE predicate on the "old_token" field.
|
||||
func OldTokenLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldOldToken, v))
|
||||
}
|
||||
|
||||
// OldTokenContains applies the Contains predicate on the "old_token" field.
|
||||
func OldTokenContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldOldToken, v))
|
||||
}
|
||||
|
||||
// OldTokenHasPrefix applies the HasPrefix predicate on the "old_token" field.
|
||||
func OldTokenHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldOldToken, v))
|
||||
}
|
||||
|
||||
// OldTokenHasSuffix applies the HasSuffix predicate on the "old_token" field.
|
||||
func OldTokenHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldOldToken, v))
|
||||
}
|
||||
|
||||
// OldTokenEqualFold applies the EqualFold predicate on the "old_token" field.
|
||||
func OldTokenEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldOldToken, v))
|
||||
}
|
||||
|
||||
// OldTokenContainsFold applies the ContainsFold predicate on the "old_token" field.
|
||||
func OldTokenContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldOldToken, v))
|
||||
}
|
||||
|
||||
// BlobEQ applies the EQ predicate on the "blob" field.
|
||||
func BlobEQ(v []byte) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldBlob, v))
|
||||
}
|
||||
|
||||
// BlobNEQ applies the NEQ predicate on the "blob" field.
|
||||
func BlobNEQ(v []byte) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldBlob, v))
|
||||
}
|
||||
|
||||
// BlobIn applies the In predicate on the "blob" field.
|
||||
func BlobIn(vs ...[]byte) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldBlob, vs...))
|
||||
}
|
||||
|
||||
// BlobNotIn applies the NotIn predicate on the "blob" field.
|
||||
func BlobNotIn(vs ...[]byte) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldBlob, vs...))
|
||||
}
|
||||
|
||||
// BlobGT applies the GT predicate on the "blob" field.
|
||||
func BlobGT(v []byte) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldBlob, v))
|
||||
}
|
||||
|
||||
// BlobGTE applies the GTE predicate on the "blob" field.
|
||||
func BlobGTE(v []byte) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldBlob, v))
|
||||
}
|
||||
|
||||
// BlobLT applies the LT predicate on the "blob" field.
|
||||
func BlobLT(v []byte) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldBlob, v))
|
||||
}
|
||||
|
||||
// BlobLTE applies the LTE predicate on the "blob" field.
|
||||
func BlobLTE(v []byte) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldBlob, v))
|
||||
}
|
||||
|
||||
// BlobIsNil applies the IsNil predicate on the "blob" field.
|
||||
func BlobIsNil() predicate.User {
|
||||
return predicate.User(sql.FieldIsNull(FieldBlob))
|
||||
}
|
||||
|
||||
// BlobNotNil applies the NotNil predicate on the "blob" field.
|
||||
func BlobNotNil() predicate.User {
|
||||
return predicate.User(sql.FieldNotNull(FieldBlob))
|
||||
}
|
||||
|
||||
// StateEQ applies the EQ predicate on the "state" field.
|
||||
func StateEQ(v State) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldState, v))
|
||||
}
|
||||
|
||||
// StateNEQ applies the NEQ predicate on the "state" field.
|
||||
func StateNEQ(v State) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldState, v))
|
||||
}
|
||||
|
||||
// StateIn applies the In predicate on the "state" field.
|
||||
func StateIn(vs ...State) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldState, vs...))
|
||||
}
|
||||
|
||||
// StateNotIn applies the NotIn predicate on the "state" field.
|
||||
func StateNotIn(vs ...State) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldState, vs...))
|
||||
}
|
||||
|
||||
// StateIsNil applies the IsNil predicate on the "state" field.
|
||||
func StateIsNil() predicate.User {
|
||||
return predicate.User(sql.FieldIsNull(FieldState))
|
||||
}
|
||||
|
||||
// StateNotNil applies the NotNil predicate on the "state" field.
|
||||
func StateNotNil() predicate.User {
|
||||
return predicate.User(sql.FieldNotNull(FieldState))
|
||||
}
|
||||
|
||||
// StatusEQ applies the EQ predicate on the "status" field.
|
||||
func StatusEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusNEQ applies the NEQ predicate on the "status" field.
|
||||
func StatusNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusIn applies the In predicate on the "status" field.
|
||||
func StatusIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldStatus, vs...))
|
||||
}
|
||||
|
||||
// StatusNotIn applies the NotIn predicate on the "status" field.
|
||||
func StatusNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldStatus, vs...))
|
||||
}
|
||||
|
||||
// StatusGT applies the GT predicate on the "status" field.
|
||||
func StatusGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusGTE applies the GTE predicate on the "status" field.
|
||||
func StatusGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusLT applies the LT predicate on the "status" field.
|
||||
func StatusLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusLTE applies the LTE predicate on the "status" field.
|
||||
func StatusLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusContains applies the Contains predicate on the "status" field.
|
||||
func StatusContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
|
||||
func StatusHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
|
||||
func StatusHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusIsNil applies the IsNil predicate on the "status" field.
|
||||
func StatusIsNil() predicate.User {
|
||||
return predicate.User(sql.FieldIsNull(FieldStatus))
|
||||
}
|
||||
|
||||
// StatusNotNil applies the NotNil predicate on the "status" field.
|
||||
func StatusNotNil() predicate.User {
|
||||
return predicate.User(sql.FieldNotNull(FieldStatus))
|
||||
}
|
||||
|
||||
// StatusEqualFold applies the EqualFold predicate on the "status" field.
|
||||
func StatusEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldStatus, v))
|
||||
}
|
||||
|
||||
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
|
||||
func StatusContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldStatus, v))
|
||||
}
|
||||
|
||||
// WorkplaceEQ applies the EQ predicate on the "workplace" field.
|
||||
func WorkplaceEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldWorkplace, v))
|
||||
}
|
||||
|
||||
// WorkplaceNEQ applies the NEQ predicate on the "workplace" field.
|
||||
func WorkplaceNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldWorkplace, v))
|
||||
}
|
||||
|
||||
// WorkplaceIn applies the In predicate on the "workplace" field.
|
||||
func WorkplaceIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldWorkplace, vs...))
|
||||
}
|
||||
|
||||
// WorkplaceNotIn applies the NotIn predicate on the "workplace" field.
|
||||
func WorkplaceNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldWorkplace, vs...))
|
||||
}
|
||||
|
||||
// WorkplaceGT applies the GT predicate on the "workplace" field.
|
||||
func WorkplaceGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldWorkplace, v))
|
||||
}
|
||||
|
||||
// WorkplaceGTE applies the GTE predicate on the "workplace" field.
|
||||
func WorkplaceGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldWorkplace, v))
|
||||
}
|
||||
|
||||
// WorkplaceLT applies the LT predicate on the "workplace" field.
|
||||
func WorkplaceLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldWorkplace, v))
|
||||
}
|
||||
|
||||
// WorkplaceLTE applies the LTE predicate on the "workplace" field.
|
||||
func WorkplaceLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldWorkplace, v))
|
||||
}
|
||||
|
||||
// WorkplaceContains applies the Contains predicate on the "workplace" field.
|
||||
func WorkplaceContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldWorkplace, v))
|
||||
}
|
||||
|
||||
// WorkplaceHasPrefix applies the HasPrefix predicate on the "workplace" field.
|
||||
func WorkplaceHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldWorkplace, v))
|
||||
}
|
||||
|
||||
// WorkplaceHasSuffix applies the HasSuffix predicate on the "workplace" field.
|
||||
func WorkplaceHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldWorkplace, v))
|
||||
}
|
||||
|
||||
// WorkplaceIsNil applies the IsNil predicate on the "workplace" field.
|
||||
func WorkplaceIsNil() predicate.User {
|
||||
return predicate.User(sql.FieldIsNull(FieldWorkplace))
|
||||
}
|
||||
|
||||
// WorkplaceNotNil applies the NotNil predicate on the "workplace" field.
|
||||
func WorkplaceNotNil() predicate.User {
|
||||
return predicate.User(sql.FieldNotNull(FieldWorkplace))
|
||||
}
|
||||
|
||||
// WorkplaceEqualFold applies the EqualFold predicate on the "workplace" field.
|
||||
func WorkplaceEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldWorkplace, v))
|
||||
}
|
||||
|
||||
// WorkplaceContainsFold applies the ContainsFold predicate on the "workplace" field.
|
||||
func WorkplaceContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldWorkplace, v))
|
||||
}
|
||||
|
||||
// DropOptionalEQ applies the EQ predicate on the "drop_optional" field.
|
||||
func DropOptionalEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldDropOptional, v))
|
||||
}
|
||||
|
||||
// DropOptionalNEQ applies the NEQ predicate on the "drop_optional" field.
|
||||
func DropOptionalNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldDropOptional, v))
|
||||
}
|
||||
|
||||
// DropOptionalIn applies the In predicate on the "drop_optional" field.
|
||||
func DropOptionalIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldDropOptional, vs...))
|
||||
}
|
||||
|
||||
// DropOptionalNotIn applies the NotIn predicate on the "drop_optional" field.
|
||||
func DropOptionalNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldDropOptional, vs...))
|
||||
}
|
||||
|
||||
// DropOptionalGT applies the GT predicate on the "drop_optional" field.
|
||||
func DropOptionalGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldDropOptional, v))
|
||||
}
|
||||
|
||||
// DropOptionalGTE applies the GTE predicate on the "drop_optional" field.
|
||||
func DropOptionalGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldDropOptional, v))
|
||||
}
|
||||
|
||||
// DropOptionalLT applies the LT predicate on the "drop_optional" field.
|
||||
func DropOptionalLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldDropOptional, v))
|
||||
}
|
||||
|
||||
// DropOptionalLTE applies the LTE predicate on the "drop_optional" field.
|
||||
func DropOptionalLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldDropOptional, v))
|
||||
}
|
||||
|
||||
// DropOptionalContains applies the Contains predicate on the "drop_optional" field.
|
||||
func DropOptionalContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldDropOptional, v))
|
||||
}
|
||||
|
||||
// DropOptionalHasPrefix applies the HasPrefix predicate on the "drop_optional" field.
|
||||
func DropOptionalHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldDropOptional, v))
|
||||
}
|
||||
|
||||
// DropOptionalHasSuffix applies the HasSuffix predicate on the "drop_optional" field.
|
||||
func DropOptionalHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldDropOptional, v))
|
||||
}
|
||||
|
||||
// DropOptionalIsNil applies the IsNil predicate on the "drop_optional" field.
|
||||
func DropOptionalIsNil() predicate.User {
|
||||
return predicate.User(sql.FieldIsNull(FieldDropOptional))
|
||||
}
|
||||
|
||||
// DropOptionalNotNil applies the NotNil predicate on the "drop_optional" field.
|
||||
func DropOptionalNotNil() predicate.User {
|
||||
return predicate.User(sql.FieldNotNull(FieldDropOptional))
|
||||
}
|
||||
|
||||
// DropOptionalEqualFold applies the EqualFold predicate on the "drop_optional" field.
|
||||
func DropOptionalEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldDropOptional, v))
|
||||
}
|
||||
|
||||
// DropOptionalContainsFold applies the ContainsFold predicate on the "drop_optional" field.
|
||||
func DropOptionalContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldDropOptional, v))
|
||||
}
|
||||
|
||||
// HasParent applies the HasEdge predicate on the "parent" edge.
|
||||
func HasParent() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, ParentTable, ParentColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasParentWith applies the HasEdge predicate on the "parent" edge with a given conditions (other predicates).
|
||||
func HasParentWith(preds ...predicate.User) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newParentStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasChildren applies the HasEdge predicate on the "children" edge.
|
||||
func HasChildren() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, ChildrenTable, ChildrenColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasChildrenWith applies the HasEdge predicate on the "children" edge with a given conditions (other predicates).
|
||||
func HasChildrenWith(preds ...predicate.User) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newChildrenStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasSpouse applies the HasEdge predicate on the "spouse" edge.
|
||||
func HasSpouse() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, SpouseTable, SpouseColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasSpouseWith applies the HasEdge predicate on the "spouse" edge with a given conditions (other predicates).
|
||||
func HasSpouseWith(preds ...predicate.User) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newSpouseStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasCar applies the HasEdge predicate on the "car" edge.
|
||||
func HasCar() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, CarTable, CarColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasCarWith applies the HasEdge predicate on the "car" edge with a given conditions (other predicates).
|
||||
func HasCarWith(preds ...predicate.Car) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newCarStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.User) predicate.User {
|
||||
return predicate.User(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.User) predicate.User {
|
||||
return predicate.User(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.User) predicate.User {
|
||||
return predicate.User(sql.NotPredicates(p))
|
||||
}
|
||||
555
entc/integration/migrate/entv1/user_create.go
Normal file
555
entc/integration/migrate/entv1/user_create.go
Normal file
@@ -0,0 +1,555 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// UserCreate is the builder for creating a User entity.
|
||||
type UserCreate struct {
|
||||
config
|
||||
mutation *UserMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetAge sets the "age" field.
|
||||
func (_c *UserCreate) SetAge(v int32) *UserCreate {
|
||||
_c.mutation.SetAge(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *UserCreate) SetName(v string) *UserCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (_c *UserCreate) SetDescription(v string) *UserCreate {
|
||||
_c.mutation.SetDescription(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableDescription(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetDescription(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNickname sets the "nickname" field.
|
||||
func (_c *UserCreate) SetNickname(v string) *UserCreate {
|
||||
_c.mutation.SetNickname(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetAddress sets the "address" field.
|
||||
func (_c *UserCreate) SetAddress(v string) *UserCreate {
|
||||
_c.mutation.SetAddress(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableAddress sets the "address" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableAddress(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetAddress(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetRenamed sets the "renamed" field.
|
||||
func (_c *UserCreate) SetRenamed(v string) *UserCreate {
|
||||
_c.mutation.SetRenamed(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableRenamed sets the "renamed" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableRenamed(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetRenamed(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetOldToken sets the "old_token" field.
|
||||
func (_c *UserCreate) SetOldToken(v string) *UserCreate {
|
||||
_c.mutation.SetOldToken(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableOldToken sets the "old_token" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableOldToken(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetOldToken(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetBlob sets the "blob" field.
|
||||
func (_c *UserCreate) SetBlob(v []byte) *UserCreate {
|
||||
_c.mutation.SetBlob(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetState sets the "state" field.
|
||||
func (_c *UserCreate) SetState(v user.State) *UserCreate {
|
||||
_c.mutation.SetState(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableState sets the "state" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableState(v *user.State) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetState(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_c *UserCreate) SetStatus(v string) *UserCreate {
|
||||
_c.mutation.SetStatus(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableStatus(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetStatus(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetWorkplace sets the "workplace" field.
|
||||
func (_c *UserCreate) SetWorkplace(v string) *UserCreate {
|
||||
_c.mutation.SetWorkplace(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableWorkplace sets the "workplace" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableWorkplace(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetWorkplace(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetDropOptional sets the "drop_optional" field.
|
||||
func (_c *UserCreate) SetDropOptional(v string) *UserCreate {
|
||||
_c.mutation.SetDropOptional(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableDropOptional sets the "drop_optional" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableDropOptional(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetDropOptional(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *UserCreate) SetID(v int) *UserCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetParentID sets the "parent" edge to the User entity by ID.
|
||||
func (_c *UserCreate) SetParentID(id int) *UserCreate {
|
||||
_c.mutation.SetParentID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableParentID sets the "parent" edge to the User entity by ID if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableParentID(id *int) *UserCreate {
|
||||
if id != nil {
|
||||
_c = _c.SetParentID(*id)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetParent sets the "parent" edge to the User entity.
|
||||
func (_c *UserCreate) SetParent(v *User) *UserCreate {
|
||||
return _c.SetParentID(v.ID)
|
||||
}
|
||||
|
||||
// AddChildIDs adds the "children" edge to the User entity by IDs.
|
||||
func (_c *UserCreate) AddChildIDs(ids ...int) *UserCreate {
|
||||
_c.mutation.AddChildIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddChildren adds the "children" edges to the User entity.
|
||||
func (_c *UserCreate) AddChildren(v ...*User) *UserCreate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddChildIDs(ids...)
|
||||
}
|
||||
|
||||
// SetSpouseID sets the "spouse" edge to the User entity by ID.
|
||||
func (_c *UserCreate) SetSpouseID(id int) *UserCreate {
|
||||
_c.mutation.SetSpouseID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableSpouseID sets the "spouse" edge to the User entity by ID if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableSpouseID(id *int) *UserCreate {
|
||||
if id != nil {
|
||||
_c = _c.SetSpouseID(*id)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetSpouse sets the "spouse" edge to the User entity.
|
||||
func (_c *UserCreate) SetSpouse(v *User) *UserCreate {
|
||||
return _c.SetSpouseID(v.ID)
|
||||
}
|
||||
|
||||
// SetCarID sets the "car" edge to the Car entity by ID.
|
||||
func (_c *UserCreate) SetCarID(id int) *UserCreate {
|
||||
_c.mutation.SetCarID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCarID sets the "car" edge to the Car entity by ID if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableCarID(id *int) *UserCreate {
|
||||
if id != nil {
|
||||
_c = _c.SetCarID(*id)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCar sets the "car" edge to the Car entity.
|
||||
func (_c *UserCreate) SetCar(v *Car) *UserCreate {
|
||||
return _c.SetCarID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (_c *UserCreate) Mutation() *UserMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the User in the database.
|
||||
func (_c *UserCreate) Save(ctx context.Context) (*User, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *UserCreate) SaveX(ctx context.Context) *User {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *UserCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *UserCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *UserCreate) defaults() {
|
||||
if _, ok := _c.mutation.OldToken(); !ok {
|
||||
v := user.DefaultOldToken()
|
||||
_c.mutation.SetOldToken(v)
|
||||
}
|
||||
if _, ok := _c.mutation.State(); !ok {
|
||||
v := user.DefaultState
|
||||
_c.mutation.SetState(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *UserCreate) check() error {
|
||||
if _, ok := _c.mutation.Age(); !ok {
|
||||
return &ValidationError{Name: "age", err: errors.New(`entv1: missing required field "User.age"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`entv1: missing required field "User.name"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Name(); ok {
|
||||
if err := user.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`entv1: validator failed for field "User.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.Nickname(); !ok {
|
||||
return &ValidationError{Name: "nickname", err: errors.New(`entv1: missing required field "User.nickname"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.OldToken(); !ok {
|
||||
return &ValidationError{Name: "old_token", err: errors.New(`entv1: missing required field "User.old_token"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Blob(); ok {
|
||||
if err := user.BlobValidator(v); err != nil {
|
||||
return &ValidationError{Name: "blob", err: fmt.Errorf(`entv1: validator failed for field "User.blob": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _c.mutation.State(); ok {
|
||||
if err := user.StateValidator(v); err != nil {
|
||||
return &ValidationError{Name: "state", err: fmt.Errorf(`entv1: validator failed for field "User.state": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _c.mutation.Workplace(); ok {
|
||||
if err := user.WorkplaceValidator(v); err != nil {
|
||||
return &ValidationError{Name: "workplace", err: fmt.Errorf(`entv1: validator failed for field "User.workplace": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_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}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if _spec.ID.Value != _node.ID {
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
}
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &User{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
)
|
||||
if id, ok := _c.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
if value, ok := _c.mutation.Age(); ok {
|
||||
_spec.SetField(user.FieldAge, field.TypeInt32, value)
|
||||
_node.Age = value
|
||||
}
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(user.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := _c.mutation.Description(); ok {
|
||||
_spec.SetField(user.FieldDescription, field.TypeString, value)
|
||||
_node.Description = value
|
||||
}
|
||||
if value, ok := _c.mutation.Nickname(); ok {
|
||||
_spec.SetField(user.FieldNickname, field.TypeString, value)
|
||||
_node.Nickname = value
|
||||
}
|
||||
if value, ok := _c.mutation.Address(); ok {
|
||||
_spec.SetField(user.FieldAddress, field.TypeString, value)
|
||||
_node.Address = value
|
||||
}
|
||||
if value, ok := _c.mutation.Renamed(); ok {
|
||||
_spec.SetField(user.FieldRenamed, field.TypeString, value)
|
||||
_node.Renamed = value
|
||||
}
|
||||
if value, ok := _c.mutation.OldToken(); ok {
|
||||
_spec.SetField(user.FieldOldToken, field.TypeString, value)
|
||||
_node.OldToken = value
|
||||
}
|
||||
if value, ok := _c.mutation.Blob(); ok {
|
||||
_spec.SetField(user.FieldBlob, field.TypeBytes, value)
|
||||
_node.Blob = value
|
||||
}
|
||||
if value, ok := _c.mutation.State(); ok {
|
||||
_spec.SetField(user.FieldState, field.TypeEnum, value)
|
||||
_node.State = value
|
||||
}
|
||||
if value, ok := _c.mutation.Status(); ok {
|
||||
_spec.SetField(user.FieldStatus, field.TypeString, value)
|
||||
_node.Status = value
|
||||
}
|
||||
if value, ok := _c.mutation.Workplace(); ok {
|
||||
_spec.SetField(user.FieldWorkplace, field.TypeString, value)
|
||||
_node.Workplace = value
|
||||
}
|
||||
if value, ok := _c.mutation.DropOptional(); ok {
|
||||
_spec.SetField(user.FieldDropOptional, field.TypeString, value)
|
||||
_node.DropOptional = value
|
||||
}
|
||||
if nodes := _c.mutation.ParentIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: user.ParentTable,
|
||||
Columns: []string{user.ParentColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.user_children = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.ChildrenIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.ChildrenTable,
|
||||
Columns: []string{user.ChildrenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.SpouseIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: user.SpouseTable,
|
||||
Columns: []string{user.SpouseColumn},
|
||||
Bidi: true,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.user_spouse = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.CarIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: user.CarTable,
|
||||
Columns: []string{user.CarColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// UserCreateBulk is the builder for creating many User entities in bulk.
|
||||
type UserCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*UserCreate
|
||||
}
|
||||
|
||||
// Save creates the User entities in the database.
|
||||
func (_c *UserCreateBulk) Save(ctx context.Context) ([]*User, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*User, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*UserMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, 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, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *UserCreateBulk) SaveX(ctx context.Context) []*User {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *UserCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *UserCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/migrate/entv1/user_delete.go
Normal file
92
entc/integration/migrate/entv1/user_delete.go
Normal file
@@ -0,0 +1,92 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// UserDelete is the builder for deleting a User entity.
|
||||
type UserDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *UserMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserDelete builder.
|
||||
func (_d *UserDelete) Where(ps ...predicate.User) *UserDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *UserDelete) 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 (_d *UserDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *UserDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
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, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// UserDeleteOne is the builder for deleting a single User entity.
|
||||
type UserDeleteOne struct {
|
||||
_d *UserDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserDelete builder.
|
||||
func (_d *UserDeleteOne) Where(ps ...predicate.User) *UserDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *UserDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{user.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *UserDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
837
entc/integration/migrate/entv1/user_query.go
Normal file
837
entc/integration/migrate/entv1/user_query.go
Normal file
@@ -0,0 +1,837 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv1
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv1/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// UserQuery is the builder for querying User entities.
|
||||
type UserQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []user.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.User
|
||||
withParent *UserQuery
|
||||
withChildren *UserQuery
|
||||
withSpouse *UserQuery
|
||||
withCar *CarQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the UserQuery builder.
|
||||
func (_q *UserQuery) Where(ps ...predicate.User) *UserQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *UserQuery) Limit(limit int) *UserQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *UserQuery) Offset(offset int) *UserQuery {
|
||||
_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 (_q *UserQuery) Unique(unique bool) *UserQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *UserQuery) Order(o ...user.OrderOption) *UserQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryParent chains the current query on the "parent" edge.
|
||||
func (_q *UserQuery) QueryParent() *UserQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, user.ParentTable, user.ParentColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryChildren chains the current query on the "children" edge.
|
||||
func (_q *UserQuery) QueryChildren() *UserQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.ChildrenTable, user.ChildrenColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QuerySpouse chains the current query on the "spouse" edge.
|
||||
func (_q *UserQuery) QuerySpouse() *UserQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.SpouseTable, user.SpouseColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryCar chains the current query on the "car" edge.
|
||||
func (_q *UserQuery) QueryCar() *CarQuery {
|
||||
query := (&CarClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(car.Table, car.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.CarTable, user.CarColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first User entity from the query.
|
||||
// Returns a *NotFoundError when no User was found.
|
||||
func (_q *UserQuery) First(ctx context.Context) (*User, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{user.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *UserQuery) FirstX(ctx context.Context) *User {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first User ID from the query.
|
||||
// Returns a *NotFoundError when no User ID was found.
|
||||
func (_q *UserQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{user.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *UserQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single User entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one User entity is found.
|
||||
// Returns a *NotFoundError when no User entities are found.
|
||||
func (_q *UserQuery) Only(ctx context.Context) (*User, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{user.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{user.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *UserQuery) OnlyX(ctx context.Context) *User {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only User ID in the query.
|
||||
// Returns a *NotSingularError when more than one User ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *UserQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = &NotSingularError{user.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *UserQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Users.
|
||||
func (_q *UserQuery) All(ctx context.Context) ([]*User, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*User, *UserQuery]()
|
||||
return withInterceptors[[]*User](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *UserQuery) AllX(ctx context.Context) []*User {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of User IDs.
|
||||
func (_q *UserQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(user.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *UserQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *UserQuery) 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, _q, querierCount[*UserQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *UserQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *UserQuery) 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:
|
||||
return false, fmt.Errorf("entv1: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *UserQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the UserQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *UserQuery) Clone() *UserQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &UserQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]user.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.User{}, _q.predicates...),
|
||||
withParent: _q.withParent.Clone(),
|
||||
withChildren: _q.withChildren.Clone(),
|
||||
withSpouse: _q.withSpouse.Clone(),
|
||||
withCar: _q.withCar.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithParent tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "parent" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *UserQuery) WithParent(opts ...func(*UserQuery)) *UserQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withParent = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithChildren tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "children" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *UserQuery) WithChildren(opts ...func(*UserQuery)) *UserQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withChildren = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithSpouse tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "spouse" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *UserQuery) WithSpouse(opts ...func(*UserQuery)) *UserQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withSpouse = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithCar tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "car" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *UserQuery) WithCar(opts ...func(*CarQuery)) *UserQuery {
|
||||
query := (&CarClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withCar = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Age int32 `json:"age,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.User.Query().
|
||||
// GroupBy(user.FieldAge).
|
||||
// Aggregate(entv1.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &UserGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = user.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Age int32 `json:"age,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.User.Query().
|
||||
// Select(user.FieldAge).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *UserQuery) Select(fields ...string) *UserSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &UserSelect{UserQuery: _q}
|
||||
sbuild.label = user.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a UserSelect configured with the given aggregations.
|
||||
func (_q *UserQuery) Aggregate(fns ...AggregateFunc) *UserSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *UserQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("entv1: uninitialized interceptor (forgotten import entv1/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !user.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("entv1: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, error) {
|
||||
var (
|
||||
nodes = []*User{}
|
||||
withFKs = _q.withFKs
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [4]bool{
|
||||
_q.withParent != nil,
|
||||
_q.withChildren != nil,
|
||||
_q.withSpouse != nil,
|
||||
_q.withCar != nil,
|
||||
}
|
||||
)
|
||||
if _q.withParent != nil || _q.withSpouse != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, user.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*User).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &User{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := _q.withParent; query != nil {
|
||||
if err := _q.loadParent(ctx, query, nodes, nil,
|
||||
func(n *User, e *User) { n.Edges.Parent = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withChildren; query != nil {
|
||||
if err := _q.loadChildren(ctx, query, nodes,
|
||||
func(n *User) { n.Edges.Children = []*User{} },
|
||||
func(n *User, e *User) { n.Edges.Children = append(n.Edges.Children, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withSpouse; query != nil {
|
||||
if err := _q.loadSpouse(ctx, query, nodes, nil,
|
||||
func(n *User, e *User) { n.Edges.Spouse = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withCar; query != nil {
|
||||
if err := _q.loadCar(ctx, query, nodes, nil,
|
||||
func(n *User, e *Car) { n.Edges.Car = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *UserQuery) loadParent(ctx context.Context, query *UserQuery, nodes []*User, init func(*User), assign func(*User, *User)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*User)
|
||||
for i := range nodes {
|
||||
if nodes[i].user_children == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].user_children
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "user_children" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *UserQuery) loadChildren(ctx context.Context, query *UserQuery, nodes []*User, init func(*User), assign func(*User, *User)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*User)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(user.ChildrenColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.user_children
|
||||
if fk == nil {
|
||||
return fmt.Errorf(`foreign-key "user_children" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "user_children" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *UserQuery) loadSpouse(ctx context.Context, query *UserQuery, nodes []*User, init func(*User), assign func(*User, *User)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*User)
|
||||
for i := range nodes {
|
||||
if nodes[i].user_spouse == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].user_spouse
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "user_spouse" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *UserQuery) loadCar(ctx context.Context, query *CarQuery, nodes []*User, init func(*User), assign func(*User, *Car)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*User)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.Car(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(user.CarColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.user_car
|
||||
if fk == nil {
|
||||
return fmt.Errorf(`foreign-key "user_car" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "user_car" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *UserQuery) 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, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *UserQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != user.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *UserQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(user.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = user.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
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 := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// UserGroupBy is the group-by builder for User entities.
|
||||
type UserGroupBy struct {
|
||||
selector
|
||||
build *UserQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *UserGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*UserQuery, *UserGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *UserGroupBy) sqlScan(ctx context.Context, root *UserQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// UserSelect is the builder for selecting fields of User entities.
|
||||
type UserSelect struct {
|
||||
*UserQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *UserSelect) Aggregate(fns ...AggregateFunc) *UserSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *UserSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*UserQuery, *UserSelect](ctx, _s.UserQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *UserSelect) sqlScan(ctx context.Context, root *UserQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
1278
entc/integration/migrate/entv1/user_update.go
Normal file
1278
entc/integration/migrate/entv1/user_update.go
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user