snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
159
entc/integration/edgefield/ent/car.go
Normal file
159
entc/integration/edgefield/ent/car.go
Normal file
@@ -0,0 +1,159 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/car"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Car is the model entity for the Car schema.
|
||||
type Car struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID uuid.UUID `json:"id,omitempty"`
|
||||
// Number holds the value of the "number" field.
|
||||
Number string `json:"number,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"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// CarEdges holds the relations/edges for other nodes in the graph.
|
||||
type CarEdges struct {
|
||||
// Rentals holds the value of the rentals edge.
|
||||
Rentals []*Rental `json:"rentals,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
namedRentals map[string][]*Rental
|
||||
}
|
||||
|
||||
// RentalsOrErr returns the Rentals value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e CarEdges) RentalsOrErr() ([]*Rental, error) {
|
||||
if e.loadedTypes[0] {
|
||||
return e.Rentals, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "rentals"}
|
||||
}
|
||||
|
||||
// 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.FieldNumber:
|
||||
values[i] = new(sql.NullString)
|
||||
case car.FieldID:
|
||||
values[i] = new(uuid.UUID)
|
||||
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:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||
} else if value != nil {
|
||||
_m.ID = *value
|
||||
}
|
||||
case car.FieldNumber:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field number", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Number = 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 Car.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Car) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryRentals queries the "rentals" edge of the Car entity.
|
||||
func (_m *Car) QueryRentals() *RentalQuery {
|
||||
return NewCarClient(_m.config).QueryRentals(_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("ent: 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.WriteString("number=")
|
||||
builder.WriteString(_m.Number)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// NamedRentals returns the Rentals named value or an error if the edge was not
|
||||
// loaded in eager-loading with this name.
|
||||
func (_m *Car) NamedRentals(name string) ([]*Rental, error) {
|
||||
if _m.Edges.namedRentals == nil {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
nodes, ok := _m.Edges.namedRentals[name]
|
||||
if !ok {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_m *Car) appendNamedRentals(name string, edges ...*Rental) {
|
||||
if _m.Edges.namedRentals == nil {
|
||||
_m.Edges.namedRentals = make(map[string][]*Rental)
|
||||
}
|
||||
if len(edges) == 0 {
|
||||
_m.Edges.namedRentals[name] = []*Rental{}
|
||||
} else {
|
||||
_m.Edges.namedRentals[name] = append(_m.Edges.namedRentals[name], edges...)
|
||||
}
|
||||
}
|
||||
|
||||
// Cars is a parsable slice of Car.
|
||||
type Cars []*Car
|
||||
88
entc/integration/edgefield/ent/car/car.go
Normal file
88
entc/integration/edgefield/ent/car/car.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 car
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
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"
|
||||
// FieldNumber holds the string denoting the number field in the database.
|
||||
FieldNumber = "number"
|
||||
// EdgeRentals holds the string denoting the rentals edge name in mutations.
|
||||
EdgeRentals = "rentals"
|
||||
// Table holds the table name of the car in the database.
|
||||
Table = "cars"
|
||||
// RentalsTable is the table that holds the rentals relation/edge.
|
||||
RentalsTable = "rentals"
|
||||
// RentalsInverseTable is the table name for the Rental entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "rental" package.
|
||||
RentalsInverseTable = "rentals"
|
||||
// RentalsColumn is the table column denoting the rentals relation/edge.
|
||||
RentalsColumn = "car_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for car fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldNumber,
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultID holds the default value on creation for the "id" field.
|
||||
DefaultID func() uuid.UUID
|
||||
)
|
||||
|
||||
// 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()
|
||||
}
|
||||
|
||||
// ByNumber orders the results by the number field.
|
||||
func ByNumber(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldNumber, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByRentalsCount orders the results by rentals count.
|
||||
func ByRentalsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newRentalsStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByRentals orders the results by rentals terms.
|
||||
func ByRentals(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newRentalsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newRentalsStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(RentalsInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, RentalsTable, RentalsColumn),
|
||||
)
|
||||
}
|
||||
348
entc/integration/edgefield/ent/car/mutation.go
Normal file
348
entc/integration/edgefield/ent/car/mutation.go
Normal file
@@ -0,0 +1,348 @@
|
||||
// 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/edgefield/ent/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Car nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
number *string
|
||||
clearedFields map[string]struct{}
|
||||
rentals map[int]struct{}
|
||||
removedrentals map[int]struct{}
|
||||
clearedrentals 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
|
||||
}
|
||||
|
||||
// SetNumber sets the "number" field.
|
||||
func (m *Mutation) SetNumber(s string) {
|
||||
m.number = &s
|
||||
}
|
||||
|
||||
// Number returns the value of the "number" field in the mutation.
|
||||
func (m *Mutation) Number() (r string, exists bool) {
|
||||
v := m.number
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearNumber clears the value of the "number" field.
|
||||
func (m *Mutation) ClearNumber() {
|
||||
m.number = nil
|
||||
m.clearedFields[FieldNumber] = struct{}{}
|
||||
}
|
||||
|
||||
// NumberCleared returns if the "number" field was cleared in this mutation.
|
||||
func (m *Mutation) NumberCleared() bool {
|
||||
_, ok := m.clearedFields[FieldNumber]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetNumber resets all changes to the "number" field.
|
||||
func (m *Mutation) ResetNumber() {
|
||||
m.number = nil
|
||||
delete(m.clearedFields, FieldNumber)
|
||||
}
|
||||
|
||||
// AddRentalIDs adds the "rentals" edge to the Rental entity by ids.
|
||||
func (m *Mutation) AddRentalIDs(ids ...int) {
|
||||
if m.rentals == nil {
|
||||
m.rentals = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
m.rentals[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// ClearRentals clears the "rentals" edge to the Rental entity.
|
||||
func (m *Mutation) ClearRentals() {
|
||||
m.clearedrentals = true
|
||||
}
|
||||
|
||||
// RentalsCleared reports if the "rentals" edge to the Rental entity was cleared.
|
||||
func (m *Mutation) RentalsCleared() bool {
|
||||
return m.clearedrentals
|
||||
}
|
||||
|
||||
// RemoveRentalIDs removes the "rentals" edge to the Rental entity by IDs.
|
||||
func (m *Mutation) RemoveRentalIDs(ids ...int) {
|
||||
if m.removedrentals == nil {
|
||||
m.removedrentals = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
delete(m.rentals, ids[i])
|
||||
m.removedrentals[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// RemovedRentals returns the removed IDs of the "rentals" edge to the Rental entity.
|
||||
func (m *Mutation) RemovedRentalsIDs() (ids []int) {
|
||||
for id := range m.removedrentals {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// RentalsIDs returns the "rentals" edge IDs in the mutation.
|
||||
func (m *Mutation) RentalsIDs() (ids []int) {
|
||||
for id := range m.rentals {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetRentals resets all changes to the "rentals" edge.
|
||||
func (m *Mutation) ResetRentals() {
|
||||
m.rentals = nil
|
||||
m.clearedrentals = false
|
||||
m.removedrentals = nil
|
||||
}
|
||||
|
||||
// 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, 1)
|
||||
if m.number != nil {
|
||||
fields = append(fields, FieldNumber)
|
||||
}
|
||||
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 FieldNumber:
|
||||
return m.Number()
|
||||
}
|
||||
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 {
|
||||
case FieldNumber:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetNumber(v)
|
||||
return nil
|
||||
}
|
||||
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 {
|
||||
switch name {
|
||||
}
|
||||
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 {
|
||||
var fields []string
|
||||
if m.FieldCleared(FieldNumber) {
|
||||
fields = append(fields, FieldNumber)
|
||||
}
|
||||
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 FieldNumber:
|
||||
m.ClearNumber()
|
||||
return nil
|
||||
}
|
||||
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 {
|
||||
switch name {
|
||||
case FieldNumber:
|
||||
m.ResetNumber()
|
||||
return nil
|
||||
}
|
||||
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.rentals != nil {
|
||||
edges = append(edges, EdgeRentals)
|
||||
}
|
||||
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 EdgeRentals:
|
||||
ids := make([]ent.Value, 0, len(m.rentals))
|
||||
for id := range m.rentals {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *Mutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
if m.removedrentals != nil {
|
||||
edges = append(edges, EdgeRentals)
|
||||
}
|
||||
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 {
|
||||
switch name {
|
||||
case EdgeRentals:
|
||||
ids := make([]ent.Value, 0, len(m.removedrentals))
|
||||
for id := range m.removedrentals {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
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.clearedrentals {
|
||||
edges = append(edges, EdgeRentals)
|
||||
}
|
||||
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 EdgeRentals:
|
||||
return m.clearedrentals
|
||||
}
|
||||
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 {
|
||||
}
|
||||
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 EdgeRentals:
|
||||
m.ResetRentals()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Car edge %s", name)
|
||||
}
|
||||
177
entc/integration/edgefield/ent/car/where.go
Normal file
177
entc/integration/edgefield/ent/car/where.go
Normal file
@@ -0,0 +1,177 @@
|
||||
// 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/edgefield/ent/predicate"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id uuid.UUID) predicate.Car {
|
||||
return predicate.Car(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id uuid.UUID) predicate.Car {
|
||||
return predicate.Car(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id uuid.UUID) predicate.Car {
|
||||
return predicate.Car(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...uuid.UUID) predicate.Car {
|
||||
return predicate.Car(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...uuid.UUID) predicate.Car {
|
||||
return predicate.Car(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id uuid.UUID) predicate.Car {
|
||||
return predicate.Car(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id uuid.UUID) predicate.Car {
|
||||
return predicate.Car(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id uuid.UUID) predicate.Car {
|
||||
return predicate.Car(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id uuid.UUID) predicate.Car {
|
||||
return predicate.Car(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Number applies equality check predicate on the "number" field. It's identical to NumberEQ.
|
||||
func Number(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldEQ(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberEQ applies the EQ predicate on the "number" field.
|
||||
func NumberEQ(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldEQ(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberNEQ applies the NEQ predicate on the "number" field.
|
||||
func NumberNEQ(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldNEQ(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberIn applies the In predicate on the "number" field.
|
||||
func NumberIn(vs ...string) predicate.Car {
|
||||
return predicate.Car(sql.FieldIn(FieldNumber, vs...))
|
||||
}
|
||||
|
||||
// NumberNotIn applies the NotIn predicate on the "number" field.
|
||||
func NumberNotIn(vs ...string) predicate.Car {
|
||||
return predicate.Car(sql.FieldNotIn(FieldNumber, vs...))
|
||||
}
|
||||
|
||||
// NumberGT applies the GT predicate on the "number" field.
|
||||
func NumberGT(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldGT(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberGTE applies the GTE predicate on the "number" field.
|
||||
func NumberGTE(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldGTE(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberLT applies the LT predicate on the "number" field.
|
||||
func NumberLT(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldLT(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberLTE applies the LTE predicate on the "number" field.
|
||||
func NumberLTE(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldLTE(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberContains applies the Contains predicate on the "number" field.
|
||||
func NumberContains(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldContains(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberHasPrefix applies the HasPrefix predicate on the "number" field.
|
||||
func NumberHasPrefix(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldHasPrefix(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberHasSuffix applies the HasSuffix predicate on the "number" field.
|
||||
func NumberHasSuffix(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldHasSuffix(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberIsNil applies the IsNil predicate on the "number" field.
|
||||
func NumberIsNil() predicate.Car {
|
||||
return predicate.Car(sql.FieldIsNull(FieldNumber))
|
||||
}
|
||||
|
||||
// NumberNotNil applies the NotNil predicate on the "number" field.
|
||||
func NumberNotNil() predicate.Car {
|
||||
return predicate.Car(sql.FieldNotNull(FieldNumber))
|
||||
}
|
||||
|
||||
// NumberEqualFold applies the EqualFold predicate on the "number" field.
|
||||
func NumberEqualFold(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldEqualFold(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberContainsFold applies the ContainsFold predicate on the "number" field.
|
||||
func NumberContainsFold(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldContainsFold(FieldNumber, v))
|
||||
}
|
||||
|
||||
// HasRentals applies the HasEdge predicate on the "rentals" edge.
|
||||
func HasRentals() predicate.Car {
|
||||
return predicate.Car(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, RentalsTable, RentalsColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasRentalsWith applies the HasEdge predicate on the "rentals" edge with a given conditions (other predicates).
|
||||
func HasRentalsWith(preds ...predicate.Rental) predicate.Car {
|
||||
return predicate.Car(func(s *sql.Selector) {
|
||||
step := newRentalsStep()
|
||||
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))
|
||||
}
|
||||
253
entc/integration/edgefield/ent/car_create.go
Normal file
253
entc/integration/edgefield/ent/car_create.go
Normal file
@@ -0,0 +1,253 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/car"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/rental"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// CarCreate is the builder for creating a Car entity.
|
||||
type CarCreate struct {
|
||||
config
|
||||
mutation *CarMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetNumber sets the "number" field.
|
||||
func (_c *CarCreate) SetNumber(v string) *CarCreate {
|
||||
_c.mutation.SetNumber(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableNumber sets the "number" field if the given value is not nil.
|
||||
func (_c *CarCreate) SetNillableNumber(v *string) *CarCreate {
|
||||
if v != nil {
|
||||
_c.SetNumber(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *CarCreate) SetID(v uuid.UUID) *CarCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableID sets the "id" field if the given value is not nil.
|
||||
func (_c *CarCreate) SetNillableID(v *uuid.UUID) *CarCreate {
|
||||
if v != nil {
|
||||
_c.SetID(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddRentalIDs adds the "rentals" edge to the Rental entity by IDs.
|
||||
func (_c *CarCreate) AddRentalIDs(ids ...int) *CarCreate {
|
||||
_c.mutation.AddRentalIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddRentals adds the "rentals" edges to the Rental entity.
|
||||
func (_c *CarCreate) AddRentals(v ...*Rental) *CarCreate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddRentalIDs(ids...)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
_c.defaults()
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *CarCreate) defaults() {
|
||||
if _, ok := _c.mutation.ID(); !ok {
|
||||
v := car.DefaultID()
|
||||
_c.mutation.SetID(v)
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
if _spec.ID.Value != nil {
|
||||
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
|
||||
_node.ID = *id
|
||||
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
_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.TypeUUID))
|
||||
)
|
||||
if id, ok := _c.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := _c.mutation.Number(); ok {
|
||||
_spec.SetField(car.FieldNumber, field.TypeString, value)
|
||||
_node.Number = value
|
||||
}
|
||||
if nodes := _c.mutation.RentalsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: car.RentalsTable,
|
||||
Columns: []string{car.RentalsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(rental.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_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]
|
||||
builder.defaults()
|
||||
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
|
||||
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/edgefield/ent/car_delete.go
Normal file
92
entc/integration/edgefield/ent/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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/car"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/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.TypeUUID))
|
||||
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)
|
||||
}
|
||||
}
|
||||
633
entc/integration/edgefield/ent/car_query.go
Normal file
633
entc/integration/edgefield/ent/car_query.go
Normal file
@@ -0,0 +1,633 @@
|
||||
// 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 ent
|
||||
|
||||
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/edgefield/ent/car"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/rental"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// CarQuery is the builder for querying Car entities.
|
||||
type CarQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []car.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Car
|
||||
withRentals *RentalQuery
|
||||
withNamedRentals map[string]*RentalQuery
|
||||
// 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
|
||||
}
|
||||
|
||||
// QueryRentals chains the current query on the "rentals" edge.
|
||||
func (_q *CarQuery) QueryRentals() *RentalQuery {
|
||||
query := (&RentalClient{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(rental.Table, rental.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, car.RentalsTable, car.RentalsColumn),
|
||||
)
|
||||
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 uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
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) uuid.UUID {
|
||||
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 uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
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) uuid.UUID {
|
||||
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 []uuid.UUID, 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) []uuid.UUID {
|
||||
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("ent: 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...),
|
||||
withRentals: _q.withRentals.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithRentals tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "rentals" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *CarQuery) WithRentals(opts ...func(*RentalQuery)) *CarQuery {
|
||||
query := (&RentalClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withRentals = 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 {
|
||||
// Number string `json:"number,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Car.Query().
|
||||
// GroupBy(car.FieldNumber).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
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.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Number string `json:"number,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Car.Query().
|
||||
// Select(car.FieldNumber).
|
||||
// Scan(ctx, &v)
|
||||
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("ent: uninitialized interceptor (forgotten import ent/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("ent: 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{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
_q.withRentals != nil,
|
||||
}
|
||||
)
|
||||
_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.withRentals; query != nil {
|
||||
if err := _q.loadRentals(ctx, query, nodes,
|
||||
func(n *Car) { n.Edges.Rentals = []*Rental{} },
|
||||
func(n *Car, e *Rental) { n.Edges.Rentals = append(n.Edges.Rentals, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
for name, query := range _q.withNamedRentals {
|
||||
if err := _q.loadRentals(ctx, query, nodes,
|
||||
func(n *Car) { n.appendNamedRentals(name) },
|
||||
func(n *Car, e *Rental) { n.appendNamedRentals(name, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *CarQuery) loadRentals(ctx context.Context, query *RentalQuery, nodes []*Car, init func(*Car), assign func(*Car, *Rental)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID]*Car)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
if len(query.ctx.Fields) > 0 {
|
||||
query.ctx.AppendFieldOnce(rental.FieldCarID)
|
||||
}
|
||||
query.Where(predicate.Rental(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(car.RentalsColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.CarID
|
||||
node, ok := nodeids[fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "car_id" returned %v for node %v`, fk, n.ID)
|
||||
}
|
||||
assign(node, 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.TypeUUID))
|
||||
_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
|
||||
}
|
||||
|
||||
// WithNamedRentals tells the query-builder to eager-load the nodes that are connected to the "rentals"
|
||||
// edge with the given name. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *CarQuery) WithNamedRentals(name string, opts ...func(*RentalQuery)) *CarQuery {
|
||||
query := (&RentalClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
if _q.withNamedRentals == nil {
|
||||
_q.withNamedRentals = make(map[string]*RentalQuery)
|
||||
}
|
||||
_q.withNamedRentals[name] = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
394
entc/integration/edgefield/ent/car_update.go
Normal file
394
entc/integration/edgefield/ent/car_update.go
Normal file
@@ -0,0 +1,394 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/car"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/rental"
|
||||
"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
|
||||
}
|
||||
|
||||
// SetNumber sets the "number" field.
|
||||
func (_u *CarUpdate) SetNumber(v string) *CarUpdate {
|
||||
_u.mutation.SetNumber(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableNumber sets the "number" field if the given value is not nil.
|
||||
func (_u *CarUpdate) SetNillableNumber(v *string) *CarUpdate {
|
||||
if v != nil {
|
||||
_u.SetNumber(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearNumber clears the value of the "number" field.
|
||||
func (_u *CarUpdate) ClearNumber() *CarUpdate {
|
||||
_u.mutation.ClearNumber()
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddRentalIDs adds the "rentals" edge to the Rental entity by IDs.
|
||||
func (_u *CarUpdate) AddRentalIDs(ids ...int) *CarUpdate {
|
||||
_u.mutation.AddRentalIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddRentals adds the "rentals" edges to the Rental entity.
|
||||
func (_u *CarUpdate) AddRentals(v ...*Rental) *CarUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddRentalIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the CarMutation object of the builder.
|
||||
func (_u *CarUpdate) Mutation() *CarMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearRentals clears all "rentals" edges to the Rental entity.
|
||||
func (_u *CarUpdate) ClearRentals() *CarUpdate {
|
||||
_u.mutation.ClearRentals()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveRentalIDs removes the "rentals" edge to Rental entities by IDs.
|
||||
func (_u *CarUpdate) RemoveRentalIDs(ids ...int) *CarUpdate {
|
||||
_u.mutation.RemoveRentalIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveRentals removes "rentals" edges to Rental entities.
|
||||
func (_u *CarUpdate) RemoveRentals(v ...*Rental) *CarUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveRentalIDs(ids...)
|
||||
}
|
||||
|
||||
// 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.TypeUUID))
|
||||
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.Number(); ok {
|
||||
_spec.SetField(car.FieldNumber, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.NumberCleared() {
|
||||
_spec.ClearField(car.FieldNumber, field.TypeString)
|
||||
}
|
||||
if _u.mutation.RentalsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: car.RentalsTable,
|
||||
Columns: []string{car.RentalsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(rental.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedRentalsIDs(); len(nodes) > 0 && !_u.mutation.RentalsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: car.RentalsTable,
|
||||
Columns: []string{car.RentalsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(rental.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RentalsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: car.RentalsTable,
|
||||
Columns: []string{car.RentalsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(rental.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
|
||||
}
|
||||
|
||||
// SetNumber sets the "number" field.
|
||||
func (_u *CarUpdateOne) SetNumber(v string) *CarUpdateOne {
|
||||
_u.mutation.SetNumber(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableNumber sets the "number" field if the given value is not nil.
|
||||
func (_u *CarUpdateOne) SetNillableNumber(v *string) *CarUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetNumber(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearNumber clears the value of the "number" field.
|
||||
func (_u *CarUpdateOne) ClearNumber() *CarUpdateOne {
|
||||
_u.mutation.ClearNumber()
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddRentalIDs adds the "rentals" edge to the Rental entity by IDs.
|
||||
func (_u *CarUpdateOne) AddRentalIDs(ids ...int) *CarUpdateOne {
|
||||
_u.mutation.AddRentalIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddRentals adds the "rentals" edges to the Rental entity.
|
||||
func (_u *CarUpdateOne) AddRentals(v ...*Rental) *CarUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddRentalIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the CarMutation object of the builder.
|
||||
func (_u *CarUpdateOne) Mutation() *CarMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearRentals clears all "rentals" edges to the Rental entity.
|
||||
func (_u *CarUpdateOne) ClearRentals() *CarUpdateOne {
|
||||
_u.mutation.ClearRentals()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveRentalIDs removes the "rentals" edge to Rental entities by IDs.
|
||||
func (_u *CarUpdateOne) RemoveRentalIDs(ids ...int) *CarUpdateOne {
|
||||
_u.mutation.RemoveRentalIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveRentals removes "rentals" edges to Rental entities.
|
||||
func (_u *CarUpdateOne) RemoveRentals(v ...*Rental) *CarUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveRentalIDs(ids...)
|
||||
}
|
||||
|
||||
// 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.TypeUUID))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: 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("ent: 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 value, ok := _u.mutation.Number(); ok {
|
||||
_spec.SetField(car.FieldNumber, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.NumberCleared() {
|
||||
_spec.ClearField(car.FieldNumber, field.TypeString)
|
||||
}
|
||||
if _u.mutation.RentalsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: car.RentalsTable,
|
||||
Columns: []string{car.RentalsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(rental.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedRentalsIDs(); len(nodes) > 0 && !_u.mutation.RentalsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: car.RentalsTable,
|
||||
Columns: []string{car.RentalsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(rental.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RentalsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: car.RentalsTable,
|
||||
Columns: []string{car.RentalsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(rental.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
|
||||
}
|
||||
147
entc/integration/edgefield/ent/card.go
Normal file
147
entc/integration/edgefield/ent/card.go
Normal file
@@ -0,0 +1,147 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/card"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
)
|
||||
|
||||
// Card is the model entity for the Card schema.
|
||||
type Card struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Number holds the value of the "number" field.
|
||||
Number string `json:"number,omitempty"`
|
||||
// OwnerID holds the value of the "owner_id" field.
|
||||
OwnerID int `json:"owner_id,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the CardQuery when eager-loading is set.
|
||||
Edges CardEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// CardEdges holds the relations/edges for other nodes in the graph.
|
||||
type CardEdges 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 CardEdges) 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 (*Card) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case card.FieldID, card.FieldOwnerID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case card.FieldNumber:
|
||||
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 Card fields.
|
||||
func (_m *Card) 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 card.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 card.FieldNumber:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field number", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Number = value.String
|
||||
}
|
||||
case card.FieldOwnerID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field owner_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.OwnerID = 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 Card.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Card) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryOwner queries the "owner" edge of the Card entity.
|
||||
func (_m *Card) QueryOwner() *UserQuery {
|
||||
return NewCardClient(_m.config).QueryOwner(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Card.
|
||||
// Note that you need to call Card.Unwrap() before calling this method if this Card
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Card) Update() *CardUpdateOne {
|
||||
return NewCardClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Card 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 *Card) Unwrap() *Card {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Card is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Card) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Card(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("number=")
|
||||
builder.WriteString(_m.Number)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("owner_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.OwnerID))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Cards is a parsable slice of Card.
|
||||
type Cards []*Card
|
||||
83
entc/integration/edgefield/ent/card/card.go
Normal file
83
entc/integration/edgefield/ent/card/card.go
Normal file
@@ -0,0 +1,83 @@
|
||||
// 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 card
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the card type in the database.
|
||||
Label = "card"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldNumber holds the string denoting the number field in the database.
|
||||
FieldNumber = "number"
|
||||
// FieldOwnerID holds the string denoting the owner_id field in the database.
|
||||
FieldOwnerID = "owner_id"
|
||||
// EdgeOwner holds the string denoting the owner edge name in mutations.
|
||||
EdgeOwner = "owner"
|
||||
// Table holds the table name of the card in the database.
|
||||
Table = "cards"
|
||||
// OwnerTable is the table that holds the owner relation/edge.
|
||||
OwnerTable = "cards"
|
||||
// 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 = "owner_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for card fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldNumber,
|
||||
FieldOwnerID,
|
||||
}
|
||||
|
||||
// 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 Card 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()
|
||||
}
|
||||
|
||||
// ByNumber orders the results by the number field.
|
||||
func ByNumber(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldNumber, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByOwnerID orders the results by the owner_id field.
|
||||
func ByOwnerID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldOwnerID, 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, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, OwnerTable, OwnerColumn),
|
||||
)
|
||||
}
|
||||
366
entc/integration/edgefield/ent/card/mutation.go
Normal file
366
entc/integration/edgefield/ent/card/mutation.go
Normal file
@@ -0,0 +1,366 @@
|
||||
// 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 card
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Card nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
number *string
|
||||
clearedFields map[string]struct{}
|
||||
owner *int
|
||||
clearedowner bool
|
||||
predicates []predicate.Card
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Card entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Card",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Card {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetNumber sets the "number" field.
|
||||
func (m *Mutation) SetNumber(s string) {
|
||||
m.number = &s
|
||||
}
|
||||
|
||||
// Number returns the value of the "number" field in the mutation.
|
||||
func (m *Mutation) Number() (r string, exists bool) {
|
||||
v := m.number
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearNumber clears the value of the "number" field.
|
||||
func (m *Mutation) ClearNumber() {
|
||||
m.number = nil
|
||||
m.clearedFields[FieldNumber] = struct{}{}
|
||||
}
|
||||
|
||||
// NumberCleared returns if the "number" field was cleared in this mutation.
|
||||
func (m *Mutation) NumberCleared() bool {
|
||||
_, ok := m.clearedFields[FieldNumber]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetNumber resets all changes to the "number" field.
|
||||
func (m *Mutation) ResetNumber() {
|
||||
m.number = nil
|
||||
delete(m.clearedFields, FieldNumber)
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner_id" field.
|
||||
func (m *Mutation) SetOwnerID(i int) {
|
||||
m.owner = &i
|
||||
}
|
||||
|
||||
// OwnerID returns the value of the "owner_id" field in the mutation.
|
||||
func (m *Mutation) OwnerID() (r int, exists bool) {
|
||||
v := m.owner
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearOwnerID clears the value of the "owner_id" field.
|
||||
func (m *Mutation) ClearOwnerID() {
|
||||
m.owner = nil
|
||||
m.clearedFields[FieldOwnerID] = struct{}{}
|
||||
}
|
||||
|
||||
// OwnerIDCleared returns if the "owner_id" field was cleared in this mutation.
|
||||
func (m *Mutation) OwnerIDCleared() bool {
|
||||
_, ok := m.clearedFields[FieldOwnerID]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetOwnerID resets all changes to the "owner_id" field.
|
||||
func (m *Mutation) ResetOwnerID() {
|
||||
m.owner = nil
|
||||
delete(m.clearedFields, FieldOwnerID)
|
||||
}
|
||||
|
||||
// ClearOwner clears the "owner" edge to the User entity.
|
||||
func (m *Mutation) ClearOwner() {
|
||||
m.clearedowner = true
|
||||
m.clearedFields[FieldOwnerID] = struct{}{}
|
||||
}
|
||||
|
||||
// OwnerCleared reports if the "owner" edge to the User entity was cleared.
|
||||
func (m *Mutation) OwnerCleared() bool {
|
||||
return m.OwnerIDCleared() || m.clearedowner
|
||||
}
|
||||
|
||||
// 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.Card) {
|
||||
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.Card, 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 (Card).
|
||||
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, 2)
|
||||
if m.number != nil {
|
||||
fields = append(fields, FieldNumber)
|
||||
}
|
||||
if m.owner != nil {
|
||||
fields = append(fields, FieldOwnerID)
|
||||
}
|
||||
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 FieldNumber:
|
||||
return m.Number()
|
||||
case FieldOwnerID:
|
||||
return m.OwnerID()
|
||||
}
|
||||
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 Card 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 FieldNumber:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetNumber(v)
|
||||
return nil
|
||||
case FieldOwnerID:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetOwnerID(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Card field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *Mutation) AddedFields() []string {
|
||||
var fields []string
|
||||
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 {
|
||||
}
|
||||
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 Card 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(FieldNumber) {
|
||||
fields = append(fields, FieldNumber)
|
||||
}
|
||||
if m.FieldCleared(FieldOwnerID) {
|
||||
fields = append(fields, FieldOwnerID)
|
||||
}
|
||||
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 FieldNumber:
|
||||
m.ClearNumber()
|
||||
return nil
|
||||
case FieldOwnerID:
|
||||
m.ClearOwnerID()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Card 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 FieldNumber:
|
||||
m.ResetNumber()
|
||||
return nil
|
||||
case FieldOwnerID:
|
||||
m.ResetOwnerID()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Card 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 Card 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 Card edge %s", name)
|
||||
}
|
||||
211
entc/integration/edgefield/ent/card/where.go
Normal file
211
entc/integration/edgefield/ent/card/where.go
Normal file
@@ -0,0 +1,211 @@
|
||||
// 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 card
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Card {
|
||||
return predicate.Card(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Card {
|
||||
return predicate.Card(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Card {
|
||||
return predicate.Card(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Card {
|
||||
return predicate.Card(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Card {
|
||||
return predicate.Card(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Card {
|
||||
return predicate.Card(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Card {
|
||||
return predicate.Card(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Card {
|
||||
return predicate.Card(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Card {
|
||||
return predicate.Card(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Number applies equality check predicate on the "number" field. It's identical to NumberEQ.
|
||||
func Number(v string) predicate.Card {
|
||||
return predicate.Card(sql.FieldEQ(FieldNumber, v))
|
||||
}
|
||||
|
||||
// OwnerID applies equality check predicate on the "owner_id" field. It's identical to OwnerIDEQ.
|
||||
func OwnerID(v int) predicate.Card {
|
||||
return predicate.Card(sql.FieldEQ(FieldOwnerID, v))
|
||||
}
|
||||
|
||||
// NumberEQ applies the EQ predicate on the "number" field.
|
||||
func NumberEQ(v string) predicate.Card {
|
||||
return predicate.Card(sql.FieldEQ(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberNEQ applies the NEQ predicate on the "number" field.
|
||||
func NumberNEQ(v string) predicate.Card {
|
||||
return predicate.Card(sql.FieldNEQ(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberIn applies the In predicate on the "number" field.
|
||||
func NumberIn(vs ...string) predicate.Card {
|
||||
return predicate.Card(sql.FieldIn(FieldNumber, vs...))
|
||||
}
|
||||
|
||||
// NumberNotIn applies the NotIn predicate on the "number" field.
|
||||
func NumberNotIn(vs ...string) predicate.Card {
|
||||
return predicate.Card(sql.FieldNotIn(FieldNumber, vs...))
|
||||
}
|
||||
|
||||
// NumberGT applies the GT predicate on the "number" field.
|
||||
func NumberGT(v string) predicate.Card {
|
||||
return predicate.Card(sql.FieldGT(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberGTE applies the GTE predicate on the "number" field.
|
||||
func NumberGTE(v string) predicate.Card {
|
||||
return predicate.Card(sql.FieldGTE(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberLT applies the LT predicate on the "number" field.
|
||||
func NumberLT(v string) predicate.Card {
|
||||
return predicate.Card(sql.FieldLT(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberLTE applies the LTE predicate on the "number" field.
|
||||
func NumberLTE(v string) predicate.Card {
|
||||
return predicate.Card(sql.FieldLTE(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberContains applies the Contains predicate on the "number" field.
|
||||
func NumberContains(v string) predicate.Card {
|
||||
return predicate.Card(sql.FieldContains(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberHasPrefix applies the HasPrefix predicate on the "number" field.
|
||||
func NumberHasPrefix(v string) predicate.Card {
|
||||
return predicate.Card(sql.FieldHasPrefix(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberHasSuffix applies the HasSuffix predicate on the "number" field.
|
||||
func NumberHasSuffix(v string) predicate.Card {
|
||||
return predicate.Card(sql.FieldHasSuffix(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberIsNil applies the IsNil predicate on the "number" field.
|
||||
func NumberIsNil() predicate.Card {
|
||||
return predicate.Card(sql.FieldIsNull(FieldNumber))
|
||||
}
|
||||
|
||||
// NumberNotNil applies the NotNil predicate on the "number" field.
|
||||
func NumberNotNil() predicate.Card {
|
||||
return predicate.Card(sql.FieldNotNull(FieldNumber))
|
||||
}
|
||||
|
||||
// NumberEqualFold applies the EqualFold predicate on the "number" field.
|
||||
func NumberEqualFold(v string) predicate.Card {
|
||||
return predicate.Card(sql.FieldEqualFold(FieldNumber, v))
|
||||
}
|
||||
|
||||
// NumberContainsFold applies the ContainsFold predicate on the "number" field.
|
||||
func NumberContainsFold(v string) predicate.Card {
|
||||
return predicate.Card(sql.FieldContainsFold(FieldNumber, v))
|
||||
}
|
||||
|
||||
// OwnerIDEQ applies the EQ predicate on the "owner_id" field.
|
||||
func OwnerIDEQ(v int) predicate.Card {
|
||||
return predicate.Card(sql.FieldEQ(FieldOwnerID, v))
|
||||
}
|
||||
|
||||
// OwnerIDNEQ applies the NEQ predicate on the "owner_id" field.
|
||||
func OwnerIDNEQ(v int) predicate.Card {
|
||||
return predicate.Card(sql.FieldNEQ(FieldOwnerID, v))
|
||||
}
|
||||
|
||||
// OwnerIDIn applies the In predicate on the "owner_id" field.
|
||||
func OwnerIDIn(vs ...int) predicate.Card {
|
||||
return predicate.Card(sql.FieldIn(FieldOwnerID, vs...))
|
||||
}
|
||||
|
||||
// OwnerIDNotIn applies the NotIn predicate on the "owner_id" field.
|
||||
func OwnerIDNotIn(vs ...int) predicate.Card {
|
||||
return predicate.Card(sql.FieldNotIn(FieldOwnerID, vs...))
|
||||
}
|
||||
|
||||
// OwnerIDIsNil applies the IsNil predicate on the "owner_id" field.
|
||||
func OwnerIDIsNil() predicate.Card {
|
||||
return predicate.Card(sql.FieldIsNull(FieldOwnerID))
|
||||
}
|
||||
|
||||
// OwnerIDNotNil applies the NotNil predicate on the "owner_id" field.
|
||||
func OwnerIDNotNil() predicate.Card {
|
||||
return predicate.Card(sql.FieldNotNull(FieldOwnerID))
|
||||
}
|
||||
|
||||
// HasOwner applies the HasEdge predicate on the "owner" edge.
|
||||
func HasOwner() predicate.Card {
|
||||
return predicate.Card(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.Card {
|
||||
return predicate.Card(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.Card) predicate.Card {
|
||||
return predicate.Card(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Card) predicate.Card {
|
||||
return predicate.Card(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Card) predicate.Card {
|
||||
return predicate.Card(sql.NotPredicates(p))
|
||||
}
|
||||
228
entc/integration/edgefield/ent/card_create.go
Normal file
228
entc/integration/edgefield/ent/card_create.go
Normal file
@@ -0,0 +1,228 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/card"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CardCreate is the builder for creating a Card entity.
|
||||
type CardCreate struct {
|
||||
config
|
||||
mutation *CardMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetNumber sets the "number" field.
|
||||
func (_c *CardCreate) SetNumber(v string) *CardCreate {
|
||||
_c.mutation.SetNumber(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableNumber sets the "number" field if the given value is not nil.
|
||||
func (_c *CardCreate) SetNillableNumber(v *string) *CardCreate {
|
||||
if v != nil {
|
||||
_c.SetNumber(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner_id" field.
|
||||
func (_c *CardCreate) SetOwnerID(v int) *CardCreate {
|
||||
_c.mutation.SetOwnerID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
|
||||
func (_c *CardCreate) SetNillableOwnerID(v *int) *CardCreate {
|
||||
if v != nil {
|
||||
_c.SetOwnerID(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" edge to the User entity.
|
||||
func (_c *CardCreate) SetOwner(v *User) *CardCreate {
|
||||
return _c.SetOwnerID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CardMutation object of the builder.
|
||||
func (_c *CardCreate) Mutation() *CardMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Card in the database.
|
||||
func (_c *CardCreate) Save(ctx context.Context) (*Card, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *CardCreate) SaveX(ctx context.Context) *Card {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *CardCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *CardCreate) 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 *CardCreate) check() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *CardCreate) sqlSave(ctx context.Context) (*Card, 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 *CardCreate) createSpec() (*Card, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Card{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(card.Table, sqlgraph.NewFieldSpec(card.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.Number(); ok {
|
||||
_spec.SetField(card.FieldNumber, field.TypeString, value)
|
||||
_node.Number = value
|
||||
}
|
||||
if nodes := _c.mutation.OwnerIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: card.OwnerTable,
|
||||
Columns: []string{card.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.OwnerID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// CardCreateBulk is the builder for creating many Card entities in bulk.
|
||||
type CardCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*CardCreate
|
||||
}
|
||||
|
||||
// Save creates the Card entities in the database.
|
||||
func (_c *CardCreateBulk) Save(ctx context.Context) ([]*Card, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Card, 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.(*CardMutation)
|
||||
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 *CardCreateBulk) SaveX(ctx context.Context) []*Card {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *CardCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *CardCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/edgefield/ent/card_delete.go
Normal file
92
entc/integration/edgefield/ent/card_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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/card"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CardDelete is the builder for deleting a Card entity.
|
||||
type CardDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CardMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CardDelete builder.
|
||||
func (_d *CardDelete) Where(ps ...predicate.Card) *CardDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *CardDelete) 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 *CardDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *CardDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(card.Table, sqlgraph.NewFieldSpec(card.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
|
||||
}
|
||||
|
||||
// CardDeleteOne is the builder for deleting a single Card entity.
|
||||
type CardDeleteOne struct {
|
||||
_d *CardDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CardDelete builder.
|
||||
func (_d *CardDeleteOne) Where(ps ...predicate.Card) *CardDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *CardDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{card.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *CardDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
610
entc/integration/edgefield/ent/card_query.go
Normal file
610
entc/integration/edgefield/ent/card_query.go
Normal file
@@ -0,0 +1,610 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/card"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CardQuery is the builder for querying Card entities.
|
||||
type CardQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []card.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Card
|
||||
withOwner *UserQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the CardQuery builder.
|
||||
func (_q *CardQuery) Where(ps ...predicate.Card) *CardQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *CardQuery) Limit(limit int) *CardQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *CardQuery) Offset(offset int) *CardQuery {
|
||||
_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 *CardQuery) Unique(unique bool) *CardQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *CardQuery) Order(o ...card.OrderOption) *CardQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryOwner chains the current query on the "owner" edge.
|
||||
func (_q *CardQuery) 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(card.Table, card.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, card.OwnerTable, card.OwnerColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Card entity from the query.
|
||||
// Returns a *NotFoundError when no Card was found.
|
||||
func (_q *CardQuery) First(ctx context.Context) (*Card, 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{card.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *CardQuery) FirstX(ctx context.Context) *Card {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Card ID from the query.
|
||||
// Returns a *NotFoundError when no Card ID was found.
|
||||
func (_q *CardQuery) 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{card.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *CardQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Card entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Card entity is found.
|
||||
// Returns a *NotFoundError when no Card entities are found.
|
||||
func (_q *CardQuery) Only(ctx context.Context) (*Card, 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{card.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{card.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *CardQuery) OnlyX(ctx context.Context) *Card {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Card ID in the query.
|
||||
// Returns a *NotSingularError when more than one Card ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *CardQuery) 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{card.Label}
|
||||
default:
|
||||
err = &NotSingularError{card.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *CardQuery) 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 Cards.
|
||||
func (_q *CardQuery) All(ctx context.Context) ([]*Card, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Card, *CardQuery]()
|
||||
return withInterceptors[[]*Card](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *CardQuery) AllX(ctx context.Context) []*Card {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Card IDs.
|
||||
func (_q *CardQuery) 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(card.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *CardQuery) 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 *CardQuery) 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[*CardQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *CardQuery) 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 *CardQuery) 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("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *CardQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the CardQuery 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 *CardQuery) Clone() *CardQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &CardQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]card.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Card{}, _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 *CardQuery) WithOwner(opts ...func(*UserQuery)) *CardQuery {
|
||||
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.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Number string `json:"number,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Card.Query().
|
||||
// GroupBy(card.FieldNumber).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *CardQuery) GroupBy(field string, fields ...string) *CardGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &CardGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = card.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 {
|
||||
// Number string `json:"number,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Card.Query().
|
||||
// Select(card.FieldNumber).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *CardQuery) Select(fields ...string) *CardSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &CardSelect{CardQuery: _q}
|
||||
sbuild.label = card.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a CardSelect configured with the given aggregations.
|
||||
func (_q *CardQuery) Aggregate(fns ...AggregateFunc) *CardSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *CardQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !card.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: 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 *CardQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Card, error) {
|
||||
var (
|
||||
nodes = []*Card{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
_q.withOwner != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Card).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Card{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 *Card, e *User) { n.Edges.Owner = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *CardQuery) loadOwner(ctx context.Context, query *UserQuery, nodes []*Card, init func(*Card), assign func(*Card, *User)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Card)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].OwnerID
|
||||
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 "owner_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *CardQuery) 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 *CardQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(card.Table, card.Columns, sqlgraph.NewFieldSpec(card.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, card.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != card.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
if _q.withOwner != nil {
|
||||
_spec.Node.AddColumnOnce(card.FieldOwnerID)
|
||||
}
|
||||
}
|
||||
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 *CardQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(card.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = card.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
|
||||
}
|
||||
|
||||
// CardGroupBy is the group-by builder for Card entities.
|
||||
type CardGroupBy struct {
|
||||
selector
|
||||
build *CardQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *CardGroupBy) Aggregate(fns ...AggregateFunc) *CardGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *CardGroupBy) 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[*CardQuery, *CardGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *CardGroupBy) sqlScan(ctx context.Context, root *CardQuery, 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)
|
||||
}
|
||||
|
||||
// CardSelect is the builder for selecting fields of Card entities.
|
||||
type CardSelect struct {
|
||||
*CardQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *CardSelect) Aggregate(fns ...AggregateFunc) *CardSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *CardSelect) 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[*CardQuery, *CardSelect](ctx, _s.CardQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *CardSelect) sqlScan(ctx context.Context, root *CardQuery, 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)
|
||||
}
|
||||
352
entc/integration/edgefield/ent/card_update.go
Normal file
352
entc/integration/edgefield/ent/card_update.go
Normal file
@@ -0,0 +1,352 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/card"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CardUpdate is the builder for updating Card entities.
|
||||
type CardUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CardMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CardUpdate builder.
|
||||
func (_u *CardUpdate) Where(ps ...predicate.Card) *CardUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNumber sets the "number" field.
|
||||
func (_u *CardUpdate) SetNumber(v string) *CardUpdate {
|
||||
_u.mutation.SetNumber(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableNumber sets the "number" field if the given value is not nil.
|
||||
func (_u *CardUpdate) SetNillableNumber(v *string) *CardUpdate {
|
||||
if v != nil {
|
||||
_u.SetNumber(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearNumber clears the value of the "number" field.
|
||||
func (_u *CardUpdate) ClearNumber() *CardUpdate {
|
||||
_u.mutation.ClearNumber()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner_id" field.
|
||||
func (_u *CardUpdate) SetOwnerID(v int) *CardUpdate {
|
||||
_u.mutation.SetOwnerID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
|
||||
func (_u *CardUpdate) SetNillableOwnerID(v *int) *CardUpdate {
|
||||
if v != nil {
|
||||
_u.SetOwnerID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearOwnerID clears the value of the "owner_id" field.
|
||||
func (_u *CardUpdate) ClearOwnerID() *CardUpdate {
|
||||
_u.mutation.ClearOwnerID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" edge to the User entity.
|
||||
func (_u *CardUpdate) SetOwner(v *User) *CardUpdate {
|
||||
return _u.SetOwnerID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CardMutation object of the builder.
|
||||
func (_u *CardUpdate) Mutation() *CardMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearOwner clears the "owner" edge to the User entity.
|
||||
func (_u *CardUpdate) ClearOwner() *CardUpdate {
|
||||
_u.mutation.ClearOwner()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *CardUpdate) 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 *CardUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *CardUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *CardUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *CardUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(card.Table, card.Columns, sqlgraph.NewFieldSpec(card.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.Number(); ok {
|
||||
_spec.SetField(card.FieldNumber, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.NumberCleared() {
|
||||
_spec.ClearField(card.FieldNumber, field.TypeString)
|
||||
}
|
||||
if _u.mutation.OwnerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: card.OwnerTable,
|
||||
Columns: []string{card.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: card.OwnerTable,
|
||||
Columns: []string{card.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{card.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// CardUpdateOne is the builder for updating a single Card entity.
|
||||
type CardUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *CardMutation
|
||||
}
|
||||
|
||||
// SetNumber sets the "number" field.
|
||||
func (_u *CardUpdateOne) SetNumber(v string) *CardUpdateOne {
|
||||
_u.mutation.SetNumber(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableNumber sets the "number" field if the given value is not nil.
|
||||
func (_u *CardUpdateOne) SetNillableNumber(v *string) *CardUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetNumber(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearNumber clears the value of the "number" field.
|
||||
func (_u *CardUpdateOne) ClearNumber() *CardUpdateOne {
|
||||
_u.mutation.ClearNumber()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner_id" field.
|
||||
func (_u *CardUpdateOne) SetOwnerID(v int) *CardUpdateOne {
|
||||
_u.mutation.SetOwnerID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
|
||||
func (_u *CardUpdateOne) SetNillableOwnerID(v *int) *CardUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetOwnerID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearOwnerID clears the value of the "owner_id" field.
|
||||
func (_u *CardUpdateOne) ClearOwnerID() *CardUpdateOne {
|
||||
_u.mutation.ClearOwnerID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" edge to the User entity.
|
||||
func (_u *CardUpdateOne) SetOwner(v *User) *CardUpdateOne {
|
||||
return _u.SetOwnerID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CardMutation object of the builder.
|
||||
func (_u *CardUpdateOne) Mutation() *CardMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearOwner clears the "owner" edge to the User entity.
|
||||
func (_u *CardUpdateOne) ClearOwner() *CardUpdateOne {
|
||||
_u.mutation.ClearOwner()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CardUpdate builder.
|
||||
func (_u *CardUpdateOne) Where(ps ...predicate.Card) *CardUpdateOne {
|
||||
_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 *CardUpdateOne) Select(field string, fields ...string) *CardUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Card entity.
|
||||
func (_u *CardUpdateOne) Save(ctx context.Context) (*Card, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *CardUpdateOne) SaveX(ctx context.Context) *Card {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *CardUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *CardUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *CardUpdateOne) sqlSave(ctx context.Context) (_node *Card, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(card.Table, card.Columns, sqlgraph.NewFieldSpec(card.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Card.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, card.FieldID)
|
||||
for _, f := range fields {
|
||||
if !card.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != card.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.Number(); ok {
|
||||
_spec.SetField(card.FieldNumber, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.NumberCleared() {
|
||||
_spec.ClearField(card.FieldNumber, field.TypeString)
|
||||
}
|
||||
if _u.mutation.OwnerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: card.OwnerTable,
|
||||
Columns: []string{card.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: card.OwnerTable,
|
||||
Columns: []string{card.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 = &Card{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{card.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
1802
entc/integration/edgefield/ent/client.go
Normal file
1802
entc/integration/edgefield/ent/client.go
Normal file
File diff suppressed because it is too large
Load Diff
628
entc/integration/edgefield/ent/ent.go
Normal file
628
entc/integration/edgefield/ent/ent.go
Normal file
@@ -0,0 +1,628 @@
|
||||
// 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 ent
|
||||
|
||||
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/edgefield/ent/car"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/card"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/info"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/metadata"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/node"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/pet"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/post"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/rental"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/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,
|
||||
card.Table: card.ValidColumn,
|
||||
info.Table: info.ValidColumn,
|
||||
metadata.Table: metadata.ValidColumn,
|
||||
node.Table: node.ValidColumn,
|
||||
pet.Table: pet.ValidColumn,
|
||||
post.Table: post.ValidColumn,
|
||||
rental.Table: rental.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("ent: %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("ent: %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(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.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("ent: %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("ent: %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("ent: %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("ent: %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 "ent: " + 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 "ent: " + 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 "ent: " + 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 "ent: 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("ent: 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("ent: 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("ent: 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("ent: 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("ent: 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("ent: 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("ent: 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("ent: 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/edgefield/ent/enttest/enttest.go
Normal file
88
entc/integration/edgefield/ent/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/edgefield/ent"
|
||||
// required by schema hooks.
|
||||
_ "entgo.io/ent/entc/integration/edgefield/ent/runtime"
|
||||
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/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 []ent.Option
|
||||
migrateOpts []schema.MigrateOption
|
||||
}
|
||||
)
|
||||
|
||||
// WithOptions forwards options to client creation.
|
||||
func WithOptions(opts ...ent.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 ent.Open and auto-run migration.
|
||||
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client {
|
||||
o := newOptions(opts)
|
||||
c, err := ent.Open(driverName, dataSourceName, o.opts...)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
migrateSchema(t, c, o)
|
||||
return c
|
||||
}
|
||||
|
||||
// NewClient calls ent.NewClient and auto-run migration.
|
||||
func NewClient(t TestingT, opts ...Option) *ent.Client {
|
||||
o := newOptions(opts)
|
||||
c := ent.NewClient(o.opts...)
|
||||
migrateSchema(t, c, o)
|
||||
return c
|
||||
}
|
||||
func migrateSchema(t TestingT, c *ent.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/edgefield/ent/generate.go
Normal file
7
entc/integration/edgefield/ent/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 ent
|
||||
|
||||
//go:generate go run entgo.io/ent/cmd/ent generate --feature namedges --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
|
||||
299
entc/integration/edgefield/ent/hook/hook.go
Normal file
299
entc/integration/edgefield/ent/hook/hook.go
Normal file
@@ -0,0 +1,299 @@
|
||||
// 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/edgefield/ent"
|
||||
)
|
||||
|
||||
// The CarFunc type is an adapter to allow the use of ordinary
|
||||
// function as Car mutator.
|
||||
type CarFunc func(context.Context, *ent.CarMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f CarFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.CarMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CarMutation", m)
|
||||
}
|
||||
|
||||
// The CardFunc type is an adapter to allow the use of ordinary
|
||||
// function as Card mutator.
|
||||
type CardFunc func(context.Context, *ent.CardMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f CardFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.CardMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.CardMutation", m)
|
||||
}
|
||||
|
||||
// The InfoFunc type is an adapter to allow the use of ordinary
|
||||
// function as Info mutator.
|
||||
type InfoFunc func(context.Context, *ent.InfoMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f InfoFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.InfoMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.InfoMutation", m)
|
||||
}
|
||||
|
||||
// The MetadataFunc type is an adapter to allow the use of ordinary
|
||||
// function as Metadata mutator.
|
||||
type MetadataFunc func(context.Context, *ent.MetadataMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f MetadataFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.MetadataMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MetadataMutation", m)
|
||||
}
|
||||
|
||||
// The NodeFunc type is an adapter to allow the use of ordinary
|
||||
// function as Node mutator.
|
||||
type NodeFunc func(context.Context, *ent.NodeMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f NodeFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.NodeMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.NodeMutation", m)
|
||||
}
|
||||
|
||||
// The PetFunc type is an adapter to allow the use of ordinary
|
||||
// function as Pet mutator.
|
||||
type PetFunc func(context.Context, *ent.PetMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f PetFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.PetMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PetMutation", m)
|
||||
}
|
||||
|
||||
// The PostFunc type is an adapter to allow the use of ordinary
|
||||
// function as Post mutator.
|
||||
type PostFunc func(context.Context, *ent.PostMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f PostFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.PostMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PostMutation", m)
|
||||
}
|
||||
|
||||
// The RentalFunc type is an adapter to allow the use of ordinary
|
||||
// function as Rental mutator.
|
||||
type RentalFunc func(context.Context, *ent.RentalMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f RentalFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.RentalMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.RentalMutation", m)
|
||||
}
|
||||
|
||||
// The UserFunc type is an adapter to allow the use of ordinary
|
||||
// function as User mutator.
|
||||
type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f UserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.UserMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m)
|
||||
}
|
||||
|
||||
// Condition is a hook condition function.
|
||||
type Condition func(context.Context, ent.Mutation) bool
|
||||
|
||||
// And groups conditions with the AND operator.
|
||||
func And(first, second Condition, rest ...Condition) Condition {
|
||||
return func(ctx context.Context, m ent.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 ent.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 ent.Mutation) bool {
|
||||
return !cond(ctx, m)
|
||||
}
|
||||
}
|
||||
|
||||
// HasOp is a condition testing mutation operation.
|
||||
func HasOp(op ent.Op) Condition {
|
||||
return func(_ context.Context, m ent.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 ent.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 ent.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 ent.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 ent.Hook, cond Condition) ent.Hook {
|
||||
return func(next ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.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, ent.Delete|ent.Create)
|
||||
func On(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, HasOp(op))
|
||||
}
|
||||
|
||||
// Unless skips the given hook only for the given operation.
|
||||
//
|
||||
// hook.Unless(Log, ent.Update|ent.UpdateOne)
|
||||
func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) ent.Hook {
|
||||
return func(ent.Mutator) ent.Mutator {
|
||||
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []ent.Hook {
|
||||
// return []ent.Hook{
|
||||
// Reject(ent.Delete|ent.Update),
|
||||
// }
|
||||
// }
|
||||
func Reject(op ent.Op) ent.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 []ent.Hook
|
||||
}
|
||||
|
||||
// NewChain creates a new chain of hooks.
|
||||
func NewChain(hooks ...ent.Hook) Chain {
|
||||
return Chain{append([]ent.Hook(nil), hooks...)}
|
||||
}
|
||||
|
||||
// Hook chains the list of hooks and returns the final hook.
|
||||
func (c Chain) Hook() ent.Hook {
|
||||
return func(mutator ent.Mutator) ent.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 ...ent.Hook) Chain {
|
||||
newHooks := make([]ent.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...)
|
||||
}
|
||||
139
entc/integration/edgefield/ent/info.go
Normal file
139
entc/integration/edgefield/ent/info.go
Normal file
@@ -0,0 +1,139 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/info"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
)
|
||||
|
||||
// Info is the model entity for the Info schema.
|
||||
type Info struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Content holds the value of the "content" field.
|
||||
Content json.RawMessage `json:"content,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the InfoQuery when eager-loading is set.
|
||||
Edges InfoEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// InfoEdges holds the relations/edges for other nodes in the graph.
|
||||
type InfoEdges struct {
|
||||
// User holds the value of the user edge.
|
||||
User *User `json:"user,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// UserOrErr returns the User value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e InfoEdges) UserOrErr() (*User, error) {
|
||||
if e.User != nil {
|
||||
return e.User, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Info) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case info.FieldContent:
|
||||
values[i] = new([]byte)
|
||||
case info.FieldID:
|
||||
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 Info fields.
|
||||
func (_m *Info) 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 info.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 info.FieldContent:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field content", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &_m.Content); err != nil {
|
||||
return fmt.Errorf("unmarshal field content: %w", err)
|
||||
}
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Info.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Info) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryUser queries the "user" edge of the Info entity.
|
||||
func (_m *Info) QueryUser() *UserQuery {
|
||||
return NewInfoClient(_m.config).QueryUser(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Info.
|
||||
// Note that you need to call Info.Unwrap() before calling this method if this Info
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Info) Update() *InfoUpdateOne {
|
||||
return NewInfoClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Info 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 *Info) Unwrap() *Info {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Info is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Info) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Info(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("content=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Content))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Infos is a parsable slice of Info.
|
||||
type Infos []*Info
|
||||
70
entc/integration/edgefield/ent/info/info.go
Normal file
70
entc/integration/edgefield/ent/info/info.go
Normal file
@@ -0,0 +1,70 @@
|
||||
// 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 info
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the info type in the database.
|
||||
Label = "info"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldContent holds the string denoting the content field in the database.
|
||||
FieldContent = "content"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// Table holds the table name of the info in the database.
|
||||
Table = "infos"
|
||||
// UserTable is the table that holds the user relation/edge.
|
||||
UserTable = "infos"
|
||||
// UserInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
UserInverseTable = "users"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for info fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldContent,
|
||||
}
|
||||
|
||||
// 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 Info 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()
|
||||
}
|
||||
|
||||
// ByUserField orders the results by user field.
|
||||
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn),
|
||||
)
|
||||
}
|
||||
317
entc/integration/edgefield/ent/info/mutation.go
Normal file
317
entc/integration/edgefield/ent/info/mutation.go
Normal file
@@ -0,0 +1,317 @@
|
||||
// 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 info
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Info nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
content *json.RawMessage
|
||||
appendcontent json.RawMessage
|
||||
clearedFields map[string]struct{}
|
||||
user *int
|
||||
cleareduser bool
|
||||
predicates []predicate.Info
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Info entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Info",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Info {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (m *Mutation) SetContent(jm json.RawMessage) {
|
||||
m.content = &jm
|
||||
m.appendcontent = nil
|
||||
}
|
||||
|
||||
// Content returns the value of the "content" field in the mutation.
|
||||
func (m *Mutation) Content() (r json.RawMessage, exists bool) {
|
||||
v := m.content
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// AppendContent adds jm to the "content" field.
|
||||
func (m *Mutation) AppendContent(jm json.RawMessage) {
|
||||
m.appendcontent = append(m.appendcontent, jm...)
|
||||
}
|
||||
|
||||
// AppendedContent returns the list of values that were appended to the "content" field in this mutation.
|
||||
func (m *Mutation) AppendedContent() (json.RawMessage, bool) {
|
||||
if len(m.appendcontent) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
return m.appendcontent, true
|
||||
}
|
||||
|
||||
// ResetContent resets all changes to the "content" field.
|
||||
func (m *Mutation) ResetContent() {
|
||||
m.content = nil
|
||||
m.appendcontent = nil
|
||||
}
|
||||
|
||||
// SetUserID sets the "user" edge to the User entity by id.
|
||||
func (m *Mutation) SetUserID(id int) {
|
||||
m.user = &id
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (m *Mutation) ClearUser() {
|
||||
m.cleareduser = true
|
||||
}
|
||||
|
||||
// UserCleared reports if the "user" edge to the User entity was cleared.
|
||||
func (m *Mutation) UserCleared() bool {
|
||||
return m.cleareduser
|
||||
}
|
||||
|
||||
// UserID returns the "user" edge ID in the mutation.
|
||||
func (m *Mutation) UserID() (id int, exists bool) {
|
||||
if m.user != nil {
|
||||
return *m.user, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// UserIDs returns the "user" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// UserID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) UserIDs() (ids []int) {
|
||||
if id := m.user; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetUser resets all changes to the "user" edge.
|
||||
func (m *Mutation) ResetUser() {
|
||||
m.user = nil
|
||||
m.cleareduser = false
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.Info) {
|
||||
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.Info, 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 (Info).
|
||||
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.content != nil {
|
||||
fields = append(fields, FieldContent)
|
||||
}
|
||||
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 FieldContent:
|
||||
return m.Content()
|
||||
}
|
||||
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 Info 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 FieldContent:
|
||||
v, ok := value.(json.RawMessage)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetContent(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Info 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 Info 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 Info 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 FieldContent:
|
||||
m.ResetContent()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Info 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.user != nil {
|
||||
edges = append(edges, EdgeUser)
|
||||
}
|
||||
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 EdgeUser:
|
||||
if id := m.user; 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.cleareduser {
|
||||
edges = append(edges, EdgeUser)
|
||||
}
|
||||
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 EdgeUser:
|
||||
return m.cleareduser
|
||||
}
|
||||
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 EdgeUser:
|
||||
m.ClearUser()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Info 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 EdgeUser:
|
||||
m.ResetUser()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Info edge %s", name)
|
||||
}
|
||||
96
entc/integration/edgefield/ent/info/where.go
Normal file
96
entc/integration/edgefield/ent/info/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 info
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Info {
|
||||
return predicate.Info(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Info {
|
||||
return predicate.Info(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Info {
|
||||
return predicate.Info(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Info {
|
||||
return predicate.Info(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Info {
|
||||
return predicate.Info(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Info {
|
||||
return predicate.Info(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Info {
|
||||
return predicate.Info(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Info {
|
||||
return predicate.Info(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Info {
|
||||
return predicate.Info(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||
func HasUser() predicate.Info {
|
||||
return predicate.Info(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||
func HasUserWith(preds ...predicate.User) predicate.Info {
|
||||
return predicate.Info(func(s *sql.Selector) {
|
||||
step := newUserStep()
|
||||
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.Info) predicate.Info {
|
||||
return predicate.Info(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Info) predicate.Info {
|
||||
return predicate.Info(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Info) predicate.Info {
|
||||
return predicate.Info(sql.NotPredicates(p))
|
||||
}
|
||||
237
entc/integration/edgefield/ent/info_create.go
Normal file
237
entc/integration/edgefield/ent/info_create.go
Normal file
@@ -0,0 +1,237 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/info"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// InfoCreate is the builder for creating a Info entity.
|
||||
type InfoCreate struct {
|
||||
config
|
||||
mutation *InfoMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (_c *InfoCreate) SetContent(v json.RawMessage) *InfoCreate {
|
||||
_c.mutation.SetContent(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *InfoCreate) SetID(v int) *InfoCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUserID sets the "user" edge to the User entity by ID.
|
||||
func (_c *InfoCreate) SetUserID(id int) *InfoCreate {
|
||||
_c.mutation.SetUserID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
|
||||
func (_c *InfoCreate) SetNillableUserID(id *int) *InfoCreate {
|
||||
if id != nil {
|
||||
_c = _c.SetUserID(*id)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (_c *InfoCreate) SetUser(v *User) *InfoCreate {
|
||||
return _c.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the InfoMutation object of the builder.
|
||||
func (_c *InfoCreate) Mutation() *InfoMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Info in the database.
|
||||
func (_c *InfoCreate) Save(ctx context.Context) (*Info, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *InfoCreate) SaveX(ctx context.Context) *Info {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *InfoCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *InfoCreate) 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 *InfoCreate) check() error {
|
||||
if _, ok := _c.mutation.Content(); !ok {
|
||||
return &ValidationError{Name: "content", err: errors.New(`ent: missing required field "Info.content"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *InfoCreate) sqlSave(ctx context.Context) (*Info, 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 *InfoCreate) createSpec() (*Info, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Info{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(info.Table, sqlgraph.NewFieldSpec(info.FieldID, field.TypeInt))
|
||||
)
|
||||
if id, ok := _c.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
if value, ok := _c.mutation.Content(); ok {
|
||||
_spec.SetField(info.FieldContent, field.TypeJSON, value)
|
||||
_node.Content = value
|
||||
}
|
||||
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: info.UserTable,
|
||||
Columns: []string{info.UserColumn},
|
||||
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.ID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// InfoCreateBulk is the builder for creating many Info entities in bulk.
|
||||
type InfoCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*InfoCreate
|
||||
}
|
||||
|
||||
// Save creates the Info entities in the database.
|
||||
func (_c *InfoCreateBulk) Save(ctx context.Context) ([]*Info, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Info, 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.(*InfoMutation)
|
||||
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 *InfoCreateBulk) SaveX(ctx context.Context) []*Info {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *InfoCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *InfoCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/edgefield/ent/info_delete.go
Normal file
92
entc/integration/edgefield/ent/info_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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/info"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// InfoDelete is the builder for deleting a Info entity.
|
||||
type InfoDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *InfoMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the InfoDelete builder.
|
||||
func (_d *InfoDelete) Where(ps ...predicate.Info) *InfoDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *InfoDelete) 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 *InfoDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *InfoDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(info.Table, sqlgraph.NewFieldSpec(info.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
|
||||
}
|
||||
|
||||
// InfoDeleteOne is the builder for deleting a single Info entity.
|
||||
type InfoDeleteOne struct {
|
||||
_d *InfoDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the InfoDelete builder.
|
||||
func (_d *InfoDeleteOne) Where(ps ...predicate.Info) *InfoDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *InfoDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{info.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *InfoDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
607
entc/integration/edgefield/ent/info_query.go
Normal file
607
entc/integration/edgefield/ent/info_query.go
Normal file
@@ -0,0 +1,607 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/info"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// InfoQuery is the builder for querying Info entities.
|
||||
type InfoQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []info.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Info
|
||||
withUser *UserQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the InfoQuery builder.
|
||||
func (_q *InfoQuery) Where(ps ...predicate.Info) *InfoQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *InfoQuery) Limit(limit int) *InfoQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *InfoQuery) Offset(offset int) *InfoQuery {
|
||||
_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 *InfoQuery) Unique(unique bool) *InfoQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *InfoQuery) Order(o ...info.OrderOption) *InfoQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryUser chains the current query on the "user" edge.
|
||||
func (_q *InfoQuery) QueryUser() *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(info.Table, info.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, info.UserTable, info.UserColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Info entity from the query.
|
||||
// Returns a *NotFoundError when no Info was found.
|
||||
func (_q *InfoQuery) First(ctx context.Context) (*Info, 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{info.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *InfoQuery) FirstX(ctx context.Context) *Info {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Info ID from the query.
|
||||
// Returns a *NotFoundError when no Info ID was found.
|
||||
func (_q *InfoQuery) 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{info.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *InfoQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Info entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Info entity is found.
|
||||
// Returns a *NotFoundError when no Info entities are found.
|
||||
func (_q *InfoQuery) Only(ctx context.Context) (*Info, 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{info.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{info.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *InfoQuery) OnlyX(ctx context.Context) *Info {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Info ID in the query.
|
||||
// Returns a *NotSingularError when more than one Info ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *InfoQuery) 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{info.Label}
|
||||
default:
|
||||
err = &NotSingularError{info.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *InfoQuery) 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 Infos.
|
||||
func (_q *InfoQuery) All(ctx context.Context) ([]*Info, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Info, *InfoQuery]()
|
||||
return withInterceptors[[]*Info](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *InfoQuery) AllX(ctx context.Context) []*Info {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Info IDs.
|
||||
func (_q *InfoQuery) 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(info.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *InfoQuery) 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 *InfoQuery) 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[*InfoQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *InfoQuery) 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 *InfoQuery) 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("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *InfoQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the InfoQuery 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 *InfoQuery) Clone() *InfoQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &InfoQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]info.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Info{}, _q.predicates...),
|
||||
withUser: _q.withUser.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *InfoQuery) WithUser(opts ...func(*UserQuery)) *InfoQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withUser = 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 {
|
||||
// Content json.RawMessage `json:"content,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Info.Query().
|
||||
// GroupBy(info.FieldContent).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *InfoQuery) GroupBy(field string, fields ...string) *InfoGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &InfoGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = info.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 {
|
||||
// Content json.RawMessage `json:"content,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Info.Query().
|
||||
// Select(info.FieldContent).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *InfoQuery) Select(fields ...string) *InfoSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &InfoSelect{InfoQuery: _q}
|
||||
sbuild.label = info.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a InfoSelect configured with the given aggregations.
|
||||
func (_q *InfoQuery) Aggregate(fns ...AggregateFunc) *InfoSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *InfoQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !info.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: 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 *InfoQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Info, error) {
|
||||
var (
|
||||
nodes = []*Info{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
_q.withUser != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Info).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Info{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.withUser; query != nil {
|
||||
if err := _q.loadUser(ctx, query, nodes, nil,
|
||||
func(n *Info, e *User) { n.Edges.User = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *InfoQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*Info, init func(*Info), assign func(*Info, *User)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Info)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].ID
|
||||
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 "id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *InfoQuery) 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 *InfoQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(info.Table, info.Columns, sqlgraph.NewFieldSpec(info.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, info.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != info.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 *InfoQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(info.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = info.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
|
||||
}
|
||||
|
||||
// InfoGroupBy is the group-by builder for Info entities.
|
||||
type InfoGroupBy struct {
|
||||
selector
|
||||
build *InfoQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *InfoGroupBy) Aggregate(fns ...AggregateFunc) *InfoGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *InfoGroupBy) 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[*InfoQuery, *InfoGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *InfoGroupBy) sqlScan(ctx context.Context, root *InfoQuery, 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)
|
||||
}
|
||||
|
||||
// InfoSelect is the builder for selecting fields of Info entities.
|
||||
type InfoSelect struct {
|
||||
*InfoQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *InfoSelect) Aggregate(fns ...AggregateFunc) *InfoSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *InfoSelect) 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[*InfoQuery, *InfoSelect](ctx, _s.InfoQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *InfoSelect) sqlScan(ctx context.Context, root *InfoQuery, 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)
|
||||
}
|
||||
330
entc/integration/edgefield/ent/info_update.go
Normal file
330
entc/integration/edgefield/ent/info_update.go
Normal file
@@ -0,0 +1,330 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/dialect/sql/sqljson"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/info"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// InfoUpdate is the builder for updating Info entities.
|
||||
type InfoUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *InfoMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the InfoUpdate builder.
|
||||
func (_u *InfoUpdate) Where(ps ...predicate.Info) *InfoUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (_u *InfoUpdate) SetContent(v json.RawMessage) *InfoUpdate {
|
||||
_u.mutation.SetContent(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AppendContent appends value to the "content" field.
|
||||
func (_u *InfoUpdate) AppendContent(v json.RawMessage) *InfoUpdate {
|
||||
_u.mutation.AppendContent(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user" edge to the User entity by ID.
|
||||
func (_u *InfoUpdate) SetUserID(id int) *InfoUpdate {
|
||||
_u.mutation.SetUserID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
|
||||
func (_u *InfoUpdate) SetNillableUserID(id *int) *InfoUpdate {
|
||||
if id != nil {
|
||||
_u = _u.SetUserID(*id)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (_u *InfoUpdate) SetUser(v *User) *InfoUpdate {
|
||||
return _u.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the InfoMutation object of the builder.
|
||||
func (_u *InfoUpdate) Mutation() *InfoMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (_u *InfoUpdate) ClearUser() *InfoUpdate {
|
||||
_u.mutation.ClearUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *InfoUpdate) 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 *InfoUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *InfoUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *InfoUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *InfoUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(info.Table, info.Columns, sqlgraph.NewFieldSpec(info.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.Content(); ok {
|
||||
_spec.SetField(info.FieldContent, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AppendedContent(); ok {
|
||||
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||
sqljson.Append(u, info.FieldContent, value)
|
||||
})
|
||||
}
|
||||
if _u.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: info.UserTable,
|
||||
Columns: []string{info.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: info.UserTable,
|
||||
Columns: []string{info.UserColumn},
|
||||
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{info.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// InfoUpdateOne is the builder for updating a single Info entity.
|
||||
type InfoUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *InfoMutation
|
||||
}
|
||||
|
||||
// SetContent sets the "content" field.
|
||||
func (_u *InfoUpdateOne) SetContent(v json.RawMessage) *InfoUpdateOne {
|
||||
_u.mutation.SetContent(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AppendContent appends value to the "content" field.
|
||||
func (_u *InfoUpdateOne) AppendContent(v json.RawMessage) *InfoUpdateOne {
|
||||
_u.mutation.AppendContent(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user" edge to the User entity by ID.
|
||||
func (_u *InfoUpdateOne) SetUserID(id int) *InfoUpdateOne {
|
||||
_u.mutation.SetUserID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
|
||||
func (_u *InfoUpdateOne) SetNillableUserID(id *int) *InfoUpdateOne {
|
||||
if id != nil {
|
||||
_u = _u.SetUserID(*id)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (_u *InfoUpdateOne) SetUser(v *User) *InfoUpdateOne {
|
||||
return _u.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the InfoMutation object of the builder.
|
||||
func (_u *InfoUpdateOne) Mutation() *InfoMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (_u *InfoUpdateOne) ClearUser() *InfoUpdateOne {
|
||||
_u.mutation.ClearUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the InfoUpdate builder.
|
||||
func (_u *InfoUpdateOne) Where(ps ...predicate.Info) *InfoUpdateOne {
|
||||
_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 *InfoUpdateOne) Select(field string, fields ...string) *InfoUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Info entity.
|
||||
func (_u *InfoUpdateOne) Save(ctx context.Context) (*Info, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *InfoUpdateOne) SaveX(ctx context.Context) *Info {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *InfoUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *InfoUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *InfoUpdateOne) sqlSave(ctx context.Context) (_node *Info, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(info.Table, info.Columns, sqlgraph.NewFieldSpec(info.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Info.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, info.FieldID)
|
||||
for _, f := range fields {
|
||||
if !info.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != info.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.Content(); ok {
|
||||
_spec.SetField(info.FieldContent, field.TypeJSON, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AppendedContent(); ok {
|
||||
_spec.AddModifier(func(u *sql.UpdateBuilder) {
|
||||
sqljson.Append(u, info.FieldContent, value)
|
||||
})
|
||||
}
|
||||
if _u.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: info.UserTable,
|
||||
Columns: []string{info.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: info.UserTable,
|
||||
Columns: []string{info.UserColumn},
|
||||
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 = &Info{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{info.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
204
entc/integration/edgefield/ent/metadata.go
Normal file
204
entc/integration/edgefield/ent/metadata.go
Normal file
@@ -0,0 +1,204 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/metadata"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
)
|
||||
|
||||
// Metadata is the model entity for the Metadata schema.
|
||||
type Metadata struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Age holds the value of the "age" field.
|
||||
Age int `json:"age,omitempty"`
|
||||
// ParentID holds the value of the "parent_id" field.
|
||||
ParentID int `json:"parent_id,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the MetadataQuery when eager-loading is set.
|
||||
Edges MetadataEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// MetadataEdges holds the relations/edges for other nodes in the graph.
|
||||
type MetadataEdges struct {
|
||||
// User holds the value of the user edge.
|
||||
User *User `json:"user,omitempty"`
|
||||
// Children holds the value of the children edge.
|
||||
Children []*Metadata `json:"children,omitempty"`
|
||||
// Parent holds the value of the parent edge.
|
||||
Parent *Metadata `json:"parent,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [3]bool
|
||||
namedChildren map[string][]*Metadata
|
||||
}
|
||||
|
||||
// UserOrErr returns the User value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e MetadataEdges) UserOrErr() (*User, error) {
|
||||
if e.User != nil {
|
||||
return e.User, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// ChildrenOrErr returns the Children value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e MetadataEdges) ChildrenOrErr() ([]*Metadata, error) {
|
||||
if e.loadedTypes[1] {
|
||||
return e.Children, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "children"}
|
||||
}
|
||||
|
||||
// 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 MetadataEdges) ParentOrErr() (*Metadata, error) {
|
||||
if e.Parent != nil {
|
||||
return e.Parent, nil
|
||||
} else if e.loadedTypes[2] {
|
||||
return nil, &NotFoundError{label: metadata.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "parent"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Metadata) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case metadata.FieldID, metadata.FieldAge, metadata.FieldParentID:
|
||||
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 Metadata fields.
|
||||
func (_m *Metadata) 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 metadata.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 metadata.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 = int(value.Int64)
|
||||
}
|
||||
case metadata.FieldParentID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field parent_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ParentID = 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 Metadata.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Metadata) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryUser queries the "user" edge of the Metadata entity.
|
||||
func (_m *Metadata) QueryUser() *UserQuery {
|
||||
return NewMetadataClient(_m.config).QueryUser(_m)
|
||||
}
|
||||
|
||||
// QueryChildren queries the "children" edge of the Metadata entity.
|
||||
func (_m *Metadata) QueryChildren() *MetadataQuery {
|
||||
return NewMetadataClient(_m.config).QueryChildren(_m)
|
||||
}
|
||||
|
||||
// QueryParent queries the "parent" edge of the Metadata entity.
|
||||
func (_m *Metadata) QueryParent() *MetadataQuery {
|
||||
return NewMetadataClient(_m.config).QueryParent(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Metadata.
|
||||
// Note that you need to call Metadata.Unwrap() before calling this method if this Metadata
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Metadata) Update() *MetadataUpdateOne {
|
||||
return NewMetadataClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Metadata 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 *Metadata) Unwrap() *Metadata {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Metadata is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Metadata) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Metadata(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("age=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Age))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("parent_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.ParentID))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// NamedChildren returns the Children named value or an error if the edge was not
|
||||
// loaded in eager-loading with this name.
|
||||
func (_m *Metadata) NamedChildren(name string) ([]*Metadata, error) {
|
||||
if _m.Edges.namedChildren == nil {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
nodes, ok := _m.Edges.namedChildren[name]
|
||||
if !ok {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_m *Metadata) appendNamedChildren(name string, edges ...*Metadata) {
|
||||
if _m.Edges.namedChildren == nil {
|
||||
_m.Edges.namedChildren = make(map[string][]*Metadata)
|
||||
}
|
||||
if len(edges) == 0 {
|
||||
_m.Edges.namedChildren[name] = []*Metadata{}
|
||||
} else {
|
||||
_m.Edges.namedChildren[name] = append(_m.Edges.namedChildren[name], edges...)
|
||||
}
|
||||
}
|
||||
|
||||
// MetadataSlice is a parsable slice of Metadata.
|
||||
type MetadataSlice []*Metadata
|
||||
135
entc/integration/edgefield/ent/metadata/metadata.go
Normal file
135
entc/integration/edgefield/ent/metadata/metadata.go
Normal file
@@ -0,0 +1,135 @@
|
||||
// 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 metadata
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the metadata type in the database.
|
||||
Label = "metadata"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldAge holds the string denoting the age field in the database.
|
||||
FieldAge = "age"
|
||||
// FieldParentID holds the string denoting the parent_id field in the database.
|
||||
FieldParentID = "parent_id"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// EdgeChildren holds the string denoting the children edge name in mutations.
|
||||
EdgeChildren = "children"
|
||||
// EdgeParent holds the string denoting the parent edge name in mutations.
|
||||
EdgeParent = "parent"
|
||||
// Table holds the table name of the metadata in the database.
|
||||
Table = "metadata"
|
||||
// UserTable is the table that holds the user relation/edge.
|
||||
UserTable = "metadata"
|
||||
// UserInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
UserInverseTable = "users"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "id"
|
||||
// ChildrenTable is the table that holds the children relation/edge.
|
||||
ChildrenTable = "metadata"
|
||||
// ChildrenColumn is the table column denoting the children relation/edge.
|
||||
ChildrenColumn = "parent_id"
|
||||
// ParentTable is the table that holds the parent relation/edge.
|
||||
ParentTable = "metadata"
|
||||
// ParentColumn is the table column denoting the parent relation/edge.
|
||||
ParentColumn = "parent_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for metadata fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldAge,
|
||||
FieldParentID,
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultAge holds the default value on creation for the "age" field.
|
||||
DefaultAge int
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the Metadata 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()
|
||||
}
|
||||
|
||||
// ByParentID orders the results by the parent_id field.
|
||||
func ByParentID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldParentID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserField orders the results by user field.
|
||||
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newUserStep(), 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...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// 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...))
|
||||
}
|
||||
}
|
||||
func newUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, UserTable, UserColumn),
|
||||
)
|
||||
}
|
||||
func newChildrenStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, ChildrenTable, ChildrenColumn),
|
||||
)
|
||||
}
|
||||
func newParentStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, ParentTable, ParentColumn),
|
||||
)
|
||||
}
|
||||
524
entc/integration/edgefield/ent/metadata/mutation.go
Normal file
524
entc/integration/edgefield/ent/metadata/mutation.go
Normal file
@@ -0,0 +1,524 @@
|
||||
// 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 metadata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Metadata nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
age *int
|
||||
addage *int
|
||||
clearedFields map[string]struct{}
|
||||
user *int
|
||||
cleareduser bool
|
||||
children map[int]struct{}
|
||||
removedchildren map[int]struct{}
|
||||
clearedchildren bool
|
||||
parent *int
|
||||
clearedparent bool
|
||||
predicates []predicate.Metadata
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Metadata entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Metadata",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Metadata {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetAge sets the "age" field.
|
||||
func (m *Mutation) SetAge(i int) {
|
||||
m.age = &i
|
||||
m.addage = nil
|
||||
}
|
||||
|
||||
// Age returns the value of the "age" field in the mutation.
|
||||
func (m *Mutation) Age() (r int, exists bool) {
|
||||
v := m.age
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// AddAge adds i to the "age" field.
|
||||
func (m *Mutation) AddAge(i int) {
|
||||
if m.addage != nil {
|
||||
*m.addage += i
|
||||
} else {
|
||||
m.addage = &i
|
||||
}
|
||||
}
|
||||
|
||||
// AddedAge returns the value that was added to the "age" field in this mutation.
|
||||
func (m *Mutation) AddedAge() (r int, exists bool) {
|
||||
v := m.addage
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ResetAge resets all changes to the "age" field.
|
||||
func (m *Mutation) ResetAge() {
|
||||
m.age = nil
|
||||
m.addage = nil
|
||||
}
|
||||
|
||||
// SetParentID sets the "parent_id" field.
|
||||
func (m *Mutation) SetParentID(i int) {
|
||||
m.parent = &i
|
||||
}
|
||||
|
||||
// ParentID returns the value of the "parent_id" field in the mutation.
|
||||
func (m *Mutation) ParentID() (r int, exists bool) {
|
||||
v := m.parent
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearParentID clears the value of the "parent_id" field.
|
||||
func (m *Mutation) ClearParentID() {
|
||||
m.parent = nil
|
||||
m.clearedFields[FieldParentID] = struct{}{}
|
||||
}
|
||||
|
||||
// ParentIDCleared returns if the "parent_id" field was cleared in this mutation.
|
||||
func (m *Mutation) ParentIDCleared() bool {
|
||||
_, ok := m.clearedFields[FieldParentID]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetParentID resets all changes to the "parent_id" field.
|
||||
func (m *Mutation) ResetParentID() {
|
||||
m.parent = nil
|
||||
delete(m.clearedFields, FieldParentID)
|
||||
}
|
||||
|
||||
// SetUserID sets the "user" edge to the User entity by id.
|
||||
func (m *Mutation) SetUserID(id int) {
|
||||
m.user = &id
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (m *Mutation) ClearUser() {
|
||||
m.cleareduser = true
|
||||
}
|
||||
|
||||
// UserCleared reports if the "user" edge to the User entity was cleared.
|
||||
func (m *Mutation) UserCleared() bool {
|
||||
return m.cleareduser
|
||||
}
|
||||
|
||||
// UserID returns the "user" edge ID in the mutation.
|
||||
func (m *Mutation) UserID() (id int, exists bool) {
|
||||
if m.user != nil {
|
||||
return *m.user, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// UserIDs returns the "user" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// UserID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) UserIDs() (ids []int) {
|
||||
if id := m.user; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetUser resets all changes to the "user" edge.
|
||||
func (m *Mutation) ResetUser() {
|
||||
m.user = nil
|
||||
m.cleareduser = false
|
||||
}
|
||||
|
||||
// AddChildIDs adds the "children" edge to the Metadata entity by ids.
|
||||
func (m *Mutation) AddChildIDs(ids ...int) {
|
||||
if m.children == nil {
|
||||
m.children = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
m.children[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// ClearChildren clears the "children" edge to the Metadata entity.
|
||||
func (m *Mutation) ClearChildren() {
|
||||
m.clearedchildren = true
|
||||
}
|
||||
|
||||
// ChildrenCleared reports if the "children" edge to the Metadata entity was cleared.
|
||||
func (m *Mutation) ChildrenCleared() bool {
|
||||
return m.clearedchildren
|
||||
}
|
||||
|
||||
// RemoveChildIDs removes the "children" edge to the Metadata entity by IDs.
|
||||
func (m *Mutation) RemoveChildIDs(ids ...int) {
|
||||
if m.removedchildren == nil {
|
||||
m.removedchildren = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
delete(m.children, ids[i])
|
||||
m.removedchildren[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// RemovedChildren returns the removed IDs of the "children" edge to the Metadata entity.
|
||||
func (m *Mutation) RemovedChildrenIDs() (ids []int) {
|
||||
for id := range m.removedchildren {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ChildrenIDs returns the "children" edge IDs in the mutation.
|
||||
func (m *Mutation) ChildrenIDs() (ids []int) {
|
||||
for id := range m.children {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetChildren resets all changes to the "children" edge.
|
||||
func (m *Mutation) ResetChildren() {
|
||||
m.children = nil
|
||||
m.clearedchildren = false
|
||||
m.removedchildren = nil
|
||||
}
|
||||
|
||||
// ClearParent clears the "parent" edge to the Metadata entity.
|
||||
func (m *Mutation) ClearParent() {
|
||||
m.clearedparent = true
|
||||
m.clearedFields[FieldParentID] = struct{}{}
|
||||
}
|
||||
|
||||
// ParentCleared reports if the "parent" edge to the Metadata entity was cleared.
|
||||
func (m *Mutation) ParentCleared() bool {
|
||||
return m.ParentIDCleared() || m.clearedparent
|
||||
}
|
||||
|
||||
// ParentIDs returns the "parent" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// ParentID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) ParentIDs() (ids []int) {
|
||||
if id := m.parent; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetParent resets all changes to the "parent" edge.
|
||||
func (m *Mutation) ResetParent() {
|
||||
m.parent = nil
|
||||
m.clearedparent = false
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.Metadata) {
|
||||
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.Metadata, 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 (Metadata).
|
||||
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, 2)
|
||||
if m.age != nil {
|
||||
fields = append(fields, FieldAge)
|
||||
}
|
||||
if m.parent != nil {
|
||||
fields = append(fields, FieldParentID)
|
||||
}
|
||||
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 FieldAge:
|
||||
return m.Age()
|
||||
case FieldParentID:
|
||||
return m.ParentID()
|
||||
}
|
||||
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 Metadata 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 FieldAge:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetAge(v)
|
||||
return nil
|
||||
case FieldParentID:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetParentID(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Metadata 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.addage != nil {
|
||||
fields = append(fields, FieldAge)
|
||||
}
|
||||
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 FieldAge:
|
||||
return m.AddedAge()
|
||||
}
|
||||
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 FieldAge:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.AddAge(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Metadata 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(FieldParentID) {
|
||||
fields = append(fields, FieldParentID)
|
||||
}
|
||||
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 FieldParentID:
|
||||
m.ClearParentID()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Metadata 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 FieldAge:
|
||||
m.ResetAge()
|
||||
return nil
|
||||
case FieldParentID:
|
||||
m.ResetParentID()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Metadata field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *Mutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 3)
|
||||
if m.user != nil {
|
||||
edges = append(edges, EdgeUser)
|
||||
}
|
||||
if m.children != nil {
|
||||
edges = append(edges, EdgeChildren)
|
||||
}
|
||||
if m.parent != nil {
|
||||
edges = append(edges, EdgeParent)
|
||||
}
|
||||
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 EdgeUser:
|
||||
if id := m.user; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
case EdgeChildren:
|
||||
ids := make([]ent.Value, 0, len(m.children))
|
||||
for id := range m.children {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
case EdgeParent:
|
||||
if id := m.parent; 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, 3)
|
||||
if m.removedchildren != nil {
|
||||
edges = append(edges, EdgeChildren)
|
||||
}
|
||||
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 {
|
||||
switch name {
|
||||
case EdgeChildren:
|
||||
ids := make([]ent.Value, 0, len(m.removedchildren))
|
||||
for id := range m.removedchildren {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *Mutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 3)
|
||||
if m.cleareduser {
|
||||
edges = append(edges, EdgeUser)
|
||||
}
|
||||
if m.clearedchildren {
|
||||
edges = append(edges, EdgeChildren)
|
||||
}
|
||||
if m.clearedparent {
|
||||
edges = append(edges, EdgeParent)
|
||||
}
|
||||
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 EdgeUser:
|
||||
return m.cleareduser
|
||||
case EdgeChildren:
|
||||
return m.clearedchildren
|
||||
case EdgeParent:
|
||||
return m.clearedparent
|
||||
}
|
||||
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 EdgeUser:
|
||||
m.ClearUser()
|
||||
return nil
|
||||
case EdgeParent:
|
||||
m.ClearParent()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Metadata 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 EdgeUser:
|
||||
m.ResetUser()
|
||||
return nil
|
||||
case EdgeChildren:
|
||||
m.ResetChildren()
|
||||
return nil
|
||||
case EdgeParent:
|
||||
m.ResetParent()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Metadata edge %s", name)
|
||||
}
|
||||
222
entc/integration/edgefield/ent/metadata/where.go
Normal file
222
entc/integration/edgefield/ent/metadata/where.go
Normal file
@@ -0,0 +1,222 @@
|
||||
// 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 metadata
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Age applies equality check predicate on the "age" field. It's identical to AgeEQ.
|
||||
func Age(v int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldEQ(FieldAge, v))
|
||||
}
|
||||
|
||||
// ParentID applies equality check predicate on the "parent_id" field. It's identical to ParentIDEQ.
|
||||
func ParentID(v int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldEQ(FieldParentID, v))
|
||||
}
|
||||
|
||||
// AgeEQ applies the EQ predicate on the "age" field.
|
||||
func AgeEQ(v int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldEQ(FieldAge, v))
|
||||
}
|
||||
|
||||
// AgeNEQ applies the NEQ predicate on the "age" field.
|
||||
func AgeNEQ(v int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldNEQ(FieldAge, v))
|
||||
}
|
||||
|
||||
// AgeIn applies the In predicate on the "age" field.
|
||||
func AgeIn(vs ...int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldIn(FieldAge, vs...))
|
||||
}
|
||||
|
||||
// AgeNotIn applies the NotIn predicate on the "age" field.
|
||||
func AgeNotIn(vs ...int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldNotIn(FieldAge, vs...))
|
||||
}
|
||||
|
||||
// AgeGT applies the GT predicate on the "age" field.
|
||||
func AgeGT(v int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldGT(FieldAge, v))
|
||||
}
|
||||
|
||||
// AgeGTE applies the GTE predicate on the "age" field.
|
||||
func AgeGTE(v int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldGTE(FieldAge, v))
|
||||
}
|
||||
|
||||
// AgeLT applies the LT predicate on the "age" field.
|
||||
func AgeLT(v int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldLT(FieldAge, v))
|
||||
}
|
||||
|
||||
// AgeLTE applies the LTE predicate on the "age" field.
|
||||
func AgeLTE(v int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldLTE(FieldAge, v))
|
||||
}
|
||||
|
||||
// ParentIDEQ applies the EQ predicate on the "parent_id" field.
|
||||
func ParentIDEQ(v int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldEQ(FieldParentID, v))
|
||||
}
|
||||
|
||||
// ParentIDNEQ applies the NEQ predicate on the "parent_id" field.
|
||||
func ParentIDNEQ(v int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldNEQ(FieldParentID, v))
|
||||
}
|
||||
|
||||
// ParentIDIn applies the In predicate on the "parent_id" field.
|
||||
func ParentIDIn(vs ...int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldIn(FieldParentID, vs...))
|
||||
}
|
||||
|
||||
// ParentIDNotIn applies the NotIn predicate on the "parent_id" field.
|
||||
func ParentIDNotIn(vs ...int) predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldNotIn(FieldParentID, vs...))
|
||||
}
|
||||
|
||||
// ParentIDIsNil applies the IsNil predicate on the "parent_id" field.
|
||||
func ParentIDIsNil() predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldIsNull(FieldParentID))
|
||||
}
|
||||
|
||||
// ParentIDNotNil applies the NotNil predicate on the "parent_id" field.
|
||||
func ParentIDNotNil() predicate.Metadata {
|
||||
return predicate.Metadata(sql.FieldNotNull(FieldParentID))
|
||||
}
|
||||
|
||||
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||
func HasUser() predicate.Metadata {
|
||||
return predicate.Metadata(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, UserTable, UserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||
func HasUserWith(preds ...predicate.User) predicate.Metadata {
|
||||
return predicate.Metadata(func(s *sql.Selector) {
|
||||
step := newUserStep()
|
||||
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.Metadata {
|
||||
return predicate.Metadata(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, 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.Metadata) predicate.Metadata {
|
||||
return predicate.Metadata(func(s *sql.Selector) {
|
||||
step := newChildrenStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasParent applies the HasEdge predicate on the "parent" edge.
|
||||
func HasParent() predicate.Metadata {
|
||||
return predicate.Metadata(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, 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.Metadata) predicate.Metadata {
|
||||
return predicate.Metadata(func(s *sql.Selector) {
|
||||
step := newParentStep()
|
||||
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.Metadata) predicate.Metadata {
|
||||
return predicate.Metadata(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Metadata) predicate.Metadata {
|
||||
return predicate.Metadata(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Metadata) predicate.Metadata {
|
||||
return predicate.Metadata(sql.NotPredicates(p))
|
||||
}
|
||||
321
entc/integration/edgefield/ent/metadata_create.go
Normal file
321
entc/integration/edgefield/ent/metadata_create.go
Normal file
@@ -0,0 +1,321 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/metadata"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// MetadataCreate is the builder for creating a Metadata entity.
|
||||
type MetadataCreate struct {
|
||||
config
|
||||
mutation *MetadataMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetAge sets the "age" field.
|
||||
func (_c *MetadataCreate) SetAge(v int) *MetadataCreate {
|
||||
_c.mutation.SetAge(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableAge sets the "age" field if the given value is not nil.
|
||||
func (_c *MetadataCreate) SetNillableAge(v *int) *MetadataCreate {
|
||||
if v != nil {
|
||||
_c.SetAge(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetParentID sets the "parent_id" field.
|
||||
func (_c *MetadataCreate) SetParentID(v int) *MetadataCreate {
|
||||
_c.mutation.SetParentID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableParentID sets the "parent_id" field if the given value is not nil.
|
||||
func (_c *MetadataCreate) SetNillableParentID(v *int) *MetadataCreate {
|
||||
if v != nil {
|
||||
_c.SetParentID(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *MetadataCreate) SetID(v int) *MetadataCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUserID sets the "user" edge to the User entity by ID.
|
||||
func (_c *MetadataCreate) SetUserID(id int) *MetadataCreate {
|
||||
_c.mutation.SetUserID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
|
||||
func (_c *MetadataCreate) SetNillableUserID(id *int) *MetadataCreate {
|
||||
if id != nil {
|
||||
_c = _c.SetUserID(*id)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (_c *MetadataCreate) SetUser(v *User) *MetadataCreate {
|
||||
return _c.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// AddChildIDs adds the "children" edge to the Metadata entity by IDs.
|
||||
func (_c *MetadataCreate) AddChildIDs(ids ...int) *MetadataCreate {
|
||||
_c.mutation.AddChildIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddChildren adds the "children" edges to the Metadata entity.
|
||||
func (_c *MetadataCreate) AddChildren(v ...*Metadata) *MetadataCreate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddChildIDs(ids...)
|
||||
}
|
||||
|
||||
// SetParent sets the "parent" edge to the Metadata entity.
|
||||
func (_c *MetadataCreate) SetParent(v *Metadata) *MetadataCreate {
|
||||
return _c.SetParentID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the MetadataMutation object of the builder.
|
||||
func (_c *MetadataCreate) Mutation() *MetadataMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Metadata in the database.
|
||||
func (_c *MetadataCreate) Save(ctx context.Context) (*Metadata, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *MetadataCreate) SaveX(ctx context.Context) *Metadata {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *MetadataCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *MetadataCreate) 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 *MetadataCreate) defaults() {
|
||||
if _, ok := _c.mutation.Age(); !ok {
|
||||
v := metadata.DefaultAge
|
||||
_c.mutation.SetAge(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *MetadataCreate) check() error {
|
||||
if _, ok := _c.mutation.Age(); !ok {
|
||||
return &ValidationError{Name: "age", err: errors.New(`ent: missing required field "Metadata.age"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *MetadataCreate) sqlSave(ctx context.Context) (*Metadata, 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 *MetadataCreate) createSpec() (*Metadata, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Metadata{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(metadata.Table, sqlgraph.NewFieldSpec(metadata.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(metadata.FieldAge, field.TypeInt, value)
|
||||
_node.Age = value
|
||||
}
|
||||
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: metadata.UserTable,
|
||||
Columns: []string{metadata.UserColumn},
|
||||
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.ID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.ChildrenIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: metadata.ChildrenTable,
|
||||
Columns: []string{metadata.ChildrenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(metadata.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.ParentIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: metadata.ParentTable,
|
||||
Columns: []string{metadata.ParentColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.ParentID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// MetadataCreateBulk is the builder for creating many Metadata entities in bulk.
|
||||
type MetadataCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*MetadataCreate
|
||||
}
|
||||
|
||||
// Save creates the Metadata entities in the database.
|
||||
func (_c *MetadataCreateBulk) Save(ctx context.Context) ([]*Metadata, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Metadata, 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.(*MetadataMutation)
|
||||
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 *MetadataCreateBulk) SaveX(ctx context.Context) []*Metadata {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *MetadataCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *MetadataCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/edgefield/ent/metadata_delete.go
Normal file
92
entc/integration/edgefield/ent/metadata_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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/metadata"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// MetadataDelete is the builder for deleting a Metadata entity.
|
||||
type MetadataDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *MetadataMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the MetadataDelete builder.
|
||||
func (_d *MetadataDelete) Where(ps ...predicate.Metadata) *MetadataDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *MetadataDelete) 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 *MetadataDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *MetadataDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(metadata.Table, sqlgraph.NewFieldSpec(metadata.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
|
||||
}
|
||||
|
||||
// MetadataDeleteOne is the builder for deleting a single Metadata entity.
|
||||
type MetadataDeleteOne struct {
|
||||
_d *MetadataDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the MetadataDelete builder.
|
||||
func (_d *MetadataDeleteOne) Where(ps ...predicate.Metadata) *MetadataDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *MetadataDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{metadata.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *MetadataDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
777
entc/integration/edgefield/ent/metadata_query.go
Normal file
777
entc/integration/edgefield/ent/metadata_query.go
Normal file
@@ -0,0 +1,777 @@
|
||||
// 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 ent
|
||||
|
||||
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/edgefield/ent/metadata"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// MetadataQuery is the builder for querying Metadata entities.
|
||||
type MetadataQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []metadata.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Metadata
|
||||
withUser *UserQuery
|
||||
withChildren *MetadataQuery
|
||||
withParent *MetadataQuery
|
||||
withNamedChildren map[string]*MetadataQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the MetadataQuery builder.
|
||||
func (_q *MetadataQuery) Where(ps ...predicate.Metadata) *MetadataQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *MetadataQuery) Limit(limit int) *MetadataQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *MetadataQuery) Offset(offset int) *MetadataQuery {
|
||||
_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 *MetadataQuery) Unique(unique bool) *MetadataQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *MetadataQuery) Order(o ...metadata.OrderOption) *MetadataQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryUser chains the current query on the "user" edge.
|
||||
func (_q *MetadataQuery) QueryUser() *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(metadata.Table, metadata.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, metadata.UserTable, metadata.UserColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryChildren chains the current query on the "children" edge.
|
||||
func (_q *MetadataQuery) QueryChildren() *MetadataQuery {
|
||||
query := (&MetadataClient{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(metadata.Table, metadata.FieldID, selector),
|
||||
sqlgraph.To(metadata.Table, metadata.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, metadata.ChildrenTable, metadata.ChildrenColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryParent chains the current query on the "parent" edge.
|
||||
func (_q *MetadataQuery) QueryParent() *MetadataQuery {
|
||||
query := (&MetadataClient{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(metadata.Table, metadata.FieldID, selector),
|
||||
sqlgraph.To(metadata.Table, metadata.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, metadata.ParentTable, metadata.ParentColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Metadata entity from the query.
|
||||
// Returns a *NotFoundError when no Metadata was found.
|
||||
func (_q *MetadataQuery) First(ctx context.Context) (*Metadata, 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{metadata.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *MetadataQuery) FirstX(ctx context.Context) *Metadata {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Metadata ID from the query.
|
||||
// Returns a *NotFoundError when no Metadata ID was found.
|
||||
func (_q *MetadataQuery) 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{metadata.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *MetadataQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Metadata entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Metadata entity is found.
|
||||
// Returns a *NotFoundError when no Metadata entities are found.
|
||||
func (_q *MetadataQuery) Only(ctx context.Context) (*Metadata, 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{metadata.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{metadata.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *MetadataQuery) OnlyX(ctx context.Context) *Metadata {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Metadata ID in the query.
|
||||
// Returns a *NotSingularError when more than one Metadata ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *MetadataQuery) 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{metadata.Label}
|
||||
default:
|
||||
err = &NotSingularError{metadata.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *MetadataQuery) 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 MetadataSlice.
|
||||
func (_q *MetadataQuery) All(ctx context.Context) ([]*Metadata, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Metadata, *MetadataQuery]()
|
||||
return withInterceptors[[]*Metadata](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *MetadataQuery) AllX(ctx context.Context) []*Metadata {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Metadata IDs.
|
||||
func (_q *MetadataQuery) 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(metadata.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *MetadataQuery) 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 *MetadataQuery) 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[*MetadataQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *MetadataQuery) 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 *MetadataQuery) 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("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *MetadataQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the MetadataQuery 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 *MetadataQuery) Clone() *MetadataQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &MetadataQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]metadata.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Metadata{}, _q.predicates...),
|
||||
withUser: _q.withUser.Clone(),
|
||||
withChildren: _q.withChildren.Clone(),
|
||||
withParent: _q.withParent.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *MetadataQuery) WithUser(opts ...func(*UserQuery)) *MetadataQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withUser = 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 *MetadataQuery) WithChildren(opts ...func(*MetadataQuery)) *MetadataQuery {
|
||||
query := (&MetadataClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withChildren = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// 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 *MetadataQuery) WithParent(opts ...func(*MetadataQuery)) *MetadataQuery {
|
||||
query := (&MetadataClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withParent = 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 int `json:"age,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Metadata.Query().
|
||||
// GroupBy(metadata.FieldAge).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *MetadataQuery) GroupBy(field string, fields ...string) *MetadataGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &MetadataGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = metadata.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 int `json:"age,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Metadata.Query().
|
||||
// Select(metadata.FieldAge).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *MetadataQuery) Select(fields ...string) *MetadataSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &MetadataSelect{MetadataQuery: _q}
|
||||
sbuild.label = metadata.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a MetadataSelect configured with the given aggregations.
|
||||
func (_q *MetadataQuery) Aggregate(fns ...AggregateFunc) *MetadataSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *MetadataQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !metadata.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: 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 *MetadataQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Metadata, error) {
|
||||
var (
|
||||
nodes = []*Metadata{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [3]bool{
|
||||
_q.withUser != nil,
|
||||
_q.withChildren != nil,
|
||||
_q.withParent != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Metadata).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Metadata{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.withUser; query != nil {
|
||||
if err := _q.loadUser(ctx, query, nodes, nil,
|
||||
func(n *Metadata, e *User) { n.Edges.User = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withChildren; query != nil {
|
||||
if err := _q.loadChildren(ctx, query, nodes,
|
||||
func(n *Metadata) { n.Edges.Children = []*Metadata{} },
|
||||
func(n *Metadata, e *Metadata) { n.Edges.Children = append(n.Edges.Children, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withParent; query != nil {
|
||||
if err := _q.loadParent(ctx, query, nodes, nil,
|
||||
func(n *Metadata, e *Metadata) { n.Edges.Parent = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
for name, query := range _q.withNamedChildren {
|
||||
if err := _q.loadChildren(ctx, query, nodes,
|
||||
func(n *Metadata) { n.appendNamedChildren(name) },
|
||||
func(n *Metadata, e *Metadata) { n.appendNamedChildren(name, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *MetadataQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*Metadata, init func(*Metadata), assign func(*Metadata, *User)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Metadata)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].ID
|
||||
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 "id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *MetadataQuery) loadChildren(ctx context.Context, query *MetadataQuery, nodes []*Metadata, init func(*Metadata), assign func(*Metadata, *Metadata)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*Metadata)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
if len(query.ctx.Fields) > 0 {
|
||||
query.ctx.AppendFieldOnce(metadata.FieldParentID)
|
||||
}
|
||||
query.Where(predicate.Metadata(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(metadata.ChildrenColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.ParentID
|
||||
node, ok := nodeids[fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "parent_id" returned %v for node %v`, fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *MetadataQuery) loadParent(ctx context.Context, query *MetadataQuery, nodes []*Metadata, init func(*Metadata), assign func(*Metadata, *Metadata)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Metadata)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].ParentID
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(metadata.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 "parent_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *MetadataQuery) 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 *MetadataQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(metadata.Table, metadata.Columns, sqlgraph.NewFieldSpec(metadata.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, metadata.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != metadata.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
if _q.withParent != nil {
|
||||
_spec.Node.AddColumnOnce(metadata.FieldParentID)
|
||||
}
|
||||
}
|
||||
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 *MetadataQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(metadata.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = metadata.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
|
||||
}
|
||||
|
||||
// WithNamedChildren tells the query-builder to eager-load the nodes that are connected to the "children"
|
||||
// edge with the given name. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *MetadataQuery) WithNamedChildren(name string, opts ...func(*MetadataQuery)) *MetadataQuery {
|
||||
query := (&MetadataClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
if _q.withNamedChildren == nil {
|
||||
_q.withNamedChildren = make(map[string]*MetadataQuery)
|
||||
}
|
||||
_q.withNamedChildren[name] = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// MetadataGroupBy is the group-by builder for Metadata entities.
|
||||
type MetadataGroupBy struct {
|
||||
selector
|
||||
build *MetadataQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *MetadataGroupBy) Aggregate(fns ...AggregateFunc) *MetadataGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *MetadataGroupBy) 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[*MetadataQuery, *MetadataGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *MetadataGroupBy) sqlScan(ctx context.Context, root *MetadataQuery, 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)
|
||||
}
|
||||
|
||||
// MetadataSelect is the builder for selecting fields of Metadata entities.
|
||||
type MetadataSelect struct {
|
||||
*MetadataQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *MetadataSelect) Aggregate(fns ...AggregateFunc) *MetadataSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *MetadataSelect) 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[*MetadataQuery, *MetadataSelect](ctx, _s.MetadataQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *MetadataSelect) sqlScan(ctx context.Context, root *MetadataQuery, 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)
|
||||
}
|
||||
624
entc/integration/edgefield/ent/metadata_update.go
Normal file
624
entc/integration/edgefield/ent/metadata_update.go
Normal file
@@ -0,0 +1,624 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/metadata"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// MetadataUpdate is the builder for updating Metadata entities.
|
||||
type MetadataUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *MetadataMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the MetadataUpdate builder.
|
||||
func (_u *MetadataUpdate) Where(ps ...predicate.Metadata) *MetadataUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAge sets the "age" field.
|
||||
func (_u *MetadataUpdate) SetAge(v int) *MetadataUpdate {
|
||||
_u.mutation.ResetAge()
|
||||
_u.mutation.SetAge(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAge sets the "age" field if the given value is not nil.
|
||||
func (_u *MetadataUpdate) SetNillableAge(v *int) *MetadataUpdate {
|
||||
if v != nil {
|
||||
_u.SetAge(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddAge adds value to the "age" field.
|
||||
func (_u *MetadataUpdate) AddAge(v int) *MetadataUpdate {
|
||||
_u.mutation.AddAge(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetParentID sets the "parent_id" field.
|
||||
func (_u *MetadataUpdate) SetParentID(v int) *MetadataUpdate {
|
||||
_u.mutation.SetParentID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableParentID sets the "parent_id" field if the given value is not nil.
|
||||
func (_u *MetadataUpdate) SetNillableParentID(v *int) *MetadataUpdate {
|
||||
if v != nil {
|
||||
_u.SetParentID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearParentID clears the value of the "parent_id" field.
|
||||
func (_u *MetadataUpdate) ClearParentID() *MetadataUpdate {
|
||||
_u.mutation.ClearParentID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user" edge to the User entity by ID.
|
||||
func (_u *MetadataUpdate) SetUserID(id int) *MetadataUpdate {
|
||||
_u.mutation.SetUserID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
|
||||
func (_u *MetadataUpdate) SetNillableUserID(id *int) *MetadataUpdate {
|
||||
if id != nil {
|
||||
_u = _u.SetUserID(*id)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (_u *MetadataUpdate) SetUser(v *User) *MetadataUpdate {
|
||||
return _u.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// AddChildIDs adds the "children" edge to the Metadata entity by IDs.
|
||||
func (_u *MetadataUpdate) AddChildIDs(ids ...int) *MetadataUpdate {
|
||||
_u.mutation.AddChildIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddChildren adds the "children" edges to the Metadata entity.
|
||||
func (_u *MetadataUpdate) AddChildren(v ...*Metadata) *MetadataUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddChildIDs(ids...)
|
||||
}
|
||||
|
||||
// SetParent sets the "parent" edge to the Metadata entity.
|
||||
func (_u *MetadataUpdate) SetParent(v *Metadata) *MetadataUpdate {
|
||||
return _u.SetParentID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the MetadataMutation object of the builder.
|
||||
func (_u *MetadataUpdate) Mutation() *MetadataMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (_u *MetadataUpdate) ClearUser() *MetadataUpdate {
|
||||
_u.mutation.ClearUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearChildren clears all "children" edges to the Metadata entity.
|
||||
func (_u *MetadataUpdate) ClearChildren() *MetadataUpdate {
|
||||
_u.mutation.ClearChildren()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveChildIDs removes the "children" edge to Metadata entities by IDs.
|
||||
func (_u *MetadataUpdate) RemoveChildIDs(ids ...int) *MetadataUpdate {
|
||||
_u.mutation.RemoveChildIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveChildren removes "children" edges to Metadata entities.
|
||||
func (_u *MetadataUpdate) RemoveChildren(v ...*Metadata) *MetadataUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveChildIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearParent clears the "parent" edge to the Metadata entity.
|
||||
func (_u *MetadataUpdate) ClearParent() *MetadataUpdate {
|
||||
_u.mutation.ClearParent()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *MetadataUpdate) 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 *MetadataUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *MetadataUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *MetadataUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *MetadataUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(metadata.Table, metadata.Columns, sqlgraph.NewFieldSpec(metadata.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.Age(); ok {
|
||||
_spec.SetField(metadata.FieldAge, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedAge(); ok {
|
||||
_spec.AddField(metadata.FieldAge, field.TypeInt, value)
|
||||
}
|
||||
if _u.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: metadata.UserTable,
|
||||
Columns: []string{metadata.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: metadata.UserTable,
|
||||
Columns: []string{metadata.UserColumn},
|
||||
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 _u.mutation.ChildrenCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: metadata.ChildrenTable,
|
||||
Columns: []string{metadata.ChildrenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: metadata.ChildrenTable,
|
||||
Columns: []string{metadata.ChildrenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.ChildrenIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: metadata.ChildrenTable,
|
||||
Columns: []string{metadata.ChildrenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.ParentCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: metadata.ParentTable,
|
||||
Columns: []string{metadata.ParentColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: metadata.ParentTable,
|
||||
Columns: []string{metadata.ParentColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(metadata.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{metadata.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// MetadataUpdateOne is the builder for updating a single Metadata entity.
|
||||
type MetadataUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *MetadataMutation
|
||||
}
|
||||
|
||||
// SetAge sets the "age" field.
|
||||
func (_u *MetadataUpdateOne) SetAge(v int) *MetadataUpdateOne {
|
||||
_u.mutation.ResetAge()
|
||||
_u.mutation.SetAge(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAge sets the "age" field if the given value is not nil.
|
||||
func (_u *MetadataUpdateOne) SetNillableAge(v *int) *MetadataUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetAge(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddAge adds value to the "age" field.
|
||||
func (_u *MetadataUpdateOne) AddAge(v int) *MetadataUpdateOne {
|
||||
_u.mutation.AddAge(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetParentID sets the "parent_id" field.
|
||||
func (_u *MetadataUpdateOne) SetParentID(v int) *MetadataUpdateOne {
|
||||
_u.mutation.SetParentID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableParentID sets the "parent_id" field if the given value is not nil.
|
||||
func (_u *MetadataUpdateOne) SetNillableParentID(v *int) *MetadataUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetParentID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearParentID clears the value of the "parent_id" field.
|
||||
func (_u *MetadataUpdateOne) ClearParentID() *MetadataUpdateOne {
|
||||
_u.mutation.ClearParentID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user" edge to the User entity by ID.
|
||||
func (_u *MetadataUpdateOne) SetUserID(id int) *MetadataUpdateOne {
|
||||
_u.mutation.SetUserID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
|
||||
func (_u *MetadataUpdateOne) SetNillableUserID(id *int) *MetadataUpdateOne {
|
||||
if id != nil {
|
||||
_u = _u.SetUserID(*id)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (_u *MetadataUpdateOne) SetUser(v *User) *MetadataUpdateOne {
|
||||
return _u.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// AddChildIDs adds the "children" edge to the Metadata entity by IDs.
|
||||
func (_u *MetadataUpdateOne) AddChildIDs(ids ...int) *MetadataUpdateOne {
|
||||
_u.mutation.AddChildIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddChildren adds the "children" edges to the Metadata entity.
|
||||
func (_u *MetadataUpdateOne) AddChildren(v ...*Metadata) *MetadataUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddChildIDs(ids...)
|
||||
}
|
||||
|
||||
// SetParent sets the "parent" edge to the Metadata entity.
|
||||
func (_u *MetadataUpdateOne) SetParent(v *Metadata) *MetadataUpdateOne {
|
||||
return _u.SetParentID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the MetadataMutation object of the builder.
|
||||
func (_u *MetadataUpdateOne) Mutation() *MetadataMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (_u *MetadataUpdateOne) ClearUser() *MetadataUpdateOne {
|
||||
_u.mutation.ClearUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearChildren clears all "children" edges to the Metadata entity.
|
||||
func (_u *MetadataUpdateOne) ClearChildren() *MetadataUpdateOne {
|
||||
_u.mutation.ClearChildren()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveChildIDs removes the "children" edge to Metadata entities by IDs.
|
||||
func (_u *MetadataUpdateOne) RemoveChildIDs(ids ...int) *MetadataUpdateOne {
|
||||
_u.mutation.RemoveChildIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveChildren removes "children" edges to Metadata entities.
|
||||
func (_u *MetadataUpdateOne) RemoveChildren(v ...*Metadata) *MetadataUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveChildIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearParent clears the "parent" edge to the Metadata entity.
|
||||
func (_u *MetadataUpdateOne) ClearParent() *MetadataUpdateOne {
|
||||
_u.mutation.ClearParent()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the MetadataUpdate builder.
|
||||
func (_u *MetadataUpdateOne) Where(ps ...predicate.Metadata) *MetadataUpdateOne {
|
||||
_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 *MetadataUpdateOne) Select(field string, fields ...string) *MetadataUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Metadata entity.
|
||||
func (_u *MetadataUpdateOne) Save(ctx context.Context) (*Metadata, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *MetadataUpdateOne) SaveX(ctx context.Context) *Metadata {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *MetadataUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *MetadataUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *MetadataUpdateOne) sqlSave(ctx context.Context) (_node *Metadata, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(metadata.Table, metadata.Columns, sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Metadata.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, metadata.FieldID)
|
||||
for _, f := range fields {
|
||||
if !metadata.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != metadata.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.Age(); ok {
|
||||
_spec.SetField(metadata.FieldAge, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedAge(); ok {
|
||||
_spec.AddField(metadata.FieldAge, field.TypeInt, value)
|
||||
}
|
||||
if _u.mutation.UserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: metadata.UserTable,
|
||||
Columns: []string{metadata.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: metadata.UserTable,
|
||||
Columns: []string{metadata.UserColumn},
|
||||
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 _u.mutation.ChildrenCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: metadata.ChildrenTable,
|
||||
Columns: []string{metadata.ChildrenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedChildrenIDs(); len(nodes) > 0 && !_u.mutation.ChildrenCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: metadata.ChildrenTable,
|
||||
Columns: []string{metadata.ChildrenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.ChildrenIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: metadata.ChildrenTable,
|
||||
Columns: []string{metadata.ChildrenColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.ParentCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: metadata.ParentTable,
|
||||
Columns: []string{metadata.ParentColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.ParentIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: metadata.ParentTable,
|
||||
Columns: []string{metadata.ParentColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(metadata.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Metadata{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{metadata.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
68
entc/integration/edgefield/ent/migrate/migrate.go
Normal file
68
entc/integration/edgefield/ent/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...)
|
||||
}
|
||||
250
entc/integration/edgefield/ent/migrate/schema.go
Normal file
250
entc/integration/edgefield/ent/migrate/schema.go
Normal file
@@ -0,0 +1,250 @@
|
||||
// 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/sql/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
var (
|
||||
// CarsColumns holds the columns for the "cars" table.
|
||||
CarsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID},
|
||||
{Name: "number", Type: field.TypeString, Nullable: true},
|
||||
}
|
||||
// CarsTable holds the schema information for the "cars" table.
|
||||
CarsTable = &schema.Table{
|
||||
Name: "cars",
|
||||
Columns: CarsColumns,
|
||||
PrimaryKey: []*schema.Column{CarsColumns[0]},
|
||||
}
|
||||
// CardsColumns holds the columns for the "cards" table.
|
||||
CardsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "number", Type: field.TypeString, Nullable: true},
|
||||
{Name: "owner_id", Type: field.TypeInt, Unique: true, Nullable: true, SchemaType: map[string]string{"sqlite3": "integer"}},
|
||||
}
|
||||
// CardsTable holds the schema information for the "cards" table.
|
||||
CardsTable = &schema.Table{
|
||||
Name: "cards",
|
||||
Columns: CardsColumns,
|
||||
PrimaryKey: []*schema.Column{CardsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "cards_users_card",
|
||||
Columns: []*schema.Column{CardsColumns[2]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "card_number_owner_id",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{CardsColumns[1], CardsColumns[2]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// InfosColumns holds the columns for the "infos" table.
|
||||
InfosColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "content", Type: field.TypeJSON},
|
||||
}
|
||||
// InfosTable holds the schema information for the "infos" table.
|
||||
InfosTable = &schema.Table{
|
||||
Name: "infos",
|
||||
Columns: InfosColumns,
|
||||
PrimaryKey: []*schema.Column{InfosColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "infos_users_user",
|
||||
Columns: []*schema.Column{InfosColumns[0]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
},
|
||||
}
|
||||
// MetadataColumns holds the columns for the "metadata" table.
|
||||
MetadataColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "age", Type: field.TypeInt, Default: 0},
|
||||
{Name: "parent_id", Type: field.TypeInt, Nullable: true},
|
||||
}
|
||||
// MetadataTable holds the schema information for the "metadata" table.
|
||||
MetadataTable = &schema.Table{
|
||||
Name: "metadata",
|
||||
Columns: MetadataColumns,
|
||||
PrimaryKey: []*schema.Column{MetadataColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "metadata_metadata_parent",
|
||||
Columns: []*schema.Column{MetadataColumns[2]},
|
||||
RefColumns: []*schema.Column{MetadataColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "metadata_users_metadata",
|
||||
Columns: []*schema.Column{MetadataColumns[0]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
},
|
||||
}
|
||||
// NodesColumns holds the columns for the "nodes" table.
|
||||
NodesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "value", Type: field.TypeInt, Default: 0},
|
||||
{Name: "prev_id", Type: field.TypeInt, Unique: true, Nullable: true},
|
||||
}
|
||||
// NodesTable holds the schema information for the "nodes" table.
|
||||
NodesTable = &schema.Table{
|
||||
Name: "nodes",
|
||||
Columns: NodesColumns,
|
||||
PrimaryKey: []*schema.Column{NodesColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "nodes_nodes_next",
|
||||
Columns: []*schema.Column{NodesColumns[2]},
|
||||
RefColumns: []*schema.Column{NodesColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
}
|
||||
// PetsColumns holds the columns for the "pets" table.
|
||||
PetsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "owner_id", Type: field.TypeInt, Nullable: true, SchemaType: map[string]string{"sqlite3": "integer"}},
|
||||
}
|
||||
// PetsTable holds the schema information for the "pets" table.
|
||||
PetsTable = &schema.Table{
|
||||
Name: "pets",
|
||||
Columns: PetsColumns,
|
||||
PrimaryKey: []*schema.Column{PetsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "pets_users_pets",
|
||||
Columns: []*schema.Column{PetsColumns[1]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
}
|
||||
// PostsColumns holds the columns for the "posts" table.
|
||||
PostsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "text", Type: field.TypeString},
|
||||
{Name: "author_id", Type: field.TypeInt, Nullable: true, SchemaType: map[string]string{"sqlite3": "integer"}},
|
||||
}
|
||||
// PostsTable holds the schema information for the "posts" table.
|
||||
PostsTable = &schema.Table{
|
||||
Name: "posts",
|
||||
Columns: PostsColumns,
|
||||
PrimaryKey: []*schema.Column{PostsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "posts_users_author",
|
||||
Columns: []*schema.Column{PostsColumns[2]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "post_author_id_text",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{PostsColumns[2], PostsColumns[1]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// RentalsColumns holds the columns for the "rentals" table.
|
||||
RentalsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "date", Type: field.TypeTime},
|
||||
{Name: "car_id", Type: field.TypeUUID},
|
||||
{Name: "user_id", Type: field.TypeInt, SchemaType: map[string]string{"sqlite3": "integer"}},
|
||||
}
|
||||
// RentalsTable holds the schema information for the "rentals" table.
|
||||
RentalsTable = &schema.Table{
|
||||
Name: "rentals",
|
||||
Columns: RentalsColumns,
|
||||
PrimaryKey: []*schema.Column{RentalsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "rentals_cars_rentals",
|
||||
Columns: []*schema.Column{RentalsColumns[2]},
|
||||
RefColumns: []*schema.Column{CarsColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
{
|
||||
Symbol: "rentals_users_rentals",
|
||||
Columns: []*schema.Column{RentalsColumns[3]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "rental_car_id_user_id",
|
||||
Unique: true,
|
||||
Columns: []*schema.Column{RentalsColumns[2], RentalsColumns[3]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// UsersColumns holds the columns for the "users" table.
|
||||
UsersColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true, SchemaType: map[string]string{"sqlite3": "integer"}},
|
||||
{Name: "parent_id", Type: field.TypeInt, Nullable: true, SchemaType: map[string]string{"sqlite3": "integer"}},
|
||||
{Name: "spouse_id", Type: field.TypeInt, Unique: true, Nullable: true, SchemaType: map[string]string{"sqlite3": "integer"}},
|
||||
}
|
||||
// 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[1]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "users_users_spouse",
|
||||
Columns: []*schema.Column{UsersColumns[2]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
CarsTable,
|
||||
CardsTable,
|
||||
InfosTable,
|
||||
MetadataTable,
|
||||
NodesTable,
|
||||
PetsTable,
|
||||
PostsTable,
|
||||
RentalsTable,
|
||||
UsersTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
CardsTable.ForeignKeys[0].RefTable = UsersTable
|
||||
InfosTable.ForeignKeys[0].RefTable = UsersTable
|
||||
MetadataTable.ForeignKeys[0].RefTable = MetadataTable
|
||||
MetadataTable.ForeignKeys[1].RefTable = UsersTable
|
||||
NodesTable.ForeignKeys[0].RefTable = NodesTable
|
||||
PetsTable.ForeignKeys[0].RefTable = UsersTable
|
||||
PostsTable.ForeignKeys[0].RefTable = UsersTable
|
||||
RentalsTable.ForeignKeys[0].RefTable = CarsTable
|
||||
RentalsTable.ForeignKeys[1].RefTable = UsersTable
|
||||
UsersTable.ForeignKeys[0].RefTable = UsersTable
|
||||
UsersTable.ForeignKeys[1].RefTable = UsersTable
|
||||
}
|
||||
1402
entc/integration/edgefield/ent/mutation.go
Normal file
1402
entc/integration/edgefield/ent/mutation.go
Normal file
File diff suppressed because it is too large
Load Diff
162
entc/integration/edgefield/ent/node.go
Normal file
162
entc/integration/edgefield/ent/node.go
Normal file
@@ -0,0 +1,162 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/node"
|
||||
)
|
||||
|
||||
// Node is the model entity for the Node schema.
|
||||
type Node struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Value holds the value of the "value" field.
|
||||
Value int `json:"value,omitempty"`
|
||||
// PrevID holds the value of the "prev_id" field.
|
||||
PrevID int `json:"prev_id,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the NodeQuery when eager-loading is set.
|
||||
Edges NodeEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// NodeEdges holds the relations/edges for other nodes in the graph.
|
||||
type NodeEdges struct {
|
||||
// Prev holds the value of the prev edge.
|
||||
Prev *Node `json:"prev,omitempty"`
|
||||
// Next holds the value of the next edge.
|
||||
Next *Node `json:"next,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [2]bool
|
||||
}
|
||||
|
||||
// PrevOrErr returns the Prev value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e NodeEdges) PrevOrErr() (*Node, error) {
|
||||
if e.Prev != nil {
|
||||
return e.Prev, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: node.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "prev"}
|
||||
}
|
||||
|
||||
// NextOrErr returns the Next value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e NodeEdges) NextOrErr() (*Node, error) {
|
||||
if e.Next != nil {
|
||||
return e.Next, nil
|
||||
} else if e.loadedTypes[1] {
|
||||
return nil, &NotFoundError{label: node.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "next"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Node) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case node.FieldID, node.FieldValue, node.FieldPrevID:
|
||||
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 Node fields.
|
||||
func (_m *Node) 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 node.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 node.FieldValue:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field value", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Value = int(value.Int64)
|
||||
}
|
||||
case node.FieldPrevID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field prev_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.PrevID = int(value.Int64)
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns the ent.Value that was dynamically selected and assigned to the Node.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Node) GetValue(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryPrev queries the "prev" edge of the Node entity.
|
||||
func (_m *Node) QueryPrev() *NodeQuery {
|
||||
return NewNodeClient(_m.config).QueryPrev(_m)
|
||||
}
|
||||
|
||||
// QueryNext queries the "next" edge of the Node entity.
|
||||
func (_m *Node) QueryNext() *NodeQuery {
|
||||
return NewNodeClient(_m.config).QueryNext(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Node.
|
||||
// Note that you need to call Node.Unwrap() before calling this method if this Node
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Node) Update() *NodeUpdateOne {
|
||||
return NewNodeClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Node 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 *Node) Unwrap() *Node {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Node is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Node) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Node(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("value=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Value))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("prev_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.PrevID))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Nodes is a parsable slice of Node.
|
||||
type Nodes []*Node
|
||||
439
entc/integration/edgefield/ent/node/mutation.go
Normal file
439
entc/integration/edgefield/ent/node/mutation.go
Normal file
@@ -0,0 +1,439 @@
|
||||
// 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 node
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Node nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
value *int
|
||||
addvalue *int
|
||||
clearedFields map[string]struct{}
|
||||
prev *int
|
||||
clearedprev bool
|
||||
next *int
|
||||
clearednext bool
|
||||
predicates []predicate.Node
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Node entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Node",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Node {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (m *Mutation) SetValue(i int) {
|
||||
m.value = &i
|
||||
m.addvalue = nil
|
||||
}
|
||||
|
||||
// Value returns the value of the "value" field in the mutation.
|
||||
func (m *Mutation) Value() (r int, exists bool) {
|
||||
v := m.value
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// AddValue adds i to the "value" field.
|
||||
func (m *Mutation) AddValue(i int) {
|
||||
if m.addvalue != nil {
|
||||
*m.addvalue += i
|
||||
} else {
|
||||
m.addvalue = &i
|
||||
}
|
||||
}
|
||||
|
||||
// AddedValue returns the value that was added to the "value" field in this mutation.
|
||||
func (m *Mutation) AddedValue() (r int, exists bool) {
|
||||
v := m.addvalue
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ResetValue resets all changes to the "value" field.
|
||||
func (m *Mutation) ResetValue() {
|
||||
m.value = nil
|
||||
m.addvalue = nil
|
||||
}
|
||||
|
||||
// SetPrevID sets the "prev_id" field.
|
||||
func (m *Mutation) SetPrevID(i int) {
|
||||
m.prev = &i
|
||||
}
|
||||
|
||||
// PrevID returns the value of the "prev_id" field in the mutation.
|
||||
func (m *Mutation) PrevID() (r int, exists bool) {
|
||||
v := m.prev
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearPrevID clears the value of the "prev_id" field.
|
||||
func (m *Mutation) ClearPrevID() {
|
||||
m.prev = nil
|
||||
m.clearedFields[FieldPrevID] = struct{}{}
|
||||
}
|
||||
|
||||
// PrevIDCleared returns if the "prev_id" field was cleared in this mutation.
|
||||
func (m *Mutation) PrevIDCleared() bool {
|
||||
_, ok := m.clearedFields[FieldPrevID]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetPrevID resets all changes to the "prev_id" field.
|
||||
func (m *Mutation) ResetPrevID() {
|
||||
m.prev = nil
|
||||
delete(m.clearedFields, FieldPrevID)
|
||||
}
|
||||
|
||||
// ClearPrev clears the "prev" edge to the Node entity.
|
||||
func (m *Mutation) ClearPrev() {
|
||||
m.clearedprev = true
|
||||
m.clearedFields[FieldPrevID] = struct{}{}
|
||||
}
|
||||
|
||||
// PrevCleared reports if the "prev" edge to the Node entity was cleared.
|
||||
func (m *Mutation) PrevCleared() bool {
|
||||
return m.PrevIDCleared() || m.clearedprev
|
||||
}
|
||||
|
||||
// PrevIDs returns the "prev" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// PrevID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) PrevIDs() (ids []int) {
|
||||
if id := m.prev; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetPrev resets all changes to the "prev" edge.
|
||||
func (m *Mutation) ResetPrev() {
|
||||
m.prev = nil
|
||||
m.clearedprev = false
|
||||
}
|
||||
|
||||
// SetNextID sets the "next" edge to the Node entity by id.
|
||||
func (m *Mutation) SetNextID(id int) {
|
||||
m.next = &id
|
||||
}
|
||||
|
||||
// ClearNext clears the "next" edge to the Node entity.
|
||||
func (m *Mutation) ClearNext() {
|
||||
m.clearednext = true
|
||||
}
|
||||
|
||||
// NextCleared reports if the "next" edge to the Node entity was cleared.
|
||||
func (m *Mutation) NextCleared() bool {
|
||||
return m.clearednext
|
||||
}
|
||||
|
||||
// NextID returns the "next" edge ID in the mutation.
|
||||
func (m *Mutation) NextID() (id int, exists bool) {
|
||||
if m.next != nil {
|
||||
return *m.next, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// NextIDs returns the "next" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// NextID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) NextIDs() (ids []int) {
|
||||
if id := m.next; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetNext resets all changes to the "next" edge.
|
||||
func (m *Mutation) ResetNext() {
|
||||
m.next = nil
|
||||
m.clearednext = false
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.Node) {
|
||||
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.Node, 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 (Node).
|
||||
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, 2)
|
||||
if m.value != nil {
|
||||
fields = append(fields, FieldValue)
|
||||
}
|
||||
if m.prev != nil {
|
||||
fields = append(fields, FieldPrevID)
|
||||
}
|
||||
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 FieldValue:
|
||||
return m.Value()
|
||||
case FieldPrevID:
|
||||
return m.PrevID()
|
||||
}
|
||||
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 Node 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 FieldValue:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetValue(v)
|
||||
return nil
|
||||
case FieldPrevID:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetPrevID(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Node 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.addvalue != nil {
|
||||
fields = append(fields, FieldValue)
|
||||
}
|
||||
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 FieldValue:
|
||||
return m.AddedValue()
|
||||
}
|
||||
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 FieldValue:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.AddValue(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Node 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(FieldPrevID) {
|
||||
fields = append(fields, FieldPrevID)
|
||||
}
|
||||
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 FieldPrevID:
|
||||
m.ClearPrevID()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Node 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 FieldValue:
|
||||
m.ResetValue()
|
||||
return nil
|
||||
case FieldPrevID:
|
||||
m.ResetPrevID()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Node field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *Mutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 2)
|
||||
if m.prev != nil {
|
||||
edges = append(edges, EdgePrev)
|
||||
}
|
||||
if m.next != nil {
|
||||
edges = append(edges, EdgeNext)
|
||||
}
|
||||
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 EdgePrev:
|
||||
if id := m.prev; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
case EdgeNext:
|
||||
if id := m.next; 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, 2)
|
||||
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, 2)
|
||||
if m.clearedprev {
|
||||
edges = append(edges, EdgePrev)
|
||||
}
|
||||
if m.clearednext {
|
||||
edges = append(edges, EdgeNext)
|
||||
}
|
||||
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 EdgePrev:
|
||||
return m.clearedprev
|
||||
case EdgeNext:
|
||||
return m.clearednext
|
||||
}
|
||||
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 EdgePrev:
|
||||
m.ClearPrev()
|
||||
return nil
|
||||
case EdgeNext:
|
||||
m.ClearNext()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Node 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 EdgePrev:
|
||||
m.ResetPrev()
|
||||
return nil
|
||||
case EdgeNext:
|
||||
m.ResetNext()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Node edge %s", name)
|
||||
}
|
||||
105
entc/integration/edgefield/ent/node/node.go
Normal file
105
entc/integration/edgefield/ent/node/node.go
Normal file
@@ -0,0 +1,105 @@
|
||||
// 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 node
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the node type in the database.
|
||||
Label = "node"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldValue holds the string denoting the value field in the database.
|
||||
FieldValue = "value"
|
||||
// FieldPrevID holds the string denoting the prev_id field in the database.
|
||||
FieldPrevID = "prev_id"
|
||||
// EdgePrev holds the string denoting the prev edge name in mutations.
|
||||
EdgePrev = "prev"
|
||||
// EdgeNext holds the string denoting the next edge name in mutations.
|
||||
EdgeNext = "next"
|
||||
// Table holds the table name of the node in the database.
|
||||
Table = "nodes"
|
||||
// PrevTable is the table that holds the prev relation/edge.
|
||||
PrevTable = "nodes"
|
||||
// PrevColumn is the table column denoting the prev relation/edge.
|
||||
PrevColumn = "prev_id"
|
||||
// NextTable is the table that holds the next relation/edge.
|
||||
NextTable = "nodes"
|
||||
// NextColumn is the table column denoting the next relation/edge.
|
||||
NextColumn = "prev_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for node fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldValue,
|
||||
FieldPrevID,
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultValue holds the default value on creation for the "value" field.
|
||||
DefaultValue int
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the Node 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()
|
||||
}
|
||||
|
||||
// ByValue orders the results by the value field.
|
||||
func ByValue(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldValue, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByPrevID orders the results by the prev_id field.
|
||||
func ByPrevID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldPrevID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByPrevField orders the results by prev field.
|
||||
func ByPrevField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newPrevStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByNextField orders the results by next field.
|
||||
func ByNextField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newNextStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newPrevStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, PrevTable, PrevColumn),
|
||||
)
|
||||
}
|
||||
func newNextStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, NextTable, NextColumn),
|
||||
)
|
||||
}
|
||||
199
entc/integration/edgefield/ent/node/where.go
Normal file
199
entc/integration/edgefield/ent/node/where.go
Normal file
@@ -0,0 +1,199 @@
|
||||
// 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 node
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Node {
|
||||
return predicate.Node(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Node {
|
||||
return predicate.Node(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Node {
|
||||
return predicate.Node(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Node {
|
||||
return predicate.Node(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Node {
|
||||
return predicate.Node(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Node {
|
||||
return predicate.Node(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Node {
|
||||
return predicate.Node(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Node {
|
||||
return predicate.Node(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Node {
|
||||
return predicate.Node(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Value applies equality check predicate on the "value" field. It's identical to ValueEQ.
|
||||
func Value(v int) predicate.Node {
|
||||
return predicate.Node(sql.FieldEQ(FieldValue, v))
|
||||
}
|
||||
|
||||
// PrevID applies equality check predicate on the "prev_id" field. It's identical to PrevIDEQ.
|
||||
func PrevID(v int) predicate.Node {
|
||||
return predicate.Node(sql.FieldEQ(FieldPrevID, v))
|
||||
}
|
||||
|
||||
// ValueEQ applies the EQ predicate on the "value" field.
|
||||
func ValueEQ(v int) predicate.Node {
|
||||
return predicate.Node(sql.FieldEQ(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueNEQ applies the NEQ predicate on the "value" field.
|
||||
func ValueNEQ(v int) predicate.Node {
|
||||
return predicate.Node(sql.FieldNEQ(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueIn applies the In predicate on the "value" field.
|
||||
func ValueIn(vs ...int) predicate.Node {
|
||||
return predicate.Node(sql.FieldIn(FieldValue, vs...))
|
||||
}
|
||||
|
||||
// ValueNotIn applies the NotIn predicate on the "value" field.
|
||||
func ValueNotIn(vs ...int) predicate.Node {
|
||||
return predicate.Node(sql.FieldNotIn(FieldValue, vs...))
|
||||
}
|
||||
|
||||
// ValueGT applies the GT predicate on the "value" field.
|
||||
func ValueGT(v int) predicate.Node {
|
||||
return predicate.Node(sql.FieldGT(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueGTE applies the GTE predicate on the "value" field.
|
||||
func ValueGTE(v int) predicate.Node {
|
||||
return predicate.Node(sql.FieldGTE(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueLT applies the LT predicate on the "value" field.
|
||||
func ValueLT(v int) predicate.Node {
|
||||
return predicate.Node(sql.FieldLT(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueLTE applies the LTE predicate on the "value" field.
|
||||
func ValueLTE(v int) predicate.Node {
|
||||
return predicate.Node(sql.FieldLTE(FieldValue, v))
|
||||
}
|
||||
|
||||
// PrevIDEQ applies the EQ predicate on the "prev_id" field.
|
||||
func PrevIDEQ(v int) predicate.Node {
|
||||
return predicate.Node(sql.FieldEQ(FieldPrevID, v))
|
||||
}
|
||||
|
||||
// PrevIDNEQ applies the NEQ predicate on the "prev_id" field.
|
||||
func PrevIDNEQ(v int) predicate.Node {
|
||||
return predicate.Node(sql.FieldNEQ(FieldPrevID, v))
|
||||
}
|
||||
|
||||
// PrevIDIn applies the In predicate on the "prev_id" field.
|
||||
func PrevIDIn(vs ...int) predicate.Node {
|
||||
return predicate.Node(sql.FieldIn(FieldPrevID, vs...))
|
||||
}
|
||||
|
||||
// PrevIDNotIn applies the NotIn predicate on the "prev_id" field.
|
||||
func PrevIDNotIn(vs ...int) predicate.Node {
|
||||
return predicate.Node(sql.FieldNotIn(FieldPrevID, vs...))
|
||||
}
|
||||
|
||||
// PrevIDIsNil applies the IsNil predicate on the "prev_id" field.
|
||||
func PrevIDIsNil() predicate.Node {
|
||||
return predicate.Node(sql.FieldIsNull(FieldPrevID))
|
||||
}
|
||||
|
||||
// PrevIDNotNil applies the NotNil predicate on the "prev_id" field.
|
||||
func PrevIDNotNil() predicate.Node {
|
||||
return predicate.Node(sql.FieldNotNull(FieldPrevID))
|
||||
}
|
||||
|
||||
// HasPrev applies the HasEdge predicate on the "prev" edge.
|
||||
func HasPrev() predicate.Node {
|
||||
return predicate.Node(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, PrevTable, PrevColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasPrevWith applies the HasEdge predicate on the "prev" edge with a given conditions (other predicates).
|
||||
func HasPrevWith(preds ...predicate.Node) predicate.Node {
|
||||
return predicate.Node(func(s *sql.Selector) {
|
||||
step := newPrevStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasNext applies the HasEdge predicate on the "next" edge.
|
||||
func HasNext() predicate.Node {
|
||||
return predicate.Node(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, NextTable, NextColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasNextWith applies the HasEdge predicate on the "next" edge with a given conditions (other predicates).
|
||||
func HasNextWith(preds ...predicate.Node) predicate.Node {
|
||||
return predicate.Node(func(s *sql.Selector) {
|
||||
step := newNextStep()
|
||||
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.Node) predicate.Node {
|
||||
return predicate.Node(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Node) predicate.Node {
|
||||
return predicate.Node(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Node) predicate.Node {
|
||||
return predicate.Node(sql.NotPredicates(p))
|
||||
}
|
||||
276
entc/integration/edgefield/ent/node_create.go
Normal file
276
entc/integration/edgefield/ent/node_create.go
Normal file
@@ -0,0 +1,276 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/node"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// NodeCreate is the builder for creating a Node entity.
|
||||
type NodeCreate struct {
|
||||
config
|
||||
mutation *NodeMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (_c *NodeCreate) SetValue(v int) *NodeCreate {
|
||||
_c.mutation.SetValue(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (_c *NodeCreate) SetNillableValue(v *int) *NodeCreate {
|
||||
if v != nil {
|
||||
_c.SetValue(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetPrevID sets the "prev_id" field.
|
||||
func (_c *NodeCreate) SetPrevID(v int) *NodeCreate {
|
||||
_c.mutation.SetPrevID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillablePrevID sets the "prev_id" field if the given value is not nil.
|
||||
func (_c *NodeCreate) SetNillablePrevID(v *int) *NodeCreate {
|
||||
if v != nil {
|
||||
_c.SetPrevID(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetPrev sets the "prev" edge to the Node entity.
|
||||
func (_c *NodeCreate) SetPrev(v *Node) *NodeCreate {
|
||||
return _c.SetPrevID(v.ID)
|
||||
}
|
||||
|
||||
// SetNextID sets the "next" edge to the Node entity by ID.
|
||||
func (_c *NodeCreate) SetNextID(id int) *NodeCreate {
|
||||
_c.mutation.SetNextID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableNextID sets the "next" edge to the Node entity by ID if the given value is not nil.
|
||||
func (_c *NodeCreate) SetNillableNextID(id *int) *NodeCreate {
|
||||
if id != nil {
|
||||
_c = _c.SetNextID(*id)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNext sets the "next" edge to the Node entity.
|
||||
func (_c *NodeCreate) SetNext(v *Node) *NodeCreate {
|
||||
return _c.SetNextID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the NodeMutation object of the builder.
|
||||
func (_c *NodeCreate) Mutation() *NodeMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Node in the database.
|
||||
func (_c *NodeCreate) Save(ctx context.Context) (*Node, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *NodeCreate) SaveX(ctx context.Context) *Node {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *NodeCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *NodeCreate) 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 *NodeCreate) defaults() {
|
||||
if _, ok := _c.mutation.Value(); !ok {
|
||||
v := node.DefaultValue
|
||||
_c.mutation.SetValue(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *NodeCreate) check() error {
|
||||
if _, ok := _c.mutation.Value(); !ok {
|
||||
return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "Node.value"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *NodeCreate) sqlSave(ctx context.Context) (*Node, 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 *NodeCreate) createSpec() (*Node, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Node{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(node.Table, sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.Value(); ok {
|
||||
_spec.SetField(node.FieldValue, field.TypeInt, value)
|
||||
_node.Value = value
|
||||
}
|
||||
if nodes := _c.mutation.PrevIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: node.PrevTable,
|
||||
Columns: []string{node.PrevColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.PrevID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.NextIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: node.NextTable,
|
||||
Columns: []string{node.NextColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// NodeCreateBulk is the builder for creating many Node entities in bulk.
|
||||
type NodeCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*NodeCreate
|
||||
}
|
||||
|
||||
// Save creates the Node entities in the database.
|
||||
func (_c *NodeCreateBulk) Save(ctx context.Context) ([]*Node, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Node, 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.(*NodeMutation)
|
||||
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 *NodeCreateBulk) SaveX(ctx context.Context) []*Node {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *NodeCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *NodeCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/edgefield/ent/node_delete.go
Normal file
92
entc/integration/edgefield/ent/node_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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/node"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// NodeDelete is the builder for deleting a Node entity.
|
||||
type NodeDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *NodeMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NodeDelete builder.
|
||||
func (_d *NodeDelete) Where(ps ...predicate.Node) *NodeDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *NodeDelete) 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 *NodeDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *NodeDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(node.Table, sqlgraph.NewFieldSpec(node.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
|
||||
}
|
||||
|
||||
// NodeDeleteOne is the builder for deleting a single Node entity.
|
||||
type NodeDeleteOne struct {
|
||||
_d *NodeDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NodeDelete builder.
|
||||
func (_d *NodeDeleteOne) Where(ps ...predicate.Node) *NodeDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *NodeDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{node.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *NodeDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
679
entc/integration/edgefield/ent/node_query.go
Normal file
679
entc/integration/edgefield/ent/node_query.go
Normal file
@@ -0,0 +1,679 @@
|
||||
// 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 ent
|
||||
|
||||
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/edgefield/ent/node"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// NodeQuery is the builder for querying Node entities.
|
||||
type NodeQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []node.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Node
|
||||
withPrev *NodeQuery
|
||||
withNext *NodeQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the NodeQuery builder.
|
||||
func (_q *NodeQuery) Where(ps ...predicate.Node) *NodeQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *NodeQuery) Limit(limit int) *NodeQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *NodeQuery) Offset(offset int) *NodeQuery {
|
||||
_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 *NodeQuery) Unique(unique bool) *NodeQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *NodeQuery) Order(o ...node.OrderOption) *NodeQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryPrev chains the current query on the "prev" edge.
|
||||
func (_q *NodeQuery) QueryPrev() *NodeQuery {
|
||||
query := (&NodeClient{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(node.Table, node.FieldID, selector),
|
||||
sqlgraph.To(node.Table, node.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, node.PrevTable, node.PrevColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryNext chains the current query on the "next" edge.
|
||||
func (_q *NodeQuery) QueryNext() *NodeQuery {
|
||||
query := (&NodeClient{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(node.Table, node.FieldID, selector),
|
||||
sqlgraph.To(node.Table, node.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, node.NextTable, node.NextColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Node entity from the query.
|
||||
// Returns a *NotFoundError when no Node was found.
|
||||
func (_q *NodeQuery) First(ctx context.Context) (*Node, 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{node.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *NodeQuery) FirstX(ctx context.Context) *Node {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Node ID from the query.
|
||||
// Returns a *NotFoundError when no Node ID was found.
|
||||
func (_q *NodeQuery) 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{node.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *NodeQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Node entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Node entity is found.
|
||||
// Returns a *NotFoundError when no Node entities are found.
|
||||
func (_q *NodeQuery) Only(ctx context.Context) (*Node, 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{node.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{node.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *NodeQuery) OnlyX(ctx context.Context) *Node {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Node ID in the query.
|
||||
// Returns a *NotSingularError when more than one Node ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *NodeQuery) 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{node.Label}
|
||||
default:
|
||||
err = &NotSingularError{node.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *NodeQuery) 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 Nodes.
|
||||
func (_q *NodeQuery) All(ctx context.Context) ([]*Node, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Node, *NodeQuery]()
|
||||
return withInterceptors[[]*Node](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *NodeQuery) AllX(ctx context.Context) []*Node {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Node IDs.
|
||||
func (_q *NodeQuery) 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(node.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *NodeQuery) 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 *NodeQuery) 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[*NodeQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *NodeQuery) 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 *NodeQuery) 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("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *NodeQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the NodeQuery 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 *NodeQuery) Clone() *NodeQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &NodeQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]node.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Node{}, _q.predicates...),
|
||||
withPrev: _q.withPrev.Clone(),
|
||||
withNext: _q.withNext.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithPrev tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "prev" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *NodeQuery) WithPrev(opts ...func(*NodeQuery)) *NodeQuery {
|
||||
query := (&NodeClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withPrev = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithNext tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "next" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *NodeQuery) WithNext(opts ...func(*NodeQuery)) *NodeQuery {
|
||||
query := (&NodeClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withNext = 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 {
|
||||
// Value int `json:"value,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Node.Query().
|
||||
// GroupBy(node.FieldValue).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *NodeQuery) GroupBy(field string, fields ...string) *NodeGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &NodeGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = node.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 {
|
||||
// Value int `json:"value,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Node.Query().
|
||||
// Select(node.FieldValue).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *NodeQuery) Select(fields ...string) *NodeSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &NodeSelect{NodeQuery: _q}
|
||||
sbuild.label = node.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a NodeSelect configured with the given aggregations.
|
||||
func (_q *NodeQuery) Aggregate(fns ...AggregateFunc) *NodeSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *NodeQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !node.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: 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 *NodeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Node, error) {
|
||||
var (
|
||||
nodes = []*Node{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [2]bool{
|
||||
_q.withPrev != nil,
|
||||
_q.withNext != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Node).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Node{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.withPrev; query != nil {
|
||||
if err := _q.loadPrev(ctx, query, nodes, nil,
|
||||
func(n *Node, e *Node) { n.Edges.Prev = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withNext; query != nil {
|
||||
if err := _q.loadNext(ctx, query, nodes, nil,
|
||||
func(n *Node, e *Node) { n.Edges.Next = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *NodeQuery) loadPrev(ctx context.Context, query *NodeQuery, nodes []*Node, init func(*Node), assign func(*Node, *Node)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Node)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].PrevID
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(node.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 "prev_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *NodeQuery) loadNext(ctx context.Context, query *NodeQuery, nodes []*Node, init func(*Node), assign func(*Node, *Node)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*Node)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
}
|
||||
if len(query.ctx.Fields) > 0 {
|
||||
query.ctx.AppendFieldOnce(node.FieldPrevID)
|
||||
}
|
||||
query.Where(predicate.Node(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(node.NextColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.PrevID
|
||||
node, ok := nodeids[fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "prev_id" returned %v for node %v`, fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *NodeQuery) 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 *NodeQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(node.Table, node.Columns, sqlgraph.NewFieldSpec(node.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, node.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != node.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
if _q.withPrev != nil {
|
||||
_spec.Node.AddColumnOnce(node.FieldPrevID)
|
||||
}
|
||||
}
|
||||
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 *NodeQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(node.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = node.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
|
||||
}
|
||||
|
||||
// NodeGroupBy is the group-by builder for Node entities.
|
||||
type NodeGroupBy struct {
|
||||
selector
|
||||
build *NodeQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *NodeGroupBy) Aggregate(fns ...AggregateFunc) *NodeGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *NodeGroupBy) 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[*NodeQuery, *NodeGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *NodeGroupBy) sqlScan(ctx context.Context, root *NodeQuery, 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)
|
||||
}
|
||||
|
||||
// NodeSelect is the builder for selecting fields of Node entities.
|
||||
type NodeSelect struct {
|
||||
*NodeQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *NodeSelect) Aggregate(fns ...AggregateFunc) *NodeSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *NodeSelect) 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[*NodeQuery, *NodeSelect](ctx, _s.NodeQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *NodeSelect) sqlScan(ctx context.Context, root *NodeQuery, 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)
|
||||
}
|
||||
461
entc/integration/edgefield/ent/node_update.go
Normal file
461
entc/integration/edgefield/ent/node_update.go
Normal file
@@ -0,0 +1,461 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/node"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// NodeUpdate is the builder for updating Node entities.
|
||||
type NodeUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *NodeMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NodeUpdate builder.
|
||||
func (_u *NodeUpdate) Where(ps ...predicate.Node) *NodeUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (_u *NodeUpdate) SetValue(v int) *NodeUpdate {
|
||||
_u.mutation.ResetValue()
|
||||
_u.mutation.SetValue(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (_u *NodeUpdate) SetNillableValue(v *int) *NodeUpdate {
|
||||
if v != nil {
|
||||
_u.SetValue(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddValue adds value to the "value" field.
|
||||
func (_u *NodeUpdate) AddValue(v int) *NodeUpdate {
|
||||
_u.mutation.AddValue(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetPrevID sets the "prev_id" field.
|
||||
func (_u *NodeUpdate) SetPrevID(v int) *NodeUpdate {
|
||||
_u.mutation.SetPrevID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillablePrevID sets the "prev_id" field if the given value is not nil.
|
||||
func (_u *NodeUpdate) SetNillablePrevID(v *int) *NodeUpdate {
|
||||
if v != nil {
|
||||
_u.SetPrevID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearPrevID clears the value of the "prev_id" field.
|
||||
func (_u *NodeUpdate) ClearPrevID() *NodeUpdate {
|
||||
_u.mutation.ClearPrevID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetPrev sets the "prev" edge to the Node entity.
|
||||
func (_u *NodeUpdate) SetPrev(v *Node) *NodeUpdate {
|
||||
return _u.SetPrevID(v.ID)
|
||||
}
|
||||
|
||||
// SetNextID sets the "next" edge to the Node entity by ID.
|
||||
func (_u *NodeUpdate) SetNextID(id int) *NodeUpdate {
|
||||
_u.mutation.SetNextID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableNextID sets the "next" edge to the Node entity by ID if the given value is not nil.
|
||||
func (_u *NodeUpdate) SetNillableNextID(id *int) *NodeUpdate {
|
||||
if id != nil {
|
||||
_u = _u.SetNextID(*id)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNext sets the "next" edge to the Node entity.
|
||||
func (_u *NodeUpdate) SetNext(v *Node) *NodeUpdate {
|
||||
return _u.SetNextID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the NodeMutation object of the builder.
|
||||
func (_u *NodeUpdate) Mutation() *NodeMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearPrev clears the "prev" edge to the Node entity.
|
||||
func (_u *NodeUpdate) ClearPrev() *NodeUpdate {
|
||||
_u.mutation.ClearPrev()
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearNext clears the "next" edge to the Node entity.
|
||||
func (_u *NodeUpdate) ClearNext() *NodeUpdate {
|
||||
_u.mutation.ClearNext()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *NodeUpdate) 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 *NodeUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *NodeUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *NodeUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *NodeUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(node.Table, node.Columns, sqlgraph.NewFieldSpec(node.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.Value(); ok {
|
||||
_spec.SetField(node.FieldValue, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedValue(); ok {
|
||||
_spec.AddField(node.FieldValue, field.TypeInt, value)
|
||||
}
|
||||
if _u.mutation.PrevCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: node.PrevTable,
|
||||
Columns: []string{node.PrevColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.PrevIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: node.PrevTable,
|
||||
Columns: []string{node.PrevColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.NextCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: node.NextTable,
|
||||
Columns: []string{node.NextColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.NextIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: node.NextTable,
|
||||
Columns: []string{node.NextColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(node.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{node.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// NodeUpdateOne is the builder for updating a single Node entity.
|
||||
type NodeUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *NodeMutation
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (_u *NodeUpdateOne) SetValue(v int) *NodeUpdateOne {
|
||||
_u.mutation.ResetValue()
|
||||
_u.mutation.SetValue(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (_u *NodeUpdateOne) SetNillableValue(v *int) *NodeUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetValue(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddValue adds value to the "value" field.
|
||||
func (_u *NodeUpdateOne) AddValue(v int) *NodeUpdateOne {
|
||||
_u.mutation.AddValue(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetPrevID sets the "prev_id" field.
|
||||
func (_u *NodeUpdateOne) SetPrevID(v int) *NodeUpdateOne {
|
||||
_u.mutation.SetPrevID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillablePrevID sets the "prev_id" field if the given value is not nil.
|
||||
func (_u *NodeUpdateOne) SetNillablePrevID(v *int) *NodeUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetPrevID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearPrevID clears the value of the "prev_id" field.
|
||||
func (_u *NodeUpdateOne) ClearPrevID() *NodeUpdateOne {
|
||||
_u.mutation.ClearPrevID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetPrev sets the "prev" edge to the Node entity.
|
||||
func (_u *NodeUpdateOne) SetPrev(v *Node) *NodeUpdateOne {
|
||||
return _u.SetPrevID(v.ID)
|
||||
}
|
||||
|
||||
// SetNextID sets the "next" edge to the Node entity by ID.
|
||||
func (_u *NodeUpdateOne) SetNextID(id int) *NodeUpdateOne {
|
||||
_u.mutation.SetNextID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableNextID sets the "next" edge to the Node entity by ID if the given value is not nil.
|
||||
func (_u *NodeUpdateOne) SetNillableNextID(id *int) *NodeUpdateOne {
|
||||
if id != nil {
|
||||
_u = _u.SetNextID(*id)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNext sets the "next" edge to the Node entity.
|
||||
func (_u *NodeUpdateOne) SetNext(v *Node) *NodeUpdateOne {
|
||||
return _u.SetNextID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the NodeMutation object of the builder.
|
||||
func (_u *NodeUpdateOne) Mutation() *NodeMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearPrev clears the "prev" edge to the Node entity.
|
||||
func (_u *NodeUpdateOne) ClearPrev() *NodeUpdateOne {
|
||||
_u.mutation.ClearPrev()
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearNext clears the "next" edge to the Node entity.
|
||||
func (_u *NodeUpdateOne) ClearNext() *NodeUpdateOne {
|
||||
_u.mutation.ClearNext()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the NodeUpdate builder.
|
||||
func (_u *NodeUpdateOne) Where(ps ...predicate.Node) *NodeUpdateOne {
|
||||
_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 *NodeUpdateOne) Select(field string, fields ...string) *NodeUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Node entity.
|
||||
func (_u *NodeUpdateOne) Save(ctx context.Context) (*Node, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *NodeUpdateOne) SaveX(ctx context.Context) *Node {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *NodeUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *NodeUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *NodeUpdateOne) sqlSave(ctx context.Context) (_node *Node, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(node.Table, node.Columns, sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Node.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, node.FieldID)
|
||||
for _, f := range fields {
|
||||
if !node.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != node.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.Value(); ok {
|
||||
_spec.SetField(node.FieldValue, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedValue(); ok {
|
||||
_spec.AddField(node.FieldValue, field.TypeInt, value)
|
||||
}
|
||||
if _u.mutation.PrevCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: node.PrevTable,
|
||||
Columns: []string{node.PrevColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.PrevIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: node.PrevTable,
|
||||
Columns: []string{node.PrevColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _u.mutation.NextCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: node.NextTable,
|
||||
Columns: []string{node.NextColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.NextIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: node.NextTable,
|
||||
Columns: []string{node.NextColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(node.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Node{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{node.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
134
entc/integration/edgefield/ent/pet.go
Normal file
134
entc/integration/edgefield/ent/pet.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 ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/pet"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
)
|
||||
|
||||
// Pet is the model entity for the Pet schema.
|
||||
type Pet struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// OwnerID holds the value of the "owner_id" field.
|
||||
OwnerID int `json:"owner_id,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the PetQuery when eager-loading is set.
|
||||
Edges PetEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// PetEdges holds the relations/edges for other nodes in the graph.
|
||||
type PetEdges 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 PetEdges) 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 (*Pet) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case pet.FieldID, pet.FieldOwnerID:
|
||||
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 Pet fields.
|
||||
func (_m *Pet) 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 pet.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 pet.FieldOwnerID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field owner_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.OwnerID = 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 Pet.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Pet) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryOwner queries the "owner" edge of the Pet entity.
|
||||
func (_m *Pet) QueryOwner() *UserQuery {
|
||||
return NewPetClient(_m.config).QueryOwner(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Pet.
|
||||
// Note that you need to call Pet.Unwrap() before calling this method if this Pet
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Pet) Update() *PetUpdateOne {
|
||||
return NewPetClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Pet 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 *Pet) Unwrap() *Pet {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Pet is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Pet) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Pet(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("owner_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.OwnerID))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Pets is a parsable slice of Pet.
|
||||
type Pets []*Pet
|
||||
312
entc/integration/edgefield/ent/pet/mutation.go
Normal file
312
entc/integration/edgefield/ent/pet/mutation.go
Normal file
@@ -0,0 +1,312 @@
|
||||
// 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 pet
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Pet nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
clearedFields map[string]struct{}
|
||||
owner *int
|
||||
clearedowner bool
|
||||
predicates []predicate.Pet
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Pet entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Pet",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Pet {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner_id" field.
|
||||
func (m *Mutation) SetOwnerID(i int) {
|
||||
m.owner = &i
|
||||
}
|
||||
|
||||
// OwnerID returns the value of the "owner_id" field in the mutation.
|
||||
func (m *Mutation) OwnerID() (r int, exists bool) {
|
||||
v := m.owner
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearOwnerID clears the value of the "owner_id" field.
|
||||
func (m *Mutation) ClearOwnerID() {
|
||||
m.owner = nil
|
||||
m.clearedFields[FieldOwnerID] = struct{}{}
|
||||
}
|
||||
|
||||
// OwnerIDCleared returns if the "owner_id" field was cleared in this mutation.
|
||||
func (m *Mutation) OwnerIDCleared() bool {
|
||||
_, ok := m.clearedFields[FieldOwnerID]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetOwnerID resets all changes to the "owner_id" field.
|
||||
func (m *Mutation) ResetOwnerID() {
|
||||
m.owner = nil
|
||||
delete(m.clearedFields, FieldOwnerID)
|
||||
}
|
||||
|
||||
// ClearOwner clears the "owner" edge to the User entity.
|
||||
func (m *Mutation) ClearOwner() {
|
||||
m.clearedowner = true
|
||||
m.clearedFields[FieldOwnerID] = struct{}{}
|
||||
}
|
||||
|
||||
// OwnerCleared reports if the "owner" edge to the User entity was cleared.
|
||||
func (m *Mutation) OwnerCleared() bool {
|
||||
return m.OwnerIDCleared() || m.clearedowner
|
||||
}
|
||||
|
||||
// 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.Pet) {
|
||||
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.Pet, 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 (Pet).
|
||||
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.owner != nil {
|
||||
fields = append(fields, FieldOwnerID)
|
||||
}
|
||||
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 FieldOwnerID:
|
||||
return m.OwnerID()
|
||||
}
|
||||
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 Pet 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 FieldOwnerID:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetOwnerID(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Pet field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *Mutation) AddedFields() []string {
|
||||
var fields []string
|
||||
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 {
|
||||
}
|
||||
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 Pet 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(FieldOwnerID) {
|
||||
fields = append(fields, FieldOwnerID)
|
||||
}
|
||||
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 FieldOwnerID:
|
||||
m.ClearOwnerID()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Pet 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 FieldOwnerID:
|
||||
m.ResetOwnerID()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Pet 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 Pet 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 Pet edge %s", name)
|
||||
}
|
||||
75
entc/integration/edgefield/ent/pet/pet.go
Normal file
75
entc/integration/edgefield/ent/pet/pet.go
Normal file
@@ -0,0 +1,75 @@
|
||||
// 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 pet
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the pet type in the database.
|
||||
Label = "pet"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldOwnerID holds the string denoting the owner_id field in the database.
|
||||
FieldOwnerID = "owner_id"
|
||||
// EdgeOwner holds the string denoting the owner edge name in mutations.
|
||||
EdgeOwner = "owner"
|
||||
// Table holds the table name of the pet in the database.
|
||||
Table = "pets"
|
||||
// OwnerTable is the table that holds the owner relation/edge.
|
||||
OwnerTable = "pets"
|
||||
// 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 = "owner_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for pet fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldOwnerID,
|
||||
}
|
||||
|
||||
// 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 Pet 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()
|
||||
}
|
||||
|
||||
// ByOwnerID orders the results by the owner_id field.
|
||||
func ByOwnerID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldOwnerID, 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, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, OwnerTable, OwnerColumn),
|
||||
)
|
||||
}
|
||||
131
entc/integration/edgefield/ent/pet/where.go
Normal file
131
entc/integration/edgefield/ent/pet/where.go
Normal file
@@ -0,0 +1,131 @@
|
||||
// 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 pet
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// OwnerID applies equality check predicate on the "owner_id" field. It's identical to OwnerIDEQ.
|
||||
func OwnerID(v int) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldEQ(FieldOwnerID, v))
|
||||
}
|
||||
|
||||
// OwnerIDEQ applies the EQ predicate on the "owner_id" field.
|
||||
func OwnerIDEQ(v int) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldEQ(FieldOwnerID, v))
|
||||
}
|
||||
|
||||
// OwnerIDNEQ applies the NEQ predicate on the "owner_id" field.
|
||||
func OwnerIDNEQ(v int) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldNEQ(FieldOwnerID, v))
|
||||
}
|
||||
|
||||
// OwnerIDIn applies the In predicate on the "owner_id" field.
|
||||
func OwnerIDIn(vs ...int) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldIn(FieldOwnerID, vs...))
|
||||
}
|
||||
|
||||
// OwnerIDNotIn applies the NotIn predicate on the "owner_id" field.
|
||||
func OwnerIDNotIn(vs ...int) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldNotIn(FieldOwnerID, vs...))
|
||||
}
|
||||
|
||||
// OwnerIDIsNil applies the IsNil predicate on the "owner_id" field.
|
||||
func OwnerIDIsNil() predicate.Pet {
|
||||
return predicate.Pet(sql.FieldIsNull(FieldOwnerID))
|
||||
}
|
||||
|
||||
// OwnerIDNotNil applies the NotNil predicate on the "owner_id" field.
|
||||
func OwnerIDNotNil() predicate.Pet {
|
||||
return predicate.Pet(sql.FieldNotNull(FieldOwnerID))
|
||||
}
|
||||
|
||||
// HasOwner applies the HasEdge predicate on the "owner" edge.
|
||||
func HasOwner() predicate.Pet {
|
||||
return predicate.Pet(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, 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.Pet {
|
||||
return predicate.Pet(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.Pet) predicate.Pet {
|
||||
return predicate.Pet(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Pet) predicate.Pet {
|
||||
return predicate.Pet(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Pet) predicate.Pet {
|
||||
return predicate.Pet(sql.NotPredicates(p))
|
||||
}
|
||||
210
entc/integration/edgefield/ent/pet_create.go
Normal file
210
entc/integration/edgefield/ent/pet_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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/pet"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// PetCreate is the builder for creating a Pet entity.
|
||||
type PetCreate struct {
|
||||
config
|
||||
mutation *PetMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner_id" field.
|
||||
func (_c *PetCreate) SetOwnerID(v int) *PetCreate {
|
||||
_c.mutation.SetOwnerID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
|
||||
func (_c *PetCreate) SetNillableOwnerID(v *int) *PetCreate {
|
||||
if v != nil {
|
||||
_c.SetOwnerID(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" edge to the User entity.
|
||||
func (_c *PetCreate) SetOwner(v *User) *PetCreate {
|
||||
return _c.SetOwnerID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the PetMutation object of the builder.
|
||||
func (_c *PetCreate) Mutation() *PetMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Pet in the database.
|
||||
func (_c *PetCreate) Save(ctx context.Context) (*Pet, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *PetCreate) SaveX(ctx context.Context) *Pet {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *PetCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *PetCreate) 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 *PetCreate) check() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *PetCreate) sqlSave(ctx context.Context) (*Pet, 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 *PetCreate) createSpec() (*Pet, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Pet{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(pet.Table, sqlgraph.NewFieldSpec(pet.FieldID, field.TypeInt))
|
||||
)
|
||||
if nodes := _c.mutation.OwnerIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: pet.OwnerTable,
|
||||
Columns: []string{pet.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.OwnerID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// PetCreateBulk is the builder for creating many Pet entities in bulk.
|
||||
type PetCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*PetCreate
|
||||
}
|
||||
|
||||
// Save creates the Pet entities in the database.
|
||||
func (_c *PetCreateBulk) Save(ctx context.Context) ([]*Pet, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Pet, 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.(*PetMutation)
|
||||
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 *PetCreateBulk) SaveX(ctx context.Context) []*Pet {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *PetCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *PetCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/edgefield/ent/pet_delete.go
Normal file
92
entc/integration/edgefield/ent/pet_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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/pet"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// PetDelete is the builder for deleting a Pet entity.
|
||||
type PetDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *PetMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the PetDelete builder.
|
||||
func (_d *PetDelete) Where(ps ...predicate.Pet) *PetDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *PetDelete) 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 *PetDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *PetDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(pet.Table, sqlgraph.NewFieldSpec(pet.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
|
||||
}
|
||||
|
||||
// PetDeleteOne is the builder for deleting a single Pet entity.
|
||||
type PetDeleteOne struct {
|
||||
_d *PetDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the PetDelete builder.
|
||||
func (_d *PetDeleteOne) Where(ps ...predicate.Pet) *PetDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *PetDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{pet.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *PetDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
610
entc/integration/edgefield/ent/pet_query.go
Normal file
610
entc/integration/edgefield/ent/pet_query.go
Normal file
@@ -0,0 +1,610 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/pet"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// PetQuery is the builder for querying Pet entities.
|
||||
type PetQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []pet.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Pet
|
||||
withOwner *UserQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the PetQuery builder.
|
||||
func (_q *PetQuery) Where(ps ...predicate.Pet) *PetQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *PetQuery) Limit(limit int) *PetQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *PetQuery) Offset(offset int) *PetQuery {
|
||||
_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 *PetQuery) Unique(unique bool) *PetQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *PetQuery) Order(o ...pet.OrderOption) *PetQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryOwner chains the current query on the "owner" edge.
|
||||
func (_q *PetQuery) 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(pet.Table, pet.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, pet.OwnerTable, pet.OwnerColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Pet entity from the query.
|
||||
// Returns a *NotFoundError when no Pet was found.
|
||||
func (_q *PetQuery) First(ctx context.Context) (*Pet, 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{pet.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *PetQuery) FirstX(ctx context.Context) *Pet {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Pet ID from the query.
|
||||
// Returns a *NotFoundError when no Pet ID was found.
|
||||
func (_q *PetQuery) 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{pet.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *PetQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Pet entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Pet entity is found.
|
||||
// Returns a *NotFoundError when no Pet entities are found.
|
||||
func (_q *PetQuery) Only(ctx context.Context) (*Pet, 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{pet.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{pet.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *PetQuery) OnlyX(ctx context.Context) *Pet {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Pet ID in the query.
|
||||
// Returns a *NotSingularError when more than one Pet ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *PetQuery) 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{pet.Label}
|
||||
default:
|
||||
err = &NotSingularError{pet.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *PetQuery) 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 Pets.
|
||||
func (_q *PetQuery) All(ctx context.Context) ([]*Pet, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Pet, *PetQuery]()
|
||||
return withInterceptors[[]*Pet](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *PetQuery) AllX(ctx context.Context) []*Pet {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Pet IDs.
|
||||
func (_q *PetQuery) 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(pet.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *PetQuery) 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 *PetQuery) 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[*PetQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *PetQuery) 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 *PetQuery) 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("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *PetQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the PetQuery 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 *PetQuery) Clone() *PetQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &PetQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]pet.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Pet{}, _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 *PetQuery) WithOwner(opts ...func(*UserQuery)) *PetQuery {
|
||||
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.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// OwnerID int `json:"owner_id,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Pet.Query().
|
||||
// GroupBy(pet.FieldOwnerID).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *PetQuery) GroupBy(field string, fields ...string) *PetGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &PetGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = pet.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 {
|
||||
// OwnerID int `json:"owner_id,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Pet.Query().
|
||||
// Select(pet.FieldOwnerID).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *PetQuery) Select(fields ...string) *PetSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &PetSelect{PetQuery: _q}
|
||||
sbuild.label = pet.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a PetSelect configured with the given aggregations.
|
||||
func (_q *PetQuery) Aggregate(fns ...AggregateFunc) *PetSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *PetQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !pet.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: 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 *PetQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Pet, error) {
|
||||
var (
|
||||
nodes = []*Pet{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
_q.withOwner != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Pet).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Pet{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 *Pet, e *User) { n.Edges.Owner = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *PetQuery) loadOwner(ctx context.Context, query *UserQuery, nodes []*Pet, init func(*Pet), assign func(*Pet, *User)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Pet)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].OwnerID
|
||||
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 "owner_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *PetQuery) 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 *PetQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(pet.Table, pet.Columns, sqlgraph.NewFieldSpec(pet.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, pet.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != pet.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
if _q.withOwner != nil {
|
||||
_spec.Node.AddColumnOnce(pet.FieldOwnerID)
|
||||
}
|
||||
}
|
||||
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 *PetQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(pet.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = pet.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
|
||||
}
|
||||
|
||||
// PetGroupBy is the group-by builder for Pet entities.
|
||||
type PetGroupBy struct {
|
||||
selector
|
||||
build *PetQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *PetGroupBy) Aggregate(fns ...AggregateFunc) *PetGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *PetGroupBy) 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[*PetQuery, *PetGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *PetGroupBy) sqlScan(ctx context.Context, root *PetQuery, 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)
|
||||
}
|
||||
|
||||
// PetSelect is the builder for selecting fields of Pet entities.
|
||||
type PetSelect struct {
|
||||
*PetQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *PetSelect) Aggregate(fns ...AggregateFunc) *PetSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *PetSelect) 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[*PetQuery, *PetSelect](ctx, _s.PetQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *PetSelect) sqlScan(ctx context.Context, root *PetQuery, 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)
|
||||
}
|
||||
300
entc/integration/edgefield/ent/pet_update.go
Normal file
300
entc/integration/edgefield/ent/pet_update.go
Normal file
@@ -0,0 +1,300 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/pet"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// PetUpdate is the builder for updating Pet entities.
|
||||
type PetUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *PetMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the PetUpdate builder.
|
||||
func (_u *PetUpdate) Where(ps ...predicate.Pet) *PetUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner_id" field.
|
||||
func (_u *PetUpdate) SetOwnerID(v int) *PetUpdate {
|
||||
_u.mutation.SetOwnerID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
|
||||
func (_u *PetUpdate) SetNillableOwnerID(v *int) *PetUpdate {
|
||||
if v != nil {
|
||||
_u.SetOwnerID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearOwnerID clears the value of the "owner_id" field.
|
||||
func (_u *PetUpdate) ClearOwnerID() *PetUpdate {
|
||||
_u.mutation.ClearOwnerID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" edge to the User entity.
|
||||
func (_u *PetUpdate) SetOwner(v *User) *PetUpdate {
|
||||
return _u.SetOwnerID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the PetMutation object of the builder.
|
||||
func (_u *PetUpdate) Mutation() *PetMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearOwner clears the "owner" edge to the User entity.
|
||||
func (_u *PetUpdate) ClearOwner() *PetUpdate {
|
||||
_u.mutation.ClearOwner()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *PetUpdate) 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 *PetUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *PetUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *PetUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *PetUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(pet.Table, pet.Columns, sqlgraph.NewFieldSpec(pet.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.M2O,
|
||||
Inverse: true,
|
||||
Table: pet.OwnerTable,
|
||||
Columns: []string{pet.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.M2O,
|
||||
Inverse: true,
|
||||
Table: pet.OwnerTable,
|
||||
Columns: []string{pet.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{pet.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// PetUpdateOne is the builder for updating a single Pet entity.
|
||||
type PetUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *PetMutation
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner_id" field.
|
||||
func (_u *PetUpdateOne) SetOwnerID(v int) *PetUpdateOne {
|
||||
_u.mutation.SetOwnerID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
|
||||
func (_u *PetUpdateOne) SetNillableOwnerID(v *int) *PetUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetOwnerID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearOwnerID clears the value of the "owner_id" field.
|
||||
func (_u *PetUpdateOne) ClearOwnerID() *PetUpdateOne {
|
||||
_u.mutation.ClearOwnerID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" edge to the User entity.
|
||||
func (_u *PetUpdateOne) SetOwner(v *User) *PetUpdateOne {
|
||||
return _u.SetOwnerID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the PetMutation object of the builder.
|
||||
func (_u *PetUpdateOne) Mutation() *PetMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearOwner clears the "owner" edge to the User entity.
|
||||
func (_u *PetUpdateOne) ClearOwner() *PetUpdateOne {
|
||||
_u.mutation.ClearOwner()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the PetUpdate builder.
|
||||
func (_u *PetUpdateOne) Where(ps ...predicate.Pet) *PetUpdateOne {
|
||||
_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 *PetUpdateOne) Select(field string, fields ...string) *PetUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Pet entity.
|
||||
func (_u *PetUpdateOne) Save(ctx context.Context) (*Pet, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *PetUpdateOne) SaveX(ctx context.Context) *Pet {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *PetUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *PetUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *PetUpdateOne) sqlSave(ctx context.Context) (_node *Pet, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(pet.Table, pet.Columns, sqlgraph.NewFieldSpec(pet.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Pet.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, pet.FieldID)
|
||||
for _, f := range fields {
|
||||
if !pet.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != pet.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.M2O,
|
||||
Inverse: true,
|
||||
Table: pet.OwnerTable,
|
||||
Columns: []string{pet.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.M2O,
|
||||
Inverse: true,
|
||||
Table: pet.OwnerTable,
|
||||
Columns: []string{pet.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 = &Pet{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{pet.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
150
entc/integration/edgefield/ent/post.go
Normal file
150
entc/integration/edgefield/ent/post.go
Normal file
@@ -0,0 +1,150 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/post"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
)
|
||||
|
||||
// Post is the model entity for the Post schema.
|
||||
type Post struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Text holds the value of the "text" field.
|
||||
Text string `json:"text,omitempty"`
|
||||
// AuthorID holds the value of the "author_id" field.
|
||||
AuthorID *int `json:"author_id,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the PostQuery when eager-loading is set.
|
||||
Edges PostEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// PostEdges holds the relations/edges for other nodes in the graph.
|
||||
type PostEdges struct {
|
||||
// Author holds the value of the author edge.
|
||||
Author *User `json:"author,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// AuthorOrErr returns the Author value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e PostEdges) AuthorOrErr() (*User, error) {
|
||||
if e.Author != nil {
|
||||
return e.Author, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "author"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Post) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case post.FieldID, post.FieldAuthorID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case post.FieldText:
|
||||
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 Post fields.
|
||||
func (_m *Post) 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 post.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 post.FieldText:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field text", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Text = value.String
|
||||
}
|
||||
case post.FieldAuthorID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field author_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.AuthorID = new(int)
|
||||
*_m.AuthorID = 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 Post.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Post) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryAuthor queries the "author" edge of the Post entity.
|
||||
func (_m *Post) QueryAuthor() *UserQuery {
|
||||
return NewPostClient(_m.config).QueryAuthor(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Post.
|
||||
// Note that you need to call Post.Unwrap() before calling this method if this Post
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Post) Update() *PostUpdateOne {
|
||||
return NewPostClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Post 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 *Post) Unwrap() *Post {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Post is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Post) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Post(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("text=")
|
||||
builder.WriteString(_m.Text)
|
||||
builder.WriteString(", ")
|
||||
if v := _m.AuthorID; v != nil {
|
||||
builder.WriteString("author_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||
}
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Posts is a parsable slice of Post.
|
||||
type Posts []*Post
|
||||
347
entc/integration/edgefield/ent/post/mutation.go
Normal file
347
entc/integration/edgefield/ent/post/mutation.go
Normal file
@@ -0,0 +1,347 @@
|
||||
// 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 post
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Post nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
text *string
|
||||
clearedFields map[string]struct{}
|
||||
author *int
|
||||
clearedauthor bool
|
||||
predicates []predicate.Post
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Post entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Post",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Post {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetText sets the "text" field.
|
||||
func (m *Mutation) SetText(s string) {
|
||||
m.text = &s
|
||||
}
|
||||
|
||||
// Text returns the value of the "text" field in the mutation.
|
||||
func (m *Mutation) Text() (r string, exists bool) {
|
||||
v := m.text
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ResetText resets all changes to the "text" field.
|
||||
func (m *Mutation) ResetText() {
|
||||
m.text = nil
|
||||
}
|
||||
|
||||
// SetAuthorID sets the "author_id" field.
|
||||
func (m *Mutation) SetAuthorID(i int) {
|
||||
m.author = &i
|
||||
}
|
||||
|
||||
// AuthorID returns the value of the "author_id" field in the mutation.
|
||||
func (m *Mutation) AuthorID() (r int, exists bool) {
|
||||
v := m.author
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearAuthorID clears the value of the "author_id" field.
|
||||
func (m *Mutation) ClearAuthorID() {
|
||||
m.author = nil
|
||||
m.clearedFields[FieldAuthorID] = struct{}{}
|
||||
}
|
||||
|
||||
// AuthorIDCleared returns if the "author_id" field was cleared in this mutation.
|
||||
func (m *Mutation) AuthorIDCleared() bool {
|
||||
_, ok := m.clearedFields[FieldAuthorID]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetAuthorID resets all changes to the "author_id" field.
|
||||
func (m *Mutation) ResetAuthorID() {
|
||||
m.author = nil
|
||||
delete(m.clearedFields, FieldAuthorID)
|
||||
}
|
||||
|
||||
// ClearAuthor clears the "author" edge to the User entity.
|
||||
func (m *Mutation) ClearAuthor() {
|
||||
m.clearedauthor = true
|
||||
m.clearedFields[FieldAuthorID] = struct{}{}
|
||||
}
|
||||
|
||||
// AuthorCleared reports if the "author" edge to the User entity was cleared.
|
||||
func (m *Mutation) AuthorCleared() bool {
|
||||
return m.AuthorIDCleared() || m.clearedauthor
|
||||
}
|
||||
|
||||
// AuthorIDs returns the "author" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// AuthorID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) AuthorIDs() (ids []int) {
|
||||
if id := m.author; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetAuthor resets all changes to the "author" edge.
|
||||
func (m *Mutation) ResetAuthor() {
|
||||
m.author = nil
|
||||
m.clearedauthor = false
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.Post) {
|
||||
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.Post, 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 (Post).
|
||||
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, 2)
|
||||
if m.text != nil {
|
||||
fields = append(fields, FieldText)
|
||||
}
|
||||
if m.author != nil {
|
||||
fields = append(fields, FieldAuthorID)
|
||||
}
|
||||
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 FieldText:
|
||||
return m.Text()
|
||||
case FieldAuthorID:
|
||||
return m.AuthorID()
|
||||
}
|
||||
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 Post 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 FieldText:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetText(v)
|
||||
return nil
|
||||
case FieldAuthorID:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetAuthorID(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Post field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *Mutation) AddedFields() []string {
|
||||
var fields []string
|
||||
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 {
|
||||
}
|
||||
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 Post 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(FieldAuthorID) {
|
||||
fields = append(fields, FieldAuthorID)
|
||||
}
|
||||
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 FieldAuthorID:
|
||||
m.ClearAuthorID()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Post 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 FieldText:
|
||||
m.ResetText()
|
||||
return nil
|
||||
case FieldAuthorID:
|
||||
m.ResetAuthorID()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Post 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.author != nil {
|
||||
edges = append(edges, EdgeAuthor)
|
||||
}
|
||||
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 EdgeAuthor:
|
||||
if id := m.author; 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.clearedauthor {
|
||||
edges = append(edges, EdgeAuthor)
|
||||
}
|
||||
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 EdgeAuthor:
|
||||
return m.clearedauthor
|
||||
}
|
||||
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 EdgeAuthor:
|
||||
m.ClearAuthor()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Post 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 EdgeAuthor:
|
||||
m.ResetAuthor()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Post edge %s", name)
|
||||
}
|
||||
83
entc/integration/edgefield/ent/post/post.go
Normal file
83
entc/integration/edgefield/ent/post/post.go
Normal file
@@ -0,0 +1,83 @@
|
||||
// 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 post
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the post type in the database.
|
||||
Label = "post"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldText holds the string denoting the text field in the database.
|
||||
FieldText = "text"
|
||||
// FieldAuthorID holds the string denoting the author_id field in the database.
|
||||
FieldAuthorID = "author_id"
|
||||
// EdgeAuthor holds the string denoting the author edge name in mutations.
|
||||
EdgeAuthor = "author"
|
||||
// Table holds the table name of the post in the database.
|
||||
Table = "posts"
|
||||
// AuthorTable is the table that holds the author relation/edge.
|
||||
AuthorTable = "posts"
|
||||
// AuthorInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
AuthorInverseTable = "users"
|
||||
// AuthorColumn is the table column denoting the author relation/edge.
|
||||
AuthorColumn = "author_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for post fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldText,
|
||||
FieldAuthorID,
|
||||
}
|
||||
|
||||
// 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 Post 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()
|
||||
}
|
||||
|
||||
// ByText orders the results by the text field.
|
||||
func ByText(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldText, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAuthorID orders the results by the author_id field.
|
||||
func ByAuthorID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldAuthorID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAuthorField orders the results by author field.
|
||||
func ByAuthorField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newAuthorStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newAuthorStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(AuthorInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, AuthorTable, AuthorColumn),
|
||||
)
|
||||
}
|
||||
201
entc/integration/edgefield/ent/post/where.go
Normal file
201
entc/integration/edgefield/ent/post/where.go
Normal file
@@ -0,0 +1,201 @@
|
||||
// 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 post
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Post {
|
||||
return predicate.Post(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Post {
|
||||
return predicate.Post(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Post {
|
||||
return predicate.Post(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Post {
|
||||
return predicate.Post(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Post {
|
||||
return predicate.Post(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Post {
|
||||
return predicate.Post(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Post {
|
||||
return predicate.Post(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Post {
|
||||
return predicate.Post(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Post {
|
||||
return predicate.Post(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Text applies equality check predicate on the "text" field. It's identical to TextEQ.
|
||||
func Text(v string) predicate.Post {
|
||||
return predicate.Post(sql.FieldEQ(FieldText, v))
|
||||
}
|
||||
|
||||
// AuthorID applies equality check predicate on the "author_id" field. It's identical to AuthorIDEQ.
|
||||
func AuthorID(v int) predicate.Post {
|
||||
return predicate.Post(sql.FieldEQ(FieldAuthorID, v))
|
||||
}
|
||||
|
||||
// TextEQ applies the EQ predicate on the "text" field.
|
||||
func TextEQ(v string) predicate.Post {
|
||||
return predicate.Post(sql.FieldEQ(FieldText, v))
|
||||
}
|
||||
|
||||
// TextNEQ applies the NEQ predicate on the "text" field.
|
||||
func TextNEQ(v string) predicate.Post {
|
||||
return predicate.Post(sql.FieldNEQ(FieldText, v))
|
||||
}
|
||||
|
||||
// TextIn applies the In predicate on the "text" field.
|
||||
func TextIn(vs ...string) predicate.Post {
|
||||
return predicate.Post(sql.FieldIn(FieldText, vs...))
|
||||
}
|
||||
|
||||
// TextNotIn applies the NotIn predicate on the "text" field.
|
||||
func TextNotIn(vs ...string) predicate.Post {
|
||||
return predicate.Post(sql.FieldNotIn(FieldText, vs...))
|
||||
}
|
||||
|
||||
// TextGT applies the GT predicate on the "text" field.
|
||||
func TextGT(v string) predicate.Post {
|
||||
return predicate.Post(sql.FieldGT(FieldText, v))
|
||||
}
|
||||
|
||||
// TextGTE applies the GTE predicate on the "text" field.
|
||||
func TextGTE(v string) predicate.Post {
|
||||
return predicate.Post(sql.FieldGTE(FieldText, v))
|
||||
}
|
||||
|
||||
// TextLT applies the LT predicate on the "text" field.
|
||||
func TextLT(v string) predicate.Post {
|
||||
return predicate.Post(sql.FieldLT(FieldText, v))
|
||||
}
|
||||
|
||||
// TextLTE applies the LTE predicate on the "text" field.
|
||||
func TextLTE(v string) predicate.Post {
|
||||
return predicate.Post(sql.FieldLTE(FieldText, v))
|
||||
}
|
||||
|
||||
// TextContains applies the Contains predicate on the "text" field.
|
||||
func TextContains(v string) predicate.Post {
|
||||
return predicate.Post(sql.FieldContains(FieldText, v))
|
||||
}
|
||||
|
||||
// TextHasPrefix applies the HasPrefix predicate on the "text" field.
|
||||
func TextHasPrefix(v string) predicate.Post {
|
||||
return predicate.Post(sql.FieldHasPrefix(FieldText, v))
|
||||
}
|
||||
|
||||
// TextHasSuffix applies the HasSuffix predicate on the "text" field.
|
||||
func TextHasSuffix(v string) predicate.Post {
|
||||
return predicate.Post(sql.FieldHasSuffix(FieldText, v))
|
||||
}
|
||||
|
||||
// TextEqualFold applies the EqualFold predicate on the "text" field.
|
||||
func TextEqualFold(v string) predicate.Post {
|
||||
return predicate.Post(sql.FieldEqualFold(FieldText, v))
|
||||
}
|
||||
|
||||
// TextContainsFold applies the ContainsFold predicate on the "text" field.
|
||||
func TextContainsFold(v string) predicate.Post {
|
||||
return predicate.Post(sql.FieldContainsFold(FieldText, v))
|
||||
}
|
||||
|
||||
// AuthorIDEQ applies the EQ predicate on the "author_id" field.
|
||||
func AuthorIDEQ(v int) predicate.Post {
|
||||
return predicate.Post(sql.FieldEQ(FieldAuthorID, v))
|
||||
}
|
||||
|
||||
// AuthorIDNEQ applies the NEQ predicate on the "author_id" field.
|
||||
func AuthorIDNEQ(v int) predicate.Post {
|
||||
return predicate.Post(sql.FieldNEQ(FieldAuthorID, v))
|
||||
}
|
||||
|
||||
// AuthorIDIn applies the In predicate on the "author_id" field.
|
||||
func AuthorIDIn(vs ...int) predicate.Post {
|
||||
return predicate.Post(sql.FieldIn(FieldAuthorID, vs...))
|
||||
}
|
||||
|
||||
// AuthorIDNotIn applies the NotIn predicate on the "author_id" field.
|
||||
func AuthorIDNotIn(vs ...int) predicate.Post {
|
||||
return predicate.Post(sql.FieldNotIn(FieldAuthorID, vs...))
|
||||
}
|
||||
|
||||
// AuthorIDIsNil applies the IsNil predicate on the "author_id" field.
|
||||
func AuthorIDIsNil() predicate.Post {
|
||||
return predicate.Post(sql.FieldIsNull(FieldAuthorID))
|
||||
}
|
||||
|
||||
// AuthorIDNotNil applies the NotNil predicate on the "author_id" field.
|
||||
func AuthorIDNotNil() predicate.Post {
|
||||
return predicate.Post(sql.FieldNotNull(FieldAuthorID))
|
||||
}
|
||||
|
||||
// HasAuthor applies the HasEdge predicate on the "author" edge.
|
||||
func HasAuthor() predicate.Post {
|
||||
return predicate.Post(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, AuthorTable, AuthorColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasAuthorWith applies the HasEdge predicate on the "author" edge with a given conditions (other predicates).
|
||||
func HasAuthorWith(preds ...predicate.User) predicate.Post {
|
||||
return predicate.Post(func(s *sql.Selector) {
|
||||
step := newAuthorStep()
|
||||
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.Post) predicate.Post {
|
||||
return predicate.Post(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Post) predicate.Post {
|
||||
return predicate.Post(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Post) predicate.Post {
|
||||
return predicate.Post(sql.NotPredicates(p))
|
||||
}
|
||||
224
entc/integration/edgefield/ent/post_create.go
Normal file
224
entc/integration/edgefield/ent/post_create.go
Normal file
@@ -0,0 +1,224 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/post"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// PostCreate is the builder for creating a Post entity.
|
||||
type PostCreate struct {
|
||||
config
|
||||
mutation *PostMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetText sets the "text" field.
|
||||
func (_c *PostCreate) SetText(v string) *PostCreate {
|
||||
_c.mutation.SetText(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetAuthorID sets the "author_id" field.
|
||||
func (_c *PostCreate) SetAuthorID(v int) *PostCreate {
|
||||
_c.mutation.SetAuthorID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableAuthorID sets the "author_id" field if the given value is not nil.
|
||||
func (_c *PostCreate) SetNillableAuthorID(v *int) *PostCreate {
|
||||
if v != nil {
|
||||
_c.SetAuthorID(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetAuthor sets the "author" edge to the User entity.
|
||||
func (_c *PostCreate) SetAuthor(v *User) *PostCreate {
|
||||
return _c.SetAuthorID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the PostMutation object of the builder.
|
||||
func (_c *PostCreate) Mutation() *PostMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Post in the database.
|
||||
func (_c *PostCreate) Save(ctx context.Context) (*Post, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *PostCreate) SaveX(ctx context.Context) *Post {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *PostCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *PostCreate) 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 *PostCreate) check() error {
|
||||
if _, ok := _c.mutation.Text(); !ok {
|
||||
return &ValidationError{Name: "text", err: errors.New(`ent: missing required field "Post.text"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *PostCreate) sqlSave(ctx context.Context) (*Post, 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 *PostCreate) createSpec() (*Post, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Post{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(post.Table, sqlgraph.NewFieldSpec(post.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.Text(); ok {
|
||||
_spec.SetField(post.FieldText, field.TypeString, value)
|
||||
_node.Text = value
|
||||
}
|
||||
if nodes := _c.mutation.AuthorIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: post.AuthorTable,
|
||||
Columns: []string{post.AuthorColumn},
|
||||
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.AuthorID = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// PostCreateBulk is the builder for creating many Post entities in bulk.
|
||||
type PostCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*PostCreate
|
||||
}
|
||||
|
||||
// Save creates the Post entities in the database.
|
||||
func (_c *PostCreateBulk) Save(ctx context.Context) ([]*Post, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Post, 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.(*PostMutation)
|
||||
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 *PostCreateBulk) SaveX(ctx context.Context) []*Post {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *PostCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *PostCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/edgefield/ent/post_delete.go
Normal file
92
entc/integration/edgefield/ent/post_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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/post"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// PostDelete is the builder for deleting a Post entity.
|
||||
type PostDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *PostMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the PostDelete builder.
|
||||
func (_d *PostDelete) Where(ps ...predicate.Post) *PostDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *PostDelete) 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 *PostDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *PostDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(post.Table, sqlgraph.NewFieldSpec(post.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
|
||||
}
|
||||
|
||||
// PostDeleteOne is the builder for deleting a single Post entity.
|
||||
type PostDeleteOne struct {
|
||||
_d *PostDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the PostDelete builder.
|
||||
func (_d *PostDeleteOne) Where(ps ...predicate.Post) *PostDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *PostDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{post.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *PostDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
613
entc/integration/edgefield/ent/post_query.go
Normal file
613
entc/integration/edgefield/ent/post_query.go
Normal file
@@ -0,0 +1,613 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/post"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// PostQuery is the builder for querying Post entities.
|
||||
type PostQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []post.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Post
|
||||
withAuthor *UserQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the PostQuery builder.
|
||||
func (_q *PostQuery) Where(ps ...predicate.Post) *PostQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *PostQuery) Limit(limit int) *PostQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *PostQuery) Offset(offset int) *PostQuery {
|
||||
_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 *PostQuery) Unique(unique bool) *PostQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *PostQuery) Order(o ...post.OrderOption) *PostQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryAuthor chains the current query on the "author" edge.
|
||||
func (_q *PostQuery) QueryAuthor() *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(post.Table, post.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, post.AuthorTable, post.AuthorColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Post entity from the query.
|
||||
// Returns a *NotFoundError when no Post was found.
|
||||
func (_q *PostQuery) First(ctx context.Context) (*Post, 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{post.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *PostQuery) FirstX(ctx context.Context) *Post {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Post ID from the query.
|
||||
// Returns a *NotFoundError when no Post ID was found.
|
||||
func (_q *PostQuery) 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{post.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *PostQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Post entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Post entity is found.
|
||||
// Returns a *NotFoundError when no Post entities are found.
|
||||
func (_q *PostQuery) Only(ctx context.Context) (*Post, 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{post.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{post.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *PostQuery) OnlyX(ctx context.Context) *Post {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Post ID in the query.
|
||||
// Returns a *NotSingularError when more than one Post ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *PostQuery) 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{post.Label}
|
||||
default:
|
||||
err = &NotSingularError{post.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *PostQuery) 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 Posts.
|
||||
func (_q *PostQuery) All(ctx context.Context) ([]*Post, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Post, *PostQuery]()
|
||||
return withInterceptors[[]*Post](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *PostQuery) AllX(ctx context.Context) []*Post {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Post IDs.
|
||||
func (_q *PostQuery) 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(post.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *PostQuery) 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 *PostQuery) 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[*PostQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *PostQuery) 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 *PostQuery) 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("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *PostQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the PostQuery 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 *PostQuery) Clone() *PostQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &PostQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]post.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Post{}, _q.predicates...),
|
||||
withAuthor: _q.withAuthor.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithAuthor tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "author" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *PostQuery) WithAuthor(opts ...func(*UserQuery)) *PostQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withAuthor = 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 {
|
||||
// Text string `json:"text,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Post.Query().
|
||||
// GroupBy(post.FieldText).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *PostQuery) GroupBy(field string, fields ...string) *PostGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &PostGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = post.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 {
|
||||
// Text string `json:"text,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Post.Query().
|
||||
// Select(post.FieldText).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *PostQuery) Select(fields ...string) *PostSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &PostSelect{PostQuery: _q}
|
||||
sbuild.label = post.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a PostSelect configured with the given aggregations.
|
||||
func (_q *PostQuery) Aggregate(fns ...AggregateFunc) *PostSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *PostQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !post.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: 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 *PostQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Post, error) {
|
||||
var (
|
||||
nodes = []*Post{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
_q.withAuthor != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Post).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Post{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.withAuthor; query != nil {
|
||||
if err := _q.loadAuthor(ctx, query, nodes, nil,
|
||||
func(n *Post, e *User) { n.Edges.Author = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *PostQuery) loadAuthor(ctx context.Context, query *UserQuery, nodes []*Post, init func(*Post), assign func(*Post, *User)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Post)
|
||||
for i := range nodes {
|
||||
if nodes[i].AuthorID == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].AuthorID
|
||||
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 "author_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *PostQuery) 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 *PostQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(post.Table, post.Columns, sqlgraph.NewFieldSpec(post.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, post.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != post.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
if _q.withAuthor != nil {
|
||||
_spec.Node.AddColumnOnce(post.FieldAuthorID)
|
||||
}
|
||||
}
|
||||
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 *PostQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(post.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = post.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
|
||||
}
|
||||
|
||||
// PostGroupBy is the group-by builder for Post entities.
|
||||
type PostGroupBy struct {
|
||||
selector
|
||||
build *PostQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *PostGroupBy) Aggregate(fns ...AggregateFunc) *PostGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *PostGroupBy) 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[*PostQuery, *PostGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *PostGroupBy) sqlScan(ctx context.Context, root *PostQuery, 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)
|
||||
}
|
||||
|
||||
// PostSelect is the builder for selecting fields of Post entities.
|
||||
type PostSelect struct {
|
||||
*PostQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *PostSelect) Aggregate(fns ...AggregateFunc) *PostSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *PostSelect) 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[*PostQuery, *PostSelect](ctx, _s.PostQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *PostSelect) sqlScan(ctx context.Context, root *PostQuery, 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)
|
||||
}
|
||||
334
entc/integration/edgefield/ent/post_update.go
Normal file
334
entc/integration/edgefield/ent/post_update.go
Normal file
@@ -0,0 +1,334 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/post"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// PostUpdate is the builder for updating Post entities.
|
||||
type PostUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *PostMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the PostUpdate builder.
|
||||
func (_u *PostUpdate) Where(ps ...predicate.Post) *PostUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetText sets the "text" field.
|
||||
func (_u *PostUpdate) SetText(v string) *PostUpdate {
|
||||
_u.mutation.SetText(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableText sets the "text" field if the given value is not nil.
|
||||
func (_u *PostUpdate) SetNillableText(v *string) *PostUpdate {
|
||||
if v != nil {
|
||||
_u.SetText(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAuthorID sets the "author_id" field.
|
||||
func (_u *PostUpdate) SetAuthorID(v int) *PostUpdate {
|
||||
_u.mutation.SetAuthorID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAuthorID sets the "author_id" field if the given value is not nil.
|
||||
func (_u *PostUpdate) SetNillableAuthorID(v *int) *PostUpdate {
|
||||
if v != nil {
|
||||
_u.SetAuthorID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearAuthorID clears the value of the "author_id" field.
|
||||
func (_u *PostUpdate) ClearAuthorID() *PostUpdate {
|
||||
_u.mutation.ClearAuthorID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAuthor sets the "author" edge to the User entity.
|
||||
func (_u *PostUpdate) SetAuthor(v *User) *PostUpdate {
|
||||
return _u.SetAuthorID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the PostMutation object of the builder.
|
||||
func (_u *PostUpdate) Mutation() *PostMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearAuthor clears the "author" edge to the User entity.
|
||||
func (_u *PostUpdate) ClearAuthor() *PostUpdate {
|
||||
_u.mutation.ClearAuthor()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *PostUpdate) 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 *PostUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *PostUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *PostUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *PostUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(post.Table, post.Columns, sqlgraph.NewFieldSpec(post.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.Text(); ok {
|
||||
_spec.SetField(post.FieldText, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.AuthorCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: post.AuthorTable,
|
||||
Columns: []string{post.AuthorColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.AuthorIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: post.AuthorTable,
|
||||
Columns: []string{post.AuthorColumn},
|
||||
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{post.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// PostUpdateOne is the builder for updating a single Post entity.
|
||||
type PostUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *PostMutation
|
||||
}
|
||||
|
||||
// SetText sets the "text" field.
|
||||
func (_u *PostUpdateOne) SetText(v string) *PostUpdateOne {
|
||||
_u.mutation.SetText(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableText sets the "text" field if the given value is not nil.
|
||||
func (_u *PostUpdateOne) SetNillableText(v *string) *PostUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetText(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAuthorID sets the "author_id" field.
|
||||
func (_u *PostUpdateOne) SetAuthorID(v int) *PostUpdateOne {
|
||||
_u.mutation.SetAuthorID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAuthorID sets the "author_id" field if the given value is not nil.
|
||||
func (_u *PostUpdateOne) SetNillableAuthorID(v *int) *PostUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetAuthorID(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearAuthorID clears the value of the "author_id" field.
|
||||
func (_u *PostUpdateOne) ClearAuthorID() *PostUpdateOne {
|
||||
_u.mutation.ClearAuthorID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAuthor sets the "author" edge to the User entity.
|
||||
func (_u *PostUpdateOne) SetAuthor(v *User) *PostUpdateOne {
|
||||
return _u.SetAuthorID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the PostMutation object of the builder.
|
||||
func (_u *PostUpdateOne) Mutation() *PostMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearAuthor clears the "author" edge to the User entity.
|
||||
func (_u *PostUpdateOne) ClearAuthor() *PostUpdateOne {
|
||||
_u.mutation.ClearAuthor()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the PostUpdate builder.
|
||||
func (_u *PostUpdateOne) Where(ps ...predicate.Post) *PostUpdateOne {
|
||||
_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 *PostUpdateOne) Select(field string, fields ...string) *PostUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Post entity.
|
||||
func (_u *PostUpdateOne) Save(ctx context.Context) (*Post, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *PostUpdateOne) SaveX(ctx context.Context) *Post {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *PostUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *PostUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *PostUpdateOne) sqlSave(ctx context.Context) (_node *Post, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(post.Table, post.Columns, sqlgraph.NewFieldSpec(post.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Post.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, post.FieldID)
|
||||
for _, f := range fields {
|
||||
if !post.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != post.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.Text(); ok {
|
||||
_spec.SetField(post.FieldText, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.AuthorCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: post.AuthorTable,
|
||||
Columns: []string{post.AuthorColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.AuthorIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: post.AuthorTable,
|
||||
Columns: []string{post.AuthorColumn},
|
||||
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 = &Post{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{post.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
38
entc/integration/edgefield/ent/predicate/predicate.go
Normal file
38
entc/integration/edgefield/ent/predicate/predicate.go
Normal file
@@ -0,0 +1,38 @@
|
||||
// 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)
|
||||
|
||||
// Card is the predicate function for card builders.
|
||||
type Card func(*sql.Selector)
|
||||
|
||||
// Info is the predicate function for info builders.
|
||||
type Info func(*sql.Selector)
|
||||
|
||||
// Metadata is the predicate function for metadata builders.
|
||||
type Metadata func(*sql.Selector)
|
||||
|
||||
// Node is the predicate function for node builders.
|
||||
type Node func(*sql.Selector)
|
||||
|
||||
// Pet is the predicate function for pet builders.
|
||||
type Pet func(*sql.Selector)
|
||||
|
||||
// Post is the predicate function for post builders.
|
||||
type Post func(*sql.Selector)
|
||||
|
||||
// Rental is the predicate function for rental builders.
|
||||
type Rental func(*sql.Selector)
|
||||
|
||||
// User is the predicate function for user builders.
|
||||
type User func(*sql.Selector)
|
||||
181
entc/integration/edgefield/ent/rental.go
Normal file
181
entc/integration/edgefield/ent/rental.go
Normal file
@@ -0,0 +1,181 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/car"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/rental"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Rental is the model entity for the Rental schema.
|
||||
type Rental struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Date holds the value of the "date" field.
|
||||
Date time.Time `json:"date,omitempty"`
|
||||
// UserID holds the value of the "user_id" field.
|
||||
UserID int `json:"user_id,omitempty"`
|
||||
// CarID holds the value of the "car_id" field.
|
||||
CarID uuid.UUID `json:"car_id,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the RentalQuery when eager-loading is set.
|
||||
Edges RentalEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// RentalEdges holds the relations/edges for other nodes in the graph.
|
||||
type RentalEdges struct {
|
||||
// User holds the value of the user edge.
|
||||
User *User `json:"user,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 [2]bool
|
||||
}
|
||||
|
||||
// UserOrErr returns the User value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e RentalEdges) UserOrErr() (*User, error) {
|
||||
if e.User != nil {
|
||||
return e.User, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// 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 RentalEdges) CarOrErr() (*Car, error) {
|
||||
if e.Car != nil {
|
||||
return e.Car, nil
|
||||
} else if e.loadedTypes[1] {
|
||||
return nil, &NotFoundError{label: car.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "car"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Rental) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case rental.FieldID, rental.FieldUserID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case rental.FieldDate:
|
||||
values[i] = new(sql.NullTime)
|
||||
case rental.FieldCarID:
|
||||
values[i] = new(uuid.UUID)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Rental fields.
|
||||
func (_m *Rental) 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 rental.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 rental.FieldDate:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field date", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Date = value.Time
|
||||
}
|
||||
case rental.FieldUserID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field user_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.UserID = int(value.Int64)
|
||||
}
|
||||
case rental.FieldCarID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field car_id", values[i])
|
||||
} else if value != nil {
|
||||
_m.CarID = *value
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Rental.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Rental) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryUser queries the "user" edge of the Rental entity.
|
||||
func (_m *Rental) QueryUser() *UserQuery {
|
||||
return NewRentalClient(_m.config).QueryUser(_m)
|
||||
}
|
||||
|
||||
// QueryCar queries the "car" edge of the Rental entity.
|
||||
func (_m *Rental) QueryCar() *CarQuery {
|
||||
return NewRentalClient(_m.config).QueryCar(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Rental.
|
||||
// Note that you need to call Rental.Unwrap() before calling this method if this Rental
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Rental) Update() *RentalUpdateOne {
|
||||
return NewRentalClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Rental 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 *Rental) Unwrap() *Rental {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Rental is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Rental) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Rental(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("date=")
|
||||
builder.WriteString(_m.Date.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("user_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.UserID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("car_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.CarID))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Rentals is a parsable slice of Rental.
|
||||
type Rentals []*Rental
|
||||
408
entc/integration/edgefield/ent/rental/mutation.go
Normal file
408
entc/integration/edgefield/ent/rental/mutation.go
Normal file
@@ -0,0 +1,408 @@
|
||||
// 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 rental
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Rental nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
date *time.Time
|
||||
clearedFields map[string]struct{}
|
||||
user *int
|
||||
cleareduser bool
|
||||
car *uuid.UUID
|
||||
clearedcar bool
|
||||
predicates []predicate.Rental
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Rental entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Rental",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Rental {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetDate sets the "date" field.
|
||||
func (m *Mutation) SetDate(t time.Time) {
|
||||
m.date = &t
|
||||
}
|
||||
|
||||
// Date returns the value of the "date" field in the mutation.
|
||||
func (m *Mutation) Date() (r time.Time, exists bool) {
|
||||
v := m.date
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ResetDate resets all changes to the "date" field.
|
||||
func (m *Mutation) ResetDate() {
|
||||
m.date = nil
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (m *Mutation) SetUserID(i int) {
|
||||
m.user = &i
|
||||
}
|
||||
|
||||
// UserID returns the value of the "user_id" field in the mutation.
|
||||
func (m *Mutation) UserID() (r int, exists bool) {
|
||||
v := m.user
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ResetUserID resets all changes to the "user_id" field.
|
||||
func (m *Mutation) ResetUserID() {
|
||||
m.user = nil
|
||||
}
|
||||
|
||||
// SetCarID sets the "car_id" field.
|
||||
func (m *Mutation) SetCarID(u uuid.UUID) {
|
||||
m.car = &u
|
||||
}
|
||||
|
||||
// CarID returns the value of the "car_id" field in the mutation.
|
||||
func (m *Mutation) CarID() (r uuid.UUID, exists bool) {
|
||||
v := m.car
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ResetCarID resets all changes to the "car_id" field.
|
||||
func (m *Mutation) ResetCarID() {
|
||||
m.car = nil
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (m *Mutation) ClearUser() {
|
||||
m.cleareduser = true
|
||||
m.clearedFields[FieldUserID] = struct{}{}
|
||||
}
|
||||
|
||||
// UserCleared reports if the "user" edge to the User entity was cleared.
|
||||
func (m *Mutation) UserCleared() bool {
|
||||
return m.cleareduser
|
||||
}
|
||||
|
||||
// UserIDs returns the "user" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// UserID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) UserIDs() (ids []int) {
|
||||
if id := m.user; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetUser resets all changes to the "user" edge.
|
||||
func (m *Mutation) ResetUser() {
|
||||
m.user = nil
|
||||
m.cleareduser = false
|
||||
}
|
||||
|
||||
// ClearCar clears the "car" edge to the Car entity.
|
||||
func (m *Mutation) ClearCar() {
|
||||
m.clearedcar = true
|
||||
m.clearedFields[FieldCarID] = struct{}{}
|
||||
}
|
||||
|
||||
// CarCleared reports if the "car" edge to the Car entity was cleared.
|
||||
func (m *Mutation) CarCleared() bool {
|
||||
return m.clearedcar
|
||||
}
|
||||
|
||||
// CarIDs returns the "car" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// CarID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) CarIDs() (ids []uuid.UUID) {
|
||||
if id := m.car; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetCar resets all changes to the "car" edge.
|
||||
func (m *Mutation) ResetCar() {
|
||||
m.car = nil
|
||||
m.clearedcar = false
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.Rental) {
|
||||
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.Rental, 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 (Rental).
|
||||
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, 3)
|
||||
if m.date != nil {
|
||||
fields = append(fields, FieldDate)
|
||||
}
|
||||
if m.user != nil {
|
||||
fields = append(fields, FieldUserID)
|
||||
}
|
||||
if m.car != nil {
|
||||
fields = append(fields, FieldCarID)
|
||||
}
|
||||
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 FieldDate:
|
||||
return m.Date()
|
||||
case FieldUserID:
|
||||
return m.UserID()
|
||||
case FieldCarID:
|
||||
return m.CarID()
|
||||
}
|
||||
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 Rental 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 FieldDate:
|
||||
v, ok := value.(time.Time)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetDate(v)
|
||||
return nil
|
||||
case FieldUserID:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUserID(v)
|
||||
return nil
|
||||
case FieldCarID:
|
||||
v, ok := value.(uuid.UUID)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetCarID(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Rental field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *Mutation) AddedFields() []string {
|
||||
var fields []string
|
||||
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 {
|
||||
}
|
||||
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 Rental 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 Rental 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 FieldDate:
|
||||
m.ResetDate()
|
||||
return nil
|
||||
case FieldUserID:
|
||||
m.ResetUserID()
|
||||
return nil
|
||||
case FieldCarID:
|
||||
m.ResetCarID()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Rental field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *Mutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 2)
|
||||
if m.user != nil {
|
||||
edges = append(edges, EdgeUser)
|
||||
}
|
||||
if m.car != nil {
|
||||
edges = append(edges, EdgeCar)
|
||||
}
|
||||
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 EdgeUser:
|
||||
if id := m.user; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
case EdgeCar:
|
||||
if id := m.car; 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, 2)
|
||||
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, 2)
|
||||
if m.cleareduser {
|
||||
edges = append(edges, EdgeUser)
|
||||
}
|
||||
if m.clearedcar {
|
||||
edges = append(edges, EdgeCar)
|
||||
}
|
||||
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 EdgeUser:
|
||||
return m.cleareduser
|
||||
case EdgeCar:
|
||||
return m.clearedcar
|
||||
}
|
||||
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 EdgeUser:
|
||||
m.ClearUser()
|
||||
return nil
|
||||
case EdgeCar:
|
||||
m.ClearCar()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Rental 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 EdgeUser:
|
||||
m.ResetUser()
|
||||
return nil
|
||||
case EdgeCar:
|
||||
m.ResetCar()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Rental edge %s", name)
|
||||
}
|
||||
121
entc/integration/edgefield/ent/rental/rental.go
Normal file
121
entc/integration/edgefield/ent/rental/rental.go
Normal file
@@ -0,0 +1,121 @@
|
||||
// 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 rental
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the rental type in the database.
|
||||
Label = "rental"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldDate holds the string denoting the date field in the database.
|
||||
FieldDate = "date"
|
||||
// FieldUserID holds the string denoting the user_id field in the database.
|
||||
FieldUserID = "user_id"
|
||||
// FieldCarID holds the string denoting the car_id field in the database.
|
||||
FieldCarID = "car_id"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// EdgeCar holds the string denoting the car edge name in mutations.
|
||||
EdgeCar = "car"
|
||||
// Table holds the table name of the rental in the database.
|
||||
Table = "rentals"
|
||||
// UserTable is the table that holds the user relation/edge.
|
||||
UserTable = "rentals"
|
||||
// UserInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
UserInverseTable = "users"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "user_id"
|
||||
// CarTable is the table that holds the car relation/edge.
|
||||
CarTable = "rentals"
|
||||
// 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 = "cars"
|
||||
// CarColumn is the table column denoting the car relation/edge.
|
||||
CarColumn = "car_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for rental fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldDate,
|
||||
FieldUserID,
|
||||
FieldCarID,
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultDate holds the default value on creation for the "date" field.
|
||||
DefaultDate func() time.Time
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the Rental 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()
|
||||
}
|
||||
|
||||
// ByDate orders the results by the date field.
|
||||
func ByDate(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDate, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserID orders the results by the user_id field.
|
||||
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUserID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCarID orders the results by the car_id field.
|
||||
func ByCarID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCarID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserField orders the results by user field.
|
||||
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newUserStep(), 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 newUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
}
|
||||
func newCarStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(CarInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, CarTable, CarColumn),
|
||||
)
|
||||
}
|
||||
217
entc/integration/edgefield/ent/rental/where.go
Normal file
217
entc/integration/edgefield/ent/rental/where.go
Normal file
@@ -0,0 +1,217 @@
|
||||
// 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 rental
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Date applies equality check predicate on the "date" field. It's identical to DateEQ.
|
||||
func Date(v time.Time) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldEQ(FieldDate, v))
|
||||
}
|
||||
|
||||
// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ.
|
||||
func UserID(v int) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// CarID applies equality check predicate on the "car_id" field. It's identical to CarIDEQ.
|
||||
func CarID(v uuid.UUID) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldEQ(FieldCarID, v))
|
||||
}
|
||||
|
||||
// DateEQ applies the EQ predicate on the "date" field.
|
||||
func DateEQ(v time.Time) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldEQ(FieldDate, v))
|
||||
}
|
||||
|
||||
// DateNEQ applies the NEQ predicate on the "date" field.
|
||||
func DateNEQ(v time.Time) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldNEQ(FieldDate, v))
|
||||
}
|
||||
|
||||
// DateIn applies the In predicate on the "date" field.
|
||||
func DateIn(vs ...time.Time) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldIn(FieldDate, vs...))
|
||||
}
|
||||
|
||||
// DateNotIn applies the NotIn predicate on the "date" field.
|
||||
func DateNotIn(vs ...time.Time) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldNotIn(FieldDate, vs...))
|
||||
}
|
||||
|
||||
// DateGT applies the GT predicate on the "date" field.
|
||||
func DateGT(v time.Time) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldGT(FieldDate, v))
|
||||
}
|
||||
|
||||
// DateGTE applies the GTE predicate on the "date" field.
|
||||
func DateGTE(v time.Time) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldGTE(FieldDate, v))
|
||||
}
|
||||
|
||||
// DateLT applies the LT predicate on the "date" field.
|
||||
func DateLT(v time.Time) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldLT(FieldDate, v))
|
||||
}
|
||||
|
||||
// DateLTE applies the LTE predicate on the "date" field.
|
||||
func DateLTE(v time.Time) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldLTE(FieldDate, v))
|
||||
}
|
||||
|
||||
// UserIDEQ applies the EQ predicate on the "user_id" field.
|
||||
func UserIDEQ(v int) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDNEQ applies the NEQ predicate on the "user_id" field.
|
||||
func UserIDNEQ(v int) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldNEQ(FieldUserID, v))
|
||||
}
|
||||
|
||||
// UserIDIn applies the In predicate on the "user_id" field.
|
||||
func UserIDIn(vs ...int) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// UserIDNotIn applies the NotIn predicate on the "user_id" field.
|
||||
func UserIDNotIn(vs ...int) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldNotIn(FieldUserID, vs...))
|
||||
}
|
||||
|
||||
// CarIDEQ applies the EQ predicate on the "car_id" field.
|
||||
func CarIDEQ(v uuid.UUID) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldEQ(FieldCarID, v))
|
||||
}
|
||||
|
||||
// CarIDNEQ applies the NEQ predicate on the "car_id" field.
|
||||
func CarIDNEQ(v uuid.UUID) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldNEQ(FieldCarID, v))
|
||||
}
|
||||
|
||||
// CarIDIn applies the In predicate on the "car_id" field.
|
||||
func CarIDIn(vs ...uuid.UUID) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldIn(FieldCarID, vs...))
|
||||
}
|
||||
|
||||
// CarIDNotIn applies the NotIn predicate on the "car_id" field.
|
||||
func CarIDNotIn(vs ...uuid.UUID) predicate.Rental {
|
||||
return predicate.Rental(sql.FieldNotIn(FieldCarID, vs...))
|
||||
}
|
||||
|
||||
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||
func HasUser() predicate.Rental {
|
||||
return predicate.Rental(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||
func HasUserWith(preds ...predicate.User) predicate.Rental {
|
||||
return predicate.Rental(func(s *sql.Selector) {
|
||||
step := newUserStep()
|
||||
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.Rental {
|
||||
return predicate.Rental(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, 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.Rental {
|
||||
return predicate.Rental(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.Rental) predicate.Rental {
|
||||
return predicate.Rental(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Rental) predicate.Rental {
|
||||
return predicate.Rental(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Rental) predicate.Rental {
|
||||
return predicate.Rental(sql.NotPredicates(p))
|
||||
}
|
||||
277
entc/integration/edgefield/ent/rental_create.go
Normal file
277
entc/integration/edgefield/ent/rental_create.go
Normal file
@@ -0,0 +1,277 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/car"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/rental"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// RentalCreate is the builder for creating a Rental entity.
|
||||
type RentalCreate struct {
|
||||
config
|
||||
mutation *RentalMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetDate sets the "date" field.
|
||||
func (_c *RentalCreate) SetDate(v time.Time) *RentalCreate {
|
||||
_c.mutation.SetDate(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableDate sets the "date" field if the given value is not nil.
|
||||
func (_c *RentalCreate) SetNillableDate(v *time.Time) *RentalCreate {
|
||||
if v != nil {
|
||||
_c.SetDate(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_c *RentalCreate) SetUserID(v int) *RentalCreate {
|
||||
_c.mutation.SetUserID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCarID sets the "car_id" field.
|
||||
func (_c *RentalCreate) SetCarID(v uuid.UUID) *RentalCreate {
|
||||
_c.mutation.SetCarID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (_c *RentalCreate) SetUser(v *User) *RentalCreate {
|
||||
return _c.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// SetCar sets the "car" edge to the Car entity.
|
||||
func (_c *RentalCreate) SetCar(v *Car) *RentalCreate {
|
||||
return _c.SetCarID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the RentalMutation object of the builder.
|
||||
func (_c *RentalCreate) Mutation() *RentalMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Rental in the database.
|
||||
func (_c *RentalCreate) Save(ctx context.Context) (*Rental, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *RentalCreate) SaveX(ctx context.Context) *Rental {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *RentalCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *RentalCreate) 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 *RentalCreate) defaults() {
|
||||
if _, ok := _c.mutation.Date(); !ok {
|
||||
v := rental.DefaultDate()
|
||||
_c.mutation.SetDate(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *RentalCreate) check() error {
|
||||
if _, ok := _c.mutation.Date(); !ok {
|
||||
return &ValidationError{Name: "date", err: errors.New(`ent: missing required field "Rental.date"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "Rental.user_id"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.CarID(); !ok {
|
||||
return &ValidationError{Name: "car_id", err: errors.New(`ent: missing required field "Rental.car_id"`)}
|
||||
}
|
||||
if len(_c.mutation.UserIDs()) == 0 {
|
||||
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "Rental.user"`)}
|
||||
}
|
||||
if len(_c.mutation.CarIDs()) == 0 {
|
||||
return &ValidationError{Name: "car", err: errors.New(`ent: missing required edge "Rental.car"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *RentalCreate) sqlSave(ctx context.Context) (*Rental, 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 *RentalCreate) createSpec() (*Rental, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Rental{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(rental.Table, sqlgraph.NewFieldSpec(rental.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.Date(); ok {
|
||||
_spec.SetField(rental.FieldDate, field.TypeTime, value)
|
||||
_node.Date = value
|
||||
}
|
||||
if nodes := _c.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: rental.UserTable,
|
||||
Columns: []string{rental.UserColumn},
|
||||
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.UserID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.CarIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: rental.CarTable,
|
||||
Columns: []string{rental.CarColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(car.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.CarID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// RentalCreateBulk is the builder for creating many Rental entities in bulk.
|
||||
type RentalCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*RentalCreate
|
||||
}
|
||||
|
||||
// Save creates the Rental entities in the database.
|
||||
func (_c *RentalCreateBulk) Save(ctx context.Context) ([]*Rental, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Rental, 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.(*RentalMutation)
|
||||
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 *RentalCreateBulk) SaveX(ctx context.Context) []*Rental {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *RentalCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *RentalCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/edgefield/ent/rental_delete.go
Normal file
92
entc/integration/edgefield/ent/rental_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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/rental"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// RentalDelete is the builder for deleting a Rental entity.
|
||||
type RentalDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *RentalMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the RentalDelete builder.
|
||||
func (_d *RentalDelete) Where(ps ...predicate.Rental) *RentalDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *RentalDelete) 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 *RentalDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *RentalDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(rental.Table, sqlgraph.NewFieldSpec(rental.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
|
||||
}
|
||||
|
||||
// RentalDeleteOne is the builder for deleting a single Rental entity.
|
||||
type RentalDeleteOne struct {
|
||||
_d *RentalDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the RentalDelete builder.
|
||||
func (_d *RentalDeleteOne) Where(ps ...predicate.Rental) *RentalDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *RentalDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{rental.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *RentalDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
686
entc/integration/edgefield/ent/rental_query.go
Normal file
686
entc/integration/edgefield/ent/rental_query.go
Normal file
@@ -0,0 +1,686 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/car"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/rental"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// RentalQuery is the builder for querying Rental entities.
|
||||
type RentalQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []rental.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Rental
|
||||
withUser *UserQuery
|
||||
withCar *CarQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the RentalQuery builder.
|
||||
func (_q *RentalQuery) Where(ps ...predicate.Rental) *RentalQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *RentalQuery) Limit(limit int) *RentalQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *RentalQuery) Offset(offset int) *RentalQuery {
|
||||
_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 *RentalQuery) Unique(unique bool) *RentalQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *RentalQuery) Order(o ...rental.OrderOption) *RentalQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryUser chains the current query on the "user" edge.
|
||||
func (_q *RentalQuery) QueryUser() *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(rental.Table, rental.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, rental.UserTable, rental.UserColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryCar chains the current query on the "car" edge.
|
||||
func (_q *RentalQuery) 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(rental.Table, rental.FieldID, selector),
|
||||
sqlgraph.To(car.Table, car.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, rental.CarTable, rental.CarColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Rental entity from the query.
|
||||
// Returns a *NotFoundError when no Rental was found.
|
||||
func (_q *RentalQuery) First(ctx context.Context) (*Rental, 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{rental.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *RentalQuery) FirstX(ctx context.Context) *Rental {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Rental ID from the query.
|
||||
// Returns a *NotFoundError when no Rental ID was found.
|
||||
func (_q *RentalQuery) 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{rental.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *RentalQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Rental entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Rental entity is found.
|
||||
// Returns a *NotFoundError when no Rental entities are found.
|
||||
func (_q *RentalQuery) Only(ctx context.Context) (*Rental, 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{rental.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{rental.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *RentalQuery) OnlyX(ctx context.Context) *Rental {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Rental ID in the query.
|
||||
// Returns a *NotSingularError when more than one Rental ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *RentalQuery) 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{rental.Label}
|
||||
default:
|
||||
err = &NotSingularError{rental.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *RentalQuery) 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 Rentals.
|
||||
func (_q *RentalQuery) All(ctx context.Context) ([]*Rental, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Rental, *RentalQuery]()
|
||||
return withInterceptors[[]*Rental](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *RentalQuery) AllX(ctx context.Context) []*Rental {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Rental IDs.
|
||||
func (_q *RentalQuery) 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(rental.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *RentalQuery) 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 *RentalQuery) 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[*RentalQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *RentalQuery) 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 *RentalQuery) 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("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *RentalQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the RentalQuery 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 *RentalQuery) Clone() *RentalQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &RentalQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]rental.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Rental{}, _q.predicates...),
|
||||
withUser: _q.withUser.Clone(),
|
||||
withCar: _q.withCar.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *RentalQuery) WithUser(opts ...func(*UserQuery)) *RentalQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withUser = 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 *RentalQuery) WithCar(opts ...func(*CarQuery)) *RentalQuery {
|
||||
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 {
|
||||
// Date time.Time `json:"date,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Rental.Query().
|
||||
// GroupBy(rental.FieldDate).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *RentalQuery) GroupBy(field string, fields ...string) *RentalGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &RentalGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = rental.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 {
|
||||
// Date time.Time `json:"date,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Rental.Query().
|
||||
// Select(rental.FieldDate).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *RentalQuery) Select(fields ...string) *RentalSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &RentalSelect{RentalQuery: _q}
|
||||
sbuild.label = rental.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a RentalSelect configured with the given aggregations.
|
||||
func (_q *RentalQuery) Aggregate(fns ...AggregateFunc) *RentalSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *RentalQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !rental.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: 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 *RentalQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Rental, error) {
|
||||
var (
|
||||
nodes = []*Rental{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [2]bool{
|
||||
_q.withUser != nil,
|
||||
_q.withCar != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Rental).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Rental{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.withUser; query != nil {
|
||||
if err := _q.loadUser(ctx, query, nodes, nil,
|
||||
func(n *Rental, e *User) { n.Edges.User = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withCar; query != nil {
|
||||
if err := _q.loadCar(ctx, query, nodes, nil,
|
||||
func(n *Rental, e *Car) { n.Edges.Car = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *RentalQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*Rental, init func(*Rental), assign func(*Rental, *User)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Rental)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].UserID
|
||||
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_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *RentalQuery) loadCar(ctx context.Context, query *CarQuery, nodes []*Rental, init func(*Rental), assign func(*Rental, *Car)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*Rental)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].CarID
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(car.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 "car_id" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *RentalQuery) 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 *RentalQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(rental.Table, rental.Columns, sqlgraph.NewFieldSpec(rental.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, rental.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != rental.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
if _q.withUser != nil {
|
||||
_spec.Node.AddColumnOnce(rental.FieldUserID)
|
||||
}
|
||||
if _q.withCar != nil {
|
||||
_spec.Node.AddColumnOnce(rental.FieldCarID)
|
||||
}
|
||||
}
|
||||
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 *RentalQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(rental.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = rental.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
|
||||
}
|
||||
|
||||
// RentalGroupBy is the group-by builder for Rental entities.
|
||||
type RentalGroupBy struct {
|
||||
selector
|
||||
build *RentalQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *RentalGroupBy) Aggregate(fns ...AggregateFunc) *RentalGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *RentalGroupBy) 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[*RentalQuery, *RentalGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *RentalGroupBy) sqlScan(ctx context.Context, root *RentalQuery, 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)
|
||||
}
|
||||
|
||||
// RentalSelect is the builder for selecting fields of Rental entities.
|
||||
type RentalSelect struct {
|
||||
*RentalQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *RentalSelect) Aggregate(fns ...AggregateFunc) *RentalSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *RentalSelect) 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[*RentalQuery, *RentalSelect](ctx, _s.RentalQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *RentalSelect) sqlScan(ctx context.Context, root *RentalQuery, 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)
|
||||
}
|
||||
242
entc/integration/edgefield/ent/rental_update.go
Normal file
242
entc/integration/edgefield/ent/rental_update.go
Normal file
@@ -0,0 +1,242 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/rental"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// RentalUpdate is the builder for updating Rental entities.
|
||||
type RentalUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *RentalMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the RentalUpdate builder.
|
||||
func (_u *RentalUpdate) Where(ps ...predicate.Rental) *RentalUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetDate sets the "date" field.
|
||||
func (_u *RentalUpdate) SetDate(v time.Time) *RentalUpdate {
|
||||
_u.mutation.SetDate(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableDate sets the "date" field if the given value is not nil.
|
||||
func (_u *RentalUpdate) SetNillableDate(v *time.Time) *RentalUpdate {
|
||||
if v != nil {
|
||||
_u.SetDate(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the RentalMutation object of the builder.
|
||||
func (_u *RentalUpdate) Mutation() *RentalMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *RentalUpdate) 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 *RentalUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *RentalUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *RentalUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *RentalUpdate) check() error {
|
||||
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "Rental.user"`)
|
||||
}
|
||||
if _u.mutation.CarCleared() && len(_u.mutation.CarIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "Rental.car"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *RentalUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(rental.Table, rental.Columns, sqlgraph.NewFieldSpec(rental.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.Date(); ok {
|
||||
_spec.SetField(rental.FieldDate, field.TypeTime, value)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{rental.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// RentalUpdateOne is the builder for updating a single Rental entity.
|
||||
type RentalUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *RentalMutation
|
||||
}
|
||||
|
||||
// SetDate sets the "date" field.
|
||||
func (_u *RentalUpdateOne) SetDate(v time.Time) *RentalUpdateOne {
|
||||
_u.mutation.SetDate(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableDate sets the "date" field if the given value is not nil.
|
||||
func (_u *RentalUpdateOne) SetNillableDate(v *time.Time) *RentalUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetDate(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the RentalMutation object of the builder.
|
||||
func (_u *RentalUpdateOne) Mutation() *RentalMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the RentalUpdate builder.
|
||||
func (_u *RentalUpdateOne) Where(ps ...predicate.Rental) *RentalUpdateOne {
|
||||
_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 *RentalUpdateOne) Select(field string, fields ...string) *RentalUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Rental entity.
|
||||
func (_u *RentalUpdateOne) Save(ctx context.Context) (*Rental, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *RentalUpdateOne) SaveX(ctx context.Context) *Rental {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *RentalUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *RentalUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *RentalUpdateOne) check() error {
|
||||
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "Rental.user"`)
|
||||
}
|
||||
if _u.mutation.CarCleared() && len(_u.mutation.CarIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "Rental.car"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *RentalUpdateOne) sqlSave(ctx context.Context) (_node *Rental, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(rental.Table, rental.Columns, sqlgraph.NewFieldSpec(rental.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Rental.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, rental.FieldID)
|
||||
for _, f := range fields {
|
||||
if !rental.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != rental.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.Date(); ok {
|
||||
_spec.SetField(rental.FieldDate, field.TypeTime, value)
|
||||
}
|
||||
_node = &Rental{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{rental.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
48
entc/integration/edgefield/ent/runtime.go
Normal file
48
entc/integration/edgefield/ent/runtime.go
Normal file
@@ -0,0 +1,48 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/car"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/metadata"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/node"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/rental"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/schema"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// 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() {
|
||||
carFields := schema.Car{}.Fields()
|
||||
_ = carFields
|
||||
// carDescID is the schema descriptor for id field.
|
||||
carDescID := carFields[0].Descriptor()
|
||||
// car.DefaultID holds the default value on creation for the id field.
|
||||
car.DefaultID = carDescID.Default.(func() uuid.UUID)
|
||||
metadataFields := schema.Metadata{}.Fields()
|
||||
_ = metadataFields
|
||||
// metadataDescAge is the schema descriptor for age field.
|
||||
metadataDescAge := metadataFields[1].Descriptor()
|
||||
// metadata.DefaultAge holds the default value on creation for the age field.
|
||||
metadata.DefaultAge = metadataDescAge.Default.(int)
|
||||
nodeFields := schema.Node{}.Fields()
|
||||
_ = nodeFields
|
||||
// nodeDescValue is the schema descriptor for value field.
|
||||
nodeDescValue := nodeFields[0].Descriptor()
|
||||
// node.DefaultValue holds the default value on creation for the value field.
|
||||
node.DefaultValue = nodeDescValue.Default.(int)
|
||||
rentalFields := schema.Rental{}.Fields()
|
||||
_ = rentalFields
|
||||
// rentalDescDate is the schema descriptor for date field.
|
||||
rentalDescDate := rentalFields[0].Descriptor()
|
||||
// rental.DefaultDate holds the default value on creation for the date field.
|
||||
rental.DefaultDate = rentalDescDate.Default.(func() time.Time)
|
||||
}
|
||||
13
entc/integration/edgefield/ent/runtime/runtime.go
Normal file
13
entc/integration/edgefield/ent/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/edgefield/ent/runtime.go
|
||||
|
||||
const (
|
||||
Version = "v0.0.0-00010101000000-000000000000" // Version of ent codegen.
|
||||
)
|
||||
34
entc/integration/edgefield/ent/schema/car.go
Normal file
34
entc/integration/edgefield/ent/schema/car.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Car holds the schema definition for the Car entity.
|
||||
type Car struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Car.
|
||||
func (Car) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.UUID{}).
|
||||
Default(uuid.New),
|
||||
field.String("number").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Car.
|
||||
func (Car) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("rentals", Rental.Type),
|
||||
}
|
||||
}
|
||||
44
entc/integration/edgefield/ent/schema/card.go
Normal file
44
entc/integration/edgefield/ent/schema/card.go
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// Card holds the schema definition for the Card entity.
|
||||
type Card struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Card.
|
||||
func (Card) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("number").
|
||||
Optional(),
|
||||
field.Int("owner_id").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Card.
|
||||
func (Card) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("owner", User.Type).
|
||||
Ref("card").
|
||||
Field("owner_id").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
// Indexes of the Card.
|
||||
func (Card) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("number", "owner_id"),
|
||||
}
|
||||
}
|
||||
33
entc/integration/edgefield/ent/schema/info.go
Normal file
33
entc/integration/edgefield/ent/schema/info.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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 (
|
||||
"encoding/json"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Info holds the schema definition for the Info entity.
|
||||
type Info struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Info) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id"),
|
||||
field.JSON("content", json.RawMessage{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (Info) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("user", User.Type).
|
||||
Unique().
|
||||
StorageKey(edge.Column("id")),
|
||||
}
|
||||
}
|
||||
37
entc/integration/edgefield/ent/schema/metadata.go
Normal file
37
entc/integration/edgefield/ent/schema/metadata.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Metadata holds the schema definition for the Metadata entity.
|
||||
type Metadata struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Metadata) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id"),
|
||||
field.Int("age").
|
||||
Default(0),
|
||||
field.Int("parent_id").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
func (Metadata) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("user", User.Type).
|
||||
Ref("metadata").
|
||||
Unique(),
|
||||
edge.To("parent", Metadata.Type).
|
||||
Field("parent_id").
|
||||
Unique().
|
||||
From("children"),
|
||||
}
|
||||
}
|
||||
37
entc/integration/edgefield/ent/schema/node.go
Normal file
37
entc/integration/edgefield/ent/schema/node.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// 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/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Node holds the schema definition for the Node entity.
|
||||
type Node struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Node.
|
||||
func (Node) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("value").
|
||||
Default(0),
|
||||
field.Int("prev_id").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Node.
|
||||
func (Node) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("next", Node.Type).
|
||||
Unique().
|
||||
From("prev").
|
||||
Field("prev_id").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
34
entc/integration/edgefield/ent/schema/pet.go
Normal file
34
entc/integration/edgefield/ent/schema/pet.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Pet holds the schema definition for the Pet entity.
|
||||
type Pet struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Pet.
|
||||
func (Pet) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("owner_id").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Dog.
|
||||
func (Pet) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("owner", User.Type).
|
||||
Ref("pets").
|
||||
Field("owner_id").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
43
entc/integration/edgefield/ent/schema/post.go
Normal file
43
entc/integration/edgefield/ent/schema/post.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// 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/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// Post holds the schema definition for the Post entity.
|
||||
type Post struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Post.
|
||||
func (Post) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("text"),
|
||||
field.Int("author_id").
|
||||
Optional().
|
||||
Nillable(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Post.
|
||||
func (Post) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("author", User.Type).
|
||||
Field("author_id").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
// Indexes of the Post.
|
||||
func (Post) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("author_id", "text"),
|
||||
}
|
||||
}
|
||||
59
entc/integration/edgefield/ent/schema/rental.go
Normal file
59
entc/integration/edgefield/ent/schema/rental.go
Normal file
@@ -0,0 +1,59 @@
|
||||
// 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 (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// Rental holds the schema definition for the Rental entity.
|
||||
type Rental struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Rental.
|
||||
func (Rental) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Time("date").
|
||||
Default(time.Now),
|
||||
field.Int("user_id").
|
||||
Immutable(),
|
||||
field.UUID("car_id", uuid.UUID{}).
|
||||
Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Rental.
|
||||
func (Rental) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("user", User.Type).
|
||||
Ref("rentals").
|
||||
Field("user_id").
|
||||
Unique().
|
||||
Required().
|
||||
Immutable(),
|
||||
edge.From("car", Car.Type).
|
||||
Ref("rentals").
|
||||
Field("car_id").
|
||||
Unique().
|
||||
Required().
|
||||
Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
// Indexes of the Rental.
|
||||
func (Rental) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("car_id", "user_id").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
57
entc/integration/edgefield/ent/schema/user.go
Normal file
57
entc/integration/edgefield/ent/schema/user.go
Normal file
@@ -0,0 +1,57 @@
|
||||
// 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/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// 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").
|
||||
SchemaType(map[string]string{
|
||||
dialect.SQLite: "integer",
|
||||
}).
|
||||
Immutable(),
|
||||
field.Int("parent_id").
|
||||
Optional().
|
||||
Immutable(),
|
||||
field.Int("spouse_id").
|
||||
Optional(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the User.
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("pets", Pet.Type),
|
||||
edge.To("children", User.Type).
|
||||
From("parent").
|
||||
Field("parent_id").
|
||||
Immutable().
|
||||
Comment("The parent edge and its field are immutable").
|
||||
Unique(),
|
||||
edge.To("spouse", User.Type).
|
||||
Field("spouse_id").
|
||||
Unique(),
|
||||
edge.To("card", Card.Type).
|
||||
Unique(),
|
||||
edge.To("metadata", Metadata.Type).
|
||||
Unique().
|
||||
StorageKey(edge.Column("id")),
|
||||
edge.From("info", Info.Type).
|
||||
Ref("user"),
|
||||
edge.To("rentals", Rental.Type),
|
||||
}
|
||||
}
|
||||
238
entc/integration/edgefield/ent/tx.go
Normal file
238
entc/integration/edgefield/ent/tx.go
Normal file
@@ -0,0 +1,238 @@
|
||||
// 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 ent
|
||||
|
||||
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
|
||||
// Card is the client for interacting with the Card builders.
|
||||
Card *CardClient
|
||||
// Info is the client for interacting with the Info builders.
|
||||
Info *InfoClient
|
||||
// Metadata is the client for interacting with the Metadata builders.
|
||||
Metadata *MetadataClient
|
||||
// Node is the client for interacting with the Node builders.
|
||||
Node *NodeClient
|
||||
// Pet is the client for interacting with the Pet builders.
|
||||
Pet *PetClient
|
||||
// Post is the client for interacting with the Post builders.
|
||||
Post *PostClient
|
||||
// Rental is the client for interacting with the Rental builders.
|
||||
Rental *RentalClient
|
||||
// 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.Card = NewCardClient(tx.config)
|
||||
tx.Info = NewInfoClient(tx.config)
|
||||
tx.Metadata = NewMetadataClient(tx.config)
|
||||
tx.Node = NewNodeClient(tx.config)
|
||||
tx.Pet = NewPetClient(tx.config)
|
||||
tx.Post = NewPostClient(tx.config)
|
||||
tx.Rental = NewRentalClient(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)
|
||||
364
entc/integration/edgefield/ent/user.go
Normal file
364
entc/integration/edgefield/ent/user.go
Normal file
@@ -0,0 +1,364 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/card"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/metadata"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
)
|
||||
|
||||
// User is the model entity for the User schema.
|
||||
type User struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// ParentID holds the value of the "parent_id" field.
|
||||
ParentID int `json:"parent_id,omitempty"`
|
||||
// SpouseID holds the value of the "spouse_id" field.
|
||||
SpouseID int `json:"spouse_id,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"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// UserEdges holds the relations/edges for other nodes in the graph.
|
||||
type UserEdges struct {
|
||||
// Pets holds the value of the pets edge.
|
||||
Pets []*Pet `json:"pets,omitempty"`
|
||||
// The parent edge and its field are immutable
|
||||
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"`
|
||||
// Card holds the value of the card edge.
|
||||
Card *Card `json:"card,omitempty"`
|
||||
// Metadata holds the value of the metadata edge.
|
||||
Metadata *Metadata `json:"metadata,omitempty"`
|
||||
// Info holds the value of the info edge.
|
||||
Info []*Info `json:"info,omitempty"`
|
||||
// Rentals holds the value of the rentals edge.
|
||||
Rentals []*Rental `json:"rentals,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [8]bool
|
||||
namedPets map[string][]*Pet
|
||||
namedChildren map[string][]*User
|
||||
namedInfo map[string][]*Info
|
||||
namedRentals map[string][]*Rental
|
||||
}
|
||||
|
||||
// PetsOrErr returns the Pets value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e UserEdges) PetsOrErr() ([]*Pet, error) {
|
||||
if e.loadedTypes[0] {
|
||||
return e.Pets, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "pets"}
|
||||
}
|
||||
|
||||
// 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[1] {
|
||||
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[2] {
|
||||
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[3] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "spouse"}
|
||||
}
|
||||
|
||||
// CardOrErr returns the Card value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e UserEdges) CardOrErr() (*Card, error) {
|
||||
if e.Card != nil {
|
||||
return e.Card, nil
|
||||
} else if e.loadedTypes[4] {
|
||||
return nil, &NotFoundError{label: card.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "card"}
|
||||
}
|
||||
|
||||
// MetadataOrErr returns the Metadata value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e UserEdges) MetadataOrErr() (*Metadata, error) {
|
||||
if e.Metadata != nil {
|
||||
return e.Metadata, nil
|
||||
} else if e.loadedTypes[5] {
|
||||
return nil, &NotFoundError{label: metadata.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "metadata"}
|
||||
}
|
||||
|
||||
// InfoOrErr returns the Info value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e UserEdges) InfoOrErr() ([]*Info, error) {
|
||||
if e.loadedTypes[6] {
|
||||
return e.Info, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "info"}
|
||||
}
|
||||
|
||||
// RentalsOrErr returns the Rentals value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e UserEdges) RentalsOrErr() ([]*Rental, error) {
|
||||
if e.loadedTypes[7] {
|
||||
return e.Rentals, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "rentals"}
|
||||
}
|
||||
|
||||
// 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.FieldID, user.FieldParentID, user.FieldSpouseID:
|
||||
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.FieldParentID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field parent_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.ParentID = int(value.Int64)
|
||||
}
|
||||
case user.FieldSpouseID:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field spouse_id", values[i])
|
||||
} else if value.Valid {
|
||||
_m.SpouseID = 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)
|
||||
}
|
||||
|
||||
// QueryPets queries the "pets" edge of the User entity.
|
||||
func (_m *User) QueryPets() *PetQuery {
|
||||
return NewUserClient(_m.config).QueryPets(_m)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// QueryCard queries the "card" edge of the User entity.
|
||||
func (_m *User) QueryCard() *CardQuery {
|
||||
return NewUserClient(_m.config).QueryCard(_m)
|
||||
}
|
||||
|
||||
// QueryMetadata queries the "metadata" edge of the User entity.
|
||||
func (_m *User) QueryMetadata() *MetadataQuery {
|
||||
return NewUserClient(_m.config).QueryMetadata(_m)
|
||||
}
|
||||
|
||||
// QueryInfo queries the "info" edge of the User entity.
|
||||
func (_m *User) QueryInfo() *InfoQuery {
|
||||
return NewUserClient(_m.config).QueryInfo(_m)
|
||||
}
|
||||
|
||||
// QueryRentals queries the "rentals" edge of the User entity.
|
||||
func (_m *User) QueryRentals() *RentalQuery {
|
||||
return NewUserClient(_m.config).QueryRentals(_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("ent: 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("parent_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.ParentID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("spouse_id=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.SpouseID))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// NamedPets returns the Pets named value or an error if the edge was not
|
||||
// loaded in eager-loading with this name.
|
||||
func (_m *User) NamedPets(name string) ([]*Pet, error) {
|
||||
if _m.Edges.namedPets == nil {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
nodes, ok := _m.Edges.namedPets[name]
|
||||
if !ok {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_m *User) appendNamedPets(name string, edges ...*Pet) {
|
||||
if _m.Edges.namedPets == nil {
|
||||
_m.Edges.namedPets = make(map[string][]*Pet)
|
||||
}
|
||||
if len(edges) == 0 {
|
||||
_m.Edges.namedPets[name] = []*Pet{}
|
||||
} else {
|
||||
_m.Edges.namedPets[name] = append(_m.Edges.namedPets[name], edges...)
|
||||
}
|
||||
}
|
||||
|
||||
// NamedChildren returns the Children named value or an error if the edge was not
|
||||
// loaded in eager-loading with this name.
|
||||
func (_m *User) NamedChildren(name string) ([]*User, error) {
|
||||
if _m.Edges.namedChildren == nil {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
nodes, ok := _m.Edges.namedChildren[name]
|
||||
if !ok {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_m *User) appendNamedChildren(name string, edges ...*User) {
|
||||
if _m.Edges.namedChildren == nil {
|
||||
_m.Edges.namedChildren = make(map[string][]*User)
|
||||
}
|
||||
if len(edges) == 0 {
|
||||
_m.Edges.namedChildren[name] = []*User{}
|
||||
} else {
|
||||
_m.Edges.namedChildren[name] = append(_m.Edges.namedChildren[name], edges...)
|
||||
}
|
||||
}
|
||||
|
||||
// NamedInfo returns the Info named value or an error if the edge was not
|
||||
// loaded in eager-loading with this name.
|
||||
func (_m *User) NamedInfo(name string) ([]*Info, error) {
|
||||
if _m.Edges.namedInfo == nil {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
nodes, ok := _m.Edges.namedInfo[name]
|
||||
if !ok {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_m *User) appendNamedInfo(name string, edges ...*Info) {
|
||||
if _m.Edges.namedInfo == nil {
|
||||
_m.Edges.namedInfo = make(map[string][]*Info)
|
||||
}
|
||||
if len(edges) == 0 {
|
||||
_m.Edges.namedInfo[name] = []*Info{}
|
||||
} else {
|
||||
_m.Edges.namedInfo[name] = append(_m.Edges.namedInfo[name], edges...)
|
||||
}
|
||||
}
|
||||
|
||||
// NamedRentals returns the Rentals named value or an error if the edge was not
|
||||
// loaded in eager-loading with this name.
|
||||
func (_m *User) NamedRentals(name string) ([]*Rental, error) {
|
||||
if _m.Edges.namedRentals == nil {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
nodes, ok := _m.Edges.namedRentals[name]
|
||||
if !ok {
|
||||
return nil, &NotLoadedError{edge: name}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_m *User) appendNamedRentals(name string, edges ...*Rental) {
|
||||
if _m.Edges.namedRentals == nil {
|
||||
_m.Edges.namedRentals = make(map[string][]*Rental)
|
||||
}
|
||||
if len(edges) == 0 {
|
||||
_m.Edges.namedRentals[name] = []*Rental{}
|
||||
} else {
|
||||
_m.Edges.namedRentals[name] = append(_m.Edges.namedRentals[name], edges...)
|
||||
}
|
||||
}
|
||||
|
||||
// Users is a parsable slice of User.
|
||||
type Users []*User
|
||||
864
entc/integration/edgefield/ent/user/mutation.go
Normal file
864
entc/integration/edgefield/ent/user/mutation.go
Normal file
@@ -0,0 +1,864 @@
|
||||
// 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 (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the User nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
clearedFields map[string]struct{}
|
||||
pets map[int]struct{}
|
||||
removedpets map[int]struct{}
|
||||
clearedpets bool
|
||||
parent *int
|
||||
clearedparent bool
|
||||
children map[int]struct{}
|
||||
removedchildren map[int]struct{}
|
||||
clearedchildren bool
|
||||
spouse *int
|
||||
clearedspouse bool
|
||||
card *int
|
||||
clearedcard bool
|
||||
metadata *int
|
||||
clearedmetadata bool
|
||||
info map[int]struct{}
|
||||
removedinfo map[int]struct{}
|
||||
clearedinfo bool
|
||||
rentals map[int]struct{}
|
||||
removedrentals map[int]struct{}
|
||||
clearedrentals bool
|
||||
predicates []predicate.User
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the User entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "User",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.User {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetParentID sets the "parent_id" field.
|
||||
func (m *Mutation) SetParentID(i int) {
|
||||
m.parent = &i
|
||||
}
|
||||
|
||||
// ParentID returns the value of the "parent_id" field in the mutation.
|
||||
func (m *Mutation) ParentID() (r int, exists bool) {
|
||||
v := m.parent
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearParentID clears the value of the "parent_id" field.
|
||||
func (m *Mutation) ClearParentID() {
|
||||
m.parent = nil
|
||||
m.clearedFields[FieldParentID] = struct{}{}
|
||||
}
|
||||
|
||||
// ParentIDCleared returns if the "parent_id" field was cleared in this mutation.
|
||||
func (m *Mutation) ParentIDCleared() bool {
|
||||
_, ok := m.clearedFields[FieldParentID]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetParentID resets all changes to the "parent_id" field.
|
||||
func (m *Mutation) ResetParentID() {
|
||||
m.parent = nil
|
||||
delete(m.clearedFields, FieldParentID)
|
||||
}
|
||||
|
||||
// SetSpouseID sets the "spouse_id" field.
|
||||
func (m *Mutation) SetSpouseID(i int) {
|
||||
m.spouse = &i
|
||||
}
|
||||
|
||||
// SpouseID returns the value of the "spouse_id" field in the mutation.
|
||||
func (m *Mutation) SpouseID() (r int, exists bool) {
|
||||
v := m.spouse
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearSpouseID clears the value of the "spouse_id" field.
|
||||
func (m *Mutation) ClearSpouseID() {
|
||||
m.spouse = nil
|
||||
m.clearedFields[FieldSpouseID] = struct{}{}
|
||||
}
|
||||
|
||||
// SpouseIDCleared returns if the "spouse_id" field was cleared in this mutation.
|
||||
func (m *Mutation) SpouseIDCleared() bool {
|
||||
_, ok := m.clearedFields[FieldSpouseID]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetSpouseID resets all changes to the "spouse_id" field.
|
||||
func (m *Mutation) ResetSpouseID() {
|
||||
m.spouse = nil
|
||||
delete(m.clearedFields, FieldSpouseID)
|
||||
}
|
||||
|
||||
// AddPetIDs adds the "pets" edge to the Pet entity by ids.
|
||||
func (m *Mutation) AddPetIDs(ids ...int) {
|
||||
if m.pets == nil {
|
||||
m.pets = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
m.pets[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// ClearPets clears the "pets" edge to the Pet entity.
|
||||
func (m *Mutation) ClearPets() {
|
||||
m.clearedpets = true
|
||||
}
|
||||
|
||||
// PetsCleared reports if the "pets" edge to the Pet entity was cleared.
|
||||
func (m *Mutation) PetsCleared() bool {
|
||||
return m.clearedpets
|
||||
}
|
||||
|
||||
// RemovePetIDs removes the "pets" edge to the Pet entity by IDs.
|
||||
func (m *Mutation) RemovePetIDs(ids ...int) {
|
||||
if m.removedpets == nil {
|
||||
m.removedpets = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
delete(m.pets, ids[i])
|
||||
m.removedpets[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// RemovedPets returns the removed IDs of the "pets" edge to the Pet entity.
|
||||
func (m *Mutation) RemovedPetsIDs() (ids []int) {
|
||||
for id := range m.removedpets {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// PetsIDs returns the "pets" edge IDs in the mutation.
|
||||
func (m *Mutation) PetsIDs() (ids []int) {
|
||||
for id := range m.pets {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetPets resets all changes to the "pets" edge.
|
||||
func (m *Mutation) ResetPets() {
|
||||
m.pets = nil
|
||||
m.clearedpets = false
|
||||
m.removedpets = nil
|
||||
}
|
||||
|
||||
// ClearParent clears the "parent" edge to the User entity.
|
||||
func (m *Mutation) ClearParent() {
|
||||
m.clearedparent = true
|
||||
m.clearedFields[FieldParentID] = struct{}{}
|
||||
}
|
||||
|
||||
// ParentCleared reports if the "parent" edge to the User entity was cleared.
|
||||
func (m *Mutation) ParentCleared() bool {
|
||||
return m.ParentIDCleared() || m.clearedparent
|
||||
}
|
||||
|
||||
// ParentIDs returns the "parent" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// ParentID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) ParentIDs() (ids []int) {
|
||||
if id := m.parent; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetParent resets all changes to the "parent" edge.
|
||||
func (m *Mutation) ResetParent() {
|
||||
m.parent = nil
|
||||
m.clearedparent = false
|
||||
}
|
||||
|
||||
// AddChildIDs adds the "children" edge to the User entity by ids.
|
||||
func (m *Mutation) AddChildIDs(ids ...int) {
|
||||
if m.children == nil {
|
||||
m.children = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
m.children[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// ClearChildren clears the "children" edge to the User entity.
|
||||
func (m *Mutation) ClearChildren() {
|
||||
m.clearedchildren = true
|
||||
}
|
||||
|
||||
// ChildrenCleared reports if the "children" edge to the User entity was cleared.
|
||||
func (m *Mutation) ChildrenCleared() bool {
|
||||
return m.clearedchildren
|
||||
}
|
||||
|
||||
// RemoveChildIDs removes the "children" edge to the User entity by IDs.
|
||||
func (m *Mutation) RemoveChildIDs(ids ...int) {
|
||||
if m.removedchildren == nil {
|
||||
m.removedchildren = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
delete(m.children, ids[i])
|
||||
m.removedchildren[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// RemovedChildren returns the removed IDs of the "children" edge to the User entity.
|
||||
func (m *Mutation) RemovedChildrenIDs() (ids []int) {
|
||||
for id := range m.removedchildren {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ChildrenIDs returns the "children" edge IDs in the mutation.
|
||||
func (m *Mutation) ChildrenIDs() (ids []int) {
|
||||
for id := range m.children {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetChildren resets all changes to the "children" edge.
|
||||
func (m *Mutation) ResetChildren() {
|
||||
m.children = nil
|
||||
m.clearedchildren = false
|
||||
m.removedchildren = nil
|
||||
}
|
||||
|
||||
// ClearSpouse clears the "spouse" edge to the User entity.
|
||||
func (m *Mutation) ClearSpouse() {
|
||||
m.clearedspouse = true
|
||||
m.clearedFields[FieldSpouseID] = struct{}{}
|
||||
}
|
||||
|
||||
// SpouseCleared reports if the "spouse" edge to the User entity was cleared.
|
||||
func (m *Mutation) SpouseCleared() bool {
|
||||
return m.SpouseIDCleared() || m.clearedspouse
|
||||
}
|
||||
|
||||
// SpouseIDs returns the "spouse" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// SpouseID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) SpouseIDs() (ids []int) {
|
||||
if id := m.spouse; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetSpouse resets all changes to the "spouse" edge.
|
||||
func (m *Mutation) ResetSpouse() {
|
||||
m.spouse = nil
|
||||
m.clearedspouse = false
|
||||
}
|
||||
|
||||
// SetCardID sets the "card" edge to the Card entity by id.
|
||||
func (m *Mutation) SetCardID(id int) {
|
||||
m.card = &id
|
||||
}
|
||||
|
||||
// ClearCard clears the "card" edge to the Card entity.
|
||||
func (m *Mutation) ClearCard() {
|
||||
m.clearedcard = true
|
||||
}
|
||||
|
||||
// CardCleared reports if the "card" edge to the Card entity was cleared.
|
||||
func (m *Mutation) CardCleared() bool {
|
||||
return m.clearedcard
|
||||
}
|
||||
|
||||
// CardID returns the "card" edge ID in the mutation.
|
||||
func (m *Mutation) CardID() (id int, exists bool) {
|
||||
if m.card != nil {
|
||||
return *m.card, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// CardIDs returns the "card" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// CardID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) CardIDs() (ids []int) {
|
||||
if id := m.card; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetCard resets all changes to the "card" edge.
|
||||
func (m *Mutation) ResetCard() {
|
||||
m.card = nil
|
||||
m.clearedcard = false
|
||||
}
|
||||
|
||||
// SetMetadataID sets the "metadata" edge to the Metadata entity by id.
|
||||
func (m *Mutation) SetMetadataID(id int) {
|
||||
m.metadata = &id
|
||||
}
|
||||
|
||||
// ClearMetadata clears the "metadata" edge to the Metadata entity.
|
||||
func (m *Mutation) ClearMetadata() {
|
||||
m.clearedmetadata = true
|
||||
}
|
||||
|
||||
// MetadataCleared reports if the "metadata" edge to the Metadata entity was cleared.
|
||||
func (m *Mutation) MetadataCleared() bool {
|
||||
return m.clearedmetadata
|
||||
}
|
||||
|
||||
// MetadataID returns the "metadata" edge ID in the mutation.
|
||||
func (m *Mutation) MetadataID() (id int, exists bool) {
|
||||
if m.metadata != nil {
|
||||
return *m.metadata, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// MetadataIDs returns the "metadata" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// MetadataID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) MetadataIDs() (ids []int) {
|
||||
if id := m.metadata; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetMetadata resets all changes to the "metadata" edge.
|
||||
func (m *Mutation) ResetMetadata() {
|
||||
m.metadata = nil
|
||||
m.clearedmetadata = false
|
||||
}
|
||||
|
||||
// AddInfoIDs adds the "info" edge to the Info entity by ids.
|
||||
func (m *Mutation) AddInfoIDs(ids ...int) {
|
||||
if m.info == nil {
|
||||
m.info = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
m.info[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// ClearInfo clears the "info" edge to the Info entity.
|
||||
func (m *Mutation) ClearInfo() {
|
||||
m.clearedinfo = true
|
||||
}
|
||||
|
||||
// InfoCleared reports if the "info" edge to the Info entity was cleared.
|
||||
func (m *Mutation) InfoCleared() bool {
|
||||
return m.clearedinfo
|
||||
}
|
||||
|
||||
// RemoveInfoIDs removes the "info" edge to the Info entity by IDs.
|
||||
func (m *Mutation) RemoveInfoIDs(ids ...int) {
|
||||
if m.removedinfo == nil {
|
||||
m.removedinfo = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
delete(m.info, ids[i])
|
||||
m.removedinfo[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// RemovedInfo returns the removed IDs of the "info" edge to the Info entity.
|
||||
func (m *Mutation) RemovedInfoIDs() (ids []int) {
|
||||
for id := range m.removedinfo {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// InfoIDs returns the "info" edge IDs in the mutation.
|
||||
func (m *Mutation) InfoIDs() (ids []int) {
|
||||
for id := range m.info {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetInfo resets all changes to the "info" edge.
|
||||
func (m *Mutation) ResetInfo() {
|
||||
m.info = nil
|
||||
m.clearedinfo = false
|
||||
m.removedinfo = nil
|
||||
}
|
||||
|
||||
// AddRentalIDs adds the "rentals" edge to the Rental entity by ids.
|
||||
func (m *Mutation) AddRentalIDs(ids ...int) {
|
||||
if m.rentals == nil {
|
||||
m.rentals = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
m.rentals[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// ClearRentals clears the "rentals" edge to the Rental entity.
|
||||
func (m *Mutation) ClearRentals() {
|
||||
m.clearedrentals = true
|
||||
}
|
||||
|
||||
// RentalsCleared reports if the "rentals" edge to the Rental entity was cleared.
|
||||
func (m *Mutation) RentalsCleared() bool {
|
||||
return m.clearedrentals
|
||||
}
|
||||
|
||||
// RemoveRentalIDs removes the "rentals" edge to the Rental entity by IDs.
|
||||
func (m *Mutation) RemoveRentalIDs(ids ...int) {
|
||||
if m.removedrentals == nil {
|
||||
m.removedrentals = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
delete(m.rentals, ids[i])
|
||||
m.removedrentals[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// RemovedRentals returns the removed IDs of the "rentals" edge to the Rental entity.
|
||||
func (m *Mutation) RemovedRentalsIDs() (ids []int) {
|
||||
for id := range m.removedrentals {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// RentalsIDs returns the "rentals" edge IDs in the mutation.
|
||||
func (m *Mutation) RentalsIDs() (ids []int) {
|
||||
for id := range m.rentals {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetRentals resets all changes to the "rentals" edge.
|
||||
func (m *Mutation) ResetRentals() {
|
||||
m.rentals = nil
|
||||
m.clearedrentals = false
|
||||
m.removedrentals = nil
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.User) {
|
||||
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.User, 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 (User).
|
||||
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, 2)
|
||||
if m.parent != nil {
|
||||
fields = append(fields, FieldParentID)
|
||||
}
|
||||
if m.spouse != nil {
|
||||
fields = append(fields, FieldSpouseID)
|
||||
}
|
||||
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 FieldParentID:
|
||||
return m.ParentID()
|
||||
case FieldSpouseID:
|
||||
return m.SpouseID()
|
||||
}
|
||||
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 User 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 FieldParentID:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetParentID(v)
|
||||
return nil
|
||||
case FieldSpouseID:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetSpouseID(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown User field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *Mutation) AddedFields() []string {
|
||||
var fields []string
|
||||
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 {
|
||||
}
|
||||
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 User 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(FieldParentID) {
|
||||
fields = append(fields, FieldParentID)
|
||||
}
|
||||
if m.FieldCleared(FieldSpouseID) {
|
||||
fields = append(fields, FieldSpouseID)
|
||||
}
|
||||
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 FieldParentID:
|
||||
m.ClearParentID()
|
||||
return nil
|
||||
case FieldSpouseID:
|
||||
m.ClearSpouseID()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown User 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 FieldParentID:
|
||||
m.ResetParentID()
|
||||
return nil
|
||||
case FieldSpouseID:
|
||||
m.ResetSpouseID()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown User field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *Mutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 8)
|
||||
if m.pets != nil {
|
||||
edges = append(edges, EdgePets)
|
||||
}
|
||||
if m.parent != nil {
|
||||
edges = append(edges, EdgeParent)
|
||||
}
|
||||
if m.children != nil {
|
||||
edges = append(edges, EdgeChildren)
|
||||
}
|
||||
if m.spouse != nil {
|
||||
edges = append(edges, EdgeSpouse)
|
||||
}
|
||||
if m.card != nil {
|
||||
edges = append(edges, EdgeCard)
|
||||
}
|
||||
if m.metadata != nil {
|
||||
edges = append(edges, EdgeMetadata)
|
||||
}
|
||||
if m.info != nil {
|
||||
edges = append(edges, EdgeInfo)
|
||||
}
|
||||
if m.rentals != nil {
|
||||
edges = append(edges, EdgeRentals)
|
||||
}
|
||||
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 EdgePets:
|
||||
ids := make([]ent.Value, 0, len(m.pets))
|
||||
for id := range m.pets {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
case EdgeParent:
|
||||
if id := m.parent; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
case EdgeChildren:
|
||||
ids := make([]ent.Value, 0, len(m.children))
|
||||
for id := range m.children {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
case EdgeSpouse:
|
||||
if id := m.spouse; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
case EdgeCard:
|
||||
if id := m.card; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
case EdgeMetadata:
|
||||
if id := m.metadata; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
case EdgeInfo:
|
||||
ids := make([]ent.Value, 0, len(m.info))
|
||||
for id := range m.info {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
case EdgeRentals:
|
||||
ids := make([]ent.Value, 0, len(m.rentals))
|
||||
for id := range m.rentals {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *Mutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 8)
|
||||
if m.removedpets != nil {
|
||||
edges = append(edges, EdgePets)
|
||||
}
|
||||
if m.removedchildren != nil {
|
||||
edges = append(edges, EdgeChildren)
|
||||
}
|
||||
if m.removedinfo != nil {
|
||||
edges = append(edges, EdgeInfo)
|
||||
}
|
||||
if m.removedrentals != nil {
|
||||
edges = append(edges, EdgeRentals)
|
||||
}
|
||||
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 {
|
||||
switch name {
|
||||
case EdgePets:
|
||||
ids := make([]ent.Value, 0, len(m.removedpets))
|
||||
for id := range m.removedpets {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
case EdgeChildren:
|
||||
ids := make([]ent.Value, 0, len(m.removedchildren))
|
||||
for id := range m.removedchildren {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
case EdgeInfo:
|
||||
ids := make([]ent.Value, 0, len(m.removedinfo))
|
||||
for id := range m.removedinfo {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
case EdgeRentals:
|
||||
ids := make([]ent.Value, 0, len(m.removedrentals))
|
||||
for id := range m.removedrentals {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *Mutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 8)
|
||||
if m.clearedpets {
|
||||
edges = append(edges, EdgePets)
|
||||
}
|
||||
if m.clearedparent {
|
||||
edges = append(edges, EdgeParent)
|
||||
}
|
||||
if m.clearedchildren {
|
||||
edges = append(edges, EdgeChildren)
|
||||
}
|
||||
if m.clearedspouse {
|
||||
edges = append(edges, EdgeSpouse)
|
||||
}
|
||||
if m.clearedcard {
|
||||
edges = append(edges, EdgeCard)
|
||||
}
|
||||
if m.clearedmetadata {
|
||||
edges = append(edges, EdgeMetadata)
|
||||
}
|
||||
if m.clearedinfo {
|
||||
edges = append(edges, EdgeInfo)
|
||||
}
|
||||
if m.clearedrentals {
|
||||
edges = append(edges, EdgeRentals)
|
||||
}
|
||||
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 EdgePets:
|
||||
return m.clearedpets
|
||||
case EdgeParent:
|
||||
return m.clearedparent
|
||||
case EdgeChildren:
|
||||
return m.clearedchildren
|
||||
case EdgeSpouse:
|
||||
return m.clearedspouse
|
||||
case EdgeCard:
|
||||
return m.clearedcard
|
||||
case EdgeMetadata:
|
||||
return m.clearedmetadata
|
||||
case EdgeInfo:
|
||||
return m.clearedinfo
|
||||
case EdgeRentals:
|
||||
return m.clearedrentals
|
||||
}
|
||||
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 EdgeParent:
|
||||
m.ClearParent()
|
||||
return nil
|
||||
case EdgeSpouse:
|
||||
m.ClearSpouse()
|
||||
return nil
|
||||
case EdgeCard:
|
||||
m.ClearCard()
|
||||
return nil
|
||||
case EdgeMetadata:
|
||||
m.ClearMetadata()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown User 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 EdgePets:
|
||||
m.ResetPets()
|
||||
return nil
|
||||
case EdgeParent:
|
||||
m.ResetParent()
|
||||
return nil
|
||||
case EdgeChildren:
|
||||
m.ResetChildren()
|
||||
return nil
|
||||
case EdgeSpouse:
|
||||
m.ResetSpouse()
|
||||
return nil
|
||||
case EdgeCard:
|
||||
m.ResetCard()
|
||||
return nil
|
||||
case EdgeMetadata:
|
||||
m.ResetMetadata()
|
||||
return nil
|
||||
case EdgeInfo:
|
||||
m.ResetInfo()
|
||||
return nil
|
||||
case EdgeRentals:
|
||||
m.ResetRentals()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown User edge %s", name)
|
||||
}
|
||||
263
entc/integration/edgefield/ent/user/user.go
Normal file
263
entc/integration/edgefield/ent/user/user.go
Normal file
@@ -0,0 +1,263 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
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 = "id"
|
||||
// FieldParentID holds the string denoting the parent_id field in the database.
|
||||
FieldParentID = "parent_id"
|
||||
// FieldSpouseID holds the string denoting the spouse_id field in the database.
|
||||
FieldSpouseID = "spouse_id"
|
||||
// EdgePets holds the string denoting the pets edge name in mutations.
|
||||
EdgePets = "pets"
|
||||
// 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"
|
||||
// EdgeCard holds the string denoting the card edge name in mutations.
|
||||
EdgeCard = "card"
|
||||
// EdgeMetadata holds the string denoting the metadata edge name in mutations.
|
||||
EdgeMetadata = "metadata"
|
||||
// EdgeInfo holds the string denoting the info edge name in mutations.
|
||||
EdgeInfo = "info"
|
||||
// EdgeRentals holds the string denoting the rentals edge name in mutations.
|
||||
EdgeRentals = "rentals"
|
||||
// Table holds the table name of the user in the database.
|
||||
Table = "users"
|
||||
// PetsTable is the table that holds the pets relation/edge.
|
||||
PetsTable = "pets"
|
||||
// PetsInverseTable is the table name for the Pet entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "pet" package.
|
||||
PetsInverseTable = "pets"
|
||||
// PetsColumn is the table column denoting the pets relation/edge.
|
||||
PetsColumn = "owner_id"
|
||||
// ParentTable is the table that holds the parent relation/edge.
|
||||
ParentTable = "users"
|
||||
// ParentColumn is the table column denoting the parent relation/edge.
|
||||
ParentColumn = "parent_id"
|
||||
// ChildrenTable is the table that holds the children relation/edge.
|
||||
ChildrenTable = "users"
|
||||
// ChildrenColumn is the table column denoting the children relation/edge.
|
||||
ChildrenColumn = "parent_id"
|
||||
// SpouseTable is the table that holds the spouse relation/edge.
|
||||
SpouseTable = "users"
|
||||
// SpouseColumn is the table column denoting the spouse relation/edge.
|
||||
SpouseColumn = "spouse_id"
|
||||
// CardTable is the table that holds the card relation/edge.
|
||||
CardTable = "cards"
|
||||
// CardInverseTable is the table name for the Card entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "card" package.
|
||||
CardInverseTable = "cards"
|
||||
// CardColumn is the table column denoting the card relation/edge.
|
||||
CardColumn = "owner_id"
|
||||
// MetadataTable is the table that holds the metadata relation/edge.
|
||||
MetadataTable = "metadata"
|
||||
// MetadataInverseTable is the table name for the Metadata entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "metadata" package.
|
||||
MetadataInverseTable = "metadata"
|
||||
// MetadataColumn is the table column denoting the metadata relation/edge.
|
||||
MetadataColumn = "id"
|
||||
// InfoTable is the table that holds the info relation/edge.
|
||||
InfoTable = "infos"
|
||||
// InfoInverseTable is the table name for the Info entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "info" package.
|
||||
InfoInverseTable = "infos"
|
||||
// InfoColumn is the table column denoting the info relation/edge.
|
||||
InfoColumn = "id"
|
||||
// RentalsTable is the table that holds the rentals relation/edge.
|
||||
RentalsTable = "rentals"
|
||||
// RentalsInverseTable is the table name for the Rental entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "rental" package.
|
||||
RentalsInverseTable = "rentals"
|
||||
// RentalsColumn is the table column denoting the rentals relation/edge.
|
||||
RentalsColumn = "user_id"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for user fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldParentID,
|
||||
FieldSpouseID,
|
||||
}
|
||||
|
||||
// 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 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()
|
||||
}
|
||||
|
||||
// ByParentID orders the results by the parent_id field.
|
||||
func ByParentID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldParentID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// BySpouseID orders the results by the spouse_id field.
|
||||
func BySpouseID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldSpouseID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByPetsCount orders the results by pets count.
|
||||
func ByPetsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newPetsStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByPets orders the results by pets terms.
|
||||
func ByPets(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newPetsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// 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...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByCardField orders the results by card field.
|
||||
func ByCardField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newCardStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByMetadataField orders the results by metadata field.
|
||||
func ByMetadataField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newMetadataStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByInfoCount orders the results by info count.
|
||||
func ByInfoCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newInfoStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByInfo orders the results by info terms.
|
||||
func ByInfo(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newInfoStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByRentalsCount orders the results by rentals count.
|
||||
func ByRentalsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newRentalsStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByRentals orders the results by rentals terms.
|
||||
func ByRentals(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newRentalsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newPetsStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(PetsInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, PetsTable, PetsColumn),
|
||||
)
|
||||
}
|
||||
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 newCardStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(CardInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, CardTable, CardColumn),
|
||||
)
|
||||
}
|
||||
func newMetadataStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(MetadataInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, MetadataTable, MetadataColumn),
|
||||
)
|
||||
}
|
||||
func newInfoStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(InfoInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, InfoTable, InfoColumn),
|
||||
)
|
||||
}
|
||||
func newRentalsStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(RentalsInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, RentalsTable, RentalsColumn),
|
||||
)
|
||||
}
|
||||
327
entc/integration/edgefield/ent/user/where.go
Normal file
327
entc/integration/edgefield/ent/user/where.go
Normal file
@@ -0,0 +1,327 @@
|
||||
// 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/edgefield/ent/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))
|
||||
}
|
||||
|
||||
// ParentID applies equality check predicate on the "parent_id" field. It's identical to ParentIDEQ.
|
||||
func ParentID(v int) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldParentID, v))
|
||||
}
|
||||
|
||||
// SpouseID applies equality check predicate on the "spouse_id" field. It's identical to SpouseIDEQ.
|
||||
func SpouseID(v int) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldSpouseID, v))
|
||||
}
|
||||
|
||||
// ParentIDEQ applies the EQ predicate on the "parent_id" field.
|
||||
func ParentIDEQ(v int) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldParentID, v))
|
||||
}
|
||||
|
||||
// ParentIDNEQ applies the NEQ predicate on the "parent_id" field.
|
||||
func ParentIDNEQ(v int) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldParentID, v))
|
||||
}
|
||||
|
||||
// ParentIDIn applies the In predicate on the "parent_id" field.
|
||||
func ParentIDIn(vs ...int) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldParentID, vs...))
|
||||
}
|
||||
|
||||
// ParentIDNotIn applies the NotIn predicate on the "parent_id" field.
|
||||
func ParentIDNotIn(vs ...int) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldParentID, vs...))
|
||||
}
|
||||
|
||||
// ParentIDIsNil applies the IsNil predicate on the "parent_id" field.
|
||||
func ParentIDIsNil() predicate.User {
|
||||
return predicate.User(sql.FieldIsNull(FieldParentID))
|
||||
}
|
||||
|
||||
// ParentIDNotNil applies the NotNil predicate on the "parent_id" field.
|
||||
func ParentIDNotNil() predicate.User {
|
||||
return predicate.User(sql.FieldNotNull(FieldParentID))
|
||||
}
|
||||
|
||||
// SpouseIDEQ applies the EQ predicate on the "spouse_id" field.
|
||||
func SpouseIDEQ(v int) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldSpouseID, v))
|
||||
}
|
||||
|
||||
// SpouseIDNEQ applies the NEQ predicate on the "spouse_id" field.
|
||||
func SpouseIDNEQ(v int) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldSpouseID, v))
|
||||
}
|
||||
|
||||
// SpouseIDIn applies the In predicate on the "spouse_id" field.
|
||||
func SpouseIDIn(vs ...int) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldSpouseID, vs...))
|
||||
}
|
||||
|
||||
// SpouseIDNotIn applies the NotIn predicate on the "spouse_id" field.
|
||||
func SpouseIDNotIn(vs ...int) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldSpouseID, vs...))
|
||||
}
|
||||
|
||||
// SpouseIDIsNil applies the IsNil predicate on the "spouse_id" field.
|
||||
func SpouseIDIsNil() predicate.User {
|
||||
return predicate.User(sql.FieldIsNull(FieldSpouseID))
|
||||
}
|
||||
|
||||
// SpouseIDNotNil applies the NotNil predicate on the "spouse_id" field.
|
||||
func SpouseIDNotNil() predicate.User {
|
||||
return predicate.User(sql.FieldNotNull(FieldSpouseID))
|
||||
}
|
||||
|
||||
// HasPets applies the HasEdge predicate on the "pets" edge.
|
||||
func HasPets() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, PetsTable, PetsColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasPetsWith applies the HasEdge predicate on the "pets" edge with a given conditions (other predicates).
|
||||
func HasPetsWith(preds ...predicate.Pet) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newPetsStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasCard applies the HasEdge predicate on the "card" edge.
|
||||
func HasCard() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, CardTable, CardColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasCardWith applies the HasEdge predicate on the "card" edge with a given conditions (other predicates).
|
||||
func HasCardWith(preds ...predicate.Card) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newCardStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasMetadata applies the HasEdge predicate on the "metadata" edge.
|
||||
func HasMetadata() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, MetadataTable, MetadataColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasMetadataWith applies the HasEdge predicate on the "metadata" edge with a given conditions (other predicates).
|
||||
func HasMetadataWith(preds ...predicate.Metadata) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newMetadataStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasInfo applies the HasEdge predicate on the "info" edge.
|
||||
func HasInfo() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, InfoTable, InfoColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasInfoWith applies the HasEdge predicate on the "info" edge with a given conditions (other predicates).
|
||||
func HasInfoWith(preds ...predicate.Info) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newInfoStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasRentals applies the HasEdge predicate on the "rentals" edge.
|
||||
func HasRentals() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, RentalsTable, RentalsColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasRentalsWith applies the HasEdge predicate on the "rentals" edge with a given conditions (other predicates).
|
||||
func HasRentalsWith(preds ...predicate.Rental) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newRentalsStep()
|
||||
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))
|
||||
}
|
||||
456
entc/integration/edgefield/ent/user_create.go
Normal file
456
entc/integration/edgefield/ent/user_create.go
Normal file
@@ -0,0 +1,456 @@
|
||||
// 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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/card"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/info"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/metadata"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/pet"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/rental"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// UserCreate is the builder for creating a User entity.
|
||||
type UserCreate struct {
|
||||
config
|
||||
mutation *UserMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetParentID sets the "parent_id" field.
|
||||
func (_c *UserCreate) SetParentID(v int) *UserCreate {
|
||||
_c.mutation.SetParentID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableParentID sets the "parent_id" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableParentID(v *int) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetParentID(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetSpouseID sets the "spouse_id" field.
|
||||
func (_c *UserCreate) SetSpouseID(v int) *UserCreate {
|
||||
_c.mutation.SetSpouseID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableSpouseID sets the "spouse_id" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableSpouseID(v *int) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetSpouseID(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *UserCreate) SetID(v int) *UserCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddPetIDs adds the "pets" edge to the Pet entity by IDs.
|
||||
func (_c *UserCreate) AddPetIDs(ids ...int) *UserCreate {
|
||||
_c.mutation.AddPetIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddPets adds the "pets" edges to the Pet entity.
|
||||
func (_c *UserCreate) AddPets(v ...*Pet) *UserCreate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddPetIDs(ids...)
|
||||
}
|
||||
|
||||
// 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...)
|
||||
}
|
||||
|
||||
// SetSpouse sets the "spouse" edge to the User entity.
|
||||
func (_c *UserCreate) SetSpouse(v *User) *UserCreate {
|
||||
return _c.SetSpouseID(v.ID)
|
||||
}
|
||||
|
||||
// SetCardID sets the "card" edge to the Card entity by ID.
|
||||
func (_c *UserCreate) SetCardID(id int) *UserCreate {
|
||||
_c.mutation.SetCardID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCardID sets the "card" edge to the Card entity by ID if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableCardID(id *int) *UserCreate {
|
||||
if id != nil {
|
||||
_c = _c.SetCardID(*id)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCard sets the "card" edge to the Card entity.
|
||||
func (_c *UserCreate) SetCard(v *Card) *UserCreate {
|
||||
return _c.SetCardID(v.ID)
|
||||
}
|
||||
|
||||
// SetMetadataID sets the "metadata" edge to the Metadata entity by ID.
|
||||
func (_c *UserCreate) SetMetadataID(id int) *UserCreate {
|
||||
_c.mutation.SetMetadataID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableMetadataID sets the "metadata" edge to the Metadata entity by ID if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableMetadataID(id *int) *UserCreate {
|
||||
if id != nil {
|
||||
_c = _c.SetMetadataID(*id)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetMetadata sets the "metadata" edge to the Metadata entity.
|
||||
func (_c *UserCreate) SetMetadata(v *Metadata) *UserCreate {
|
||||
return _c.SetMetadataID(v.ID)
|
||||
}
|
||||
|
||||
// AddInfoIDs adds the "info" edge to the Info entity by IDs.
|
||||
func (_c *UserCreate) AddInfoIDs(ids ...int) *UserCreate {
|
||||
_c.mutation.AddInfoIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddInfo adds the "info" edges to the Info entity.
|
||||
func (_c *UserCreate) AddInfo(v ...*Info) *UserCreate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddInfoIDs(ids...)
|
||||
}
|
||||
|
||||
// AddRentalIDs adds the "rentals" edge to the Rental entity by IDs.
|
||||
func (_c *UserCreate) AddRentalIDs(ids ...int) *UserCreate {
|
||||
_c.mutation.AddRentalIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddRentals adds the "rentals" edges to the Rental entity.
|
||||
func (_c *UserCreate) AddRentals(v ...*Rental) *UserCreate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddRentalIDs(ids...)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *UserCreate) check() error {
|
||||
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 nodes := _c.mutation.PetsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.PetsTable,
|
||||
Columns: []string{user.PetsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(pet.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.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.ParentID = 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.SpouseID = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.CardIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: user.CardTable,
|
||||
Columns: []string{user.CardColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(card.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.MetadataIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: user.MetadataTable,
|
||||
Columns: []string{user.MetadataColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(metadata.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.InfoIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: user.InfoTable,
|
||||
Columns: []string{user.InfoColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(info.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.RentalsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.RentalsTable,
|
||||
Columns: []string{user.RentalsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(rental.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]
|
||||
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/edgefield/ent/user_delete.go
Normal file
92
entc/integration/edgefield/ent/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 ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/predicate"
|
||||
"entgo.io/ent/entc/integration/edgefield/ent/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)
|
||||
}
|
||||
}
|
||||
1201
entc/integration/edgefield/ent/user_query.go
Normal file
1201
entc/integration/edgefield/ent/user_query.go
Normal file
File diff suppressed because it is too large
Load Diff
1168
entc/integration/edgefield/ent/user_update.go
Normal file
1168
entc/integration/edgefield/ent/user_update.go
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user