snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
131
entc/integration/migrate/entv2/blog.go
Normal file
131
entc/integration/migrate/entv2/blog.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 entv2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/blog"
|
||||
)
|
||||
|
||||
// Blog is the model entity for the Blog schema.
|
||||
type Blog struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Oid holds the value of the "oid" field.
|
||||
Oid int `json:"oid,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the BlogQuery when eager-loading is set.
|
||||
Edges BlogEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// BlogEdges holds the relations/edges for other nodes in the graph.
|
||||
type BlogEdges struct {
|
||||
// Admins holds the value of the admins edge.
|
||||
Admins []*User `json:"admins,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// AdminsOrErr returns the Admins value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e BlogEdges) AdminsOrErr() ([]*User, error) {
|
||||
if e.loadedTypes[0] {
|
||||
return e.Admins, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "admins"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Blog) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case blog.FieldID, blog.FieldOid:
|
||||
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 Blog fields.
|
||||
func (_m *Blog) 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 blog.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 blog.FieldOid:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field oid", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Oid = 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 Blog.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Blog) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryAdmins queries the "admins" edge of the Blog entity.
|
||||
func (_m *Blog) QueryAdmins() *UserQuery {
|
||||
return NewBlogClient(_m.config).QueryAdmins(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Blog.
|
||||
// Note that you need to call Blog.Unwrap() before calling this method if this Blog
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Blog) Update() *BlogUpdateOne {
|
||||
return NewBlogClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Blog 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 *Blog) Unwrap() *Blog {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("entv2: Blog is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Blog) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Blog(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("oid=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Oid))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Blogs is a parsable slice of Blog.
|
||||
type Blogs []*Blog
|
||||
84
entc/integration/migrate/entv2/blog/blog.go
Normal file
84
entc/integration/migrate/entv2/blog/blog.go
Normal file
@@ -0,0 +1,84 @@
|
||||
// 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 blog
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the blog type in the database.
|
||||
Label = "blog"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldOid holds the string denoting the oid field in the database.
|
||||
FieldOid = "oid"
|
||||
// EdgeAdmins holds the string denoting the admins edge name in mutations.
|
||||
EdgeAdmins = "admins"
|
||||
// UserFieldID holds the string denoting the ID field of the User.
|
||||
UserFieldID = "oid"
|
||||
// Table holds the table name of the blog in the database.
|
||||
Table = "blogs"
|
||||
// AdminsTable is the table that holds the admins relation/edge.
|
||||
AdminsTable = "users"
|
||||
// AdminsInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
AdminsInverseTable = "users"
|
||||
// AdminsColumn is the table column denoting the admins relation/edge.
|
||||
AdminsColumn = "blog_admins"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for blog fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldOid,
|
||||
}
|
||||
|
||||
// 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 Blog 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()
|
||||
}
|
||||
|
||||
// ByOid orders the results by the oid field.
|
||||
func ByOid(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldOid, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAdminsCount orders the results by admins count.
|
||||
func ByAdminsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newAdminsStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByAdmins orders the results by admins terms.
|
||||
func ByAdmins(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newAdminsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newAdminsStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(AdminsInverseTable, UserFieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, AdminsTable, AdminsColumn),
|
||||
)
|
||||
}
|
||||
362
entc/integration/migrate/entv2/blog/mutation.go
Normal file
362
entc/integration/migrate/entv2/blog/mutation.go
Normal file
@@ -0,0 +1,362 @@
|
||||
// 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 blog
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Blog nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
oid *int
|
||||
addoid *int
|
||||
clearedFields map[string]struct{}
|
||||
admins map[int]struct{}
|
||||
removedadmins map[int]struct{}
|
||||
clearedadmins bool
|
||||
predicates []predicate.Blog
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Blog entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Blog",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Blog {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetOid sets the "oid" field.
|
||||
func (m *Mutation) SetOid(i int) {
|
||||
m.oid = &i
|
||||
m.addoid = nil
|
||||
}
|
||||
|
||||
// Oid returns the value of the "oid" field in the mutation.
|
||||
func (m *Mutation) Oid() (r int, exists bool) {
|
||||
v := m.oid
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// AddOid adds i to the "oid" field.
|
||||
func (m *Mutation) AddOid(i int) {
|
||||
if m.addoid != nil {
|
||||
*m.addoid += i
|
||||
} else {
|
||||
m.addoid = &i
|
||||
}
|
||||
}
|
||||
|
||||
// AddedOid returns the value that was added to the "oid" field in this mutation.
|
||||
func (m *Mutation) AddedOid() (r int, exists bool) {
|
||||
v := m.addoid
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ResetOid resets all changes to the "oid" field.
|
||||
func (m *Mutation) ResetOid() {
|
||||
m.oid = nil
|
||||
m.addoid = nil
|
||||
}
|
||||
|
||||
// AddAdminIDs adds the "admins" edge to the User entity by ids.
|
||||
func (m *Mutation) AddAdminIDs(ids ...int) {
|
||||
if m.admins == nil {
|
||||
m.admins = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
m.admins[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// ClearAdmins clears the "admins" edge to the User entity.
|
||||
func (m *Mutation) ClearAdmins() {
|
||||
m.clearedadmins = true
|
||||
}
|
||||
|
||||
// AdminsCleared reports if the "admins" edge to the User entity was cleared.
|
||||
func (m *Mutation) AdminsCleared() bool {
|
||||
return m.clearedadmins
|
||||
}
|
||||
|
||||
// RemoveAdminIDs removes the "admins" edge to the User entity by IDs.
|
||||
func (m *Mutation) RemoveAdminIDs(ids ...int) {
|
||||
if m.removedadmins == nil {
|
||||
m.removedadmins = make(map[int]struct{})
|
||||
}
|
||||
for i := range ids {
|
||||
delete(m.admins, ids[i])
|
||||
m.removedadmins[ids[i]] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
// RemovedAdmins returns the removed IDs of the "admins" edge to the User entity.
|
||||
func (m *Mutation) RemovedAdminsIDs() (ids []int) {
|
||||
for id := range m.removedadmins {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// AdminsIDs returns the "admins" edge IDs in the mutation.
|
||||
func (m *Mutation) AdminsIDs() (ids []int) {
|
||||
for id := range m.admins {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetAdmins resets all changes to the "admins" edge.
|
||||
func (m *Mutation) ResetAdmins() {
|
||||
m.admins = nil
|
||||
m.clearedadmins = false
|
||||
m.removedadmins = nil
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.Blog) {
|
||||
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.Blog, 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 (Blog).
|
||||
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.oid != nil {
|
||||
fields = append(fields, FieldOid)
|
||||
}
|
||||
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 FieldOid:
|
||||
return m.Oid()
|
||||
}
|
||||
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 Blog 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 FieldOid:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetOid(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Blog 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.addoid != nil {
|
||||
fields = append(fields, FieldOid)
|
||||
}
|
||||
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 FieldOid:
|
||||
return m.AddedOid()
|
||||
}
|
||||
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 FieldOid:
|
||||
v, ok := value.(int)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.AddOid(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Blog 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 Blog 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 FieldOid:
|
||||
m.ResetOid()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Blog 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.admins != nil {
|
||||
edges = append(edges, EdgeAdmins)
|
||||
}
|
||||
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 EdgeAdmins:
|
||||
ids := make([]ent.Value, 0, len(m.admins))
|
||||
for id := range m.admins {
|
||||
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.removedadmins != nil {
|
||||
edges = append(edges, EdgeAdmins)
|
||||
}
|
||||
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 EdgeAdmins:
|
||||
ids := make([]ent.Value, 0, len(m.removedadmins))
|
||||
for id := range m.removedadmins {
|
||||
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.clearedadmins {
|
||||
edges = append(edges, EdgeAdmins)
|
||||
}
|
||||
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 EdgeAdmins:
|
||||
return m.clearedadmins
|
||||
}
|
||||
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 Blog 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 EdgeAdmins:
|
||||
m.ResetAdmins()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Blog edge %s", name)
|
||||
}
|
||||
141
entc/integration/migrate/entv2/blog/where.go
Normal file
141
entc/integration/migrate/entv2/blog/where.go
Normal file
@@ -0,0 +1,141 @@
|
||||
// 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 blog
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Oid applies equality check predicate on the "oid" field. It's identical to OidEQ.
|
||||
func Oid(v int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldEQ(FieldOid, v))
|
||||
}
|
||||
|
||||
// OidEQ applies the EQ predicate on the "oid" field.
|
||||
func OidEQ(v int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldEQ(FieldOid, v))
|
||||
}
|
||||
|
||||
// OidNEQ applies the NEQ predicate on the "oid" field.
|
||||
func OidNEQ(v int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldNEQ(FieldOid, v))
|
||||
}
|
||||
|
||||
// OidIn applies the In predicate on the "oid" field.
|
||||
func OidIn(vs ...int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldIn(FieldOid, vs...))
|
||||
}
|
||||
|
||||
// OidNotIn applies the NotIn predicate on the "oid" field.
|
||||
func OidNotIn(vs ...int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldNotIn(FieldOid, vs...))
|
||||
}
|
||||
|
||||
// OidGT applies the GT predicate on the "oid" field.
|
||||
func OidGT(v int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldGT(FieldOid, v))
|
||||
}
|
||||
|
||||
// OidGTE applies the GTE predicate on the "oid" field.
|
||||
func OidGTE(v int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldGTE(FieldOid, v))
|
||||
}
|
||||
|
||||
// OidLT applies the LT predicate on the "oid" field.
|
||||
func OidLT(v int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldLT(FieldOid, v))
|
||||
}
|
||||
|
||||
// OidLTE applies the LTE predicate on the "oid" field.
|
||||
func OidLTE(v int) predicate.Blog {
|
||||
return predicate.Blog(sql.FieldLTE(FieldOid, v))
|
||||
}
|
||||
|
||||
// HasAdmins applies the HasEdge predicate on the "admins" edge.
|
||||
func HasAdmins() predicate.Blog {
|
||||
return predicate.Blog(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, AdminsTable, AdminsColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasAdminsWith applies the HasEdge predicate on the "admins" edge with a given conditions (other predicates).
|
||||
func HasAdminsWith(preds ...predicate.User) predicate.Blog {
|
||||
return predicate.Blog(func(s *sql.Selector) {
|
||||
step := newAdminsStep()
|
||||
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.Blog) predicate.Blog {
|
||||
return predicate.Blog(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Blog) predicate.Blog {
|
||||
return predicate.Blog(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Blog) predicate.Blog {
|
||||
return predicate.Blog(sql.NotPredicates(p))
|
||||
}
|
||||
235
entc/integration/migrate/entv2/blog_create.go
Normal file
235
entc/integration/migrate/entv2/blog_create.go
Normal file
@@ -0,0 +1,235 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/blog"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// BlogCreate is the builder for creating a Blog entity.
|
||||
type BlogCreate struct {
|
||||
config
|
||||
mutation *BlogMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetOid sets the "oid" field.
|
||||
func (_c *BlogCreate) SetOid(v int) *BlogCreate {
|
||||
_c.mutation.SetOid(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *BlogCreate) SetID(v int) *BlogCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddAdminIDs adds the "admins" edge to the User entity by IDs.
|
||||
func (_c *BlogCreate) AddAdminIDs(ids ...int) *BlogCreate {
|
||||
_c.mutation.AddAdminIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddAdmins adds the "admins" edges to the User entity.
|
||||
func (_c *BlogCreate) AddAdmins(v ...*User) *BlogCreate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddAdminIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the BlogMutation object of the builder.
|
||||
func (_c *BlogCreate) Mutation() *BlogMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Blog in the database.
|
||||
func (_c *BlogCreate) Save(ctx context.Context) (*Blog, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *BlogCreate) SaveX(ctx context.Context) *Blog {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *BlogCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *BlogCreate) 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 *BlogCreate) check() error {
|
||||
switch _c.driver.Dialect() {
|
||||
case dialect.MySQL, dialect.SQLite:
|
||||
if _, ok := _c.mutation.Oid(); !ok {
|
||||
return &ValidationError{Name: "oid", err: errors.New(`entv2: missing required field "Blog.oid"`)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *BlogCreate) sqlSave(ctx context.Context) (*Blog, 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 *BlogCreate) createSpec() (*Blog, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Blog{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(blog.Table, sqlgraph.NewFieldSpec(blog.FieldID, field.TypeInt))
|
||||
)
|
||||
if id, ok := _c.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
if value, ok := _c.mutation.Oid(); ok {
|
||||
_spec.SetField(blog.FieldOid, field.TypeInt, value)
|
||||
_node.Oid = value
|
||||
}
|
||||
if nodes := _c.mutation.AdminsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: blog.AdminsTable,
|
||||
Columns: []string{blog.AdminsColumn},
|
||||
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)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// BlogCreateBulk is the builder for creating many Blog entities in bulk.
|
||||
type BlogCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*BlogCreate
|
||||
}
|
||||
|
||||
// Save creates the Blog entities in the database.
|
||||
func (_c *BlogCreateBulk) Save(ctx context.Context) ([]*Blog, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Blog, 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.(*BlogMutation)
|
||||
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 *BlogCreateBulk) SaveX(ctx context.Context) []*Blog {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *BlogCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *BlogCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/migrate/entv2/blog_delete.go
Normal file
92
entc/integration/migrate/entv2/blog_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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/blog"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// BlogDelete is the builder for deleting a Blog entity.
|
||||
type BlogDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *BlogMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the BlogDelete builder.
|
||||
func (_d *BlogDelete) Where(ps ...predicate.Blog) *BlogDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *BlogDelete) 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 *BlogDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *BlogDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(blog.Table, sqlgraph.NewFieldSpec(blog.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
|
||||
}
|
||||
|
||||
// BlogDeleteOne is the builder for deleting a single Blog entity.
|
||||
type BlogDeleteOne struct {
|
||||
_d *BlogDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the BlogDelete builder.
|
||||
func (_d *BlogDeleteOne) Where(ps ...predicate.Blog) *BlogDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *BlogDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{blog.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *BlogDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
611
entc/integration/migrate/entv2/blog_query.go
Normal file
611
entc/integration/migrate/entv2/blog_query.go
Normal file
@@ -0,0 +1,611 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/blog"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// BlogQuery is the builder for querying Blog entities.
|
||||
type BlogQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []blog.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Blog
|
||||
withAdmins *UserQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the BlogQuery builder.
|
||||
func (_q *BlogQuery) Where(ps ...predicate.Blog) *BlogQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *BlogQuery) Limit(limit int) *BlogQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *BlogQuery) Offset(offset int) *BlogQuery {
|
||||
_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 *BlogQuery) Unique(unique bool) *BlogQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *BlogQuery) Order(o ...blog.OrderOption) *BlogQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryAdmins chains the current query on the "admins" edge.
|
||||
func (_q *BlogQuery) QueryAdmins() *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(blog.Table, blog.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, blog.AdminsTable, blog.AdminsColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Blog entity from the query.
|
||||
// Returns a *NotFoundError when no Blog was found.
|
||||
func (_q *BlogQuery) First(ctx context.Context) (*Blog, 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{blog.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *BlogQuery) FirstX(ctx context.Context) *Blog {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Blog ID from the query.
|
||||
// Returns a *NotFoundError when no Blog ID was found.
|
||||
func (_q *BlogQuery) 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{blog.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *BlogQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Blog entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Blog entity is found.
|
||||
// Returns a *NotFoundError when no Blog entities are found.
|
||||
func (_q *BlogQuery) Only(ctx context.Context) (*Blog, 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{blog.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{blog.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *BlogQuery) OnlyX(ctx context.Context) *Blog {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Blog ID in the query.
|
||||
// Returns a *NotSingularError when more than one Blog ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *BlogQuery) 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{blog.Label}
|
||||
default:
|
||||
err = &NotSingularError{blog.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *BlogQuery) 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 Blogs.
|
||||
func (_q *BlogQuery) All(ctx context.Context) ([]*Blog, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Blog, *BlogQuery]()
|
||||
return withInterceptors[[]*Blog](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *BlogQuery) AllX(ctx context.Context) []*Blog {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Blog IDs.
|
||||
func (_q *BlogQuery) 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(blog.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *BlogQuery) 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 *BlogQuery) 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[*BlogQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *BlogQuery) 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 *BlogQuery) 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("entv2: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *BlogQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the BlogQuery 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 *BlogQuery) Clone() *BlogQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &BlogQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]blog.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Blog{}, _q.predicates...),
|
||||
withAdmins: _q.withAdmins.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithAdmins tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "admins" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *BlogQuery) WithAdmins(opts ...func(*UserQuery)) *BlogQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withAdmins = 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 {
|
||||
// Oid int `json:"oid,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Blog.Query().
|
||||
// GroupBy(blog.FieldOid).
|
||||
// Aggregate(entv2.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *BlogQuery) GroupBy(field string, fields ...string) *BlogGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &BlogGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = blog.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 {
|
||||
// Oid int `json:"oid,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Blog.Query().
|
||||
// Select(blog.FieldOid).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *BlogQuery) Select(fields ...string) *BlogSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &BlogSelect{BlogQuery: _q}
|
||||
sbuild.label = blog.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a BlogSelect configured with the given aggregations.
|
||||
func (_q *BlogQuery) Aggregate(fns ...AggregateFunc) *BlogSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *BlogQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("entv2: uninitialized interceptor (forgotten import entv2/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !blog.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("entv2: 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 *BlogQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Blog, error) {
|
||||
var (
|
||||
nodes = []*Blog{}
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
_q.withAdmins != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Blog).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Blog{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.withAdmins; query != nil {
|
||||
if err := _q.loadAdmins(ctx, query, nodes,
|
||||
func(n *Blog) { n.Edges.Admins = []*User{} },
|
||||
func(n *Blog, e *User) { n.Edges.Admins = append(n.Edges.Admins, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *BlogQuery) loadAdmins(ctx context.Context, query *UserQuery, nodes []*Blog, init func(*Blog), assign func(*Blog, *User)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*Blog)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.User(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(blog.AdminsColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.blog_admins
|
||||
if fk == nil {
|
||||
return fmt.Errorf(`foreign-key "blog_admins" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "blog_admins" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *BlogQuery) 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 *BlogQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(blog.Table, blog.Columns, sqlgraph.NewFieldSpec(blog.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, blog.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != blog.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 *BlogQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(blog.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = blog.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
|
||||
}
|
||||
|
||||
// BlogGroupBy is the group-by builder for Blog entities.
|
||||
type BlogGroupBy struct {
|
||||
selector
|
||||
build *BlogQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *BlogGroupBy) Aggregate(fns ...AggregateFunc) *BlogGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *BlogGroupBy) 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[*BlogQuery, *BlogGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *BlogGroupBy) sqlScan(ctx context.Context, root *BlogQuery, 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)
|
||||
}
|
||||
|
||||
// BlogSelect is the builder for selecting fields of Blog entities.
|
||||
type BlogSelect struct {
|
||||
*BlogQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *BlogSelect) Aggregate(fns ...AggregateFunc) *BlogSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *BlogSelect) 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[*BlogQuery, *BlogSelect](ctx, _s.BlogQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *BlogSelect) sqlScan(ctx context.Context, root *BlogQuery, 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)
|
||||
}
|
||||
396
entc/integration/migrate/entv2/blog_update.go
Normal file
396
entc/integration/migrate/entv2/blog_update.go
Normal file
@@ -0,0 +1,396 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/blog"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// BlogUpdate is the builder for updating Blog entities.
|
||||
type BlogUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *BlogMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the BlogUpdate builder.
|
||||
func (_u *BlogUpdate) Where(ps ...predicate.Blog) *BlogUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOid sets the "oid" field.
|
||||
func (_u *BlogUpdate) SetOid(v int) *BlogUpdate {
|
||||
_u.mutation.ResetOid()
|
||||
_u.mutation.SetOid(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableOid sets the "oid" field if the given value is not nil.
|
||||
func (_u *BlogUpdate) SetNillableOid(v *int) *BlogUpdate {
|
||||
if v != nil {
|
||||
_u.SetOid(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddOid adds value to the "oid" field.
|
||||
func (_u *BlogUpdate) AddOid(v int) *BlogUpdate {
|
||||
_u.mutation.AddOid(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddAdminIDs adds the "admins" edge to the User entity by IDs.
|
||||
func (_u *BlogUpdate) AddAdminIDs(ids ...int) *BlogUpdate {
|
||||
_u.mutation.AddAdminIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddAdmins adds the "admins" edges to the User entity.
|
||||
func (_u *BlogUpdate) AddAdmins(v ...*User) *BlogUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddAdminIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the BlogMutation object of the builder.
|
||||
func (_u *BlogUpdate) Mutation() *BlogMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearAdmins clears all "admins" edges to the User entity.
|
||||
func (_u *BlogUpdate) ClearAdmins() *BlogUpdate {
|
||||
_u.mutation.ClearAdmins()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveAdminIDs removes the "admins" edge to User entities by IDs.
|
||||
func (_u *BlogUpdate) RemoveAdminIDs(ids ...int) *BlogUpdate {
|
||||
_u.mutation.RemoveAdminIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveAdmins removes "admins" edges to User entities.
|
||||
func (_u *BlogUpdate) RemoveAdmins(v ...*User) *BlogUpdate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveAdminIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *BlogUpdate) 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 *BlogUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *BlogUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *BlogUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *BlogUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(blog.Table, blog.Columns, sqlgraph.NewFieldSpec(blog.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.Oid(); ok {
|
||||
_spec.SetField(blog.FieldOid, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedOid(); ok {
|
||||
_spec.AddField(blog.FieldOid, field.TypeInt, value)
|
||||
}
|
||||
if _u.mutation.AdminsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: blog.AdminsTable,
|
||||
Columns: []string{blog.AdminsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedAdminsIDs(); len(nodes) > 0 && !_u.mutation.AdminsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: blog.AdminsTable,
|
||||
Columns: []string{blog.AdminsColumn},
|
||||
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.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.AdminsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: blog.AdminsTable,
|
||||
Columns: []string{blog.AdminsColumn},
|
||||
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{blog.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// BlogUpdateOne is the builder for updating a single Blog entity.
|
||||
type BlogUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *BlogMutation
|
||||
}
|
||||
|
||||
// SetOid sets the "oid" field.
|
||||
func (_u *BlogUpdateOne) SetOid(v int) *BlogUpdateOne {
|
||||
_u.mutation.ResetOid()
|
||||
_u.mutation.SetOid(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableOid sets the "oid" field if the given value is not nil.
|
||||
func (_u *BlogUpdateOne) SetNillableOid(v *int) *BlogUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetOid(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddOid adds value to the "oid" field.
|
||||
func (_u *BlogUpdateOne) AddOid(v int) *BlogUpdateOne {
|
||||
_u.mutation.AddOid(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddAdminIDs adds the "admins" edge to the User entity by IDs.
|
||||
func (_u *BlogUpdateOne) AddAdminIDs(ids ...int) *BlogUpdateOne {
|
||||
_u.mutation.AddAdminIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddAdmins adds the "admins" edges to the User entity.
|
||||
func (_u *BlogUpdateOne) AddAdmins(v ...*User) *BlogUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.AddAdminIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the BlogMutation object of the builder.
|
||||
func (_u *BlogUpdateOne) Mutation() *BlogMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearAdmins clears all "admins" edges to the User entity.
|
||||
func (_u *BlogUpdateOne) ClearAdmins() *BlogUpdateOne {
|
||||
_u.mutation.ClearAdmins()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveAdminIDs removes the "admins" edge to User entities by IDs.
|
||||
func (_u *BlogUpdateOne) RemoveAdminIDs(ids ...int) *BlogUpdateOne {
|
||||
_u.mutation.RemoveAdminIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveAdmins removes "admins" edges to User entities.
|
||||
func (_u *BlogUpdateOne) RemoveAdmins(v ...*User) *BlogUpdateOne {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _u.RemoveAdminIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the BlogUpdate builder.
|
||||
func (_u *BlogUpdateOne) Where(ps ...predicate.Blog) *BlogUpdateOne {
|
||||
_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 *BlogUpdateOne) Select(field string, fields ...string) *BlogUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Blog entity.
|
||||
func (_u *BlogUpdateOne) Save(ctx context.Context) (*Blog, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *BlogUpdateOne) SaveX(ctx context.Context) *Blog {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *BlogUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *BlogUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *BlogUpdateOne) sqlSave(ctx context.Context) (_node *Blog, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(blog.Table, blog.Columns, sqlgraph.NewFieldSpec(blog.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`entv2: missing "Blog.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, blog.FieldID)
|
||||
for _, f := range fields {
|
||||
if !blog.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("entv2: invalid field %q for query", f)}
|
||||
}
|
||||
if f != blog.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.Oid(); ok {
|
||||
_spec.SetField(blog.FieldOid, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedOid(); ok {
|
||||
_spec.AddField(blog.FieldOid, field.TypeInt, value)
|
||||
}
|
||||
if _u.mutation.AdminsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: blog.AdminsTable,
|
||||
Columns: []string{blog.AdminsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.RemovedAdminsIDs(); len(nodes) > 0 && !_u.mutation.AdminsCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: blog.AdminsTable,
|
||||
Columns: []string{blog.AdminsColumn},
|
||||
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.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.AdminsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: blog.AdminsTable,
|
||||
Columns: []string{blog.AdminsColumn},
|
||||
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 = &Blog{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{blog.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
146
entc/integration/migrate/entv2/car.go
Normal file
146
entc/integration/migrate/entv2/car.go
Normal file
@@ -0,0 +1,146 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
)
|
||||
|
||||
// Car is the model entity for the Car schema.
|
||||
type Car struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the CarQuery when eager-loading is set.
|
||||
Edges CarEdges `json:"edges"`
|
||||
user_car *int
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// CarEdges holds the relations/edges for other nodes in the graph.
|
||||
type CarEdges struct {
|
||||
// Owner holds the value of the owner edge.
|
||||
Owner *User `json:"owner,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// OwnerOrErr returns the Owner value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e CarEdges) OwnerOrErr() (*User, error) {
|
||||
if e.Owner != nil {
|
||||
return e.Owner, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "owner"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Car) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case car.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case car.FieldName:
|
||||
values[i] = new(sql.NullString)
|
||||
case car.ForeignKeys[0]: // user_car
|
||||
values[i] = new(sql.NullInt64)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Car fields.
|
||||
func (_m *Car) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case car.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int(value.Int64)
|
||||
case car.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Name = value.String
|
||||
}
|
||||
case car.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field user_car", value)
|
||||
} else if value.Valid {
|
||||
_m.user_car = new(int)
|
||||
*_m.user_car = int(value.Int64)
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Car.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Car) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryOwner queries the "owner" edge of the Car entity.
|
||||
func (_m *Car) QueryOwner() *UserQuery {
|
||||
return NewCarClient(_m.config).QueryOwner(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Car.
|
||||
// Note that you need to call Car.Unwrap() before calling this method if this Car
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Car) Update() *CarUpdateOne {
|
||||
return NewCarClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Car entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (_m *Car) Unwrap() *Car {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("entv2: 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("name=")
|
||||
builder.WriteString(_m.Name)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Cars is a parsable slice of Car.
|
||||
type Cars []*Car
|
||||
88
entc/integration/migrate/entv2/car/car.go
Normal file
88
entc/integration/migrate/entv2/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"
|
||||
)
|
||||
|
||||
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"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// EdgeOwner holds the string denoting the owner edge name in mutations.
|
||||
EdgeOwner = "owner"
|
||||
// UserFieldID holds the string denoting the ID field of the User.
|
||||
UserFieldID = "oid"
|
||||
// Table holds the table name of the car in the database.
|
||||
Table = "Car"
|
||||
// OwnerTable is the table that holds the owner relation/edge.
|
||||
OwnerTable = "Car"
|
||||
// OwnerInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
OwnerInverseTable = "users"
|
||||
// OwnerColumn is the table column denoting the owner relation/edge.
|
||||
OwnerColumn = "user_car"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for car fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldName,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "Car"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"user_car",
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for i := range ForeignKeys {
|
||||
if column == ForeignKeys[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the Car queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByOwnerField orders the results by owner field.
|
||||
func ByOwnerField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newOwnerStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newOwnerStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(OwnerInverseTable, UserFieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, OwnerTable, OwnerColumn),
|
||||
)
|
||||
}
|
||||
322
entc/integration/migrate/entv2/car/mutation.go
Normal file
322
entc/integration/migrate/entv2/car/mutation.go
Normal file
@@ -0,0 +1,322 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package car
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Car nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
name *string
|
||||
clearedFields map[string]struct{}
|
||||
owner *int
|
||||
clearedowner bool
|
||||
predicates []predicate.Car
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Car entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Car",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Car {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (m *Mutation) SetName(s string) {
|
||||
m.name = &s
|
||||
}
|
||||
|
||||
// Name returns the value of the "name" field in the mutation.
|
||||
func (m *Mutation) Name() (r string, exists bool) {
|
||||
v := m.name
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearName clears the value of the "name" field.
|
||||
func (m *Mutation) ClearName() {
|
||||
m.name = nil
|
||||
m.clearedFields[FieldName] = struct{}{}
|
||||
}
|
||||
|
||||
// NameCleared returns if the "name" field was cleared in this mutation.
|
||||
func (m *Mutation) NameCleared() bool {
|
||||
_, ok := m.clearedFields[FieldName]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetName resets all changes to the "name" field.
|
||||
func (m *Mutation) ResetName() {
|
||||
m.name = nil
|
||||
delete(m.clearedFields, FieldName)
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner" edge to the User entity by id.
|
||||
func (m *Mutation) SetOwnerID(id int) {
|
||||
m.owner = &id
|
||||
}
|
||||
|
||||
// ClearOwner clears the "owner" edge to the User entity.
|
||||
func (m *Mutation) ClearOwner() {
|
||||
m.clearedowner = true
|
||||
}
|
||||
|
||||
// OwnerCleared reports if the "owner" edge to the User entity was cleared.
|
||||
func (m *Mutation) OwnerCleared() bool {
|
||||
return m.clearedowner
|
||||
}
|
||||
|
||||
// OwnerID returns the "owner" edge ID in the mutation.
|
||||
func (m *Mutation) OwnerID() (id int, exists bool) {
|
||||
if m.owner != nil {
|
||||
return *m.owner, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OwnerIDs returns the "owner" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// OwnerID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) OwnerIDs() (ids []int) {
|
||||
if id := m.owner; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetOwner resets all changes to the "owner" edge.
|
||||
func (m *Mutation) ResetOwner() {
|
||||
m.owner = nil
|
||||
m.clearedowner = false
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.Car) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the Mutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *Mutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.Car, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *Mutation) Op() ent.Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *Mutation) SetOp(op ent.Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (Car).
|
||||
func (m *Mutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *Mutation) Fields() []string {
|
||||
fields := make([]string, 0, 1)
|
||||
if m.name != nil {
|
||||
fields = append(fields, FieldName)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *Mutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case FieldName:
|
||||
return m.Name()
|
||||
}
|
||||
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 FieldName:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetName(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(FieldName) {
|
||||
fields = append(fields, FieldName)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
// cleared in this mutation.
|
||||
func (m *Mutation) FieldCleared(name string) bool {
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *Mutation) ClearField(name string) error {
|
||||
switch name {
|
||||
case FieldName:
|
||||
m.ClearName()
|
||||
return nil
|
||||
}
|
||||
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 FieldName:
|
||||
m.ResetName()
|
||||
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.owner != nil {
|
||||
edges = append(edges, EdgeOwner)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *Mutation) AddedIDs(name string) []ent.Value {
|
||||
switch name {
|
||||
case EdgeOwner:
|
||||
if id := m.owner; id != nil {
|
||||
return []ent.Value{*id}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *Mutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *Mutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *Mutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 1)
|
||||
if m.clearedowner {
|
||||
edges = append(edges, EdgeOwner)
|
||||
}
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *Mutation) EdgeCleared(name string) bool {
|
||||
switch name {
|
||||
case EdgeOwner:
|
||||
return m.clearedowner
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *Mutation) ClearEdge(name string) error {
|
||||
switch name {
|
||||
case EdgeOwner:
|
||||
m.ClearOwner()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Car unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *Mutation) ResetEdge(name string) error {
|
||||
switch name {
|
||||
case EdgeOwner:
|
||||
m.ResetOwner()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Car edge %s", name)
|
||||
}
|
||||
176
entc/integration/migrate/entv2/car/where.go
Normal file
176
entc/integration/migrate/entv2/car/where.go
Normal file
@@ -0,0 +1,176 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package car
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Car {
|
||||
return predicate.Car(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Car {
|
||||
return predicate.Car(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Car {
|
||||
return predicate.Car(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Car {
|
||||
return predicate.Car(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Car {
|
||||
return predicate.Car(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Car {
|
||||
return predicate.Car(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Car {
|
||||
return predicate.Car(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Car {
|
||||
return predicate.Car(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Car {
|
||||
return predicate.Car(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.Car {
|
||||
return predicate.Car(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.Car {
|
||||
return predicate.Car(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIsNil applies the IsNil predicate on the "name" field.
|
||||
func NameIsNil() predicate.Car {
|
||||
return predicate.Car(sql.FieldIsNull(FieldName))
|
||||
}
|
||||
|
||||
// NameNotNil applies the NotNil predicate on the "name" field.
|
||||
func NameNotNil() predicate.Car {
|
||||
return predicate.Car(sql.FieldNotNull(FieldName))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.Car {
|
||||
return predicate.Car(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// HasOwner applies the HasEdge predicate on the "owner" edge.
|
||||
func HasOwner() predicate.Car {
|
||||
return predicate.Car(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.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.Car {
|
||||
return predicate.Car(func(s *sql.Selector) {
|
||||
step := newOwnerStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Car) predicate.Car {
|
||||
return predicate.Car(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Car) predicate.Car {
|
||||
return predicate.Car(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Car) predicate.Car {
|
||||
return predicate.Car(sql.NotPredicates(p))
|
||||
}
|
||||
224
entc/integration/migrate/entv2/car_create.go
Normal file
224
entc/integration/migrate/entv2/car_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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CarCreate is the builder for creating a Car entity.
|
||||
type CarCreate struct {
|
||||
config
|
||||
mutation *CarMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *CarCreate) SetName(v string) *CarCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_c *CarCreate) SetNillableName(v *string) *CarCreate {
|
||||
if v != nil {
|
||||
_c.SetName(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner" edge to the User entity by ID.
|
||||
func (_c *CarCreate) SetOwnerID(id int) *CarCreate {
|
||||
_c.mutation.SetOwnerID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" edge to the User entity.
|
||||
func (_c *CarCreate) SetOwner(v *User) *CarCreate {
|
||||
return _c.SetOwnerID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CarMutation object of the builder.
|
||||
func (_c *CarCreate) Mutation() *CarMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Car in the database.
|
||||
func (_c *CarCreate) Save(ctx context.Context) (*Car, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *CarCreate) SaveX(ctx context.Context) *Car {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *CarCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *CarCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *CarCreate) check() error {
|
||||
if len(_c.mutation.OwnerIDs()) == 0 {
|
||||
return &ValidationError{Name: "owner", err: errors.New(`entv2: missing required edge "Car.owner"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *CarCreate) sqlSave(ctx context.Context) (*Car, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *CarCreate) createSpec() (*Car, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Car{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(car.Table, sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(car.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if nodes := _c.mutation.OwnerIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: car.OwnerTable,
|
||||
Columns: []string{car.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.user_car = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// CarCreateBulk is the builder for creating many Car entities in bulk.
|
||||
type CarCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*CarCreate
|
||||
}
|
||||
|
||||
// Save creates the Car entities in the database.
|
||||
func (_c *CarCreateBulk) Save(ctx context.Context) ([]*Car, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Car, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*CarMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *CarCreateBulk) SaveX(ctx context.Context) []*Car {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *CarCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *CarCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/migrate/entv2/car_delete.go
Normal file
92
entc/integration/migrate/entv2/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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CarDelete is the builder for deleting a Car entity.
|
||||
type CarDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CarMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CarDelete builder.
|
||||
func (_d *CarDelete) Where(ps ...predicate.Car) *CarDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *CarDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *CarDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *CarDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(car.Table, sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt))
|
||||
if ps := _d.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// CarDeleteOne is the builder for deleting a single Car entity.
|
||||
type CarDeleteOne struct {
|
||||
_d *CarDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CarDelete builder.
|
||||
func (_d *CarDeleteOne) Where(ps ...predicate.Car) *CarDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *CarDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{car.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *CarDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
618
entc/integration/migrate/entv2/car_query.go
Normal file
618
entc/integration/migrate/entv2/car_query.go
Normal file
@@ -0,0 +1,618 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CarQuery is the builder for querying Car entities.
|
||||
type CarQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []car.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Car
|
||||
withOwner *UserQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the CarQuery builder.
|
||||
func (_q *CarQuery) Where(ps ...predicate.Car) *CarQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *CarQuery) Limit(limit int) *CarQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *CarQuery) Offset(offset int) *CarQuery {
|
||||
_q.ctx.Offset = &offset
|
||||
return _q
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (_q *CarQuery) Unique(unique bool) *CarQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *CarQuery) Order(o ...car.OrderOption) *CarQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryOwner chains the current query on the "owner" edge.
|
||||
func (_q *CarQuery) QueryOwner() *UserQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(car.Table, car.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, car.OwnerTable, car.OwnerColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Car entity from the query.
|
||||
// Returns a *NotFoundError when no Car was found.
|
||||
func (_q *CarQuery) First(ctx context.Context) (*Car, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{car.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *CarQuery) FirstX(ctx context.Context) *Car {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Car ID from the query.
|
||||
// Returns a *NotFoundError when no Car ID was found.
|
||||
func (_q *CarQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{car.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *CarQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Car entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Car entity is found.
|
||||
// Returns a *NotFoundError when no Car entities are found.
|
||||
func (_q *CarQuery) Only(ctx context.Context) (*Car, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{car.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{car.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *CarQuery) OnlyX(ctx context.Context) *Car {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Car ID in the query.
|
||||
// Returns a *NotSingularError when more than one Car ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *CarQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{car.Label}
|
||||
default:
|
||||
err = &NotSingularError{car.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *CarQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Cars.
|
||||
func (_q *CarQuery) All(ctx context.Context) ([]*Car, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Car, *CarQuery]()
|
||||
return withInterceptors[[]*Car](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *CarQuery) AllX(ctx context.Context) []*Car {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Car IDs.
|
||||
func (_q *CarQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(car.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *CarQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *CarQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, _q, querierCount[*CarQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *CarQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *CarQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||
switch _, err := _q.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("entv2: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *CarQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the CarQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *CarQuery) Clone() *CarQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &CarQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]car.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Car{}, _q.predicates...),
|
||||
withOwner: _q.withOwner.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithOwner tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "owner" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *CarQuery) WithOwner(opts ...func(*UserQuery)) *CarQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withOwner = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Car.Query().
|
||||
// GroupBy(car.FieldName).
|
||||
// Aggregate(entv2.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 {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Car.Query().
|
||||
// Select(car.FieldName).
|
||||
// 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("entv2: uninitialized interceptor (forgotten import entv2/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("entv2: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *CarQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Car, error) {
|
||||
var (
|
||||
nodes = []*Car{}
|
||||
withFKs = _q.withFKs
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
_q.withOwner != nil,
|
||||
}
|
||||
)
|
||||
if _q.withOwner != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, car.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Car).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Car{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := _q.withOwner; query != nil {
|
||||
if err := _q.loadOwner(ctx, query, nodes, nil,
|
||||
func(n *Car, e *User) { n.Edges.Owner = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *CarQuery) loadOwner(ctx context.Context, query *UserQuery, nodes []*Car, init func(*Car), assign func(*Car, *User)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Car)
|
||||
for i := range nodes {
|
||||
if nodes[i].user_car == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].user_car
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "user_car" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *CarQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Columns = _q.ctx.Fields
|
||||
if len(_q.ctx.Fields) > 0 {
|
||||
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *CarQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(car.Table, car.Columns, sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, car.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != car.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *CarQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(car.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = car.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// CarGroupBy is the group-by builder for Car entities.
|
||||
type CarGroupBy struct {
|
||||
selector
|
||||
build *CarQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *CarGroupBy) Aggregate(fns ...AggregateFunc) *CarGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *CarGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*CarQuery, *CarGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *CarGroupBy) sqlScan(ctx context.Context, root *CarQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// CarSelect is the builder for selecting fields of Car entities.
|
||||
type CarSelect struct {
|
||||
*CarQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *CarSelect) Aggregate(fns ...AggregateFunc) *CarSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *CarSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*CarQuery, *CarSelect](ctx, _s.CarQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *CarSelect) sqlScan(ctx context.Context, root *CarQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
346
entc/integration/migrate/entv2/car_update.go
Normal file
346
entc/integration/migrate/entv2/car_update.go
Normal file
@@ -0,0 +1,346 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CarUpdate is the builder for updating Car entities.
|
||||
type CarUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CarMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CarUpdate builder.
|
||||
func (_u *CarUpdate) Where(ps ...predicate.Car) *CarUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *CarUpdate) SetName(v string) *CarUpdate {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *CarUpdate) SetNillableName(v *string) *CarUpdate {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearName clears the value of the "name" field.
|
||||
func (_u *CarUpdate) ClearName() *CarUpdate {
|
||||
_u.mutation.ClearName()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner" edge to the User entity by ID.
|
||||
func (_u *CarUpdate) SetOwnerID(id int) *CarUpdate {
|
||||
_u.mutation.SetOwnerID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" edge to the User entity.
|
||||
func (_u *CarUpdate) SetOwner(v *User) *CarUpdate {
|
||||
return _u.SetOwnerID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CarMutation object of the builder.
|
||||
func (_u *CarUpdate) Mutation() *CarMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearOwner clears the "owner" edge to the User entity.
|
||||
func (_u *CarUpdate) ClearOwner() *CarUpdate {
|
||||
_u.mutation.ClearOwner()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *CarUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *CarUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *CarUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *CarUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *CarUpdate) check() error {
|
||||
if _u.mutation.OwnerCleared() && len(_u.mutation.OwnerIDs()) > 0 {
|
||||
return errors.New(`entv2: clearing a required unique edge "Car.owner"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *CarUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(car.Table, car.Columns, sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(car.FieldName, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.NameCleared() {
|
||||
_spec.ClearField(car.FieldName, field.TypeString)
|
||||
}
|
||||
if _u.mutation.OwnerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: car.OwnerTable,
|
||||
Columns: []string{car.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.OwnerIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: car.OwnerTable,
|
||||
Columns: []string{car.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{car.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// CarUpdateOne is the builder for updating a single Car entity.
|
||||
type CarUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *CarMutation
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *CarUpdateOne) SetName(v string) *CarUpdateOne {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *CarUpdateOne) SetNillableName(v *string) *CarUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearName clears the value of the "name" field.
|
||||
func (_u *CarUpdateOne) ClearName() *CarUpdateOne {
|
||||
_u.mutation.ClearName()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner" edge to the User entity by ID.
|
||||
func (_u *CarUpdateOne) SetOwnerID(id int) *CarUpdateOne {
|
||||
_u.mutation.SetOwnerID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" edge to the User entity.
|
||||
func (_u *CarUpdateOne) SetOwner(v *User) *CarUpdateOne {
|
||||
return _u.SetOwnerID(v.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the CarMutation object of the builder.
|
||||
func (_u *CarUpdateOne) Mutation() *CarMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearOwner clears the "owner" edge to the User entity.
|
||||
func (_u *CarUpdateOne) ClearOwner() *CarUpdateOne {
|
||||
_u.mutation.ClearOwner()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CarUpdate builder.
|
||||
func (_u *CarUpdateOne) Where(ps ...predicate.Car) *CarUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (_u *CarUpdateOne) Select(field string, fields ...string) *CarUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Car entity.
|
||||
func (_u *CarUpdateOne) Save(ctx context.Context) (*Car, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *CarUpdateOne) SaveX(ctx context.Context) *Car {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *CarUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *CarUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *CarUpdateOne) check() error {
|
||||
if _u.mutation.OwnerCleared() && len(_u.mutation.OwnerIDs()) > 0 {
|
||||
return errors.New(`entv2: clearing a required unique edge "Car.owner"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *CarUpdateOne) sqlSave(ctx context.Context) (_node *Car, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(car.Table, car.Columns, sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`entv2: 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("entv2: 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.Name(); ok {
|
||||
_spec.SetField(car.FieldName, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.NameCleared() {
|
||||
_spec.ClearField(car.FieldName, field.TypeString)
|
||||
}
|
||||
if _u.mutation.OwnerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: car.OwnerTable,
|
||||
Columns: []string{car.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := _u.mutation.OwnerIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: car.OwnerTable,
|
||||
Columns: []string{car.OwnerColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Car{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{car.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
1580
entc/integration/migrate/entv2/client.go
Normal file
1580
entc/integration/migrate/entv2/client.go
Normal file
File diff suppressed because it is too large
Load Diff
195
entc/integration/migrate/entv2/conversion.go
Normal file
195
entc/integration/migrate/entv2/conversion.go
Normal file
@@ -0,0 +1,195 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/conversion"
|
||||
)
|
||||
|
||||
// Conversion is the model entity for the Conversion schema.
|
||||
type Conversion struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Int8ToString holds the value of the "int8_to_string" field.
|
||||
Int8ToString string `json:"int8_to_string,omitempty"`
|
||||
// Uint8ToString holds the value of the "uint8_to_string" field.
|
||||
Uint8ToString string `json:"uint8_to_string,omitempty"`
|
||||
// Int16ToString holds the value of the "int16_to_string" field.
|
||||
Int16ToString string `json:"int16_to_string,omitempty"`
|
||||
// Uint16ToString holds the value of the "uint16_to_string" field.
|
||||
Uint16ToString string `json:"uint16_to_string,omitempty"`
|
||||
// Int32ToString holds the value of the "int32_to_string" field.
|
||||
Int32ToString string `json:"int32_to_string,omitempty"`
|
||||
// Uint32ToString holds the value of the "uint32_to_string" field.
|
||||
Uint32ToString string `json:"uint32_to_string,omitempty"`
|
||||
// Int64ToString holds the value of the "int64_to_string" field.
|
||||
Int64ToString string `json:"int64_to_string,omitempty"`
|
||||
// Uint64ToString holds the value of the "uint64_to_string" field.
|
||||
Uint64ToString string `json:"uint64_to_string,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Conversion) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case conversion.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case conversion.FieldName, conversion.FieldInt8ToString, conversion.FieldUint8ToString, conversion.FieldInt16ToString, conversion.FieldUint16ToString, conversion.FieldInt32ToString, conversion.FieldUint32ToString, conversion.FieldInt64ToString, conversion.FieldUint64ToString:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Conversion fields.
|
||||
func (_m *Conversion) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case conversion.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int(value.Int64)
|
||||
case conversion.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Name = value.String
|
||||
}
|
||||
case conversion.FieldInt8ToString:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field int8_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Int8ToString = value.String
|
||||
}
|
||||
case conversion.FieldUint8ToString:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field uint8_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Uint8ToString = value.String
|
||||
}
|
||||
case conversion.FieldInt16ToString:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field int16_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Int16ToString = value.String
|
||||
}
|
||||
case conversion.FieldUint16ToString:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field uint16_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Uint16ToString = value.String
|
||||
}
|
||||
case conversion.FieldInt32ToString:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field int32_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Int32ToString = value.String
|
||||
}
|
||||
case conversion.FieldUint32ToString:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field uint32_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Uint32ToString = value.String
|
||||
}
|
||||
case conversion.FieldInt64ToString:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field int64_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Int64ToString = value.String
|
||||
}
|
||||
case conversion.FieldUint64ToString:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field uint64_to_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Uint64ToString = 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 Conversion.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Conversion) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Conversion.
|
||||
// Note that you need to call Conversion.Unwrap() before calling this method if this Conversion
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Conversion) Update() *ConversionUpdateOne {
|
||||
return NewConversionClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Conversion entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (_m *Conversion) Unwrap() *Conversion {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("entv2: Conversion is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Conversion) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Conversion(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(_m.Name)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("int8_to_string=")
|
||||
builder.WriteString(_m.Int8ToString)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("uint8_to_string=")
|
||||
builder.WriteString(_m.Uint8ToString)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("int16_to_string=")
|
||||
builder.WriteString(_m.Int16ToString)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("uint16_to_string=")
|
||||
builder.WriteString(_m.Uint16ToString)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("int32_to_string=")
|
||||
builder.WriteString(_m.Int32ToString)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("uint32_to_string=")
|
||||
builder.WriteString(_m.Uint32ToString)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("int64_to_string=")
|
||||
builder.WriteString(_m.Int64ToString)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("uint64_to_string=")
|
||||
builder.WriteString(_m.Uint64ToString)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Conversions is a parsable slice of Conversion.
|
||||
type Conversions []*Conversion
|
||||
115
entc/integration/migrate/entv2/conversion/conversion.go
Normal file
115
entc/integration/migrate/entv2/conversion/conversion.go
Normal file
@@ -0,0 +1,115 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package conversion
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the conversion type in the database.
|
||||
Label = "conversion"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// FieldInt8ToString holds the string denoting the int8_to_string field in the database.
|
||||
FieldInt8ToString = "int8_to_string"
|
||||
// FieldUint8ToString holds the string denoting the uint8_to_string field in the database.
|
||||
FieldUint8ToString = "uint8_to_string"
|
||||
// FieldInt16ToString holds the string denoting the int16_to_string field in the database.
|
||||
FieldInt16ToString = "int16_to_string"
|
||||
// FieldUint16ToString holds the string denoting the uint16_to_string field in the database.
|
||||
FieldUint16ToString = "uint16_to_string"
|
||||
// FieldInt32ToString holds the string denoting the int32_to_string field in the database.
|
||||
FieldInt32ToString = "int32_to_string"
|
||||
// FieldUint32ToString holds the string denoting the uint32_to_string field in the database.
|
||||
FieldUint32ToString = "uint32_to_string"
|
||||
// FieldInt64ToString holds the string denoting the int64_to_string field in the database.
|
||||
FieldInt64ToString = "int64_to_string"
|
||||
// FieldUint64ToString holds the string denoting the uint64_to_string field in the database.
|
||||
FieldUint64ToString = "uint64_to_string"
|
||||
// Table holds the table name of the conversion in the database.
|
||||
Table = "conversions"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for conversion fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldName,
|
||||
FieldInt8ToString,
|
||||
FieldUint8ToString,
|
||||
FieldInt16ToString,
|
||||
FieldUint16ToString,
|
||||
FieldInt32ToString,
|
||||
FieldUint32ToString,
|
||||
FieldInt64ToString,
|
||||
FieldUint64ToString,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the Conversion queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByInt8ToString orders the results by the int8_to_string field.
|
||||
func ByInt8ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldInt8ToString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUint8ToString orders the results by the uint8_to_string field.
|
||||
func ByUint8ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUint8ToString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByInt16ToString orders the results by the int16_to_string field.
|
||||
func ByInt16ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldInt16ToString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUint16ToString orders the results by the uint16_to_string field.
|
||||
func ByUint16ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUint16ToString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByInt32ToString orders the results by the int32_to_string field.
|
||||
func ByInt32ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldInt32ToString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUint32ToString orders the results by the uint32_to_string field.
|
||||
func ByUint32ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUint32ToString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByInt64ToString orders the results by the int64_to_string field.
|
||||
func ByInt64ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldInt64ToString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUint64ToString orders the results by the uint64_to_string field.
|
||||
func ByUint64ToString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUint64ToString, opts...).ToFunc()
|
||||
}
|
||||
687
entc/integration/migrate/entv2/conversion/mutation.go
Normal file
687
entc/integration/migrate/entv2/conversion/mutation.go
Normal file
@@ -0,0 +1,687 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package conversion
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Conversion nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
name *string
|
||||
int8_to_string *string
|
||||
uint8_to_string *string
|
||||
int16_to_string *string
|
||||
uint16_to_string *string
|
||||
int32_to_string *string
|
||||
uint32_to_string *string
|
||||
int64_to_string *string
|
||||
uint64_to_string *string
|
||||
clearedFields map[string]struct{}
|
||||
predicates []predicate.Conversion
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Conversion entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Conversion",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Conversion {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (m *Mutation) SetName(s string) {
|
||||
m.name = &s
|
||||
}
|
||||
|
||||
// Name returns the value of the "name" field in the mutation.
|
||||
func (m *Mutation) Name() (r string, exists bool) {
|
||||
v := m.name
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearName clears the value of the "name" field.
|
||||
func (m *Mutation) ClearName() {
|
||||
m.name = nil
|
||||
m.clearedFields[FieldName] = struct{}{}
|
||||
}
|
||||
|
||||
// NameCleared returns if the "name" field was cleared in this mutation.
|
||||
func (m *Mutation) NameCleared() bool {
|
||||
_, ok := m.clearedFields[FieldName]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetName resets all changes to the "name" field.
|
||||
func (m *Mutation) ResetName() {
|
||||
m.name = nil
|
||||
delete(m.clearedFields, FieldName)
|
||||
}
|
||||
|
||||
// SetInt8ToString sets the "int8_to_string" field.
|
||||
func (m *Mutation) SetInt8ToString(s string) {
|
||||
m.int8_to_string = &s
|
||||
}
|
||||
|
||||
// Int8ToString returns the value of the "int8_to_string" field in the mutation.
|
||||
func (m *Mutation) Int8ToString() (r string, exists bool) {
|
||||
v := m.int8_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearInt8ToString clears the value of the "int8_to_string" field.
|
||||
func (m *Mutation) ClearInt8ToString() {
|
||||
m.int8_to_string = nil
|
||||
m.clearedFields[FieldInt8ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Int8ToStringCleared returns if the "int8_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Int8ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldInt8ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetInt8ToString resets all changes to the "int8_to_string" field.
|
||||
func (m *Mutation) ResetInt8ToString() {
|
||||
m.int8_to_string = nil
|
||||
delete(m.clearedFields, FieldInt8ToString)
|
||||
}
|
||||
|
||||
// SetUint8ToString sets the "uint8_to_string" field.
|
||||
func (m *Mutation) SetUint8ToString(s string) {
|
||||
m.uint8_to_string = &s
|
||||
}
|
||||
|
||||
// Uint8ToString returns the value of the "uint8_to_string" field in the mutation.
|
||||
func (m *Mutation) Uint8ToString() (r string, exists bool) {
|
||||
v := m.uint8_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearUint8ToString clears the value of the "uint8_to_string" field.
|
||||
func (m *Mutation) ClearUint8ToString() {
|
||||
m.uint8_to_string = nil
|
||||
m.clearedFields[FieldUint8ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Uint8ToStringCleared returns if the "uint8_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Uint8ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldUint8ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetUint8ToString resets all changes to the "uint8_to_string" field.
|
||||
func (m *Mutation) ResetUint8ToString() {
|
||||
m.uint8_to_string = nil
|
||||
delete(m.clearedFields, FieldUint8ToString)
|
||||
}
|
||||
|
||||
// SetInt16ToString sets the "int16_to_string" field.
|
||||
func (m *Mutation) SetInt16ToString(s string) {
|
||||
m.int16_to_string = &s
|
||||
}
|
||||
|
||||
// Int16ToString returns the value of the "int16_to_string" field in the mutation.
|
||||
func (m *Mutation) Int16ToString() (r string, exists bool) {
|
||||
v := m.int16_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearInt16ToString clears the value of the "int16_to_string" field.
|
||||
func (m *Mutation) ClearInt16ToString() {
|
||||
m.int16_to_string = nil
|
||||
m.clearedFields[FieldInt16ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Int16ToStringCleared returns if the "int16_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Int16ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldInt16ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetInt16ToString resets all changes to the "int16_to_string" field.
|
||||
func (m *Mutation) ResetInt16ToString() {
|
||||
m.int16_to_string = nil
|
||||
delete(m.clearedFields, FieldInt16ToString)
|
||||
}
|
||||
|
||||
// SetUint16ToString sets the "uint16_to_string" field.
|
||||
func (m *Mutation) SetUint16ToString(s string) {
|
||||
m.uint16_to_string = &s
|
||||
}
|
||||
|
||||
// Uint16ToString returns the value of the "uint16_to_string" field in the mutation.
|
||||
func (m *Mutation) Uint16ToString() (r string, exists bool) {
|
||||
v := m.uint16_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearUint16ToString clears the value of the "uint16_to_string" field.
|
||||
func (m *Mutation) ClearUint16ToString() {
|
||||
m.uint16_to_string = nil
|
||||
m.clearedFields[FieldUint16ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Uint16ToStringCleared returns if the "uint16_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Uint16ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldUint16ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetUint16ToString resets all changes to the "uint16_to_string" field.
|
||||
func (m *Mutation) ResetUint16ToString() {
|
||||
m.uint16_to_string = nil
|
||||
delete(m.clearedFields, FieldUint16ToString)
|
||||
}
|
||||
|
||||
// SetInt32ToString sets the "int32_to_string" field.
|
||||
func (m *Mutation) SetInt32ToString(s string) {
|
||||
m.int32_to_string = &s
|
||||
}
|
||||
|
||||
// Int32ToString returns the value of the "int32_to_string" field in the mutation.
|
||||
func (m *Mutation) Int32ToString() (r string, exists bool) {
|
||||
v := m.int32_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearInt32ToString clears the value of the "int32_to_string" field.
|
||||
func (m *Mutation) ClearInt32ToString() {
|
||||
m.int32_to_string = nil
|
||||
m.clearedFields[FieldInt32ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Int32ToStringCleared returns if the "int32_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Int32ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldInt32ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetInt32ToString resets all changes to the "int32_to_string" field.
|
||||
func (m *Mutation) ResetInt32ToString() {
|
||||
m.int32_to_string = nil
|
||||
delete(m.clearedFields, FieldInt32ToString)
|
||||
}
|
||||
|
||||
// SetUint32ToString sets the "uint32_to_string" field.
|
||||
func (m *Mutation) SetUint32ToString(s string) {
|
||||
m.uint32_to_string = &s
|
||||
}
|
||||
|
||||
// Uint32ToString returns the value of the "uint32_to_string" field in the mutation.
|
||||
func (m *Mutation) Uint32ToString() (r string, exists bool) {
|
||||
v := m.uint32_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearUint32ToString clears the value of the "uint32_to_string" field.
|
||||
func (m *Mutation) ClearUint32ToString() {
|
||||
m.uint32_to_string = nil
|
||||
m.clearedFields[FieldUint32ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Uint32ToStringCleared returns if the "uint32_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Uint32ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldUint32ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetUint32ToString resets all changes to the "uint32_to_string" field.
|
||||
func (m *Mutation) ResetUint32ToString() {
|
||||
m.uint32_to_string = nil
|
||||
delete(m.clearedFields, FieldUint32ToString)
|
||||
}
|
||||
|
||||
// SetInt64ToString sets the "int64_to_string" field.
|
||||
func (m *Mutation) SetInt64ToString(s string) {
|
||||
m.int64_to_string = &s
|
||||
}
|
||||
|
||||
// Int64ToString returns the value of the "int64_to_string" field in the mutation.
|
||||
func (m *Mutation) Int64ToString() (r string, exists bool) {
|
||||
v := m.int64_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearInt64ToString clears the value of the "int64_to_string" field.
|
||||
func (m *Mutation) ClearInt64ToString() {
|
||||
m.int64_to_string = nil
|
||||
m.clearedFields[FieldInt64ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Int64ToStringCleared returns if the "int64_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Int64ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldInt64ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetInt64ToString resets all changes to the "int64_to_string" field.
|
||||
func (m *Mutation) ResetInt64ToString() {
|
||||
m.int64_to_string = nil
|
||||
delete(m.clearedFields, FieldInt64ToString)
|
||||
}
|
||||
|
||||
// SetUint64ToString sets the "uint64_to_string" field.
|
||||
func (m *Mutation) SetUint64ToString(s string) {
|
||||
m.uint64_to_string = &s
|
||||
}
|
||||
|
||||
// Uint64ToString returns the value of the "uint64_to_string" field in the mutation.
|
||||
func (m *Mutation) Uint64ToString() (r string, exists bool) {
|
||||
v := m.uint64_to_string
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearUint64ToString clears the value of the "uint64_to_string" field.
|
||||
func (m *Mutation) ClearUint64ToString() {
|
||||
m.uint64_to_string = nil
|
||||
m.clearedFields[FieldUint64ToString] = struct{}{}
|
||||
}
|
||||
|
||||
// Uint64ToStringCleared returns if the "uint64_to_string" field was cleared in this mutation.
|
||||
func (m *Mutation) Uint64ToStringCleared() bool {
|
||||
_, ok := m.clearedFields[FieldUint64ToString]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetUint64ToString resets all changes to the "uint64_to_string" field.
|
||||
func (m *Mutation) ResetUint64ToString() {
|
||||
m.uint64_to_string = nil
|
||||
delete(m.clearedFields, FieldUint64ToString)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.Conversion) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the Mutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *Mutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.Conversion, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *Mutation) Op() ent.Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *Mutation) SetOp(op ent.Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (Conversion).
|
||||
func (m *Mutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *Mutation) Fields() []string {
|
||||
fields := make([]string, 0, 9)
|
||||
if m.name != nil {
|
||||
fields = append(fields, FieldName)
|
||||
}
|
||||
if m.int8_to_string != nil {
|
||||
fields = append(fields, FieldInt8ToString)
|
||||
}
|
||||
if m.uint8_to_string != nil {
|
||||
fields = append(fields, FieldUint8ToString)
|
||||
}
|
||||
if m.int16_to_string != nil {
|
||||
fields = append(fields, FieldInt16ToString)
|
||||
}
|
||||
if m.uint16_to_string != nil {
|
||||
fields = append(fields, FieldUint16ToString)
|
||||
}
|
||||
if m.int32_to_string != nil {
|
||||
fields = append(fields, FieldInt32ToString)
|
||||
}
|
||||
if m.uint32_to_string != nil {
|
||||
fields = append(fields, FieldUint32ToString)
|
||||
}
|
||||
if m.int64_to_string != nil {
|
||||
fields = append(fields, FieldInt64ToString)
|
||||
}
|
||||
if m.uint64_to_string != nil {
|
||||
fields = append(fields, FieldUint64ToString)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *Mutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case FieldName:
|
||||
return m.Name()
|
||||
case FieldInt8ToString:
|
||||
return m.Int8ToString()
|
||||
case FieldUint8ToString:
|
||||
return m.Uint8ToString()
|
||||
case FieldInt16ToString:
|
||||
return m.Int16ToString()
|
||||
case FieldUint16ToString:
|
||||
return m.Uint16ToString()
|
||||
case FieldInt32ToString:
|
||||
return m.Int32ToString()
|
||||
case FieldUint32ToString:
|
||||
return m.Uint32ToString()
|
||||
case FieldInt64ToString:
|
||||
return m.Int64ToString()
|
||||
case FieldUint64ToString:
|
||||
return m.Uint64ToString()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *Mutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("unknown Conversion field %s", name)
|
||||
}
|
||||
|
||||
// SetField sets the value of a field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *Mutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case FieldName:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetName(v)
|
||||
return nil
|
||||
case FieldInt8ToString:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetInt8ToString(v)
|
||||
return nil
|
||||
case FieldUint8ToString:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUint8ToString(v)
|
||||
return nil
|
||||
case FieldInt16ToString:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetInt16ToString(v)
|
||||
return nil
|
||||
case FieldUint16ToString:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUint16ToString(v)
|
||||
return nil
|
||||
case FieldInt32ToString:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetInt32ToString(v)
|
||||
return nil
|
||||
case FieldUint32ToString:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUint32ToString(v)
|
||||
return nil
|
||||
case FieldInt64ToString:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetInt64ToString(v)
|
||||
return nil
|
||||
case FieldUint64ToString:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUint64ToString(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Conversion field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *Mutation) AddedFields() []string {
|
||||
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 Conversion numeric field %s", name)
|
||||
}
|
||||
|
||||
// ClearedFields returns all nullable fields that were cleared during this
|
||||
// mutation.
|
||||
func (m *Mutation) ClearedFields() []string {
|
||||
var fields []string
|
||||
if m.FieldCleared(FieldName) {
|
||||
fields = append(fields, FieldName)
|
||||
}
|
||||
if m.FieldCleared(FieldInt8ToString) {
|
||||
fields = append(fields, FieldInt8ToString)
|
||||
}
|
||||
if m.FieldCleared(FieldUint8ToString) {
|
||||
fields = append(fields, FieldUint8ToString)
|
||||
}
|
||||
if m.FieldCleared(FieldInt16ToString) {
|
||||
fields = append(fields, FieldInt16ToString)
|
||||
}
|
||||
if m.FieldCleared(FieldUint16ToString) {
|
||||
fields = append(fields, FieldUint16ToString)
|
||||
}
|
||||
if m.FieldCleared(FieldInt32ToString) {
|
||||
fields = append(fields, FieldInt32ToString)
|
||||
}
|
||||
if m.FieldCleared(FieldUint32ToString) {
|
||||
fields = append(fields, FieldUint32ToString)
|
||||
}
|
||||
if m.FieldCleared(FieldInt64ToString) {
|
||||
fields = append(fields, FieldInt64ToString)
|
||||
}
|
||||
if m.FieldCleared(FieldUint64ToString) {
|
||||
fields = append(fields, FieldUint64ToString)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
// cleared in this mutation.
|
||||
func (m *Mutation) FieldCleared(name string) bool {
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *Mutation) ClearField(name string) error {
|
||||
switch name {
|
||||
case FieldName:
|
||||
m.ClearName()
|
||||
return nil
|
||||
case FieldInt8ToString:
|
||||
m.ClearInt8ToString()
|
||||
return nil
|
||||
case FieldUint8ToString:
|
||||
m.ClearUint8ToString()
|
||||
return nil
|
||||
case FieldInt16ToString:
|
||||
m.ClearInt16ToString()
|
||||
return nil
|
||||
case FieldUint16ToString:
|
||||
m.ClearUint16ToString()
|
||||
return nil
|
||||
case FieldInt32ToString:
|
||||
m.ClearInt32ToString()
|
||||
return nil
|
||||
case FieldUint32ToString:
|
||||
m.ClearUint32ToString()
|
||||
return nil
|
||||
case FieldInt64ToString:
|
||||
m.ClearInt64ToString()
|
||||
return nil
|
||||
case FieldUint64ToString:
|
||||
m.ClearUint64ToString()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Conversion nullable field %s", name)
|
||||
}
|
||||
|
||||
// ResetField resets all changes in the mutation for the field with the given name.
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *Mutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case FieldName:
|
||||
m.ResetName()
|
||||
return nil
|
||||
case FieldInt8ToString:
|
||||
m.ResetInt8ToString()
|
||||
return nil
|
||||
case FieldUint8ToString:
|
||||
m.ResetUint8ToString()
|
||||
return nil
|
||||
case FieldInt16ToString:
|
||||
m.ResetInt16ToString()
|
||||
return nil
|
||||
case FieldUint16ToString:
|
||||
m.ResetUint16ToString()
|
||||
return nil
|
||||
case FieldInt32ToString:
|
||||
m.ResetInt32ToString()
|
||||
return nil
|
||||
case FieldUint32ToString:
|
||||
m.ResetUint32ToString()
|
||||
return nil
|
||||
case FieldInt64ToString:
|
||||
m.ResetInt64ToString()
|
||||
return nil
|
||||
case FieldUint64ToString:
|
||||
m.ResetUint64ToString()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Conversion field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *Mutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *Mutation) AddedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *Mutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *Mutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *Mutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *Mutation) EdgeCleared(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *Mutation) ClearEdge(name string) error {
|
||||
return fmt.Errorf("unknown Conversion unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *Mutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown Conversion edge %s", name)
|
||||
}
|
||||
792
entc/integration/migrate/entv2/conversion/where.go
Normal file
792
entc/integration/migrate/entv2/conversion/where.go
Normal file
@@ -0,0 +1,792 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package conversion
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// Int8ToString applies equality check predicate on the "int8_to_string" field. It's identical to Int8ToStringEQ.
|
||||
func Int8ToString(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToString applies equality check predicate on the "uint8_to_string" field. It's identical to Uint8ToStringEQ.
|
||||
func Uint8ToString(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToString applies equality check predicate on the "int16_to_string" field. It's identical to Int16ToStringEQ.
|
||||
func Int16ToString(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToString applies equality check predicate on the "uint16_to_string" field. It's identical to Uint16ToStringEQ.
|
||||
func Uint16ToString(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToString applies equality check predicate on the "int32_to_string" field. It's identical to Int32ToStringEQ.
|
||||
func Int32ToString(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToString applies equality check predicate on the "uint32_to_string" field. It's identical to Uint32ToStringEQ.
|
||||
func Uint32ToString(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToString applies equality check predicate on the "int64_to_string" field. It's identical to Int64ToStringEQ.
|
||||
func Int64ToString(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToString applies equality check predicate on the "uint64_to_string" field. It's identical to Uint64ToStringEQ.
|
||||
func Uint64ToString(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIsNil applies the IsNil predicate on the "name" field.
|
||||
func NameIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldName))
|
||||
}
|
||||
|
||||
// NameNotNil applies the NotNil predicate on the "name" field.
|
||||
func NameNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldName))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// Int8ToStringEQ applies the EQ predicate on the "int8_to_string" field.
|
||||
func Int8ToStringEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringNEQ applies the NEQ predicate on the "int8_to_string" field.
|
||||
func Int8ToStringNEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringIn applies the In predicate on the "int8_to_string" field.
|
||||
func Int8ToStringIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldInt8ToString, vs...))
|
||||
}
|
||||
|
||||
// Int8ToStringNotIn applies the NotIn predicate on the "int8_to_string" field.
|
||||
func Int8ToStringNotIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldInt8ToString, vs...))
|
||||
}
|
||||
|
||||
// Int8ToStringGT applies the GT predicate on the "int8_to_string" field.
|
||||
func Int8ToStringGT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringGTE applies the GTE predicate on the "int8_to_string" field.
|
||||
func Int8ToStringGTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringLT applies the LT predicate on the "int8_to_string" field.
|
||||
func Int8ToStringLT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringLTE applies the LTE predicate on the "int8_to_string" field.
|
||||
func Int8ToStringLTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringContains applies the Contains predicate on the "int8_to_string" field.
|
||||
func Int8ToStringContains(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContains(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringHasPrefix applies the HasPrefix predicate on the "int8_to_string" field.
|
||||
func Int8ToStringHasPrefix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasPrefix(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringHasSuffix applies the HasSuffix predicate on the "int8_to_string" field.
|
||||
func Int8ToStringHasSuffix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasSuffix(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringIsNil applies the IsNil predicate on the "int8_to_string" field.
|
||||
func Int8ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldInt8ToString))
|
||||
}
|
||||
|
||||
// Int8ToStringNotNil applies the NotNil predicate on the "int8_to_string" field.
|
||||
func Int8ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldInt8ToString))
|
||||
}
|
||||
|
||||
// Int8ToStringEqualFold applies the EqualFold predicate on the "int8_to_string" field.
|
||||
func Int8ToStringEqualFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEqualFold(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Int8ToStringContainsFold applies the ContainsFold predicate on the "int8_to_string" field.
|
||||
func Int8ToStringContainsFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContainsFold(FieldInt8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringEQ applies the EQ predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringNEQ applies the NEQ predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringNEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringIn applies the In predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldUint8ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint8ToStringNotIn applies the NotIn predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringNotIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldUint8ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint8ToStringGT applies the GT predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringGT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringGTE applies the GTE predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringGTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringLT applies the LT predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringLT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringLTE applies the LTE predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringLTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringContains applies the Contains predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringContains(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContains(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringHasPrefix applies the HasPrefix predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringHasPrefix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasPrefix(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringHasSuffix applies the HasSuffix predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringHasSuffix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasSuffix(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringIsNil applies the IsNil predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldUint8ToString))
|
||||
}
|
||||
|
||||
// Uint8ToStringNotNil applies the NotNil predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldUint8ToString))
|
||||
}
|
||||
|
||||
// Uint8ToStringEqualFold applies the EqualFold predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringEqualFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEqualFold(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Uint8ToStringContainsFold applies the ContainsFold predicate on the "uint8_to_string" field.
|
||||
func Uint8ToStringContainsFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContainsFold(FieldUint8ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringEQ applies the EQ predicate on the "int16_to_string" field.
|
||||
func Int16ToStringEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringNEQ applies the NEQ predicate on the "int16_to_string" field.
|
||||
func Int16ToStringNEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringIn applies the In predicate on the "int16_to_string" field.
|
||||
func Int16ToStringIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldInt16ToString, vs...))
|
||||
}
|
||||
|
||||
// Int16ToStringNotIn applies the NotIn predicate on the "int16_to_string" field.
|
||||
func Int16ToStringNotIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldInt16ToString, vs...))
|
||||
}
|
||||
|
||||
// Int16ToStringGT applies the GT predicate on the "int16_to_string" field.
|
||||
func Int16ToStringGT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringGTE applies the GTE predicate on the "int16_to_string" field.
|
||||
func Int16ToStringGTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringLT applies the LT predicate on the "int16_to_string" field.
|
||||
func Int16ToStringLT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringLTE applies the LTE predicate on the "int16_to_string" field.
|
||||
func Int16ToStringLTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringContains applies the Contains predicate on the "int16_to_string" field.
|
||||
func Int16ToStringContains(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContains(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringHasPrefix applies the HasPrefix predicate on the "int16_to_string" field.
|
||||
func Int16ToStringHasPrefix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasPrefix(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringHasSuffix applies the HasSuffix predicate on the "int16_to_string" field.
|
||||
func Int16ToStringHasSuffix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasSuffix(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringIsNil applies the IsNil predicate on the "int16_to_string" field.
|
||||
func Int16ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldInt16ToString))
|
||||
}
|
||||
|
||||
// Int16ToStringNotNil applies the NotNil predicate on the "int16_to_string" field.
|
||||
func Int16ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldInt16ToString))
|
||||
}
|
||||
|
||||
// Int16ToStringEqualFold applies the EqualFold predicate on the "int16_to_string" field.
|
||||
func Int16ToStringEqualFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEqualFold(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Int16ToStringContainsFold applies the ContainsFold predicate on the "int16_to_string" field.
|
||||
func Int16ToStringContainsFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContainsFold(FieldInt16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringEQ applies the EQ predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringNEQ applies the NEQ predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringNEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringIn applies the In predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldUint16ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint16ToStringNotIn applies the NotIn predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringNotIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldUint16ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint16ToStringGT applies the GT predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringGT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringGTE applies the GTE predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringGTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringLT applies the LT predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringLT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringLTE applies the LTE predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringLTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringContains applies the Contains predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringContains(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContains(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringHasPrefix applies the HasPrefix predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringHasPrefix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasPrefix(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringHasSuffix applies the HasSuffix predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringHasSuffix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasSuffix(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringIsNil applies the IsNil predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldUint16ToString))
|
||||
}
|
||||
|
||||
// Uint16ToStringNotNil applies the NotNil predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldUint16ToString))
|
||||
}
|
||||
|
||||
// Uint16ToStringEqualFold applies the EqualFold predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringEqualFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEqualFold(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Uint16ToStringContainsFold applies the ContainsFold predicate on the "uint16_to_string" field.
|
||||
func Uint16ToStringContainsFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContainsFold(FieldUint16ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringEQ applies the EQ predicate on the "int32_to_string" field.
|
||||
func Int32ToStringEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringNEQ applies the NEQ predicate on the "int32_to_string" field.
|
||||
func Int32ToStringNEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringIn applies the In predicate on the "int32_to_string" field.
|
||||
func Int32ToStringIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldInt32ToString, vs...))
|
||||
}
|
||||
|
||||
// Int32ToStringNotIn applies the NotIn predicate on the "int32_to_string" field.
|
||||
func Int32ToStringNotIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldInt32ToString, vs...))
|
||||
}
|
||||
|
||||
// Int32ToStringGT applies the GT predicate on the "int32_to_string" field.
|
||||
func Int32ToStringGT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringGTE applies the GTE predicate on the "int32_to_string" field.
|
||||
func Int32ToStringGTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringLT applies the LT predicate on the "int32_to_string" field.
|
||||
func Int32ToStringLT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringLTE applies the LTE predicate on the "int32_to_string" field.
|
||||
func Int32ToStringLTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringContains applies the Contains predicate on the "int32_to_string" field.
|
||||
func Int32ToStringContains(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContains(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringHasPrefix applies the HasPrefix predicate on the "int32_to_string" field.
|
||||
func Int32ToStringHasPrefix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasPrefix(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringHasSuffix applies the HasSuffix predicate on the "int32_to_string" field.
|
||||
func Int32ToStringHasSuffix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasSuffix(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringIsNil applies the IsNil predicate on the "int32_to_string" field.
|
||||
func Int32ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldInt32ToString))
|
||||
}
|
||||
|
||||
// Int32ToStringNotNil applies the NotNil predicate on the "int32_to_string" field.
|
||||
func Int32ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldInt32ToString))
|
||||
}
|
||||
|
||||
// Int32ToStringEqualFold applies the EqualFold predicate on the "int32_to_string" field.
|
||||
func Int32ToStringEqualFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEqualFold(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Int32ToStringContainsFold applies the ContainsFold predicate on the "int32_to_string" field.
|
||||
func Int32ToStringContainsFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContainsFold(FieldInt32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringEQ applies the EQ predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringNEQ applies the NEQ predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringNEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringIn applies the In predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldUint32ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint32ToStringNotIn applies the NotIn predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringNotIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldUint32ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint32ToStringGT applies the GT predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringGT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringGTE applies the GTE predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringGTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringLT applies the LT predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringLT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringLTE applies the LTE predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringLTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringContains applies the Contains predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringContains(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContains(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringHasPrefix applies the HasPrefix predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringHasPrefix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasPrefix(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringHasSuffix applies the HasSuffix predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringHasSuffix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasSuffix(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringIsNil applies the IsNil predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldUint32ToString))
|
||||
}
|
||||
|
||||
// Uint32ToStringNotNil applies the NotNil predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldUint32ToString))
|
||||
}
|
||||
|
||||
// Uint32ToStringEqualFold applies the EqualFold predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringEqualFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEqualFold(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Uint32ToStringContainsFold applies the ContainsFold predicate on the "uint32_to_string" field.
|
||||
func Uint32ToStringContainsFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContainsFold(FieldUint32ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringEQ applies the EQ predicate on the "int64_to_string" field.
|
||||
func Int64ToStringEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringNEQ applies the NEQ predicate on the "int64_to_string" field.
|
||||
func Int64ToStringNEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringIn applies the In predicate on the "int64_to_string" field.
|
||||
func Int64ToStringIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldInt64ToString, vs...))
|
||||
}
|
||||
|
||||
// Int64ToStringNotIn applies the NotIn predicate on the "int64_to_string" field.
|
||||
func Int64ToStringNotIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldInt64ToString, vs...))
|
||||
}
|
||||
|
||||
// Int64ToStringGT applies the GT predicate on the "int64_to_string" field.
|
||||
func Int64ToStringGT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringGTE applies the GTE predicate on the "int64_to_string" field.
|
||||
func Int64ToStringGTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringLT applies the LT predicate on the "int64_to_string" field.
|
||||
func Int64ToStringLT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringLTE applies the LTE predicate on the "int64_to_string" field.
|
||||
func Int64ToStringLTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringContains applies the Contains predicate on the "int64_to_string" field.
|
||||
func Int64ToStringContains(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContains(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringHasPrefix applies the HasPrefix predicate on the "int64_to_string" field.
|
||||
func Int64ToStringHasPrefix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasPrefix(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringHasSuffix applies the HasSuffix predicate on the "int64_to_string" field.
|
||||
func Int64ToStringHasSuffix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasSuffix(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringIsNil applies the IsNil predicate on the "int64_to_string" field.
|
||||
func Int64ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldInt64ToString))
|
||||
}
|
||||
|
||||
// Int64ToStringNotNil applies the NotNil predicate on the "int64_to_string" field.
|
||||
func Int64ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldInt64ToString))
|
||||
}
|
||||
|
||||
// Int64ToStringEqualFold applies the EqualFold predicate on the "int64_to_string" field.
|
||||
func Int64ToStringEqualFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEqualFold(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Int64ToStringContainsFold applies the ContainsFold predicate on the "int64_to_string" field.
|
||||
func Int64ToStringContainsFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContainsFold(FieldInt64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringEQ applies the EQ predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEQ(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringNEQ applies the NEQ predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringNEQ(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNEQ(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringIn applies the In predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIn(FieldUint64ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint64ToStringNotIn applies the NotIn predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringNotIn(vs ...string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotIn(FieldUint64ToString, vs...))
|
||||
}
|
||||
|
||||
// Uint64ToStringGT applies the GT predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringGT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGT(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringGTE applies the GTE predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringGTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldGTE(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringLT applies the LT predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringLT(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLT(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringLTE applies the LTE predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringLTE(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldLTE(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringContains applies the Contains predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringContains(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContains(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringHasPrefix applies the HasPrefix predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringHasPrefix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasPrefix(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringHasSuffix applies the HasSuffix predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringHasSuffix(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldHasSuffix(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringIsNil applies the IsNil predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringIsNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldIsNull(FieldUint64ToString))
|
||||
}
|
||||
|
||||
// Uint64ToStringNotNil applies the NotNil predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringNotNil() predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldNotNull(FieldUint64ToString))
|
||||
}
|
||||
|
||||
// Uint64ToStringEqualFold applies the EqualFold predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringEqualFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldEqualFold(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// Uint64ToStringContainsFold applies the ContainsFold predicate on the "uint64_to_string" field.
|
||||
func Uint64ToStringContainsFold(v string) predicate.Conversion {
|
||||
return predicate.Conversion(sql.FieldContainsFold(FieldUint64ToString, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Conversion) predicate.Conversion {
|
||||
return predicate.Conversion(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Conversion) predicate.Conversion {
|
||||
return predicate.Conversion(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Conversion) predicate.Conversion {
|
||||
return predicate.Conversion(sql.NotPredicates(p))
|
||||
}
|
||||
335
entc/integration/migrate/entv2/conversion_create.go
Normal file
335
entc/integration/migrate/entv2/conversion_create.go
Normal file
@@ -0,0 +1,335 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/conversion"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ConversionCreate is the builder for creating a Conversion entity.
|
||||
type ConversionCreate struct {
|
||||
config
|
||||
mutation *ConversionMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *ConversionCreate) SetName(v string) *ConversionCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableName(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetName(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetInt8ToString sets the "int8_to_string" field.
|
||||
func (_c *ConversionCreate) SetInt8ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetInt8ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableInt8ToString sets the "int8_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableInt8ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetInt8ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUint8ToString sets the "uint8_to_string" field.
|
||||
func (_c *ConversionCreate) SetUint8ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetUint8ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUint8ToString sets the "uint8_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableUint8ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetUint8ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetInt16ToString sets the "int16_to_string" field.
|
||||
func (_c *ConversionCreate) SetInt16ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetInt16ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableInt16ToString sets the "int16_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableInt16ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetInt16ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUint16ToString sets the "uint16_to_string" field.
|
||||
func (_c *ConversionCreate) SetUint16ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetUint16ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUint16ToString sets the "uint16_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableUint16ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetUint16ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetInt32ToString sets the "int32_to_string" field.
|
||||
func (_c *ConversionCreate) SetInt32ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetInt32ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableInt32ToString sets the "int32_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableInt32ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetInt32ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUint32ToString sets the "uint32_to_string" field.
|
||||
func (_c *ConversionCreate) SetUint32ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetUint32ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUint32ToString sets the "uint32_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableUint32ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetUint32ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetInt64ToString sets the "int64_to_string" field.
|
||||
func (_c *ConversionCreate) SetInt64ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetInt64ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableInt64ToString sets the "int64_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableInt64ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetInt64ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUint64ToString sets the "uint64_to_string" field.
|
||||
func (_c *ConversionCreate) SetUint64ToString(v string) *ConversionCreate {
|
||||
_c.mutation.SetUint64ToString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUint64ToString sets the "uint64_to_string" field if the given value is not nil.
|
||||
func (_c *ConversionCreate) SetNillableUint64ToString(v *string) *ConversionCreate {
|
||||
if v != nil {
|
||||
_c.SetUint64ToString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the ConversionMutation object of the builder.
|
||||
func (_c *ConversionCreate) Mutation() *ConversionMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Conversion in the database.
|
||||
func (_c *ConversionCreate) Save(ctx context.Context) (*Conversion, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *ConversionCreate) SaveX(ctx context.Context) *Conversion {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *ConversionCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *ConversionCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *ConversionCreate) check() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *ConversionCreate) sqlSave(ctx context.Context) (*Conversion, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *ConversionCreate) createSpec() (*Conversion, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Conversion{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(conversion.Table, sqlgraph.NewFieldSpec(conversion.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(conversion.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := _c.mutation.Int8ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt8ToString, field.TypeString, value)
|
||||
_node.Int8ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Uint8ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint8ToString, field.TypeString, value)
|
||||
_node.Uint8ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Int16ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt16ToString, field.TypeString, value)
|
||||
_node.Int16ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Uint16ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint16ToString, field.TypeString, value)
|
||||
_node.Uint16ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Int32ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt32ToString, field.TypeString, value)
|
||||
_node.Int32ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Uint32ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint32ToString, field.TypeString, value)
|
||||
_node.Uint32ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Int64ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt64ToString, field.TypeString, value)
|
||||
_node.Int64ToString = value
|
||||
}
|
||||
if value, ok := _c.mutation.Uint64ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint64ToString, field.TypeString, value)
|
||||
_node.Uint64ToString = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// ConversionCreateBulk is the builder for creating many Conversion entities in bulk.
|
||||
type ConversionCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*ConversionCreate
|
||||
}
|
||||
|
||||
// Save creates the Conversion entities in the database.
|
||||
func (_c *ConversionCreateBulk) Save(ctx context.Context) ([]*Conversion, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Conversion, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*ConversionMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *ConversionCreateBulk) SaveX(ctx context.Context) []*Conversion {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *ConversionCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *ConversionCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/migrate/entv2/conversion_delete.go
Normal file
92
entc/integration/migrate/entv2/conversion_delete.go
Normal file
@@ -0,0 +1,92 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/conversion"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ConversionDelete is the builder for deleting a Conversion entity.
|
||||
type ConversionDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ConversionMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ConversionDelete builder.
|
||||
func (_d *ConversionDelete) Where(ps ...predicate.Conversion) *ConversionDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *ConversionDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *ConversionDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *ConversionDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(conversion.Table, sqlgraph.NewFieldSpec(conversion.FieldID, field.TypeInt))
|
||||
if ps := _d.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// ConversionDeleteOne is the builder for deleting a single Conversion entity.
|
||||
type ConversionDeleteOne struct {
|
||||
_d *ConversionDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ConversionDelete builder.
|
||||
func (_d *ConversionDeleteOne) Where(ps ...predicate.Conversion) *ConversionDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *ConversionDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{conversion.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *ConversionDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
531
entc/integration/migrate/entv2/conversion_query.go
Normal file
531
entc/integration/migrate/entv2/conversion_query.go
Normal file
@@ -0,0 +1,531 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/conversion"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ConversionQuery is the builder for querying Conversion entities.
|
||||
type ConversionQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []conversion.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Conversion
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the ConversionQuery builder.
|
||||
func (_q *ConversionQuery) Where(ps ...predicate.Conversion) *ConversionQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *ConversionQuery) Limit(limit int) *ConversionQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *ConversionQuery) Offset(offset int) *ConversionQuery {
|
||||
_q.ctx.Offset = &offset
|
||||
return _q
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (_q *ConversionQuery) Unique(unique bool) *ConversionQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *ConversionQuery) Order(o ...conversion.OrderOption) *ConversionQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// First returns the first Conversion entity from the query.
|
||||
// Returns a *NotFoundError when no Conversion was found.
|
||||
func (_q *ConversionQuery) First(ctx context.Context) (*Conversion, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{conversion.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) FirstX(ctx context.Context) *Conversion {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Conversion ID from the query.
|
||||
// Returns a *NotFoundError when no Conversion ID was found.
|
||||
func (_q *ConversionQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{conversion.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Conversion entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Conversion entity is found.
|
||||
// Returns a *NotFoundError when no Conversion entities are found.
|
||||
func (_q *ConversionQuery) Only(ctx context.Context) (*Conversion, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{conversion.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{conversion.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) OnlyX(ctx context.Context) *Conversion {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Conversion ID in the query.
|
||||
// Returns a *NotSingularError when more than one Conversion ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *ConversionQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{conversion.Label}
|
||||
default:
|
||||
err = &NotSingularError{conversion.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Conversions.
|
||||
func (_q *ConversionQuery) All(ctx context.Context) ([]*Conversion, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Conversion, *ConversionQuery]()
|
||||
return withInterceptors[[]*Conversion](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) AllX(ctx context.Context) []*Conversion {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Conversion IDs.
|
||||
func (_q *ConversionQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(conversion.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *ConversionQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, _q, querierCount[*ConversionQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *ConversionQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||
switch _, err := _q.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("entv2: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *ConversionQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the ConversionQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *ConversionQuery) Clone() *ConversionQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &ConversionQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]conversion.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Conversion{}, _q.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Conversion.Query().
|
||||
// GroupBy(conversion.FieldName).
|
||||
// Aggregate(entv2.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *ConversionQuery) GroupBy(field string, fields ...string) *ConversionGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &ConversionGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = conversion.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Conversion.Query().
|
||||
// Select(conversion.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *ConversionQuery) Select(fields ...string) *ConversionSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &ConversionSelect{ConversionQuery: _q}
|
||||
sbuild.label = conversion.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a ConversionSelect configured with the given aggregations.
|
||||
func (_q *ConversionQuery) Aggregate(fns ...AggregateFunc) *ConversionSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *ConversionQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("entv2: uninitialized interceptor (forgotten import entv2/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !conversion.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("entv2: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *ConversionQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Conversion, error) {
|
||||
var (
|
||||
nodes = []*Conversion{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Conversion).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Conversion{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *ConversionQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Columns = _q.ctx.Fields
|
||||
if len(_q.ctx.Fields) > 0 {
|
||||
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *ConversionQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(conversion.Table, conversion.Columns, sqlgraph.NewFieldSpec(conversion.FieldID, field.TypeInt))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, conversion.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != conversion.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *ConversionQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(conversion.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = conversion.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// ConversionGroupBy is the group-by builder for Conversion entities.
|
||||
type ConversionGroupBy struct {
|
||||
selector
|
||||
build *ConversionQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *ConversionGroupBy) Aggregate(fns ...AggregateFunc) *ConversionGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *ConversionGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*ConversionQuery, *ConversionGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *ConversionGroupBy) sqlScan(ctx context.Context, root *ConversionQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// ConversionSelect is the builder for selecting fields of Conversion entities.
|
||||
type ConversionSelect struct {
|
||||
*ConversionQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *ConversionSelect) Aggregate(fns ...AggregateFunc) *ConversionSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *ConversionSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*ConversionQuery, *ConversionSelect](ctx, _s.ConversionQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *ConversionSelect) sqlScan(ctx context.Context, root *ConversionQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
647
entc/integration/migrate/entv2/conversion_update.go
Normal file
647
entc/integration/migrate/entv2/conversion_update.go
Normal file
@@ -0,0 +1,647 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/conversion"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ConversionUpdate is the builder for updating Conversion entities.
|
||||
type ConversionUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ConversionMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ConversionUpdate builder.
|
||||
func (_u *ConversionUpdate) Where(ps ...predicate.Conversion) *ConversionUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *ConversionUpdate) SetName(v string) *ConversionUpdate {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableName(v *string) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearName clears the value of the "name" field.
|
||||
func (_u *ConversionUpdate) ClearName() *ConversionUpdate {
|
||||
_u.mutation.ClearName()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt8ToString sets the "int8_to_string" field.
|
||||
func (_u *ConversionUpdate) SetInt8ToString(v string) *ConversionUpdate {
|
||||
_u.mutation.SetInt8ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt8ToString sets the "int8_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableInt8ToString(v *string) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetInt8ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt8ToString clears the value of the "int8_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearInt8ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearInt8ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint8ToString sets the "uint8_to_string" field.
|
||||
func (_u *ConversionUpdate) SetUint8ToString(v string) *ConversionUpdate {
|
||||
_u.mutation.SetUint8ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint8ToString sets the "uint8_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableUint8ToString(v *string) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetUint8ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint8ToString clears the value of the "uint8_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearUint8ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearUint8ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt16ToString sets the "int16_to_string" field.
|
||||
func (_u *ConversionUpdate) SetInt16ToString(v string) *ConversionUpdate {
|
||||
_u.mutation.SetInt16ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt16ToString sets the "int16_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableInt16ToString(v *string) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetInt16ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt16ToString clears the value of the "int16_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearInt16ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearInt16ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint16ToString sets the "uint16_to_string" field.
|
||||
func (_u *ConversionUpdate) SetUint16ToString(v string) *ConversionUpdate {
|
||||
_u.mutation.SetUint16ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint16ToString sets the "uint16_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableUint16ToString(v *string) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetUint16ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint16ToString clears the value of the "uint16_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearUint16ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearUint16ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt32ToString sets the "int32_to_string" field.
|
||||
func (_u *ConversionUpdate) SetInt32ToString(v string) *ConversionUpdate {
|
||||
_u.mutation.SetInt32ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt32ToString sets the "int32_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableInt32ToString(v *string) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetInt32ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt32ToString clears the value of the "int32_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearInt32ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearInt32ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint32ToString sets the "uint32_to_string" field.
|
||||
func (_u *ConversionUpdate) SetUint32ToString(v string) *ConversionUpdate {
|
||||
_u.mutation.SetUint32ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint32ToString sets the "uint32_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableUint32ToString(v *string) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetUint32ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint32ToString clears the value of the "uint32_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearUint32ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearUint32ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt64ToString sets the "int64_to_string" field.
|
||||
func (_u *ConversionUpdate) SetInt64ToString(v string) *ConversionUpdate {
|
||||
_u.mutation.SetInt64ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt64ToString sets the "int64_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableInt64ToString(v *string) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetInt64ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt64ToString clears the value of the "int64_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearInt64ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearInt64ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint64ToString sets the "uint64_to_string" field.
|
||||
func (_u *ConversionUpdate) SetUint64ToString(v string) *ConversionUpdate {
|
||||
_u.mutation.SetUint64ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint64ToString sets the "uint64_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdate) SetNillableUint64ToString(v *string) *ConversionUpdate {
|
||||
if v != nil {
|
||||
_u.SetUint64ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint64ToString clears the value of the "uint64_to_string" field.
|
||||
func (_u *ConversionUpdate) ClearUint64ToString() *ConversionUpdate {
|
||||
_u.mutation.ClearUint64ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the ConversionMutation object of the builder.
|
||||
func (_u *ConversionUpdate) Mutation() *ConversionMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *ConversionUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *ConversionUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *ConversionUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *ConversionUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *ConversionUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(conversion.Table, conversion.Columns, sqlgraph.NewFieldSpec(conversion.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(conversion.FieldName, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.NameCleared() {
|
||||
_spec.ClearField(conversion.FieldName, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Int8ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt8ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Int8ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt8ToString, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint8ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint8ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Uint8ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint8ToString, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Int16ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt16ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Int16ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt16ToString, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint16ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint16ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Uint16ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint16ToString, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Int32ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt32ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Int32ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt32ToString, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint32ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint32ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Uint32ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint32ToString, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Int64ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt64ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Int64ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt64ToString, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint64ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint64ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Uint64ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint64ToString, field.TypeString)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{conversion.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// ConversionUpdateOne is the builder for updating a single Conversion entity.
|
||||
type ConversionUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *ConversionMutation
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *ConversionUpdateOne) SetName(v string) *ConversionUpdateOne {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableName(v *string) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearName clears the value of the "name" field.
|
||||
func (_u *ConversionUpdateOne) ClearName() *ConversionUpdateOne {
|
||||
_u.mutation.ClearName()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt8ToString sets the "int8_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetInt8ToString(v string) *ConversionUpdateOne {
|
||||
_u.mutation.SetInt8ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt8ToString sets the "int8_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableInt8ToString(v *string) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetInt8ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt8ToString clears the value of the "int8_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearInt8ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearInt8ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint8ToString sets the "uint8_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetUint8ToString(v string) *ConversionUpdateOne {
|
||||
_u.mutation.SetUint8ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint8ToString sets the "uint8_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableUint8ToString(v *string) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUint8ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint8ToString clears the value of the "uint8_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearUint8ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearUint8ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt16ToString sets the "int16_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetInt16ToString(v string) *ConversionUpdateOne {
|
||||
_u.mutation.SetInt16ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt16ToString sets the "int16_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableInt16ToString(v *string) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetInt16ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt16ToString clears the value of the "int16_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearInt16ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearInt16ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint16ToString sets the "uint16_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetUint16ToString(v string) *ConversionUpdateOne {
|
||||
_u.mutation.SetUint16ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint16ToString sets the "uint16_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableUint16ToString(v *string) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUint16ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint16ToString clears the value of the "uint16_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearUint16ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearUint16ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt32ToString sets the "int32_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetInt32ToString(v string) *ConversionUpdateOne {
|
||||
_u.mutation.SetInt32ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt32ToString sets the "int32_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableInt32ToString(v *string) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetInt32ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt32ToString clears the value of the "int32_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearInt32ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearInt32ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint32ToString sets the "uint32_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetUint32ToString(v string) *ConversionUpdateOne {
|
||||
_u.mutation.SetUint32ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint32ToString sets the "uint32_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableUint32ToString(v *string) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUint32ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint32ToString clears the value of the "uint32_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearUint32ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearUint32ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetInt64ToString sets the "int64_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetInt64ToString(v string) *ConversionUpdateOne {
|
||||
_u.mutation.SetInt64ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableInt64ToString sets the "int64_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableInt64ToString(v *string) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetInt64ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearInt64ToString clears the value of the "int64_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearInt64ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearInt64ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUint64ToString sets the "uint64_to_string" field.
|
||||
func (_u *ConversionUpdateOne) SetUint64ToString(v string) *ConversionUpdateOne {
|
||||
_u.mutation.SetUint64ToString(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUint64ToString sets the "uint64_to_string" field if the given value is not nil.
|
||||
func (_u *ConversionUpdateOne) SetNillableUint64ToString(v *string) *ConversionUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUint64ToString(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUint64ToString clears the value of the "uint64_to_string" field.
|
||||
func (_u *ConversionUpdateOne) ClearUint64ToString() *ConversionUpdateOne {
|
||||
_u.mutation.ClearUint64ToString()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the ConversionMutation object of the builder.
|
||||
func (_u *ConversionUpdateOne) Mutation() *ConversionMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ConversionUpdate builder.
|
||||
func (_u *ConversionUpdateOne) Where(ps ...predicate.Conversion) *ConversionUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (_u *ConversionUpdateOne) Select(field string, fields ...string) *ConversionUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Conversion entity.
|
||||
func (_u *ConversionUpdateOne) Save(ctx context.Context) (*Conversion, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *ConversionUpdateOne) SaveX(ctx context.Context) *Conversion {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *ConversionUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *ConversionUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *ConversionUpdateOne) sqlSave(ctx context.Context) (_node *Conversion, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(conversion.Table, conversion.Columns, sqlgraph.NewFieldSpec(conversion.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`entv2: missing "Conversion.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, conversion.FieldID)
|
||||
for _, f := range fields {
|
||||
if !conversion.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("entv2: invalid field %q for query", f)}
|
||||
}
|
||||
if f != conversion.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(conversion.FieldName, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.NameCleared() {
|
||||
_spec.ClearField(conversion.FieldName, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Int8ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt8ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Int8ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt8ToString, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint8ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint8ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Uint8ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint8ToString, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Int16ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt16ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Int16ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt16ToString, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint16ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint16ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Uint16ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint16ToString, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Int32ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt32ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Int32ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt32ToString, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint32ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint32ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Uint32ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint32ToString, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Int64ToString(); ok {
|
||||
_spec.SetField(conversion.FieldInt64ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Int64ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldInt64ToString, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Uint64ToString(); ok {
|
||||
_spec.SetField(conversion.FieldUint64ToString, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.Uint64ToStringCleared() {
|
||||
_spec.ClearField(conversion.FieldUint64ToString, field.TypeString)
|
||||
}
|
||||
_node = &Conversion{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{conversion.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
132
entc/integration/migrate/entv2/customtype.go
Normal file
132
entc/integration/migrate/entv2/customtype.go
Normal file
@@ -0,0 +1,132 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/customtype"
|
||||
)
|
||||
|
||||
// CustomType is the model entity for the CustomType schema.
|
||||
type CustomType struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Custom holds the value of the "custom" field.
|
||||
Custom string `json:"custom,omitempty"`
|
||||
// Tz0 holds the value of the "tz0" field.
|
||||
Tz0 time.Time `json:"tz0,omitempty"`
|
||||
// Tz3 holds the value of the "tz3" field.
|
||||
Tz3 time.Time `json:"tz3,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*CustomType) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case customtype.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case customtype.FieldCustom:
|
||||
values[i] = new(sql.NullString)
|
||||
case customtype.FieldTz0, customtype.FieldTz3:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the CustomType fields.
|
||||
func (_m *CustomType) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case customtype.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int(value.Int64)
|
||||
case customtype.FieldCustom:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field custom", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Custom = value.String
|
||||
}
|
||||
case customtype.FieldTz0:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field tz0", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Tz0 = value.Time
|
||||
}
|
||||
case customtype.FieldTz3:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field tz3", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Tz3 = value.Time
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the CustomType.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *CustomType) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this CustomType.
|
||||
// Note that you need to call CustomType.Unwrap() before calling this method if this CustomType
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *CustomType) Update() *CustomTypeUpdateOne {
|
||||
return NewCustomTypeClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the CustomType entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (_m *CustomType) Unwrap() *CustomType {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("entv2: CustomType is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *CustomType) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("CustomType(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("custom=")
|
||||
builder.WriteString(_m.Custom)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("tz0=")
|
||||
builder.WriteString(_m.Tz0.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("tz3=")
|
||||
builder.WriteString(_m.Tz3.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// CustomTypes is a parsable slice of CustomType.
|
||||
type CustomTypes []*CustomType
|
||||
67
entc/integration/migrate/entv2/customtype/customtype.go
Normal file
67
entc/integration/migrate/entv2/customtype/customtype.go
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package customtype
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the customtype type in the database.
|
||||
Label = "custom_type"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCustom holds the string denoting the custom field in the database.
|
||||
FieldCustom = "custom"
|
||||
// FieldTz0 holds the string denoting the tz0 field in the database.
|
||||
FieldTz0 = "tz0"
|
||||
// FieldTz3 holds the string denoting the tz3 field in the database.
|
||||
FieldTz3 = "tz3"
|
||||
// Table holds the table name of the customtype in the database.
|
||||
Table = "custom_types"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for customtype fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCustom,
|
||||
FieldTz0,
|
||||
FieldTz3,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the CustomType queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCustom orders the results by the custom field.
|
||||
func ByCustom(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCustom, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTz0 orders the results by the tz0 field.
|
||||
func ByTz0(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTz0, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTz3 orders the results by the tz3 field.
|
||||
func ByTz3(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTz3, opts...).ToFunc()
|
||||
}
|
||||
364
entc/integration/migrate/entv2/customtype/mutation.go
Normal file
364
entc/integration/migrate/entv2/customtype/mutation.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 customtype
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the CustomType nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
custom *string
|
||||
tz0 *time.Time
|
||||
tz3 *time.Time
|
||||
clearedFields map[string]struct{}
|
||||
predicates []predicate.CustomType
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the CustomType entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "CustomType",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.CustomType {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetCustom sets the "custom" field.
|
||||
func (m *Mutation) SetCustom(s string) {
|
||||
m.custom = &s
|
||||
}
|
||||
|
||||
// Custom returns the value of the "custom" field in the mutation.
|
||||
func (m *Mutation) Custom() (r string, exists bool) {
|
||||
v := m.custom
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearCustom clears the value of the "custom" field.
|
||||
func (m *Mutation) ClearCustom() {
|
||||
m.custom = nil
|
||||
m.clearedFields[FieldCustom] = struct{}{}
|
||||
}
|
||||
|
||||
// CustomCleared returns if the "custom" field was cleared in this mutation.
|
||||
func (m *Mutation) CustomCleared() bool {
|
||||
_, ok := m.clearedFields[FieldCustom]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetCustom resets all changes to the "custom" field.
|
||||
func (m *Mutation) ResetCustom() {
|
||||
m.custom = nil
|
||||
delete(m.clearedFields, FieldCustom)
|
||||
}
|
||||
|
||||
// SetTz0 sets the "tz0" field.
|
||||
func (m *Mutation) SetTz0(t time.Time) {
|
||||
m.tz0 = &t
|
||||
}
|
||||
|
||||
// Tz0 returns the value of the "tz0" field in the mutation.
|
||||
func (m *Mutation) Tz0() (r time.Time, exists bool) {
|
||||
v := m.tz0
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearTz0 clears the value of the "tz0" field.
|
||||
func (m *Mutation) ClearTz0() {
|
||||
m.tz0 = nil
|
||||
m.clearedFields[FieldTz0] = struct{}{}
|
||||
}
|
||||
|
||||
// Tz0Cleared returns if the "tz0" field was cleared in this mutation.
|
||||
func (m *Mutation) Tz0Cleared() bool {
|
||||
_, ok := m.clearedFields[FieldTz0]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetTz0 resets all changes to the "tz0" field.
|
||||
func (m *Mutation) ResetTz0() {
|
||||
m.tz0 = nil
|
||||
delete(m.clearedFields, FieldTz0)
|
||||
}
|
||||
|
||||
// SetTz3 sets the "tz3" field.
|
||||
func (m *Mutation) SetTz3(t time.Time) {
|
||||
m.tz3 = &t
|
||||
}
|
||||
|
||||
// Tz3 returns the value of the "tz3" field in the mutation.
|
||||
func (m *Mutation) Tz3() (r time.Time, exists bool) {
|
||||
v := m.tz3
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearTz3 clears the value of the "tz3" field.
|
||||
func (m *Mutation) ClearTz3() {
|
||||
m.tz3 = nil
|
||||
m.clearedFields[FieldTz3] = struct{}{}
|
||||
}
|
||||
|
||||
// Tz3Cleared returns if the "tz3" field was cleared in this mutation.
|
||||
func (m *Mutation) Tz3Cleared() bool {
|
||||
_, ok := m.clearedFields[FieldTz3]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetTz3 resets all changes to the "tz3" field.
|
||||
func (m *Mutation) ResetTz3() {
|
||||
m.tz3 = nil
|
||||
delete(m.clearedFields, FieldTz3)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.CustomType) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the Mutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *Mutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.CustomType, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *Mutation) Op() ent.Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *Mutation) SetOp(op ent.Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (CustomType).
|
||||
func (m *Mutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *Mutation) Fields() []string {
|
||||
fields := make([]string, 0, 3)
|
||||
if m.custom != nil {
|
||||
fields = append(fields, FieldCustom)
|
||||
}
|
||||
if m.tz0 != nil {
|
||||
fields = append(fields, FieldTz0)
|
||||
}
|
||||
if m.tz3 != nil {
|
||||
fields = append(fields, FieldTz3)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *Mutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case FieldCustom:
|
||||
return m.Custom()
|
||||
case FieldTz0:
|
||||
return m.Tz0()
|
||||
case FieldTz3:
|
||||
return m.Tz3()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *Mutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("unknown CustomType field %s", name)
|
||||
}
|
||||
|
||||
// SetField sets the value of a field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *Mutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case FieldCustom:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetCustom(v)
|
||||
return nil
|
||||
case FieldTz0:
|
||||
v, ok := value.(time.Time)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetTz0(v)
|
||||
return nil
|
||||
case FieldTz3:
|
||||
v, ok := value.(time.Time)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetTz3(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown CustomType field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *Mutation) AddedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||
// with the given name. The second boolean return value indicates that this field
|
||||
// was not set, or was not defined in the schema.
|
||||
func (m *Mutation) AddedField(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// AddField adds the value to the field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *Mutation) AddField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
}
|
||||
return fmt.Errorf("unknown CustomType numeric field %s", name)
|
||||
}
|
||||
|
||||
// ClearedFields returns all nullable fields that were cleared during this
|
||||
// mutation.
|
||||
func (m *Mutation) ClearedFields() []string {
|
||||
var fields []string
|
||||
if m.FieldCleared(FieldCustom) {
|
||||
fields = append(fields, FieldCustom)
|
||||
}
|
||||
if m.FieldCleared(FieldTz0) {
|
||||
fields = append(fields, FieldTz0)
|
||||
}
|
||||
if m.FieldCleared(FieldTz3) {
|
||||
fields = append(fields, FieldTz3)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
// cleared in this mutation.
|
||||
func (m *Mutation) FieldCleared(name string) bool {
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *Mutation) ClearField(name string) error {
|
||||
switch name {
|
||||
case FieldCustom:
|
||||
m.ClearCustom()
|
||||
return nil
|
||||
case FieldTz0:
|
||||
m.ClearTz0()
|
||||
return nil
|
||||
case FieldTz3:
|
||||
m.ClearTz3()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown CustomType nullable field %s", name)
|
||||
}
|
||||
|
||||
// ResetField resets all changes in the mutation for the field with the given name.
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *Mutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case FieldCustom:
|
||||
m.ResetCustom()
|
||||
return nil
|
||||
case FieldTz0:
|
||||
m.ResetTz0()
|
||||
return nil
|
||||
case FieldTz3:
|
||||
m.ResetTz3()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown CustomType field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *Mutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *Mutation) AddedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *Mutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *Mutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *Mutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *Mutation) EdgeCleared(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *Mutation) ClearEdge(name string) error {
|
||||
return fmt.Errorf("unknown CustomType unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *Mutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown CustomType edge %s", name)
|
||||
}
|
||||
264
entc/integration/migrate/entv2/customtype/where.go
Normal file
264
entc/integration/migrate/entv2/customtype/where.go
Normal file
@@ -0,0 +1,264 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package customtype
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Custom applies equality check predicate on the "custom" field. It's identical to CustomEQ.
|
||||
func Custom(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldEQ(FieldCustom, v))
|
||||
}
|
||||
|
||||
// Tz0 applies equality check predicate on the "tz0" field. It's identical to Tz0EQ.
|
||||
func Tz0(v time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldEQ(FieldTz0, v))
|
||||
}
|
||||
|
||||
// Tz3 applies equality check predicate on the "tz3" field. It's identical to Tz3EQ.
|
||||
func Tz3(v time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldEQ(FieldTz3, v))
|
||||
}
|
||||
|
||||
// CustomEQ applies the EQ predicate on the "custom" field.
|
||||
func CustomEQ(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldEQ(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomNEQ applies the NEQ predicate on the "custom" field.
|
||||
func CustomNEQ(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNEQ(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomIn applies the In predicate on the "custom" field.
|
||||
func CustomIn(vs ...string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldIn(FieldCustom, vs...))
|
||||
}
|
||||
|
||||
// CustomNotIn applies the NotIn predicate on the "custom" field.
|
||||
func CustomNotIn(vs ...string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNotIn(FieldCustom, vs...))
|
||||
}
|
||||
|
||||
// CustomGT applies the GT predicate on the "custom" field.
|
||||
func CustomGT(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldGT(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomGTE applies the GTE predicate on the "custom" field.
|
||||
func CustomGTE(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldGTE(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomLT applies the LT predicate on the "custom" field.
|
||||
func CustomLT(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldLT(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomLTE applies the LTE predicate on the "custom" field.
|
||||
func CustomLTE(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldLTE(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomContains applies the Contains predicate on the "custom" field.
|
||||
func CustomContains(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldContains(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomHasPrefix applies the HasPrefix predicate on the "custom" field.
|
||||
func CustomHasPrefix(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldHasPrefix(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomHasSuffix applies the HasSuffix predicate on the "custom" field.
|
||||
func CustomHasSuffix(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldHasSuffix(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomIsNil applies the IsNil predicate on the "custom" field.
|
||||
func CustomIsNil() predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldIsNull(FieldCustom))
|
||||
}
|
||||
|
||||
// CustomNotNil applies the NotNil predicate on the "custom" field.
|
||||
func CustomNotNil() predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNotNull(FieldCustom))
|
||||
}
|
||||
|
||||
// CustomEqualFold applies the EqualFold predicate on the "custom" field.
|
||||
func CustomEqualFold(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldEqualFold(FieldCustom, v))
|
||||
}
|
||||
|
||||
// CustomContainsFold applies the ContainsFold predicate on the "custom" field.
|
||||
func CustomContainsFold(v string) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldContainsFold(FieldCustom, v))
|
||||
}
|
||||
|
||||
// Tz0EQ applies the EQ predicate on the "tz0" field.
|
||||
func Tz0EQ(v time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldEQ(FieldTz0, v))
|
||||
}
|
||||
|
||||
// Tz0NEQ applies the NEQ predicate on the "tz0" field.
|
||||
func Tz0NEQ(v time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNEQ(FieldTz0, v))
|
||||
}
|
||||
|
||||
// Tz0In applies the In predicate on the "tz0" field.
|
||||
func Tz0In(vs ...time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldIn(FieldTz0, vs...))
|
||||
}
|
||||
|
||||
// Tz0NotIn applies the NotIn predicate on the "tz0" field.
|
||||
func Tz0NotIn(vs ...time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNotIn(FieldTz0, vs...))
|
||||
}
|
||||
|
||||
// Tz0GT applies the GT predicate on the "tz0" field.
|
||||
func Tz0GT(v time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldGT(FieldTz0, v))
|
||||
}
|
||||
|
||||
// Tz0GTE applies the GTE predicate on the "tz0" field.
|
||||
func Tz0GTE(v time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldGTE(FieldTz0, v))
|
||||
}
|
||||
|
||||
// Tz0LT applies the LT predicate on the "tz0" field.
|
||||
func Tz0LT(v time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldLT(FieldTz0, v))
|
||||
}
|
||||
|
||||
// Tz0LTE applies the LTE predicate on the "tz0" field.
|
||||
func Tz0LTE(v time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldLTE(FieldTz0, v))
|
||||
}
|
||||
|
||||
// Tz0IsNil applies the IsNil predicate on the "tz0" field.
|
||||
func Tz0IsNil() predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldIsNull(FieldTz0))
|
||||
}
|
||||
|
||||
// Tz0NotNil applies the NotNil predicate on the "tz0" field.
|
||||
func Tz0NotNil() predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNotNull(FieldTz0))
|
||||
}
|
||||
|
||||
// Tz3EQ applies the EQ predicate on the "tz3" field.
|
||||
func Tz3EQ(v time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldEQ(FieldTz3, v))
|
||||
}
|
||||
|
||||
// Tz3NEQ applies the NEQ predicate on the "tz3" field.
|
||||
func Tz3NEQ(v time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNEQ(FieldTz3, v))
|
||||
}
|
||||
|
||||
// Tz3In applies the In predicate on the "tz3" field.
|
||||
func Tz3In(vs ...time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldIn(FieldTz3, vs...))
|
||||
}
|
||||
|
||||
// Tz3NotIn applies the NotIn predicate on the "tz3" field.
|
||||
func Tz3NotIn(vs ...time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNotIn(FieldTz3, vs...))
|
||||
}
|
||||
|
||||
// Tz3GT applies the GT predicate on the "tz3" field.
|
||||
func Tz3GT(v time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldGT(FieldTz3, v))
|
||||
}
|
||||
|
||||
// Tz3GTE applies the GTE predicate on the "tz3" field.
|
||||
func Tz3GTE(v time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldGTE(FieldTz3, v))
|
||||
}
|
||||
|
||||
// Tz3LT applies the LT predicate on the "tz3" field.
|
||||
func Tz3LT(v time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldLT(FieldTz3, v))
|
||||
}
|
||||
|
||||
// Tz3LTE applies the LTE predicate on the "tz3" field.
|
||||
func Tz3LTE(v time.Time) predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldLTE(FieldTz3, v))
|
||||
}
|
||||
|
||||
// Tz3IsNil applies the IsNil predicate on the "tz3" field.
|
||||
func Tz3IsNil() predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldIsNull(FieldTz3))
|
||||
}
|
||||
|
||||
// Tz3NotNil applies the NotNil predicate on the "tz3" field.
|
||||
func Tz3NotNil() predicate.CustomType {
|
||||
return predicate.CustomType(sql.FieldNotNull(FieldTz3))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.CustomType) predicate.CustomType {
|
||||
return predicate.CustomType(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.CustomType) predicate.CustomType {
|
||||
return predicate.CustomType(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.CustomType) predicate.CustomType {
|
||||
return predicate.CustomType(sql.NotPredicates(p))
|
||||
}
|
||||
228
entc/integration/migrate/entv2/customtype_create.go
Normal file
228
entc/integration/migrate/entv2/customtype_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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/customtype"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CustomTypeCreate is the builder for creating a CustomType entity.
|
||||
type CustomTypeCreate struct {
|
||||
config
|
||||
mutation *CustomTypeMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetCustom sets the "custom" field.
|
||||
func (_c *CustomTypeCreate) SetCustom(v string) *CustomTypeCreate {
|
||||
_c.mutation.SetCustom(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCustom sets the "custom" field if the given value is not nil.
|
||||
func (_c *CustomTypeCreate) SetNillableCustom(v *string) *CustomTypeCreate {
|
||||
if v != nil {
|
||||
_c.SetCustom(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetTz0 sets the "tz0" field.
|
||||
func (_c *CustomTypeCreate) SetTz0(v time.Time) *CustomTypeCreate {
|
||||
_c.mutation.SetTz0(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableTz0 sets the "tz0" field if the given value is not nil.
|
||||
func (_c *CustomTypeCreate) SetNillableTz0(v *time.Time) *CustomTypeCreate {
|
||||
if v != nil {
|
||||
_c.SetTz0(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetTz3 sets the "tz3" field.
|
||||
func (_c *CustomTypeCreate) SetTz3(v time.Time) *CustomTypeCreate {
|
||||
_c.mutation.SetTz3(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableTz3 sets the "tz3" field if the given value is not nil.
|
||||
func (_c *CustomTypeCreate) SetNillableTz3(v *time.Time) *CustomTypeCreate {
|
||||
if v != nil {
|
||||
_c.SetTz3(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the CustomTypeMutation object of the builder.
|
||||
func (_c *CustomTypeCreate) Mutation() *CustomTypeMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the CustomType in the database.
|
||||
func (_c *CustomTypeCreate) Save(ctx context.Context) (*CustomType, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *CustomTypeCreate) SaveX(ctx context.Context) *CustomType {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *CustomTypeCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *CustomTypeCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *CustomTypeCreate) check() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *CustomTypeCreate) sqlSave(ctx context.Context) (*CustomType, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *CustomTypeCreate) createSpec() (*CustomType, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &CustomType{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(customtype.Table, sqlgraph.NewFieldSpec(customtype.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.Custom(); ok {
|
||||
_spec.SetField(customtype.FieldCustom, field.TypeString, value)
|
||||
_node.Custom = value
|
||||
}
|
||||
if value, ok := _c.mutation.Tz0(); ok {
|
||||
_spec.SetField(customtype.FieldTz0, field.TypeTime, value)
|
||||
_node.Tz0 = value
|
||||
}
|
||||
if value, ok := _c.mutation.Tz3(); ok {
|
||||
_spec.SetField(customtype.FieldTz3, field.TypeTime, value)
|
||||
_node.Tz3 = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// CustomTypeCreateBulk is the builder for creating many CustomType entities in bulk.
|
||||
type CustomTypeCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*CustomTypeCreate
|
||||
}
|
||||
|
||||
// Save creates the CustomType entities in the database.
|
||||
func (_c *CustomTypeCreateBulk) Save(ctx context.Context) ([]*CustomType, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*CustomType, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*CustomTypeMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *CustomTypeCreateBulk) SaveX(ctx context.Context) []*CustomType {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *CustomTypeCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *CustomTypeCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/migrate/entv2/customtype_delete.go
Normal file
92
entc/integration/migrate/entv2/customtype_delete.go
Normal file
@@ -0,0 +1,92 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/customtype"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CustomTypeDelete is the builder for deleting a CustomType entity.
|
||||
type CustomTypeDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CustomTypeMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CustomTypeDelete builder.
|
||||
func (_d *CustomTypeDelete) Where(ps ...predicate.CustomType) *CustomTypeDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *CustomTypeDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *CustomTypeDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *CustomTypeDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(customtype.Table, sqlgraph.NewFieldSpec(customtype.FieldID, field.TypeInt))
|
||||
if ps := _d.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
_d.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// CustomTypeDeleteOne is the builder for deleting a single CustomType entity.
|
||||
type CustomTypeDeleteOne struct {
|
||||
_d *CustomTypeDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CustomTypeDelete builder.
|
||||
func (_d *CustomTypeDeleteOne) Where(ps ...predicate.CustomType) *CustomTypeDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *CustomTypeDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{customtype.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *CustomTypeDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
531
entc/integration/migrate/entv2/customtype_query.go
Normal file
531
entc/integration/migrate/entv2/customtype_query.go
Normal file
@@ -0,0 +1,531 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/customtype"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CustomTypeQuery is the builder for querying CustomType entities.
|
||||
type CustomTypeQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []customtype.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.CustomType
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the CustomTypeQuery builder.
|
||||
func (_q *CustomTypeQuery) Where(ps ...predicate.CustomType) *CustomTypeQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *CustomTypeQuery) Limit(limit int) *CustomTypeQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *CustomTypeQuery) Offset(offset int) *CustomTypeQuery {
|
||||
_q.ctx.Offset = &offset
|
||||
return _q
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (_q *CustomTypeQuery) Unique(unique bool) *CustomTypeQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *CustomTypeQuery) Order(o ...customtype.OrderOption) *CustomTypeQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// First returns the first CustomType entity from the query.
|
||||
// Returns a *NotFoundError when no CustomType was found.
|
||||
func (_q *CustomTypeQuery) First(ctx context.Context) (*CustomType, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{customtype.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) FirstX(ctx context.Context) *CustomType {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first CustomType ID from the query.
|
||||
// Returns a *NotFoundError when no CustomType ID was found.
|
||||
func (_q *CustomTypeQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{customtype.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single CustomType entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one CustomType entity is found.
|
||||
// Returns a *NotFoundError when no CustomType entities are found.
|
||||
func (_q *CustomTypeQuery) Only(ctx context.Context) (*CustomType, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{customtype.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{customtype.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) OnlyX(ctx context.Context) *CustomType {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only CustomType ID in the query.
|
||||
// Returns a *NotSingularError when more than one CustomType ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *CustomTypeQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{customtype.Label}
|
||||
default:
|
||||
err = &NotSingularError{customtype.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of CustomTypes.
|
||||
func (_q *CustomTypeQuery) All(ctx context.Context) ([]*CustomType, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*CustomType, *CustomTypeQuery]()
|
||||
return withInterceptors[[]*CustomType](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) AllX(ctx context.Context) []*CustomType {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of CustomType IDs.
|
||||
func (_q *CustomTypeQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(customtype.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *CustomTypeQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, _q, querierCount[*CustomTypeQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *CustomTypeQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||
switch _, err := _q.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("entv2: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *CustomTypeQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the CustomTypeQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *CustomTypeQuery) Clone() *CustomTypeQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &CustomTypeQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]customtype.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.CustomType{}, _q.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Custom string `json:"custom,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.CustomType.Query().
|
||||
// GroupBy(customtype.FieldCustom).
|
||||
// Aggregate(entv2.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *CustomTypeQuery) GroupBy(field string, fields ...string) *CustomTypeGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &CustomTypeGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = customtype.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Custom string `json:"custom,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.CustomType.Query().
|
||||
// Select(customtype.FieldCustom).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *CustomTypeQuery) Select(fields ...string) *CustomTypeSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &CustomTypeSelect{CustomTypeQuery: _q}
|
||||
sbuild.label = customtype.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a CustomTypeSelect configured with the given aggregations.
|
||||
func (_q *CustomTypeQuery) Aggregate(fns ...AggregateFunc) *CustomTypeSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *CustomTypeQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("entv2: uninitialized interceptor (forgotten import entv2/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !customtype.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("entv2: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *CustomTypeQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*CustomType, error) {
|
||||
var (
|
||||
nodes = []*CustomType{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*CustomType).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &CustomType{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *CustomTypeQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Columns = _q.ctx.Fields
|
||||
if len(_q.ctx.Fields) > 0 {
|
||||
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *CustomTypeQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(customtype.Table, customtype.Columns, sqlgraph.NewFieldSpec(customtype.FieldID, field.TypeInt))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, customtype.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != customtype.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *CustomTypeQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(customtype.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = customtype.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// CustomTypeGroupBy is the group-by builder for CustomType entities.
|
||||
type CustomTypeGroupBy struct {
|
||||
selector
|
||||
build *CustomTypeQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *CustomTypeGroupBy) Aggregate(fns ...AggregateFunc) *CustomTypeGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *CustomTypeGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*CustomTypeQuery, *CustomTypeGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *CustomTypeGroupBy) sqlScan(ctx context.Context, root *CustomTypeQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// CustomTypeSelect is the builder for selecting fields of CustomType entities.
|
||||
type CustomTypeSelect struct {
|
||||
*CustomTypeQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *CustomTypeSelect) Aggregate(fns ...AggregateFunc) *CustomTypeSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *CustomTypeSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*CustomTypeQuery, *CustomTypeSelect](ctx, _s.CustomTypeQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *CustomTypeSelect) sqlScan(ctx context.Context, root *CustomTypeQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
336
entc/integration/migrate/entv2/customtype_update.go
Normal file
336
entc/integration/migrate/entv2/customtype_update.go
Normal file
@@ -0,0 +1,336 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/customtype"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CustomTypeUpdate is the builder for updating CustomType entities.
|
||||
type CustomTypeUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *CustomTypeMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CustomTypeUpdate builder.
|
||||
func (_u *CustomTypeUpdate) Where(ps ...predicate.CustomType) *CustomTypeUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetCustom sets the "custom" field.
|
||||
func (_u *CustomTypeUpdate) SetCustom(v string) *CustomTypeUpdate {
|
||||
_u.mutation.SetCustom(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCustom sets the "custom" field if the given value is not nil.
|
||||
func (_u *CustomTypeUpdate) SetNillableCustom(v *string) *CustomTypeUpdate {
|
||||
if v != nil {
|
||||
_u.SetCustom(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearCustom clears the value of the "custom" field.
|
||||
func (_u *CustomTypeUpdate) ClearCustom() *CustomTypeUpdate {
|
||||
_u.mutation.ClearCustom()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetTz0 sets the "tz0" field.
|
||||
func (_u *CustomTypeUpdate) SetTz0(v time.Time) *CustomTypeUpdate {
|
||||
_u.mutation.SetTz0(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableTz0 sets the "tz0" field if the given value is not nil.
|
||||
func (_u *CustomTypeUpdate) SetNillableTz0(v *time.Time) *CustomTypeUpdate {
|
||||
if v != nil {
|
||||
_u.SetTz0(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearTz0 clears the value of the "tz0" field.
|
||||
func (_u *CustomTypeUpdate) ClearTz0() *CustomTypeUpdate {
|
||||
_u.mutation.ClearTz0()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetTz3 sets the "tz3" field.
|
||||
func (_u *CustomTypeUpdate) SetTz3(v time.Time) *CustomTypeUpdate {
|
||||
_u.mutation.SetTz3(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableTz3 sets the "tz3" field if the given value is not nil.
|
||||
func (_u *CustomTypeUpdate) SetNillableTz3(v *time.Time) *CustomTypeUpdate {
|
||||
if v != nil {
|
||||
_u.SetTz3(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearTz3 clears the value of the "tz3" field.
|
||||
func (_u *CustomTypeUpdate) ClearTz3() *CustomTypeUpdate {
|
||||
_u.mutation.ClearTz3()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the CustomTypeMutation object of the builder.
|
||||
func (_u *CustomTypeUpdate) Mutation() *CustomTypeMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *CustomTypeUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *CustomTypeUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *CustomTypeUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *CustomTypeUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *CustomTypeUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(customtype.Table, customtype.Columns, sqlgraph.NewFieldSpec(customtype.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.Custom(); ok {
|
||||
_spec.SetField(customtype.FieldCustom, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.CustomCleared() {
|
||||
_spec.ClearField(customtype.FieldCustom, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Tz0(); ok {
|
||||
_spec.SetField(customtype.FieldTz0, field.TypeTime, value)
|
||||
}
|
||||
if _u.mutation.Tz0Cleared() {
|
||||
_spec.ClearField(customtype.FieldTz0, field.TypeTime)
|
||||
}
|
||||
if value, ok := _u.mutation.Tz3(); ok {
|
||||
_spec.SetField(customtype.FieldTz3, field.TypeTime, value)
|
||||
}
|
||||
if _u.mutation.Tz3Cleared() {
|
||||
_spec.ClearField(customtype.FieldTz3, field.TypeTime)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{customtype.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// CustomTypeUpdateOne is the builder for updating a single CustomType entity.
|
||||
type CustomTypeUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *CustomTypeMutation
|
||||
}
|
||||
|
||||
// SetCustom sets the "custom" field.
|
||||
func (_u *CustomTypeUpdateOne) SetCustom(v string) *CustomTypeUpdateOne {
|
||||
_u.mutation.SetCustom(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableCustom sets the "custom" field if the given value is not nil.
|
||||
func (_u *CustomTypeUpdateOne) SetNillableCustom(v *string) *CustomTypeUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetCustom(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearCustom clears the value of the "custom" field.
|
||||
func (_u *CustomTypeUpdateOne) ClearCustom() *CustomTypeUpdateOne {
|
||||
_u.mutation.ClearCustom()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetTz0 sets the "tz0" field.
|
||||
func (_u *CustomTypeUpdateOne) SetTz0(v time.Time) *CustomTypeUpdateOne {
|
||||
_u.mutation.SetTz0(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableTz0 sets the "tz0" field if the given value is not nil.
|
||||
func (_u *CustomTypeUpdateOne) SetNillableTz0(v *time.Time) *CustomTypeUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetTz0(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearTz0 clears the value of the "tz0" field.
|
||||
func (_u *CustomTypeUpdateOne) ClearTz0() *CustomTypeUpdateOne {
|
||||
_u.mutation.ClearTz0()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetTz3 sets the "tz3" field.
|
||||
func (_u *CustomTypeUpdateOne) SetTz3(v time.Time) *CustomTypeUpdateOne {
|
||||
_u.mutation.SetTz3(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableTz3 sets the "tz3" field if the given value is not nil.
|
||||
func (_u *CustomTypeUpdateOne) SetNillableTz3(v *time.Time) *CustomTypeUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetTz3(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearTz3 clears the value of the "tz3" field.
|
||||
func (_u *CustomTypeUpdateOne) ClearTz3() *CustomTypeUpdateOne {
|
||||
_u.mutation.ClearTz3()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the CustomTypeMutation object of the builder.
|
||||
func (_u *CustomTypeUpdateOne) Mutation() *CustomTypeMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the CustomTypeUpdate builder.
|
||||
func (_u *CustomTypeUpdateOne) Where(ps ...predicate.CustomType) *CustomTypeUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (_u *CustomTypeUpdateOne) Select(field string, fields ...string) *CustomTypeUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated CustomType entity.
|
||||
func (_u *CustomTypeUpdateOne) Save(ctx context.Context) (*CustomType, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *CustomTypeUpdateOne) SaveX(ctx context.Context) *CustomType {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *CustomTypeUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *CustomTypeUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *CustomTypeUpdateOne) sqlSave(ctx context.Context) (_node *CustomType, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(customtype.Table, customtype.Columns, sqlgraph.NewFieldSpec(customtype.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`entv2: missing "CustomType.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, customtype.FieldID)
|
||||
for _, f := range fields {
|
||||
if !customtype.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("entv2: invalid field %q for query", f)}
|
||||
}
|
||||
if f != customtype.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.Predicates(); len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.Custom(); ok {
|
||||
_spec.SetField(customtype.FieldCustom, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.CustomCleared() {
|
||||
_spec.ClearField(customtype.FieldCustom, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Tz0(); ok {
|
||||
_spec.SetField(customtype.FieldTz0, field.TypeTime, value)
|
||||
}
|
||||
if _u.mutation.Tz0Cleared() {
|
||||
_spec.ClearField(customtype.FieldTz0, field.TypeTime)
|
||||
}
|
||||
if value, ok := _u.mutation.Tz3(); ok {
|
||||
_spec.SetField(customtype.FieldTz3, field.TypeTime, value)
|
||||
}
|
||||
if _u.mutation.Tz3Cleared() {
|
||||
_spec.ClearField(customtype.FieldTz3, field.TypeTime)
|
||||
}
|
||||
_node = &CustomType{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{customtype.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
628
entc/integration/migrate/entv2/ent.go
Normal file
628
entc/integration/migrate/entv2/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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/blog"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/conversion"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/customtype"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/group"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/media"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/pet"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/zoo"
|
||||
)
|
||||
|
||||
// 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{
|
||||
blog.Table: blog.ValidColumn,
|
||||
car.Table: car.ValidColumn,
|
||||
conversion.Table: conversion.ValidColumn,
|
||||
customtype.Table: customtype.ValidColumn,
|
||||
group.Table: group.ValidColumn,
|
||||
media.Table: media.ValidColumn,
|
||||
pet.Table: pet.ValidColumn,
|
||||
user.Table: user.ValidColumn,
|
||||
zoo.Table: zoo.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("entv2: %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("entv2: %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(entv2.As(entv2.Sum(field1), "sum_field1"), (entv2.As(entv2.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("entv2: %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("entv2: %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("entv2: %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("entv2: %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 "entv2: " + 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 "entv2: " + 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 "entv2: " + 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 "entv2: 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("entv2: 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("entv2: 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("entv2: 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("entv2: 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("entv2: 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("entv2: 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("entv2: 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("entv2: Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (s *selector) BoolX(ctx context.Context) bool {
|
||||
v, err := s.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// withHooks invokes the builder operation with the given hooks, if any.
|
||||
func withHooks[V Value, M any, PM interface {
|
||||
*M
|
||||
Mutation
|
||||
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
|
||||
if len(hooks) == 0 {
|
||||
return exec(ctx)
|
||||
}
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutationT, ok := any(m).(PM)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
// Set the mutation to the builder.
|
||||
*mutation = *mutationT
|
||||
return exec(ctx)
|
||||
})
|
||||
for i := len(hooks) - 1; i >= 0; i-- {
|
||||
if hooks[i] == nil {
|
||||
return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||
}
|
||||
mut = hooks[i](mut)
|
||||
}
|
||||
v, err := mut.Mutate(ctx, mutation)
|
||||
if err != nil {
|
||||
return value, err
|
||||
}
|
||||
nv, ok := v.(V)
|
||||
if !ok {
|
||||
return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
|
||||
}
|
||||
return nv, nil
|
||||
}
|
||||
|
||||
// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
|
||||
func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
|
||||
if ent.QueryFromContext(ctx) == nil {
|
||||
qc.Op = op
|
||||
ctx = ent.NewQueryContext(ctx, qc)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
func querierAll[V Value, Q interface {
|
||||
sqlAll(context.Context, ...queryHook) (V, error)
|
||||
}]() Querier {
|
||||
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
return query.sqlAll(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func querierCount[Q interface {
|
||||
sqlCount(context.Context) (int, error)
|
||||
}]() Querier {
|
||||
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
return query.sqlCount(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
|
||||
for i := len(inters) - 1; i >= 0; i-- {
|
||||
qr = inters[i].Intercept(qr)
|
||||
}
|
||||
rv, err := qr.Query(ctx, q)
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
vt, ok := rv.(V)
|
||||
if !ok {
|
||||
return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
|
||||
}
|
||||
return vt, nil
|
||||
}
|
||||
|
||||
func scanWithInterceptors[Q1 ent.Query, Q2 interface {
|
||||
sqlScan(context.Context, Q1, any) error
|
||||
}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
|
||||
rv := reflect.ValueOf(v)
|
||||
var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
query, ok := q.(Q1)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected query type %T", q)
|
||||
}
|
||||
if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
|
||||
return rv.Elem().Interface(), nil
|
||||
}
|
||||
return v, nil
|
||||
})
|
||||
for i := len(inters) - 1; i >= 0; i-- {
|
||||
qr = inters[i].Intercept(qr)
|
||||
}
|
||||
vv, err := qr.Query(ctx, rootQuery)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch rv2 := reflect.ValueOf(vv); {
|
||||
case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
|
||||
case rv.Type() == rv2.Type():
|
||||
rv.Elem().Set(rv2.Elem())
|
||||
case rv.Elem().Type() == rv2.Type():
|
||||
rv.Elem().Set(rv2)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// queryHook describes an internal hook for the different sqlAll methods.
|
||||
type queryHook func(context.Context, *sqlgraph.QuerySpec)
|
||||
88
entc/integration/migrate/entv2/enttest/enttest.go
Normal file
88
entc/integration/migrate/entv2/enttest/enttest.go
Normal file
@@ -0,0 +1,88 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package enttest
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/entc/integration/migrate/entv2"
|
||||
// required by schema hooks.
|
||||
_ "entgo.io/ent/entc/integration/migrate/entv2/runtime"
|
||||
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/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 []entv2.Option
|
||||
migrateOpts []schema.MigrateOption
|
||||
}
|
||||
)
|
||||
|
||||
// WithOptions forwards options to client creation.
|
||||
func WithOptions(opts ...entv2.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 entv2.Open and auto-run migration.
|
||||
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *entv2.Client {
|
||||
o := newOptions(opts)
|
||||
c, err := entv2.Open(driverName, dataSourceName, o.opts...)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
migrateSchema(t, c, o)
|
||||
return c
|
||||
}
|
||||
|
||||
// NewClient calls entv2.NewClient and auto-run migration.
|
||||
func NewClient(t TestingT, opts ...Option) *entv2.Client {
|
||||
o := newOptions(opts)
|
||||
c := entv2.NewClient(o.opts...)
|
||||
migrateSchema(t, c, o)
|
||||
return c
|
||||
}
|
||||
func migrateSchema(t TestingT, c *entv2.Client, o *options) {
|
||||
tables, err := schema.CopyTables(migrate.Tables)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil {
|
||||
t.Error(err)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
7
entc/integration/migrate/entv2/generate.go
Normal file
7
entc/integration/migrate/entv2/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 entv2
|
||||
|
||||
//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate --feature sql/versioned-migration --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
|
||||
95
entc/integration/migrate/entv2/group.go
Normal file
95
entc/integration/migrate/entv2/group.go
Normal file
@@ -0,0 +1,95 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/group"
|
||||
)
|
||||
|
||||
// Group is the model entity for the Group schema.
|
||||
type Group struct {
|
||||
config
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Group) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case group.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 Group fields.
|
||||
func (_m *Group) 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 group.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = 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 Group.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Group) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Group.
|
||||
// Note that you need to call Group.Unwrap() before calling this method if this Group
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Group) Update() *GroupUpdateOne {
|
||||
return NewGroupClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Group 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 *Group) Unwrap() *Group {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("entv2: Group is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Group) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Group(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v", _m.ID))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Groups is a parsable slice of Group.
|
||||
type Groups []*Group
|
||||
43
entc/integration/migrate/entv2/group/group.go
Normal file
43
entc/integration/migrate/entv2/group/group.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.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package group
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the group type in the database.
|
||||
Label = "group"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// Table holds the table name of the group in the database.
|
||||
Table = "groups"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for group fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
}
|
||||
|
||||
// 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 Group 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()
|
||||
}
|
||||
192
entc/integration/migrate/entv2/group/mutation.go
Normal file
192
entc/integration/migrate/entv2/group/mutation.go
Normal file
@@ -0,0 +1,192 @@
|
||||
// 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 group
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Group nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
clearedFields map[string]struct{}
|
||||
predicates []predicate.Group
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Group entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Group",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Group {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.Group) {
|
||||
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.Group, 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 (Group).
|
||||
func (m *Mutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *Mutation) Fields() []string {
|
||||
fields := make([]string, 0, 0)
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *Mutation) Field(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *Mutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("unknown Group field %s", name)
|
||||
}
|
||||
|
||||
// SetField sets the value of a field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *Mutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
}
|
||||
return fmt.Errorf("unknown Group field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *Mutation) AddedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||
// with the given name. The second boolean return value indicates that this field
|
||||
// was not set, or was not defined in the schema.
|
||||
func (m *Mutation) AddedField(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// AddField adds the value to the field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *Mutation) AddField(name string, value ent.Value) error {
|
||||
return fmt.Errorf("unknown Group 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 Group nullable field %s", name)
|
||||
}
|
||||
|
||||
// ResetField resets all changes in the mutation for the field with the given name.
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *Mutation) ResetField(name string) error {
|
||||
return fmt.Errorf("unknown Group field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *Mutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *Mutation) AddedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *Mutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *Mutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *Mutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *Mutation) EdgeCleared(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *Mutation) ClearEdge(name string) error {
|
||||
return fmt.Errorf("unknown Group unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *Mutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown Group edge %s", name)
|
||||
}
|
||||
72
entc/integration/migrate/entv2/group/where.go
Normal file
72
entc/integration/migrate/entv2/group/where.go
Normal file
@@ -0,0 +1,72 @@
|
||||
// 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 group
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Group {
|
||||
return predicate.Group(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Group {
|
||||
return predicate.Group(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Group {
|
||||
return predicate.Group(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Group {
|
||||
return predicate.Group(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Group {
|
||||
return predicate.Group(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Group {
|
||||
return predicate.Group(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Group {
|
||||
return predicate.Group(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Group {
|
||||
return predicate.Group(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Group {
|
||||
return predicate.Group(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Group) predicate.Group {
|
||||
return predicate.Group(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Group) predicate.Group {
|
||||
return predicate.Group(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Group) predicate.Group {
|
||||
return predicate.Group(sql.NotPredicates(p))
|
||||
}
|
||||
173
entc/integration/migrate/entv2/group_create.go
Normal file
173
entc/integration/migrate/entv2/group_create.go
Normal file
@@ -0,0 +1,173 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/group"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// GroupCreate is the builder for creating a Group entity.
|
||||
type GroupCreate struct {
|
||||
config
|
||||
mutation *GroupMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// Mutation returns the GroupMutation object of the builder.
|
||||
func (_c *GroupCreate) Mutation() *GroupMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Group in the database.
|
||||
func (_c *GroupCreate) Save(ctx context.Context) (*Group, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *GroupCreate) SaveX(ctx context.Context) *Group {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *GroupCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *GroupCreate) 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 *GroupCreate) check() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *GroupCreate) sqlSave(ctx context.Context) (*Group, 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 *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Group{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(group.Table, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt))
|
||||
)
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// GroupCreateBulk is the builder for creating many Group entities in bulk.
|
||||
type GroupCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*GroupCreate
|
||||
}
|
||||
|
||||
// Save creates the Group entities in the database.
|
||||
func (_c *GroupCreateBulk) Save(ctx context.Context) ([]*Group, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Group, 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.(*GroupMutation)
|
||||
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 *GroupCreateBulk) SaveX(ctx context.Context) []*Group {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *GroupCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *GroupCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/migrate/entv2/group_delete.go
Normal file
92
entc/integration/migrate/entv2/group_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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/group"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// GroupDelete is the builder for deleting a Group entity.
|
||||
type GroupDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *GroupMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GroupDelete builder.
|
||||
func (_d *GroupDelete) Where(ps ...predicate.Group) *GroupDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *GroupDelete) 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 *GroupDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *GroupDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(group.Table, sqlgraph.NewFieldSpec(group.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
|
||||
}
|
||||
|
||||
// GroupDeleteOne is the builder for deleting a single Group entity.
|
||||
type GroupDeleteOne struct {
|
||||
_d *GroupDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GroupDelete builder.
|
||||
func (_d *GroupDeleteOne) Where(ps ...predicate.Group) *GroupDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *GroupDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{group.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *GroupDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
509
entc/integration/migrate/entv2/group_query.go
Normal file
509
entc/integration/migrate/entv2/group_query.go
Normal file
@@ -0,0 +1,509 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/group"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// GroupQuery is the builder for querying Group entities.
|
||||
type GroupQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []group.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Group
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the GroupQuery builder.
|
||||
func (_q *GroupQuery) Where(ps ...predicate.Group) *GroupQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *GroupQuery) Limit(limit int) *GroupQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *GroupQuery) Offset(offset int) *GroupQuery {
|
||||
_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 *GroupQuery) Unique(unique bool) *GroupQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *GroupQuery) Order(o ...group.OrderOption) *GroupQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// First returns the first Group entity from the query.
|
||||
// Returns a *NotFoundError when no Group was found.
|
||||
func (_q *GroupQuery) First(ctx context.Context) (*Group, 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{group.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *GroupQuery) FirstX(ctx context.Context) *Group {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Group ID from the query.
|
||||
// Returns a *NotFoundError when no Group ID was found.
|
||||
func (_q *GroupQuery) 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{group.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *GroupQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Group entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Group entity is found.
|
||||
// Returns a *NotFoundError when no Group entities are found.
|
||||
func (_q *GroupQuery) Only(ctx context.Context) (*Group, 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{group.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{group.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *GroupQuery) OnlyX(ctx context.Context) *Group {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Group ID in the query.
|
||||
// Returns a *NotSingularError when more than one Group ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *GroupQuery) 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{group.Label}
|
||||
default:
|
||||
err = &NotSingularError{group.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *GroupQuery) 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 Groups.
|
||||
func (_q *GroupQuery) All(ctx context.Context) ([]*Group, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Group, *GroupQuery]()
|
||||
return withInterceptors[[]*Group](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *GroupQuery) AllX(ctx context.Context) []*Group {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Group IDs.
|
||||
func (_q *GroupQuery) 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(group.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *GroupQuery) 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 *GroupQuery) 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[*GroupQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *GroupQuery) 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 *GroupQuery) 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("entv2: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *GroupQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the GroupQuery 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 *GroupQuery) Clone() *GroupQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &GroupQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]group.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Group{}, _q.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
func (_q *GroupQuery) GroupBy(field string, fields ...string) *GroupGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &GroupGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = group.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
func (_q *GroupQuery) Select(fields ...string) *GroupSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &GroupSelect{GroupQuery: _q}
|
||||
sbuild.label = group.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a GroupSelect configured with the given aggregations.
|
||||
func (_q *GroupQuery) Aggregate(fns ...AggregateFunc) *GroupSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *GroupQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("entv2: uninitialized interceptor (forgotten import entv2/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !group.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("entv2: 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 *GroupQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Group, error) {
|
||||
var (
|
||||
nodes = []*Group{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Group).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Group{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *GroupQuery) 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 *GroupQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.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, group.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != group.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 *GroupQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(group.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = group.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
|
||||
}
|
||||
|
||||
// GroupGroupBy is the group-by builder for Group entities.
|
||||
type GroupGroupBy struct {
|
||||
selector
|
||||
build *GroupQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *GroupGroupBy) Aggregate(fns ...AggregateFunc) *GroupGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *GroupGroupBy) 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[*GroupQuery, *GroupGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *GroupGroupBy) sqlScan(ctx context.Context, root *GroupQuery, 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)
|
||||
}
|
||||
|
||||
// GroupSelect is the builder for selecting fields of Group entities.
|
||||
type GroupSelect struct {
|
||||
*GroupQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *GroupSelect) Aggregate(fns ...AggregateFunc) *GroupSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *GroupSelect) 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[*GroupQuery, *GroupSelect](ctx, _s.GroupQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *GroupSelect) sqlScan(ctx context.Context, root *GroupQuery, 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)
|
||||
}
|
||||
179
entc/integration/migrate/entv2/group_update.go
Normal file
179
entc/integration/migrate/entv2/group_update.go
Normal file
@@ -0,0 +1,179 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/group"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// GroupUpdate is the builder for updating Group entities.
|
||||
type GroupUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *GroupMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GroupUpdate builder.
|
||||
func (_u *GroupUpdate) Where(ps ...predicate.Group) *GroupUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the GroupMutation object of the builder.
|
||||
func (_u *GroupUpdate) Mutation() *GroupMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *GroupUpdate) 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 *GroupUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *GroupUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *GroupUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *GroupUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.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 _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{group.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// GroupUpdateOne is the builder for updating a single Group entity.
|
||||
type GroupUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *GroupMutation
|
||||
}
|
||||
|
||||
// Mutation returns the GroupMutation object of the builder.
|
||||
func (_u *GroupUpdateOne) Mutation() *GroupMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the GroupUpdate builder.
|
||||
func (_u *GroupUpdateOne) Where(ps ...predicate.Group) *GroupUpdateOne {
|
||||
_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 *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Group entity.
|
||||
func (_u *GroupUpdateOne) Save(ctx context.Context) (*Group, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *GroupUpdateOne) SaveX(ctx context.Context) *Group {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *GroupUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *GroupUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(group.Table, group.Columns, sqlgraph.NewFieldSpec(group.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`entv2: missing "Group.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, group.FieldID)
|
||||
for _, f := range fields {
|
||||
if !group.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("entv2: invalid field %q for query", f)}
|
||||
}
|
||||
if f != group.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
_node = &Group{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{group.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
299
entc/integration/migrate/entv2/hook/hook.go
Normal file
299
entc/integration/migrate/entv2/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/migrate/entv2"
|
||||
)
|
||||
|
||||
// The BlogFunc type is an adapter to allow the use of ordinary
|
||||
// function as Blog mutator.
|
||||
type BlogFunc func(context.Context, *entv2.BlogMutation) (entv2.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f BlogFunc) Mutate(ctx context.Context, m entv2.Mutation) (entv2.Value, error) {
|
||||
if mv, ok := m.(*entv2.BlogMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *entv2.BlogMutation", m)
|
||||
}
|
||||
|
||||
// The CarFunc type is an adapter to allow the use of ordinary
|
||||
// function as Car mutator.
|
||||
type CarFunc func(context.Context, *entv2.CarMutation) (entv2.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f CarFunc) Mutate(ctx context.Context, m entv2.Mutation) (entv2.Value, error) {
|
||||
if mv, ok := m.(*entv2.CarMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *entv2.CarMutation", m)
|
||||
}
|
||||
|
||||
// The ConversionFunc type is an adapter to allow the use of ordinary
|
||||
// function as Conversion mutator.
|
||||
type ConversionFunc func(context.Context, *entv2.ConversionMutation) (entv2.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f ConversionFunc) Mutate(ctx context.Context, m entv2.Mutation) (entv2.Value, error) {
|
||||
if mv, ok := m.(*entv2.ConversionMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *entv2.ConversionMutation", m)
|
||||
}
|
||||
|
||||
// The CustomTypeFunc type is an adapter to allow the use of ordinary
|
||||
// function as CustomType mutator.
|
||||
type CustomTypeFunc func(context.Context, *entv2.CustomTypeMutation) (entv2.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f CustomTypeFunc) Mutate(ctx context.Context, m entv2.Mutation) (entv2.Value, error) {
|
||||
if mv, ok := m.(*entv2.CustomTypeMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *entv2.CustomTypeMutation", m)
|
||||
}
|
||||
|
||||
// The GroupFunc type is an adapter to allow the use of ordinary
|
||||
// function as Group mutator.
|
||||
type GroupFunc func(context.Context, *entv2.GroupMutation) (entv2.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f GroupFunc) Mutate(ctx context.Context, m entv2.Mutation) (entv2.Value, error) {
|
||||
if mv, ok := m.(*entv2.GroupMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *entv2.GroupMutation", m)
|
||||
}
|
||||
|
||||
// The MediaFunc type is an adapter to allow the use of ordinary
|
||||
// function as Media mutator.
|
||||
type MediaFunc func(context.Context, *entv2.MediaMutation) (entv2.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f MediaFunc) Mutate(ctx context.Context, m entv2.Mutation) (entv2.Value, error) {
|
||||
if mv, ok := m.(*entv2.MediaMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *entv2.MediaMutation", m)
|
||||
}
|
||||
|
||||
// The PetFunc type is an adapter to allow the use of ordinary
|
||||
// function as Pet mutator.
|
||||
type PetFunc func(context.Context, *entv2.PetMutation) (entv2.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f PetFunc) Mutate(ctx context.Context, m entv2.Mutation) (entv2.Value, error) {
|
||||
if mv, ok := m.(*entv2.PetMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *entv2.PetMutation", m)
|
||||
}
|
||||
|
||||
// The UserFunc type is an adapter to allow the use of ordinary
|
||||
// function as User mutator.
|
||||
type UserFunc func(context.Context, *entv2.UserMutation) (entv2.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f UserFunc) Mutate(ctx context.Context, m entv2.Mutation) (entv2.Value, error) {
|
||||
if mv, ok := m.(*entv2.UserMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *entv2.UserMutation", m)
|
||||
}
|
||||
|
||||
// The ZooFunc type is an adapter to allow the use of ordinary
|
||||
// function as Zoo mutator.
|
||||
type ZooFunc func(context.Context, *entv2.ZooMutation) (entv2.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f ZooFunc) Mutate(ctx context.Context, m entv2.Mutation) (entv2.Value, error) {
|
||||
if mv, ok := m.(*entv2.ZooMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *entv2.ZooMutation", m)
|
||||
}
|
||||
|
||||
// Condition is a hook condition function.
|
||||
type Condition func(context.Context, entv2.Mutation) bool
|
||||
|
||||
// And groups conditions with the AND operator.
|
||||
func And(first, second Condition, rest ...Condition) Condition {
|
||||
return func(ctx context.Context, m entv2.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 entv2.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 entv2.Mutation) bool {
|
||||
return !cond(ctx, m)
|
||||
}
|
||||
}
|
||||
|
||||
// HasOp is a condition testing mutation operation.
|
||||
func HasOp(op entv2.Op) Condition {
|
||||
return func(_ context.Context, m entv2.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 entv2.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 entv2.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 entv2.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 entv2.Hook, cond Condition) entv2.Hook {
|
||||
return func(next entv2.Mutator) entv2.Mutator {
|
||||
return entv2.MutateFunc(func(ctx context.Context, m entv2.Mutation) (entv2.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, entv2.Delete|entv2.Create)
|
||||
func On(hk entv2.Hook, op entv2.Op) entv2.Hook {
|
||||
return If(hk, HasOp(op))
|
||||
}
|
||||
|
||||
// Unless skips the given hook only for the given operation.
|
||||
//
|
||||
// hook.Unless(Log, entv2.Update|entv2.UpdateOne)
|
||||
func Unless(hk entv2.Hook, op entv2.Op) entv2.Hook {
|
||||
return If(hk, Not(HasOp(op)))
|
||||
}
|
||||
|
||||
// FixedError is a hook returning a fixed error.
|
||||
func FixedError(err error) entv2.Hook {
|
||||
return func(entv2.Mutator) entv2.Mutator {
|
||||
return entv2.MutateFunc(func(context.Context, entv2.Mutation) (entv2.Value, error) {
|
||||
return nil, err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Reject returns a hook that rejects all operations that match op.
|
||||
//
|
||||
// func (T) Hooks() []entv2.Hook {
|
||||
// return []entv2.Hook{
|
||||
// Reject(entv2.Delete|entv2.Update),
|
||||
// }
|
||||
// }
|
||||
func Reject(op entv2.Op) entv2.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 []entv2.Hook
|
||||
}
|
||||
|
||||
// NewChain creates a new chain of hooks.
|
||||
func NewChain(hooks ...entv2.Hook) Chain {
|
||||
return Chain{append([]entv2.Hook(nil), hooks...)}
|
||||
}
|
||||
|
||||
// Hook chains the list of hooks and returns the final hook.
|
||||
func (c Chain) Hook() entv2.Hook {
|
||||
return func(mutator entv2.Mutator) entv2.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 ...entv2.Hook) Chain {
|
||||
newHooks := make([]entv2.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...)
|
||||
}
|
||||
129
entc/integration/migrate/entv2/media.go
Normal file
129
entc/integration/migrate/entv2/media.go
Normal file
@@ -0,0 +1,129 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/media"
|
||||
)
|
||||
|
||||
// Comment that appears in both the schema and the generated code
|
||||
type Media struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Source holds the value of the "source" field.
|
||||
Source string `json:"source,omitempty"`
|
||||
// source_ui text
|
||||
SourceURI string `json:"source_uri,omitempty"`
|
||||
// media text
|
||||
Text string `json:"text,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Media) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case media.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case media.FieldSource, media.FieldSourceURI, media.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 Media fields.
|
||||
func (_m *Media) 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 media.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 media.FieldSource:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field source", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Source = value.String
|
||||
}
|
||||
case media.FieldSourceURI:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field source_uri", values[i])
|
||||
} else if value.Valid {
|
||||
_m.SourceURI = value.String
|
||||
}
|
||||
case media.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
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Media.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Media) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Media.
|
||||
// Note that you need to call Media.Unwrap() before calling this method if this Media
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Media) Update() *MediaUpdateOne {
|
||||
return NewMediaClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Media 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 *Media) Unwrap() *Media {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("entv2: Media is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Media) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Media(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("source=")
|
||||
builder.WriteString(_m.Source)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("source_uri=")
|
||||
builder.WriteString(_m.SourceURI)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("text=")
|
||||
builder.WriteString(_m.Text)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// MediaSlice is a parsable slice of Media.
|
||||
type MediaSlice []*Media
|
||||
67
entc/integration/migrate/entv2/media/media.go
Normal file
67
entc/integration/migrate/entv2/media/media.go
Normal file
@@ -0,0 +1,67 @@
|
||||
// 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 media
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the media type in the database.
|
||||
Label = "media"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldSource holds the string denoting the source field in the database.
|
||||
FieldSource = "source"
|
||||
// FieldSourceURI holds the string denoting the source_uri field in the database.
|
||||
FieldSourceURI = "source_uri"
|
||||
// FieldText holds the string denoting the text field in the database.
|
||||
FieldText = "text"
|
||||
// Table holds the table name of the media in the database.
|
||||
Table = "media"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for media fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldSource,
|
||||
FieldSourceURI,
|
||||
FieldText,
|
||||
}
|
||||
|
||||
// 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 Media 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()
|
||||
}
|
||||
|
||||
// BySource orders the results by the source field.
|
||||
func BySource(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldSource, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// BySourceURI orders the results by the source_uri field.
|
||||
func BySourceURI(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldSourceURI, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByText orders the results by the text field.
|
||||
func ByText(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldText, opts...).ToFunc()
|
||||
}
|
||||
363
entc/integration/migrate/entv2/media/mutation.go
Normal file
363
entc/integration/migrate/entv2/media/mutation.go
Normal file
@@ -0,0 +1,363 @@
|
||||
// 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 media
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Media nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
source *string
|
||||
source_uri *string
|
||||
text *string
|
||||
clearedFields map[string]struct{}
|
||||
predicates []predicate.Media
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Media entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Media",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Media {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// SetSource sets the "source" field.
|
||||
func (m *Mutation) SetSource(s string) {
|
||||
m.source = &s
|
||||
}
|
||||
|
||||
// Source returns the value of the "source" field in the mutation.
|
||||
func (m *Mutation) Source() (r string, exists bool) {
|
||||
v := m.source
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearSource clears the value of the "source" field.
|
||||
func (m *Mutation) ClearSource() {
|
||||
m.source = nil
|
||||
m.clearedFields[FieldSource] = struct{}{}
|
||||
}
|
||||
|
||||
// SourceCleared returns if the "source" field was cleared in this mutation.
|
||||
func (m *Mutation) SourceCleared() bool {
|
||||
_, ok := m.clearedFields[FieldSource]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetSource resets all changes to the "source" field.
|
||||
func (m *Mutation) ResetSource() {
|
||||
m.source = nil
|
||||
delete(m.clearedFields, FieldSource)
|
||||
}
|
||||
|
||||
// SetSourceURI sets the "source_uri" field.
|
||||
func (m *Mutation) SetSourceURI(s string) {
|
||||
m.source_uri = &s
|
||||
}
|
||||
|
||||
// SourceURI returns the value of the "source_uri" field in the mutation.
|
||||
func (m *Mutation) SourceURI() (r string, exists bool) {
|
||||
v := m.source_uri
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearSourceURI clears the value of the "source_uri" field.
|
||||
func (m *Mutation) ClearSourceURI() {
|
||||
m.source_uri = nil
|
||||
m.clearedFields[FieldSourceURI] = struct{}{}
|
||||
}
|
||||
|
||||
// SourceURICleared returns if the "source_uri" field was cleared in this mutation.
|
||||
func (m *Mutation) SourceURICleared() bool {
|
||||
_, ok := m.clearedFields[FieldSourceURI]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetSourceURI resets all changes to the "source_uri" field.
|
||||
func (m *Mutation) ResetSourceURI() {
|
||||
m.source_uri = nil
|
||||
delete(m.clearedFields, FieldSourceURI)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// ClearText clears the value of the "text" field.
|
||||
func (m *Mutation) ClearText() {
|
||||
m.text = nil
|
||||
m.clearedFields[FieldText] = struct{}{}
|
||||
}
|
||||
|
||||
// TextCleared returns if the "text" field was cleared in this mutation.
|
||||
func (m *Mutation) TextCleared() bool {
|
||||
_, ok := m.clearedFields[FieldText]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetText resets all changes to the "text" field.
|
||||
func (m *Mutation) ResetText() {
|
||||
m.text = nil
|
||||
delete(m.clearedFields, FieldText)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.Media) {
|
||||
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.Media, 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 (Media).
|
||||
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.source != nil {
|
||||
fields = append(fields, FieldSource)
|
||||
}
|
||||
if m.source_uri != nil {
|
||||
fields = append(fields, FieldSourceURI)
|
||||
}
|
||||
if m.text != nil {
|
||||
fields = append(fields, FieldText)
|
||||
}
|
||||
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 FieldSource:
|
||||
return m.Source()
|
||||
case FieldSourceURI:
|
||||
return m.SourceURI()
|
||||
case FieldText:
|
||||
return m.Text()
|
||||
}
|
||||
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 Media 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 FieldSource:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetSource(v)
|
||||
return nil
|
||||
case FieldSourceURI:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetSourceURI(v)
|
||||
return nil
|
||||
case FieldText:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetText(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Media 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 Media 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(FieldSource) {
|
||||
fields = append(fields, FieldSource)
|
||||
}
|
||||
if m.FieldCleared(FieldSourceURI) {
|
||||
fields = append(fields, FieldSourceURI)
|
||||
}
|
||||
if m.FieldCleared(FieldText) {
|
||||
fields = append(fields, FieldText)
|
||||
}
|
||||
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 FieldSource:
|
||||
m.ClearSource()
|
||||
return nil
|
||||
case FieldSourceURI:
|
||||
m.ClearSourceURI()
|
||||
return nil
|
||||
case FieldText:
|
||||
m.ClearText()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Media 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 FieldSource:
|
||||
m.ResetSource()
|
||||
return nil
|
||||
case FieldSourceURI:
|
||||
m.ResetSourceURI()
|
||||
return nil
|
||||
case FieldText:
|
||||
m.ResetText()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Media field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *Mutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *Mutation) AddedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *Mutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *Mutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *Mutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *Mutation) EdgeCleared(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *Mutation) ClearEdge(name string) error {
|
||||
return fmt.Errorf("unknown Media unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *Mutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown Media edge %s", name)
|
||||
}
|
||||
312
entc/integration/migrate/entv2/media/where.go
Normal file
312
entc/integration/migrate/entv2/media/where.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 media
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Media {
|
||||
return predicate.Media(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Media {
|
||||
return predicate.Media(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Media {
|
||||
return predicate.Media(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Media {
|
||||
return predicate.Media(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Media {
|
||||
return predicate.Media(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Media {
|
||||
return predicate.Media(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Media {
|
||||
return predicate.Media(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Media {
|
||||
return predicate.Media(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Media {
|
||||
return predicate.Media(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Source applies equality check predicate on the "source" field. It's identical to SourceEQ.
|
||||
func Source(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldEQ(FieldSource, v))
|
||||
}
|
||||
|
||||
// SourceURI applies equality check predicate on the "source_uri" field. It's identical to SourceURIEQ.
|
||||
func SourceURI(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldEQ(FieldSourceURI, v))
|
||||
}
|
||||
|
||||
// Text applies equality check predicate on the "text" field. It's identical to TextEQ.
|
||||
func Text(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldEQ(FieldText, v))
|
||||
}
|
||||
|
||||
// SourceEQ applies the EQ predicate on the "source" field.
|
||||
func SourceEQ(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldEQ(FieldSource, v))
|
||||
}
|
||||
|
||||
// SourceNEQ applies the NEQ predicate on the "source" field.
|
||||
func SourceNEQ(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldNEQ(FieldSource, v))
|
||||
}
|
||||
|
||||
// SourceIn applies the In predicate on the "source" field.
|
||||
func SourceIn(vs ...string) predicate.Media {
|
||||
return predicate.Media(sql.FieldIn(FieldSource, vs...))
|
||||
}
|
||||
|
||||
// SourceNotIn applies the NotIn predicate on the "source" field.
|
||||
func SourceNotIn(vs ...string) predicate.Media {
|
||||
return predicate.Media(sql.FieldNotIn(FieldSource, vs...))
|
||||
}
|
||||
|
||||
// SourceGT applies the GT predicate on the "source" field.
|
||||
func SourceGT(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldGT(FieldSource, v))
|
||||
}
|
||||
|
||||
// SourceGTE applies the GTE predicate on the "source" field.
|
||||
func SourceGTE(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldGTE(FieldSource, v))
|
||||
}
|
||||
|
||||
// SourceLT applies the LT predicate on the "source" field.
|
||||
func SourceLT(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldLT(FieldSource, v))
|
||||
}
|
||||
|
||||
// SourceLTE applies the LTE predicate on the "source" field.
|
||||
func SourceLTE(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldLTE(FieldSource, v))
|
||||
}
|
||||
|
||||
// SourceContains applies the Contains predicate on the "source" field.
|
||||
func SourceContains(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldContains(FieldSource, v))
|
||||
}
|
||||
|
||||
// SourceHasPrefix applies the HasPrefix predicate on the "source" field.
|
||||
func SourceHasPrefix(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldHasPrefix(FieldSource, v))
|
||||
}
|
||||
|
||||
// SourceHasSuffix applies the HasSuffix predicate on the "source" field.
|
||||
func SourceHasSuffix(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldHasSuffix(FieldSource, v))
|
||||
}
|
||||
|
||||
// SourceIsNil applies the IsNil predicate on the "source" field.
|
||||
func SourceIsNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldIsNull(FieldSource))
|
||||
}
|
||||
|
||||
// SourceNotNil applies the NotNil predicate on the "source" field.
|
||||
func SourceNotNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldNotNull(FieldSource))
|
||||
}
|
||||
|
||||
// SourceEqualFold applies the EqualFold predicate on the "source" field.
|
||||
func SourceEqualFold(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldEqualFold(FieldSource, v))
|
||||
}
|
||||
|
||||
// SourceContainsFold applies the ContainsFold predicate on the "source" field.
|
||||
func SourceContainsFold(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldContainsFold(FieldSource, v))
|
||||
}
|
||||
|
||||
// SourceURIEQ applies the EQ predicate on the "source_uri" field.
|
||||
func SourceURIEQ(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldEQ(FieldSourceURI, v))
|
||||
}
|
||||
|
||||
// SourceURINEQ applies the NEQ predicate on the "source_uri" field.
|
||||
func SourceURINEQ(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldNEQ(FieldSourceURI, v))
|
||||
}
|
||||
|
||||
// SourceURIIn applies the In predicate on the "source_uri" field.
|
||||
func SourceURIIn(vs ...string) predicate.Media {
|
||||
return predicate.Media(sql.FieldIn(FieldSourceURI, vs...))
|
||||
}
|
||||
|
||||
// SourceURINotIn applies the NotIn predicate on the "source_uri" field.
|
||||
func SourceURINotIn(vs ...string) predicate.Media {
|
||||
return predicate.Media(sql.FieldNotIn(FieldSourceURI, vs...))
|
||||
}
|
||||
|
||||
// SourceURIGT applies the GT predicate on the "source_uri" field.
|
||||
func SourceURIGT(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldGT(FieldSourceURI, v))
|
||||
}
|
||||
|
||||
// SourceURIGTE applies the GTE predicate on the "source_uri" field.
|
||||
func SourceURIGTE(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldGTE(FieldSourceURI, v))
|
||||
}
|
||||
|
||||
// SourceURILT applies the LT predicate on the "source_uri" field.
|
||||
func SourceURILT(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldLT(FieldSourceURI, v))
|
||||
}
|
||||
|
||||
// SourceURILTE applies the LTE predicate on the "source_uri" field.
|
||||
func SourceURILTE(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldLTE(FieldSourceURI, v))
|
||||
}
|
||||
|
||||
// SourceURIContains applies the Contains predicate on the "source_uri" field.
|
||||
func SourceURIContains(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldContains(FieldSourceURI, v))
|
||||
}
|
||||
|
||||
// SourceURIHasPrefix applies the HasPrefix predicate on the "source_uri" field.
|
||||
func SourceURIHasPrefix(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldHasPrefix(FieldSourceURI, v))
|
||||
}
|
||||
|
||||
// SourceURIHasSuffix applies the HasSuffix predicate on the "source_uri" field.
|
||||
func SourceURIHasSuffix(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldHasSuffix(FieldSourceURI, v))
|
||||
}
|
||||
|
||||
// SourceURIIsNil applies the IsNil predicate on the "source_uri" field.
|
||||
func SourceURIIsNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldIsNull(FieldSourceURI))
|
||||
}
|
||||
|
||||
// SourceURINotNil applies the NotNil predicate on the "source_uri" field.
|
||||
func SourceURINotNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldNotNull(FieldSourceURI))
|
||||
}
|
||||
|
||||
// SourceURIEqualFold applies the EqualFold predicate on the "source_uri" field.
|
||||
func SourceURIEqualFold(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldEqualFold(FieldSourceURI, v))
|
||||
}
|
||||
|
||||
// SourceURIContainsFold applies the ContainsFold predicate on the "source_uri" field.
|
||||
func SourceURIContainsFold(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldContainsFold(FieldSourceURI, v))
|
||||
}
|
||||
|
||||
// TextEQ applies the EQ predicate on the "text" field.
|
||||
func TextEQ(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldEQ(FieldText, v))
|
||||
}
|
||||
|
||||
// TextNEQ applies the NEQ predicate on the "text" field.
|
||||
func TextNEQ(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldNEQ(FieldText, v))
|
||||
}
|
||||
|
||||
// TextIn applies the In predicate on the "text" field.
|
||||
func TextIn(vs ...string) predicate.Media {
|
||||
return predicate.Media(sql.FieldIn(FieldText, vs...))
|
||||
}
|
||||
|
||||
// TextNotIn applies the NotIn predicate on the "text" field.
|
||||
func TextNotIn(vs ...string) predicate.Media {
|
||||
return predicate.Media(sql.FieldNotIn(FieldText, vs...))
|
||||
}
|
||||
|
||||
// TextGT applies the GT predicate on the "text" field.
|
||||
func TextGT(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldGT(FieldText, v))
|
||||
}
|
||||
|
||||
// TextGTE applies the GTE predicate on the "text" field.
|
||||
func TextGTE(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldGTE(FieldText, v))
|
||||
}
|
||||
|
||||
// TextLT applies the LT predicate on the "text" field.
|
||||
func TextLT(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldLT(FieldText, v))
|
||||
}
|
||||
|
||||
// TextLTE applies the LTE predicate on the "text" field.
|
||||
func TextLTE(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldLTE(FieldText, v))
|
||||
}
|
||||
|
||||
// TextContains applies the Contains predicate on the "text" field.
|
||||
func TextContains(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldContains(FieldText, v))
|
||||
}
|
||||
|
||||
// TextHasPrefix applies the HasPrefix predicate on the "text" field.
|
||||
func TextHasPrefix(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldHasPrefix(FieldText, v))
|
||||
}
|
||||
|
||||
// TextHasSuffix applies the HasSuffix predicate on the "text" field.
|
||||
func TextHasSuffix(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldHasSuffix(FieldText, v))
|
||||
}
|
||||
|
||||
// TextIsNil applies the IsNil predicate on the "text" field.
|
||||
func TextIsNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldIsNull(FieldText))
|
||||
}
|
||||
|
||||
// TextNotNil applies the NotNil predicate on the "text" field.
|
||||
func TextNotNil() predicate.Media {
|
||||
return predicate.Media(sql.FieldNotNull(FieldText))
|
||||
}
|
||||
|
||||
// TextEqualFold applies the EqualFold predicate on the "text" field.
|
||||
func TextEqualFold(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldEqualFold(FieldText, v))
|
||||
}
|
||||
|
||||
// TextContainsFold applies the ContainsFold predicate on the "text" field.
|
||||
func TextContainsFold(v string) predicate.Media {
|
||||
return predicate.Media(sql.FieldContainsFold(FieldText, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Media) predicate.Media {
|
||||
return predicate.Media(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Media) predicate.Media {
|
||||
return predicate.Media(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Media) predicate.Media {
|
||||
return predicate.Media(sql.NotPredicates(p))
|
||||
}
|
||||
227
entc/integration/migrate/entv2/media_create.go
Normal file
227
entc/integration/migrate/entv2/media_create.go
Normal file
@@ -0,0 +1,227 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/media"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// MediaCreate is the builder for creating a Media entity.
|
||||
type MediaCreate struct {
|
||||
config
|
||||
mutation *MediaMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetSource sets the "source" field.
|
||||
func (_c *MediaCreate) SetSource(v string) *MediaCreate {
|
||||
_c.mutation.SetSource(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableSource sets the "source" field if the given value is not nil.
|
||||
func (_c *MediaCreate) SetNillableSource(v *string) *MediaCreate {
|
||||
if v != nil {
|
||||
_c.SetSource(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetSourceURI sets the "source_uri" field.
|
||||
func (_c *MediaCreate) SetSourceURI(v string) *MediaCreate {
|
||||
_c.mutation.SetSourceURI(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableSourceURI sets the "source_uri" field if the given value is not nil.
|
||||
func (_c *MediaCreate) SetNillableSourceURI(v *string) *MediaCreate {
|
||||
if v != nil {
|
||||
_c.SetSourceURI(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetText sets the "text" field.
|
||||
func (_c *MediaCreate) SetText(v string) *MediaCreate {
|
||||
_c.mutation.SetText(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableText sets the "text" field if the given value is not nil.
|
||||
func (_c *MediaCreate) SetNillableText(v *string) *MediaCreate {
|
||||
if v != nil {
|
||||
_c.SetText(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the MediaMutation object of the builder.
|
||||
func (_c *MediaCreate) Mutation() *MediaMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Media in the database.
|
||||
func (_c *MediaCreate) Save(ctx context.Context) (*Media, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *MediaCreate) SaveX(ctx context.Context) *Media {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *MediaCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *MediaCreate) 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 *MediaCreate) check() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *MediaCreate) sqlSave(ctx context.Context) (*Media, 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 *MediaCreate) createSpec() (*Media, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Media{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(media.Table, sqlgraph.NewFieldSpec(media.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.Source(); ok {
|
||||
_spec.SetField(media.FieldSource, field.TypeString, value)
|
||||
_node.Source = value
|
||||
}
|
||||
if value, ok := _c.mutation.SourceURI(); ok {
|
||||
_spec.SetField(media.FieldSourceURI, field.TypeString, value)
|
||||
_node.SourceURI = value
|
||||
}
|
||||
if value, ok := _c.mutation.Text(); ok {
|
||||
_spec.SetField(media.FieldText, field.TypeString, value)
|
||||
_node.Text = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// MediaCreateBulk is the builder for creating many Media entities in bulk.
|
||||
type MediaCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*MediaCreate
|
||||
}
|
||||
|
||||
// Save creates the Media entities in the database.
|
||||
func (_c *MediaCreateBulk) Save(ctx context.Context) ([]*Media, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Media, 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.(*MediaMutation)
|
||||
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 *MediaCreateBulk) SaveX(ctx context.Context) []*Media {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *MediaCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *MediaCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/migrate/entv2/media_delete.go
Normal file
92
entc/integration/migrate/entv2/media_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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/media"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// MediaDelete is the builder for deleting a Media entity.
|
||||
type MediaDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *MediaMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the MediaDelete builder.
|
||||
func (_d *MediaDelete) Where(ps ...predicate.Media) *MediaDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *MediaDelete) 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 *MediaDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *MediaDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(media.Table, sqlgraph.NewFieldSpec(media.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
|
||||
}
|
||||
|
||||
// MediaDeleteOne is the builder for deleting a single Media entity.
|
||||
type MediaDeleteOne struct {
|
||||
_d *MediaDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the MediaDelete builder.
|
||||
func (_d *MediaDeleteOne) Where(ps ...predicate.Media) *MediaDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *MediaDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{media.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *MediaDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
531
entc/integration/migrate/entv2/media_query.go
Normal file
531
entc/integration/migrate/entv2/media_query.go
Normal file
@@ -0,0 +1,531 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/media"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// MediaQuery is the builder for querying Media entities.
|
||||
type MediaQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []media.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Media
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the MediaQuery builder.
|
||||
func (_q *MediaQuery) Where(ps ...predicate.Media) *MediaQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *MediaQuery) Limit(limit int) *MediaQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *MediaQuery) Offset(offset int) *MediaQuery {
|
||||
_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 *MediaQuery) Unique(unique bool) *MediaQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *MediaQuery) Order(o ...media.OrderOption) *MediaQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// First returns the first Media entity from the query.
|
||||
// Returns a *NotFoundError when no Media was found.
|
||||
func (_q *MediaQuery) First(ctx context.Context) (*Media, 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{media.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *MediaQuery) FirstX(ctx context.Context) *Media {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Media ID from the query.
|
||||
// Returns a *NotFoundError when no Media ID was found.
|
||||
func (_q *MediaQuery) 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{media.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *MediaQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Media entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Media entity is found.
|
||||
// Returns a *NotFoundError when no Media entities are found.
|
||||
func (_q *MediaQuery) Only(ctx context.Context) (*Media, 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{media.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{media.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *MediaQuery) OnlyX(ctx context.Context) *Media {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Media ID in the query.
|
||||
// Returns a *NotSingularError when more than one Media ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *MediaQuery) 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{media.Label}
|
||||
default:
|
||||
err = &NotSingularError{media.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *MediaQuery) 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 MediaSlice.
|
||||
func (_q *MediaQuery) All(ctx context.Context) ([]*Media, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Media, *MediaQuery]()
|
||||
return withInterceptors[[]*Media](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *MediaQuery) AllX(ctx context.Context) []*Media {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Media IDs.
|
||||
func (_q *MediaQuery) 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(media.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *MediaQuery) 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 *MediaQuery) 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[*MediaQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *MediaQuery) 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 *MediaQuery) 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("entv2: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *MediaQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the MediaQuery 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 *MediaQuery) Clone() *MediaQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &MediaQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]media.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Media{}, _q.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// Source string `json:"source,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Media.Query().
|
||||
// GroupBy(media.FieldSource).
|
||||
// Aggregate(entv2.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *MediaQuery) GroupBy(field string, fields ...string) *MediaGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &MediaGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = media.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 {
|
||||
// Source string `json:"source,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Media.Query().
|
||||
// Select(media.FieldSource).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *MediaQuery) Select(fields ...string) *MediaSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &MediaSelect{MediaQuery: _q}
|
||||
sbuild.label = media.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a MediaSelect configured with the given aggregations.
|
||||
func (_q *MediaQuery) Aggregate(fns ...AggregateFunc) *MediaSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *MediaQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("entv2: uninitialized interceptor (forgotten import entv2/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !media.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("entv2: 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 *MediaQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Media, error) {
|
||||
var (
|
||||
nodes = []*Media{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Media).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Media{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *MediaQuery) 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 *MediaQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(media.Table, media.Columns, sqlgraph.NewFieldSpec(media.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, media.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != media.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 *MediaQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(media.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = media.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
|
||||
}
|
||||
|
||||
// MediaGroupBy is the group-by builder for Media entities.
|
||||
type MediaGroupBy struct {
|
||||
selector
|
||||
build *MediaQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *MediaGroupBy) Aggregate(fns ...AggregateFunc) *MediaGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *MediaGroupBy) 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[*MediaQuery, *MediaGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *MediaGroupBy) sqlScan(ctx context.Context, root *MediaQuery, 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)
|
||||
}
|
||||
|
||||
// MediaSelect is the builder for selecting fields of Media entities.
|
||||
type MediaSelect struct {
|
||||
*MediaQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *MediaSelect) Aggregate(fns ...AggregateFunc) *MediaSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *MediaSelect) 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[*MediaQuery, *MediaSelect](ctx, _s.MediaQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *MediaSelect) sqlScan(ctx context.Context, root *MediaQuery, 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)
|
||||
}
|
||||
335
entc/integration/migrate/entv2/media_update.go
Normal file
335
entc/integration/migrate/entv2/media_update.go
Normal file
@@ -0,0 +1,335 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/media"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// MediaUpdate is the builder for updating Media entities.
|
||||
type MediaUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *MediaMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the MediaUpdate builder.
|
||||
func (_u *MediaUpdate) Where(ps ...predicate.Media) *MediaUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSource sets the "source" field.
|
||||
func (_u *MediaUpdate) SetSource(v string) *MediaUpdate {
|
||||
_u.mutation.SetSource(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableSource sets the "source" field if the given value is not nil.
|
||||
func (_u *MediaUpdate) SetNillableSource(v *string) *MediaUpdate {
|
||||
if v != nil {
|
||||
_u.SetSource(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearSource clears the value of the "source" field.
|
||||
func (_u *MediaUpdate) ClearSource() *MediaUpdate {
|
||||
_u.mutation.ClearSource()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSourceURI sets the "source_uri" field.
|
||||
func (_u *MediaUpdate) SetSourceURI(v string) *MediaUpdate {
|
||||
_u.mutation.SetSourceURI(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableSourceURI sets the "source_uri" field if the given value is not nil.
|
||||
func (_u *MediaUpdate) SetNillableSourceURI(v *string) *MediaUpdate {
|
||||
if v != nil {
|
||||
_u.SetSourceURI(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearSourceURI clears the value of the "source_uri" field.
|
||||
func (_u *MediaUpdate) ClearSourceURI() *MediaUpdate {
|
||||
_u.mutation.ClearSourceURI()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetText sets the "text" field.
|
||||
func (_u *MediaUpdate) SetText(v string) *MediaUpdate {
|
||||
_u.mutation.SetText(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableText sets the "text" field if the given value is not nil.
|
||||
func (_u *MediaUpdate) SetNillableText(v *string) *MediaUpdate {
|
||||
if v != nil {
|
||||
_u.SetText(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearText clears the value of the "text" field.
|
||||
func (_u *MediaUpdate) ClearText() *MediaUpdate {
|
||||
_u.mutation.ClearText()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the MediaMutation object of the builder.
|
||||
func (_u *MediaUpdate) Mutation() *MediaMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *MediaUpdate) 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 *MediaUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *MediaUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *MediaUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *MediaUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(media.Table, media.Columns, sqlgraph.NewFieldSpec(media.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.Source(); ok {
|
||||
_spec.SetField(media.FieldSource, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.SourceCleared() {
|
||||
_spec.ClearField(media.FieldSource, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.SourceURI(); ok {
|
||||
_spec.SetField(media.FieldSourceURI, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.SourceURICleared() {
|
||||
_spec.ClearField(media.FieldSourceURI, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Text(); ok {
|
||||
_spec.SetField(media.FieldText, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.TextCleared() {
|
||||
_spec.ClearField(media.FieldText, field.TypeString)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{media.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// MediaUpdateOne is the builder for updating a single Media entity.
|
||||
type MediaUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *MediaMutation
|
||||
}
|
||||
|
||||
// SetSource sets the "source" field.
|
||||
func (_u *MediaUpdateOne) SetSource(v string) *MediaUpdateOne {
|
||||
_u.mutation.SetSource(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableSource sets the "source" field if the given value is not nil.
|
||||
func (_u *MediaUpdateOne) SetNillableSource(v *string) *MediaUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetSource(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearSource clears the value of the "source" field.
|
||||
func (_u *MediaUpdateOne) ClearSource() *MediaUpdateOne {
|
||||
_u.mutation.ClearSource()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSourceURI sets the "source_uri" field.
|
||||
func (_u *MediaUpdateOne) SetSourceURI(v string) *MediaUpdateOne {
|
||||
_u.mutation.SetSourceURI(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableSourceURI sets the "source_uri" field if the given value is not nil.
|
||||
func (_u *MediaUpdateOne) SetNillableSourceURI(v *string) *MediaUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetSourceURI(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearSourceURI clears the value of the "source_uri" field.
|
||||
func (_u *MediaUpdateOne) ClearSourceURI() *MediaUpdateOne {
|
||||
_u.mutation.ClearSourceURI()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetText sets the "text" field.
|
||||
func (_u *MediaUpdateOne) SetText(v string) *MediaUpdateOne {
|
||||
_u.mutation.SetText(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableText sets the "text" field if the given value is not nil.
|
||||
func (_u *MediaUpdateOne) SetNillableText(v *string) *MediaUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetText(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearText clears the value of the "text" field.
|
||||
func (_u *MediaUpdateOne) ClearText() *MediaUpdateOne {
|
||||
_u.mutation.ClearText()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the MediaMutation object of the builder.
|
||||
func (_u *MediaUpdateOne) Mutation() *MediaMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the MediaUpdate builder.
|
||||
func (_u *MediaUpdateOne) Where(ps ...predicate.Media) *MediaUpdateOne {
|
||||
_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 *MediaUpdateOne) Select(field string, fields ...string) *MediaUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Media entity.
|
||||
func (_u *MediaUpdateOne) Save(ctx context.Context) (*Media, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *MediaUpdateOne) SaveX(ctx context.Context) *Media {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *MediaUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *MediaUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *MediaUpdateOne) sqlSave(ctx context.Context) (_node *Media, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(media.Table, media.Columns, sqlgraph.NewFieldSpec(media.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`entv2: missing "Media.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, media.FieldID)
|
||||
for _, f := range fields {
|
||||
if !media.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("entv2: invalid field %q for query", f)}
|
||||
}
|
||||
if f != media.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.Source(); ok {
|
||||
_spec.SetField(media.FieldSource, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.SourceCleared() {
|
||||
_spec.ClearField(media.FieldSource, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.SourceURI(); ok {
|
||||
_spec.SetField(media.FieldSourceURI, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.SourceURICleared() {
|
||||
_spec.ClearField(media.FieldSourceURI, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Text(); ok {
|
||||
_spec.SetField(media.FieldText, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.TextCleared() {
|
||||
_spec.ClearField(media.FieldText, field.TypeString)
|
||||
}
|
||||
_node = &Media{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{media.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
100
entc/integration/migrate/entv2/migrate/migrate.go
Normal file
100
entc/integration/migrate/entv2/migrate/migrate.go
Normal file
@@ -0,0 +1,100 @@
|
||||
// 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...)
|
||||
}
|
||||
|
||||
// Diff compares the state read from a database connection or migration directory with
|
||||
// the state defined by the Ent schema. Changes will be written to new migration files.
|
||||
func Diff(ctx context.Context, url string, opts ...schema.MigrateOption) error {
|
||||
return NamedDiff(ctx, url, "changes", opts...)
|
||||
}
|
||||
|
||||
// NamedDiff compares the state read from a database connection or migration directory with
|
||||
// the state defined by the Ent schema. Changes will be written to new named migration files.
|
||||
func NamedDiff(ctx context.Context, url, name string, opts ...schema.MigrateOption) error {
|
||||
return schema.Diff(ctx, url, name, Tables, opts...)
|
||||
}
|
||||
|
||||
// Diff creates a migration file containing the statements to resolve the diff
|
||||
// between the Ent schema and the connected database.
|
||||
func (s *Schema) Diff(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ent/migrate: %w", err)
|
||||
}
|
||||
return migrate.Diff(ctx, Tables...)
|
||||
}
|
||||
|
||||
// NamedDiff creates a named migration file containing the statements to resolve the diff
|
||||
// between the Ent schema and the connected database.
|
||||
func (s *Schema) NamedDiff(ctx context.Context, name string, opts ...schema.MigrateOption) error {
|
||||
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ent/migrate: %w", err)
|
||||
}
|
||||
return migrate.NamedDiff(ctx, name, 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...)
|
||||
}
|
||||
309
entc/integration/migrate/entv2/migrate/schema.go
Normal file
309
entc/integration/migrate/entv2/migrate/schema.go
Normal file
@@ -0,0 +1,309 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
var (
|
||||
// BlogsColumns holds the columns for the "blogs" table.
|
||||
BlogsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true, SchemaType: map[string]string{"postgres": "serial"}},
|
||||
{Name: "oid", Type: field.TypeInt, SchemaType: map[string]string{"postgres": "serial"}},
|
||||
}
|
||||
// BlogsTable holds the schema information for the "blogs" table.
|
||||
BlogsTable = &schema.Table{
|
||||
Name: "blogs",
|
||||
Columns: BlogsColumns,
|
||||
PrimaryKey: []*schema.Column{BlogsColumns[0]},
|
||||
}
|
||||
// CarColumns holds the columns for the "Car" table.
|
||||
CarColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString, Unique: true, Nullable: true},
|
||||
{Name: "user_car", Type: field.TypeInt},
|
||||
}
|
||||
// CarTable holds the schema information for the "Car" table.
|
||||
CarTable = &schema.Table{
|
||||
Name: "Car",
|
||||
Columns: CarColumns,
|
||||
PrimaryKey: []*schema.Column{CarColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "Car_users_car",
|
||||
Columns: []*schema.Column{CarColumns[2]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
},
|
||||
}
|
||||
// ConversionsColumns holds the columns for the "conversions" table.
|
||||
ConversionsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString, Nullable: true},
|
||||
{Name: "int8_to_string", Type: field.TypeString, Nullable: true, Size: 6},
|
||||
{Name: "uint8_to_string", Type: field.TypeString, Nullable: true, Size: 6},
|
||||
{Name: "int16_to_string", Type: field.TypeString, Nullable: true, Size: 6},
|
||||
{Name: "uint16_to_string", Type: field.TypeString, Nullable: true, Size: 6},
|
||||
{Name: "int32_to_string", Type: field.TypeString, Nullable: true, Size: 12},
|
||||
{Name: "uint32_to_string", Type: field.TypeString, Nullable: true, Size: 12},
|
||||
{Name: "int64_to_string", Type: field.TypeString, Nullable: true, Size: 21},
|
||||
{Name: "uint64_to_string", Type: field.TypeString, Nullable: true, Size: 21},
|
||||
}
|
||||
// ConversionsTable holds the schema information for the "conversions" table.
|
||||
ConversionsTable = &schema.Table{
|
||||
Name: "conversions",
|
||||
Columns: ConversionsColumns,
|
||||
PrimaryKey: []*schema.Column{ConversionsColumns[0]},
|
||||
}
|
||||
// CustomTypesColumns holds the columns for the "custom_types" table.
|
||||
CustomTypesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "custom", Type: field.TypeString, Nullable: true, SchemaType: map[string]string{"postgres": "customtype"}},
|
||||
{Name: "tz0", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"mysql": "timestamp(0)", "postgres": "timestamptz(0)"}},
|
||||
{Name: "tz3", Type: field.TypeTime, Nullable: true, SchemaType: map[string]string{"mysql": "timestamp(3)", "postgres": "timestamptz(3)"}},
|
||||
}
|
||||
// CustomTypesTable holds the schema information for the "custom_types" table.
|
||||
CustomTypesTable = &schema.Table{
|
||||
Name: "custom_types",
|
||||
Columns: CustomTypesColumns,
|
||||
PrimaryKey: []*schema.Column{CustomTypesColumns[0]},
|
||||
}
|
||||
// GroupsColumns holds the columns for the "groups" table.
|
||||
GroupsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
}
|
||||
// GroupsTable holds the schema information for the "groups" table.
|
||||
GroupsTable = &schema.Table{
|
||||
Name: "groups",
|
||||
Columns: GroupsColumns,
|
||||
PrimaryKey: []*schema.Column{GroupsColumns[0]},
|
||||
}
|
||||
// MediaColumns holds the columns for the "media" table.
|
||||
MediaColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "source", Type: field.TypeString, Nullable: true},
|
||||
{Name: "source_uri", Type: field.TypeString, Nullable: true},
|
||||
{Name: "text", Type: field.TypeString, Nullable: true, Size: 2147483647, Comment: "media text"},
|
||||
}
|
||||
// MediaTable holds the schema information for the "media" table.
|
||||
MediaTable = &schema.Table{
|
||||
Name: "media",
|
||||
Comment: "Comment that appears in both the schema and the generated code",
|
||||
Columns: MediaColumns,
|
||||
PrimaryKey: []*schema.Column{MediaColumns[0]},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "media_source_source_uri",
|
||||
Unique: true,
|
||||
Columns: []*schema.Column{MediaColumns[1], MediaColumns[2]},
|
||||
Annotation: &entsql.IndexAnnotation{
|
||||
PrefixColumns: map[string]uint{
|
||||
MediaColumns[1].Name: 100,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "media_text",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{MediaColumns[3]},
|
||||
Annotation: &entsql.IndexAnnotation{
|
||||
Prefix: 100,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
// PetsColumns holds the columns for the "pets" table.
|
||||
PetsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString, Unique: true, Nullable: true},
|
||||
{Name: "owner_id", Type: field.TypeInt, Unique: true, Nullable: true},
|
||||
}
|
||||
// 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: "user_pet_id",
|
||||
Columns: []*schema.Column{PetsColumns[2]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
}
|
||||
// UsersColumns holds the columns for the "users" table.
|
||||
UsersColumns = []*schema.Column{
|
||||
{Name: "oid", Type: field.TypeInt, Increment: true},
|
||||
{Name: "mixed_string", Type: field.TypeString, Default: "default"},
|
||||
{Name: "mixed_enum", Type: field.TypeEnum, Enums: []string{"on", "off"}, Default: "on"},
|
||||
{Name: "active", Type: field.TypeBool, Default: true},
|
||||
{Name: "age", Type: field.TypeInt},
|
||||
{Name: "name", Type: field.TypeString, Size: 2147483647},
|
||||
{Name: "description", Type: field.TypeString, Nullable: true, Size: 2147483647},
|
||||
{Name: "nickname", Type: field.TypeString, Size: 255},
|
||||
{Name: "phone", Type: field.TypeString, Default: "unknown"},
|
||||
{Name: "buffer", Type: field.TypeBytes, Nullable: true},
|
||||
{Name: "title", Type: field.TypeString, Default: "SWE"},
|
||||
{Name: "renamed", Type: field.TypeString, Nullable: true},
|
||||
{Name: "new_token", Type: field.TypeString},
|
||||
{Name: "blob", Type: field.TypeBytes, Nullable: true, Size: 1000},
|
||||
{Name: "state", Type: field.TypeEnum, Nullable: true, Enums: []string{"logged_in", "logged_out", "online"}, Default: "logged_in"},
|
||||
{Name: "status", Type: field.TypeEnum, Nullable: true, Enums: []string{"done", "pending"}},
|
||||
{Name: "workplace", Type: field.TypeString, Nullable: true},
|
||||
{Name: "roles", Type: field.TypeJSON, Nullable: true, Default: "[]"},
|
||||
{Name: "default_expr", Type: field.TypeString, Nullable: true, Default: schema.Expr("lower('hello')")},
|
||||
{Name: "default_exprs", Type: field.TypeString, Nullable: true, Default: map[string]schema.Expr{"mysql": "TO_BASE64('ent')", "postgres": "md5('ent')", "sqlite3": "hex('ent')"}},
|
||||
{Name: "created_at", Type: field.TypeTime, Default: "CURRENT_TIMESTAMP"},
|
||||
{Name: "drop_optional", Type: field.TypeString},
|
||||
{Name: "blog_admins", Type: field.TypeInt, Nullable: true, SchemaType: map[string]string{"postgres": "serial"}},
|
||||
}
|
||||
// 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_blogs_admins",
|
||||
Columns: []*schema.Column{UsersColumns[22]},
|
||||
RefColumns: []*schema.Column{BlogsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "user_description",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UsersColumns[6]},
|
||||
Annotation: &entsql.IndexAnnotation{
|
||||
Prefix: 100,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "user_phone_age",
|
||||
Unique: true,
|
||||
Columns: []*schema.Column{UsersColumns[8], UsersColumns[4]},
|
||||
},
|
||||
{
|
||||
Name: "user_age",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UsersColumns[4]},
|
||||
Annotation: &entsql.IndexAnnotation{
|
||||
Desc: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "user_nickname",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UsersColumns[7]},
|
||||
Annotation: &entsql.IndexAnnotation{
|
||||
Types: map[string]string{
|
||||
"mysql": "FULLTEXT",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "user_workplace",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UsersColumns[16]},
|
||||
Annotation: &entsql.IndexAnnotation{
|
||||
IncludeColumns: []string{
|
||||
UsersColumns[7].Name,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "user_phone",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UsersColumns[8]},
|
||||
Annotation: &entsql.IndexAnnotation{
|
||||
Where: "active AND \"phone\" <> ''",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "user_age_phone",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UsersColumns[4], UsersColumns[8]},
|
||||
Annotation: &entsql.IndexAnnotation{
|
||||
OpClassColumns: map[string]string{
|
||||
UsersColumns[8].Name: "bpchar_pattern_ops",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
// ZoosColumns holds the columns for the "zoos" table.
|
||||
ZoosColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true, Default: map[string]schema.Expr{"mysql": "floor(rand() * ~(1<<31))", "postgres": "floor(random() * ~(1<<31))", "sqlite3": "abs(random())"}},
|
||||
}
|
||||
// ZoosTable holds the schema information for the "zoos" table.
|
||||
ZoosTable = &schema.Table{
|
||||
Name: "zoos",
|
||||
Columns: ZoosColumns,
|
||||
PrimaryKey: []*schema.Column{ZoosColumns[0]},
|
||||
}
|
||||
// FriendsColumns holds the columns for the "friends" table.
|
||||
FriendsColumns = []*schema.Column{
|
||||
{Name: "user", Type: field.TypeInt},
|
||||
{Name: "friend", Type: field.TypeInt},
|
||||
}
|
||||
// FriendsTable holds the schema information for the "friends" table.
|
||||
FriendsTable = &schema.Table{
|
||||
Name: "friends",
|
||||
Columns: FriendsColumns,
|
||||
PrimaryKey: []*schema.Column{FriendsColumns[0], FriendsColumns[1]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "user_friend_id1",
|
||||
Columns: []*schema.Column{FriendsColumns[0]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "user_friend_id2",
|
||||
Columns: []*schema.Column{FriendsColumns[1]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
},
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
BlogsTable,
|
||||
CarTable,
|
||||
ConversionsTable,
|
||||
CustomTypesTable,
|
||||
GroupsTable,
|
||||
MediaTable,
|
||||
PetsTable,
|
||||
UsersTable,
|
||||
ZoosTable,
|
||||
FriendsTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
CarTable.ForeignKeys[0].RefTable = UsersTable
|
||||
CarTable.Annotation = &entsql.Annotation{
|
||||
Table: "Car",
|
||||
}
|
||||
MediaTable.Annotation = &entsql.Annotation{
|
||||
Check: "text <> 'boring'",
|
||||
}
|
||||
MediaTable.Annotation.Checks = map[string]string{
|
||||
"boring_check": "source_uri <> 'entgo.io'",
|
||||
}
|
||||
PetsTable.ForeignKeys[0].RefTable = UsersTable
|
||||
UsersTable.ForeignKeys[0].RefTable = BlogsTable
|
||||
FriendsTable.ForeignKeys[0].RefTable = UsersTable
|
||||
FriendsTable.ForeignKeys[1].RefTable = UsersTable
|
||||
}
|
||||
1827
entc/integration/migrate/entv2/mutation.go
Normal file
1827
entc/integration/migrate/entv2/mutation.go
Normal file
File diff suppressed because it is too large
Load Diff
146
entc/integration/migrate/entv2/pet.go
Normal file
146
entc/integration/migrate/entv2/pet.go
Normal file
@@ -0,0 +1,146 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/pet"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
)
|
||||
|
||||
// Pet is the model entity for the Pet schema.
|
||||
type Pet struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// 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"`
|
||||
owner_id *int
|
||||
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:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case pet.FieldName:
|
||||
values[i] = new(sql.NullString)
|
||||
case pet.ForeignKeys[0]: // owner_id
|
||||
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.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Name = value.String
|
||||
}
|
||||
case pet.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field owner_id", value)
|
||||
} else if value.Valid {
|
||||
_m.owner_id = new(int)
|
||||
*_m.owner_id = 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("entv2: 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("name=")
|
||||
builder.WriteString(_m.Name)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Pets is a parsable slice of Pet.
|
||||
type Pets []*Pet
|
||||
322
entc/integration/migrate/entv2/pet/mutation.go
Normal file
322
entc/integration/migrate/entv2/pet/mutation.go
Normal file
@@ -0,0 +1,322 @@
|
||||
// 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/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Pet nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
name *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
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (m *Mutation) SetName(s string) {
|
||||
m.name = &s
|
||||
}
|
||||
|
||||
// Name returns the value of the "name" field in the mutation.
|
||||
func (m *Mutation) Name() (r string, exists bool) {
|
||||
v := m.name
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// ClearName clears the value of the "name" field.
|
||||
func (m *Mutation) ClearName() {
|
||||
m.name = nil
|
||||
m.clearedFields[FieldName] = struct{}{}
|
||||
}
|
||||
|
||||
// NameCleared returns if the "name" field was cleared in this mutation.
|
||||
func (m *Mutation) NameCleared() bool {
|
||||
_, ok := m.clearedFields[FieldName]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetName resets all changes to the "name" field.
|
||||
func (m *Mutation) ResetName() {
|
||||
m.name = nil
|
||||
delete(m.clearedFields, FieldName)
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner" edge to the User entity by id.
|
||||
func (m *Mutation) SetOwnerID(id int) {
|
||||
m.owner = &id
|
||||
}
|
||||
|
||||
// ClearOwner clears the "owner" edge to the User entity.
|
||||
func (m *Mutation) ClearOwner() {
|
||||
m.clearedowner = true
|
||||
}
|
||||
|
||||
// OwnerCleared reports if the "owner" edge to the User entity was cleared.
|
||||
func (m *Mutation) OwnerCleared() bool {
|
||||
return m.clearedowner
|
||||
}
|
||||
|
||||
// OwnerID returns the "owner" edge ID in the mutation.
|
||||
func (m *Mutation) OwnerID() (id int, exists bool) {
|
||||
if m.owner != nil {
|
||||
return *m.owner, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OwnerIDs returns the "owner" edge IDs in the mutation.
|
||||
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
|
||||
// OwnerID instead. It exists only for internal usage by the builders.
|
||||
func (m *Mutation) OwnerIDs() (ids []int) {
|
||||
if id := m.owner; id != nil {
|
||||
ids = append(ids, *id)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ResetOwner resets all changes to the "owner" edge.
|
||||
func (m *Mutation) ResetOwner() {
|
||||
m.owner = nil
|
||||
m.clearedowner = false
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.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.name != nil {
|
||||
fields = append(fields, FieldName)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *Mutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case FieldName:
|
||||
return m.Name()
|
||||
}
|
||||
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 FieldName:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetName(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 {
|
||||
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 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(FieldName) {
|
||||
fields = append(fields, FieldName)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
// cleared in this mutation.
|
||||
func (m *Mutation) FieldCleared(name string) bool {
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *Mutation) ClearField(name string) error {
|
||||
switch name {
|
||||
case FieldName:
|
||||
m.ClearName()
|
||||
return nil
|
||||
}
|
||||
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 FieldName:
|
||||
m.ResetName()
|
||||
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)
|
||||
}
|
||||
88
entc/integration/migrate/entv2/pet/pet.go
Normal file
88
entc/integration/migrate/entv2/pet/pet.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 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"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// EdgeOwner holds the string denoting the owner edge name in mutations.
|
||||
EdgeOwner = "owner"
|
||||
// UserFieldID holds the string denoting the ID field of the User.
|
||||
UserFieldID = "oid"
|
||||
// Table holds the table name of the 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,
|
||||
FieldName,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "pets"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"owner_id",
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for i := range ForeignKeys {
|
||||
if column == ForeignKeys[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the 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()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByOwnerField orders the results by owner field.
|
||||
func ByOwnerField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newOwnerStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newOwnerStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(OwnerInverseTable, UserFieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, OwnerTable, OwnerColumn),
|
||||
)
|
||||
}
|
||||
176
entc/integration/migrate/entv2/pet/where.go
Normal file
176
entc/integration/migrate/entv2/pet/where.go
Normal file
@@ -0,0 +1,176 @@
|
||||
// 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/migrate/entv2/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))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIsNil applies the IsNil predicate on the "name" field.
|
||||
func NameIsNil() predicate.Pet {
|
||||
return predicate.Pet(sql.FieldIsNull(FieldName))
|
||||
}
|
||||
|
||||
// NameNotNil applies the NotNil predicate on the "name" field.
|
||||
func NameNotNil() predicate.Pet {
|
||||
return predicate.Pet(sql.FieldNotNull(FieldName))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.Pet {
|
||||
return predicate.Pet(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// 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.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.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))
|
||||
}
|
||||
228
entc/integration/migrate/entv2/pet_create.go
Normal file
228
entc/integration/migrate/entv2/pet_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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/pet"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// PetCreate is the builder for creating a Pet entity.
|
||||
type PetCreate struct {
|
||||
config
|
||||
mutation *PetMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *PetCreate) SetName(v string) *PetCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_c *PetCreate) SetNillableName(v *string) *PetCreate {
|
||||
if v != nil {
|
||||
_c.SetName(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner" edge to the User entity by ID.
|
||||
func (_c *PetCreate) SetOwnerID(id int) *PetCreate {
|
||||
_c.mutation.SetOwnerID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableOwnerID sets the "owner" edge to the User entity by ID if the given value is not nil.
|
||||
func (_c *PetCreate) SetNillableOwnerID(id *int) *PetCreate {
|
||||
if id != nil {
|
||||
_c = _c.SetOwnerID(*id)
|
||||
}
|
||||
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 value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(pet.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if nodes := _c.mutation.OwnerIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
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.owner_id = &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/migrate/entv2/pet_delete.go
Normal file
92
entc/integration/migrate/entv2/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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/pet"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/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)
|
||||
}
|
||||
}
|
||||
618
entc/integration/migrate/entv2/pet_query.go
Normal file
618
entc/integration/migrate/entv2/pet_query.go
Normal file
@@ -0,0 +1,618 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/pet"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/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
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the 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.O2O, 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("entv2: 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 {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Pet.Query().
|
||||
// GroupBy(pet.FieldName).
|
||||
// Aggregate(entv2.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 {
|
||||
// Name string `json:"name,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Pet.Query().
|
||||
// Select(pet.FieldName).
|
||||
// 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("entv2: uninitialized interceptor (forgotten import entv2/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("entv2: 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{}
|
||||
withFKs = _q.withFKs
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
_q.withOwner != nil,
|
||||
}
|
||||
)
|
||||
if _q.withOwner != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, pet.ForeignKeys...)
|
||||
}
|
||||
_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 {
|
||||
if nodes[i].owner_id == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].owner_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 "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 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)
|
||||
}
|
||||
340
entc/integration/migrate/entv2/pet_update.go
Normal file
340
entc/integration/migrate/entv2/pet_update.go
Normal file
@@ -0,0 +1,340 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/pet"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/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
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *PetUpdate) SetName(v string) *PetUpdate {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *PetUpdate) SetNillableName(v *string) *PetUpdate {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearName clears the value of the "name" field.
|
||||
func (_u *PetUpdate) ClearName() *PetUpdate {
|
||||
_u.mutation.ClearName()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner" edge to the User entity by ID.
|
||||
func (_u *PetUpdate) SetOwnerID(id int) *PetUpdate {
|
||||
_u.mutation.SetOwnerID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableOwnerID sets the "owner" edge to the User entity by ID if the given value is not nil.
|
||||
func (_u *PetUpdate) SetNillableOwnerID(id *int) *PetUpdate {
|
||||
if id != nil {
|
||||
_u = _u.SetOwnerID(*id)
|
||||
}
|
||||
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 value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(pet.FieldName, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.NameCleared() {
|
||||
_spec.ClearField(pet.FieldName, field.TypeString)
|
||||
}
|
||||
if _u.mutation.OwnerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
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.O2O,
|
||||
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
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *PetUpdateOne) SetName(v string) *PetUpdateOne {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *PetUpdateOne) SetNillableName(v *string) *PetUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearName clears the value of the "name" field.
|
||||
func (_u *PetUpdateOne) ClearName() *PetUpdateOne {
|
||||
_u.mutation.ClearName()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetOwnerID sets the "owner" edge to the User entity by ID.
|
||||
func (_u *PetUpdateOne) SetOwnerID(id int) *PetUpdateOne {
|
||||
_u.mutation.SetOwnerID(id)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableOwnerID sets the "owner" edge to the User entity by ID if the given value is not nil.
|
||||
func (_u *PetUpdateOne) SetNillableOwnerID(id *int) *PetUpdateOne {
|
||||
if id != nil {
|
||||
_u = _u.SetOwnerID(*id)
|
||||
}
|
||||
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(`entv2: 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("entv2: 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 value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(pet.FieldName, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.NameCleared() {
|
||||
_spec.ClearField(pet.FieldName, field.TypeString)
|
||||
}
|
||||
if _u.mutation.OwnerCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
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.O2O,
|
||||
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
|
||||
}
|
||||
38
entc/integration/migrate/entv2/predicate/predicate.go
Normal file
38
entc/integration/migrate/entv2/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"
|
||||
)
|
||||
|
||||
// Blog is the predicate function for blog builders.
|
||||
type Blog func(*sql.Selector)
|
||||
|
||||
// Car is the predicate function for car builders.
|
||||
type Car func(*sql.Selector)
|
||||
|
||||
// Conversion is the predicate function for conversion builders.
|
||||
type Conversion func(*sql.Selector)
|
||||
|
||||
// CustomType is the predicate function for customtype builders.
|
||||
type CustomType func(*sql.Selector)
|
||||
|
||||
// Group is the predicate function for group builders.
|
||||
type Group func(*sql.Selector)
|
||||
|
||||
// Media is the predicate function for media builders.
|
||||
type Media func(*sql.Selector)
|
||||
|
||||
// Pet is the predicate function for pet builders.
|
||||
type Pet func(*sql.Selector)
|
||||
|
||||
// User is the predicate function for user builders.
|
||||
type User func(*sql.Selector)
|
||||
|
||||
// Zoo is the predicate function for zoo builders.
|
||||
type Zoo func(*sql.Selector)
|
||||
65
entc/integration/migrate/entv2/runtime.go
Normal file
65
entc/integration/migrate/entv2/runtime.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/schema"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
)
|
||||
|
||||
// The init function reads all schema descriptors with runtime code
|
||||
// (default values, validators, hooks and policies) and stitches it
|
||||
// to their package variables.
|
||||
func init() {
|
||||
userMixin := schema.User{}.Mixin()
|
||||
userMixinFields0 := userMixin[0].Fields()
|
||||
_ = userMixinFields0
|
||||
userFields := schema.User{}.Fields()
|
||||
_ = userFields
|
||||
// userDescMixedString is the schema descriptor for mixed_string field.
|
||||
userDescMixedString := userMixinFields0[0].Descriptor()
|
||||
// user.DefaultMixedString holds the default value on creation for the mixed_string field.
|
||||
user.DefaultMixedString = userDescMixedString.Default.(string)
|
||||
// userDescActive is the schema descriptor for active field.
|
||||
userDescActive := userFields[1].Descriptor()
|
||||
// user.DefaultActive holds the default value on creation for the active field.
|
||||
user.DefaultActive = userDescActive.Default.(bool)
|
||||
// userDescNickname is the schema descriptor for nickname field.
|
||||
userDescNickname := userFields[5].Descriptor()
|
||||
// user.NicknameValidator is a validator for the "nickname" field. It is called by the builders before save.
|
||||
user.NicknameValidator = userDescNickname.Validators[0].(func(string) error)
|
||||
// userDescPhone is the schema descriptor for phone field.
|
||||
userDescPhone := userFields[6].Descriptor()
|
||||
// user.DefaultPhone holds the default value on creation for the phone field.
|
||||
user.DefaultPhone = userDescPhone.Default.(string)
|
||||
// userDescBuffer is the schema descriptor for buffer field.
|
||||
userDescBuffer := userFields[7].Descriptor()
|
||||
// user.DefaultBuffer holds the default value on creation for the buffer field.
|
||||
user.DefaultBuffer = userDescBuffer.Default.(func() []byte)
|
||||
// userDescTitle is the schema descriptor for title field.
|
||||
userDescTitle := userFields[8].Descriptor()
|
||||
// user.DefaultTitle holds the default value on creation for the title field.
|
||||
user.DefaultTitle = userDescTitle.Default.(string)
|
||||
// userDescNewToken is the schema descriptor for new_token field.
|
||||
userDescNewToken := userFields[10].Descriptor()
|
||||
// user.DefaultNewToken holds the default value on creation for the new_token field.
|
||||
user.DefaultNewToken = userDescNewToken.Default.(func() string)
|
||||
// userDescBlob is the schema descriptor for blob field.
|
||||
userDescBlob := userFields[11].Descriptor()
|
||||
// user.BlobValidator is a validator for the "blob" field. It is called by the builders before save.
|
||||
user.BlobValidator = userDescBlob.Validators[0].(func([]byte) error)
|
||||
// userDescCreatedAt is the schema descriptor for created_at field.
|
||||
userDescCreatedAt := userFields[18].Descriptor()
|
||||
// user.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
user.DefaultCreatedAt = userDescCreatedAt.Default.(func() time.Time)
|
||||
// userDescDropOptional is the schema descriptor for drop_optional field.
|
||||
userDescDropOptional := userFields[19].Descriptor()
|
||||
// user.DefaultDropOptional holds the default value on creation for the drop_optional field.
|
||||
user.DefaultDropOptional = userDescDropOptional.Default.(func() string)
|
||||
}
|
||||
13
entc/integration/migrate/entv2/runtime/runtime.go
Normal file
13
entc/integration/migrate/entv2/runtime/runtime.go
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package runtime
|
||||
|
||||
// The schema-stitching logic is generated in entgo.io/ent/entc/integration/migrate/entv2/runtime.go
|
||||
|
||||
const (
|
||||
Version = "v0.0.0-00010101000000-000000000000" // Version of ent codegen.
|
||||
)
|
||||
51
entc/integration/migrate/entv2/schema/conversion.go
Normal file
51
entc/integration/migrate/entv2/schema/conversion.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Conversion holds the schema definition for the Conversion entity.
|
||||
type Conversion struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Conversion.
|
||||
func (Conversion) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name").
|
||||
Optional(),
|
||||
// Convert integer fields to string
|
||||
// Postgres uses the same type for int8 and int16
|
||||
// Postgres loses unsigned so we have assume value is signed
|
||||
field.String("int8_to_string").
|
||||
Optional().
|
||||
Annotations(entsql.Annotation{Size: 6}),
|
||||
field.String("uint8_to_string").
|
||||
Optional().
|
||||
Annotations(entsql.Annotation{Size: 6}),
|
||||
field.String("int16_to_string").
|
||||
Optional().
|
||||
Annotations(entsql.Annotation{Size: 6}),
|
||||
field.String("uint16_to_string").
|
||||
Optional().
|
||||
Annotations(entsql.Annotation{Size: 6}),
|
||||
field.String("int32_to_string").
|
||||
Optional().
|
||||
Annotations(entsql.Annotation{Size: 12}),
|
||||
field.String("uint32_to_string").
|
||||
Optional().
|
||||
Annotations(entsql.Annotation{Size: 12}),
|
||||
field.String("int64_to_string").
|
||||
Optional().
|
||||
Annotations(entsql.Annotation{Size: 21}),
|
||||
field.String("uint64_to_string").
|
||||
Optional().
|
||||
Annotations(entsql.Annotation{Size: 21}),
|
||||
}
|
||||
}
|
||||
39
entc/integration/migrate/entv2/schema/customtype.go
Normal file
39
entc/integration/migrate/entv2/schema/customtype.go
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// CustomType holds the schema definition for the CustomType entity.
|
||||
type CustomType struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the CustomType.
|
||||
func (CustomType) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("custom").
|
||||
Optional().
|
||||
SchemaType(map[string]string{
|
||||
dialect.Postgres: "customtype",
|
||||
}),
|
||||
field.Time("tz0").
|
||||
Optional().
|
||||
SchemaType(map[string]string{
|
||||
dialect.MySQL: "timestamp(0)",
|
||||
dialect.Postgres: "timestamptz(0)",
|
||||
}),
|
||||
field.Time("tz3").
|
||||
Optional().
|
||||
SchemaType(map[string]string{
|
||||
dialect.MySQL: "timestamp(3)",
|
||||
dialect.Postgres: "timestamptz(3)",
|
||||
}),
|
||||
}
|
||||
}
|
||||
57
entc/integration/migrate/entv2/schema/media.go
Normal file
57
entc/integration/migrate/entv2/schema/media.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/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// Media holds the schema definition for the Media entity.
|
||||
type Media struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Media.
|
||||
func (Media) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("source").
|
||||
Optional(),
|
||||
field.String("source_uri").
|
||||
Optional().
|
||||
Comment("source_ui text").
|
||||
Annotations(entsql.WithComments(false)),
|
||||
field.Text("text").
|
||||
Optional().
|
||||
Comment("media text"),
|
||||
}
|
||||
}
|
||||
|
||||
// Indexes of the Media.
|
||||
func (Media) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("source", "source_uri").
|
||||
Annotations(entsql.PrefixColumn("source", 100)).
|
||||
Unique(),
|
||||
// MySQL allow indexing text column prefix.
|
||||
index.Fields("text").
|
||||
Annotations(entsql.Prefix(100)),
|
||||
}
|
||||
}
|
||||
|
||||
// Annotations of the Media.
|
||||
func (Media) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
schema.Comment("Comment that appears in both the schema and the generated code"),
|
||||
entsql.WithComments(true),
|
||||
entsql.Check("text <> 'boring'"),
|
||||
entsql.Checks(map[string]string{
|
||||
"boring_check": "source_uri <> 'entgo.io'",
|
||||
}),
|
||||
}
|
||||
}
|
||||
260
entc/integration/migrate/entv2/schema/user.go
Normal file
260
entc/integration/migrate/entv2/schema/user.go
Normal file
@@ -0,0 +1,260 @@
|
||||
// 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"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
|
||||
"ariga.io/atlas/sql/postgres"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Mixin struct {
|
||||
mixin.Schema
|
||||
}
|
||||
|
||||
func (m Mixin) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("mixed_string").
|
||||
Default("default"),
|
||||
field.Enum("mixed_enum").
|
||||
Values("on", "off").
|
||||
Default("on"),
|
||||
}
|
||||
}
|
||||
|
||||
// User holds the schema definition for the User entity.
|
||||
type User struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (User) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
Mixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the User.
|
||||
func (User) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").
|
||||
StorageKey("oid"),
|
||||
// add a new column.
|
||||
field.Bool("active").
|
||||
Default(true),
|
||||
// changing the type of the field.
|
||||
field.Int("age"),
|
||||
// extending name field to longtext.
|
||||
field.Text("name"),
|
||||
// extending the index prefix below (on MySQL).
|
||||
field.Text("description").
|
||||
Optional(),
|
||||
// changing nickname from unique no non-unique.
|
||||
field.String("nickname").
|
||||
MaxLen(255),
|
||||
// adding new columns (must be either optional, or with a default value).
|
||||
field.String("phone").
|
||||
Default("unknown"),
|
||||
field.Bytes("buffer").
|
||||
Optional().
|
||||
DefaultFunc(func() []byte { return []byte("null") }),
|
||||
// adding new column with supported default value
|
||||
// in the database side, will append this value to
|
||||
// all existing rows.
|
||||
field.String("title").
|
||||
Default("SWE"),
|
||||
// change column name and reference it to the
|
||||
// previous one using storage-key ("renamed").
|
||||
field.String("new_name").
|
||||
Optional().
|
||||
StorageKey("renamed"),
|
||||
// change column name from "old_token" to "new_token"
|
||||
// and use Atlas diff hook in the migration.
|
||||
field.String("new_token").
|
||||
DefaultFunc(uuid.NewString),
|
||||
// extending the blob size.
|
||||
field.Bytes("blob").
|
||||
Optional().
|
||||
MaxLen(1000),
|
||||
// adding enum to the `state` column.
|
||||
field.Enum("state").
|
||||
Optional().
|
||||
Values("logged_in", "logged_out", "online").
|
||||
Default("logged_in"),
|
||||
// convert string to enum.
|
||||
field.Enum("status").
|
||||
Optional().
|
||||
Values("done", "pending"),
|
||||
// remove the max-length constraint from varchar.
|
||||
field.String("workplace").
|
||||
Optional(),
|
||||
// JSON field with database-default value.
|
||||
field.Strings("roles").
|
||||
Optional().
|
||||
Annotations(entsql.Default(`[]`)),
|
||||
field.String("default_expr").
|
||||
Optional().
|
||||
Annotations(entsql.DefaultExpr("lower('hello')")),
|
||||
field.String("default_exprs").
|
||||
Optional().
|
||||
Annotations(entsql.DefaultExprs(map[string]string{
|
||||
dialect.MySQL: "TO_BASE64('ent')",
|
||||
dialect.SQLite: "hex('ent')",
|
||||
dialect.Postgres: "md5('ent')",
|
||||
})),
|
||||
// add a new column with generated values by the database.
|
||||
field.Time("created_at").
|
||||
Default(time.Now).
|
||||
Annotations(&entsql.Annotation{
|
||||
Default: "CURRENT_TIMESTAMP",
|
||||
}),
|
||||
// nullable field was changed to non-nullable without a static
|
||||
// default value, and it requires apply hook to fix this.
|
||||
field.String("drop_optional").
|
||||
DefaultFunc(uuid.NewString),
|
||||
// deleting the `address` column.
|
||||
}
|
||||
}
|
||||
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
// Edge(children<-M2O->parent) to be dropped.
|
||||
// Edge(spouse<-O2O->spouse) to be dropped.
|
||||
edge.To("car", Car.Type),
|
||||
// New edges to added.
|
||||
edge.To("pets", Pet.Type).
|
||||
StorageKey(edge.Column("owner_id"), edge.Symbol("user_pet_id")).
|
||||
Unique(),
|
||||
edge.To("friends", User.Type).
|
||||
StorageKey(
|
||||
edge.Table("friends"),
|
||||
edge.Columns("user", "friend"),
|
||||
edge.Symbols("user_friend_id1", "user_friend_id2"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func (User) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
// Extend the column prefix by drop and create
|
||||
// this index on MySQL.
|
||||
index.Fields("description").
|
||||
Annotations(entsql.Prefix(100)),
|
||||
// Deleting old indexes (name, address),
|
||||
// and defining a new one.
|
||||
index.Fields("phone", "age").
|
||||
Unique(),
|
||||
index.Fields("age").
|
||||
Annotations(entsql.Desc()),
|
||||
// Enable FULLTEXT search on "nickname"
|
||||
// field only in MySQL.
|
||||
index.Fields("nickname").
|
||||
Annotations(
|
||||
entsql.IndexTypes(map[string]string{
|
||||
dialect.MySQL: "FULLTEXT",
|
||||
}),
|
||||
),
|
||||
// For PostgreSQL, we can include in the index non-key columns.
|
||||
index.Fields("workplace").
|
||||
Annotations(
|
||||
entsql.IncludeColumns("nickname"),
|
||||
),
|
||||
// For PostgreSQL and SQLite, users can define partial indexes.
|
||||
index.Fields("phone").
|
||||
Annotations(
|
||||
entsql.IndexWhere(`active AND "phone" <> ''`),
|
||||
),
|
||||
// For PostgreSQL, operator classes can be configured for each field.
|
||||
index.Fields("age", "phone").
|
||||
Annotations(
|
||||
entsql.OpClassColumn("phone", "bpchar_pattern_ops"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
type Car struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Annotations of the Car.
|
||||
func (Car) Annotations() []schema.Annotation {
|
||||
return []schema.Annotation{
|
||||
entsql.Annotation{Table: "Car"},
|
||||
}
|
||||
}
|
||||
|
||||
func (Car) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name").
|
||||
Optional().
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Car) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("owner", User.Type).
|
||||
Ref("car").
|
||||
Unique().
|
||||
// Make the M20 edge from nullable to required edge.
|
||||
// Requires column and foreign-key migration.
|
||||
Required(),
|
||||
}
|
||||
}
|
||||
|
||||
// Group schema.
|
||||
type Group struct{ ent.Schema }
|
||||
|
||||
// Blog schema.
|
||||
type Blog struct{ ent.Schema }
|
||||
|
||||
func (Blog) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").
|
||||
SchemaType(map[string]string{
|
||||
dialect.Postgres: postgres.TypeSerial,
|
||||
}),
|
||||
field.Int("oid").
|
||||
SchemaType(map[string]string{
|
||||
dialect.Postgres: postgres.TypeSerial,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
func (Blog) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("admins", User.Type),
|
||||
}
|
||||
}
|
||||
|
||||
// Pet schema.
|
||||
type Pet struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (Pet) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("name").
|
||||
Optional().
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Pet) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("owner", User.Type).
|
||||
Ref("pets").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
31
entc/integration/migrate/entv2/schema/zoo.go
Normal file
31
entc/integration/migrate/entv2/schema/zoo.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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/dialect/entsql"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Zoo holds the schema definition for the Zoo entity.
|
||||
type Zoo struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Zoo.
|
||||
func (Zoo) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Int("id").
|
||||
Annotations(
|
||||
entsql.DefaultExprs(map[string]string{
|
||||
dialect.MySQL: "floor(rand() * ~(1<<31))",
|
||||
dialect.SQLite: "abs(random())",
|
||||
dialect.Postgres: "floor(random() * ~(1<<31))",
|
||||
}),
|
||||
),
|
||||
}
|
||||
}
|
||||
238
entc/integration/migrate/entv2/tx.go
Normal file
238
entc/integration/migrate/entv2/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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
)
|
||||
|
||||
// Tx is a transactional client that is created by calling Client.Tx().
|
||||
type Tx struct {
|
||||
config
|
||||
// Blog is the client for interacting with the Blog builders.
|
||||
Blog *BlogClient
|
||||
// Car is the client for interacting with the Car builders.
|
||||
Car *CarClient
|
||||
// Conversion is the client for interacting with the Conversion builders.
|
||||
Conversion *ConversionClient
|
||||
// CustomType is the client for interacting with the CustomType builders.
|
||||
CustomType *CustomTypeClient
|
||||
// Group is the client for interacting with the Group builders.
|
||||
Group *GroupClient
|
||||
// Media is the client for interacting with the Media builders.
|
||||
Media *MediaClient
|
||||
// Pet is the client for interacting with the Pet builders.
|
||||
Pet *PetClient
|
||||
// User is the client for interacting with the User builders.
|
||||
User *UserClient
|
||||
// Zoo is the client for interacting with the Zoo builders.
|
||||
Zoo *ZooClient
|
||||
|
||||
// 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.Blog = NewBlogClient(tx.config)
|
||||
tx.Car = NewCarClient(tx.config)
|
||||
tx.Conversion = NewConversionClient(tx.config)
|
||||
tx.CustomType = NewCustomTypeClient(tx.config)
|
||||
tx.Group = NewGroupClient(tx.config)
|
||||
tx.Media = NewMediaClient(tx.config)
|
||||
tx.Pet = NewPetClient(tx.config)
|
||||
tx.User = NewUserClient(tx.config)
|
||||
tx.Zoo = NewZooClient(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: Blog.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)
|
||||
408
entc/integration/migrate/entv2/user.go
Normal file
408
entc/integration/migrate/entv2/user.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 entv2
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/pet"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
)
|
||||
|
||||
// User is the model entity for the User schema.
|
||||
type User struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// MixedString holds the value of the "mixed_string" field.
|
||||
MixedString string `json:"mixed_string,omitempty"`
|
||||
// MixedEnum holds the value of the "mixed_enum" field.
|
||||
MixedEnum user.MixedEnum `json:"mixed_enum,omitempty"`
|
||||
// Active holds the value of the "active" field.
|
||||
Active bool `json:"active,omitempty"`
|
||||
// Age holds the value of the "age" field.
|
||||
Age int `json:"age,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// Description holds the value of the "description" field.
|
||||
Description string `json:"description,omitempty"`
|
||||
// Nickname holds the value of the "nickname" field.
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
// Phone holds the value of the "phone" field.
|
||||
Phone string `json:"phone,omitempty"`
|
||||
// Buffer holds the value of the "buffer" field.
|
||||
Buffer []byte `json:"buffer,omitempty"`
|
||||
// Title holds the value of the "title" field.
|
||||
Title string `json:"title,omitempty"`
|
||||
// NewName holds the value of the "new_name" field.
|
||||
NewName string `json:"new_name,omitempty"`
|
||||
// NewToken holds the value of the "new_token" field.
|
||||
NewToken string `json:"new_token,omitempty"`
|
||||
// Blob holds the value of the "blob" field.
|
||||
Blob []byte `json:"blob,omitempty"`
|
||||
// State holds the value of the "state" field.
|
||||
State user.State `json:"state,omitempty"`
|
||||
// Status holds the value of the "status" field.
|
||||
Status user.Status `json:"status,omitempty"`
|
||||
// Workplace holds the value of the "workplace" field.
|
||||
Workplace string `json:"workplace,omitempty"`
|
||||
// Roles holds the value of the "roles" field.
|
||||
Roles []string `json:"roles,omitempty"`
|
||||
// DefaultExpr holds the value of the "default_expr" field.
|
||||
DefaultExpr string `json:"default_expr,omitempty"`
|
||||
// DefaultExprs holds the value of the "default_exprs" field.
|
||||
DefaultExprs string `json:"default_exprs,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// DropOptional holds the value of the "drop_optional" field.
|
||||
DropOptional string `json:"drop_optional,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the UserQuery when eager-loading is set.
|
||||
Edges UserEdges `json:"edges"`
|
||||
blog_admins *int
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// UserEdges holds the relations/edges for other nodes in the graph.
|
||||
type UserEdges struct {
|
||||
// Car holds the value of the car edge.
|
||||
Car []*Car `json:"car,omitempty"`
|
||||
// Pets holds the value of the pets edge.
|
||||
Pets *Pet `json:"pets,omitempty"`
|
||||
// Friends holds the value of the friends edge.
|
||||
Friends []*User `json:"friends,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [3]bool
|
||||
}
|
||||
|
||||
// CarOrErr returns the Car value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e UserEdges) CarOrErr() ([]*Car, error) {
|
||||
if e.loadedTypes[0] {
|
||||
return e.Car, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "car"}
|
||||
}
|
||||
|
||||
// PetsOrErr returns the Pets value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e UserEdges) PetsOrErr() (*Pet, error) {
|
||||
if e.Pets != nil {
|
||||
return e.Pets, nil
|
||||
} else if e.loadedTypes[1] {
|
||||
return nil, &NotFoundError{label: pet.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "pets"}
|
||||
}
|
||||
|
||||
// FriendsOrErr returns the Friends value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e UserEdges) FriendsOrErr() ([]*User, error) {
|
||||
if e.loadedTypes[2] {
|
||||
return e.Friends, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "friends"}
|
||||
}
|
||||
|
||||
// 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.FieldBuffer, user.FieldBlob, user.FieldRoles:
|
||||
values[i] = new([]byte)
|
||||
case user.FieldActive:
|
||||
values[i] = new(sql.NullBool)
|
||||
case user.FieldID, user.FieldAge:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case user.FieldMixedString, user.FieldMixedEnum, user.FieldName, user.FieldDescription, user.FieldNickname, user.FieldPhone, user.FieldTitle, user.FieldNewName, user.FieldNewToken, user.FieldState, user.FieldStatus, user.FieldWorkplace, user.FieldDefaultExpr, user.FieldDefaultExprs, user.FieldDropOptional:
|
||||
values[i] = new(sql.NullString)
|
||||
case user.FieldCreatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
case user.ForeignKeys[0]: // blog_admins
|
||||
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.FieldMixedString:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field mixed_string", values[i])
|
||||
} else if value.Valid {
|
||||
_m.MixedString = value.String
|
||||
}
|
||||
case user.FieldMixedEnum:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field mixed_enum", values[i])
|
||||
} else if value.Valid {
|
||||
_m.MixedEnum = user.MixedEnum(value.String)
|
||||
}
|
||||
case user.FieldActive:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field active", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Active = value.Bool
|
||||
}
|
||||
case user.FieldAge:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field age", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Age = int(value.Int64)
|
||||
}
|
||||
case user.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Name = value.String
|
||||
}
|
||||
case user.FieldDescription:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field description", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Description = value.String
|
||||
}
|
||||
case user.FieldNickname:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field nickname", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Nickname = value.String
|
||||
}
|
||||
case user.FieldPhone:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field phone", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Phone = value.String
|
||||
}
|
||||
case user.FieldBuffer:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field buffer", values[i])
|
||||
} else if value != nil {
|
||||
_m.Buffer = *value
|
||||
}
|
||||
case user.FieldTitle:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field title", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Title = value.String
|
||||
}
|
||||
case user.FieldNewName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field new_name", values[i])
|
||||
} else if value.Valid {
|
||||
_m.NewName = value.String
|
||||
}
|
||||
case user.FieldNewToken:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field new_token", values[i])
|
||||
} else if value.Valid {
|
||||
_m.NewToken = value.String
|
||||
}
|
||||
case user.FieldBlob:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field blob", values[i])
|
||||
} else if value != nil {
|
||||
_m.Blob = *value
|
||||
}
|
||||
case user.FieldState:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field state", values[i])
|
||||
} else if value.Valid {
|
||||
_m.State = user.State(value.String)
|
||||
}
|
||||
case user.FieldStatus:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field status", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Status = user.Status(value.String)
|
||||
}
|
||||
case user.FieldWorkplace:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field workplace", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Workplace = value.String
|
||||
}
|
||||
case user.FieldRoles:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field roles", values[i])
|
||||
} else if value != nil && len(*value) > 0 {
|
||||
if err := json.Unmarshal(*value, &_m.Roles); err != nil {
|
||||
return fmt.Errorf("unmarshal field roles: %w", err)
|
||||
}
|
||||
}
|
||||
case user.FieldDefaultExpr:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field default_expr", values[i])
|
||||
} else if value.Valid {
|
||||
_m.DefaultExpr = value.String
|
||||
}
|
||||
case user.FieldDefaultExprs:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field default_exprs", values[i])
|
||||
} else if value.Valid {
|
||||
_m.DefaultExprs = value.String
|
||||
}
|
||||
case user.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.CreatedAt = value.Time
|
||||
}
|
||||
case user.FieldDropOptional:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field drop_optional", values[i])
|
||||
} else if value.Valid {
|
||||
_m.DropOptional = value.String
|
||||
}
|
||||
case user.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field blog_admins", value)
|
||||
} else if value.Valid {
|
||||
_m.blog_admins = new(int)
|
||||
*_m.blog_admins = 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)
|
||||
}
|
||||
|
||||
// QueryCar queries the "car" edge of the User entity.
|
||||
func (_m *User) QueryCar() *CarQuery {
|
||||
return NewUserClient(_m.config).QueryCar(_m)
|
||||
}
|
||||
|
||||
// QueryPets queries the "pets" edge of the User entity.
|
||||
func (_m *User) QueryPets() *PetQuery {
|
||||
return NewUserClient(_m.config).QueryPets(_m)
|
||||
}
|
||||
|
||||
// QueryFriends queries the "friends" edge of the User entity.
|
||||
func (_m *User) QueryFriends() *UserQuery {
|
||||
return NewUserClient(_m.config).QueryFriends(_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("entv2: 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("mixed_string=")
|
||||
builder.WriteString(_m.MixedString)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("mixed_enum=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.MixedEnum))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("active=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Active))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("age=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Age))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(_m.Name)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("description=")
|
||||
builder.WriteString(_m.Description)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("nickname=")
|
||||
builder.WriteString(_m.Nickname)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("phone=")
|
||||
builder.WriteString(_m.Phone)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("buffer=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Buffer))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("title=")
|
||||
builder.WriteString(_m.Title)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("new_name=")
|
||||
builder.WriteString(_m.NewName)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("new_token=")
|
||||
builder.WriteString(_m.NewToken)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("blob=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Blob))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("state=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.State))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("status=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Status))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("workplace=")
|
||||
builder.WriteString(_m.Workplace)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("roles=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Roles))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("default_expr=")
|
||||
builder.WriteString(_m.DefaultExpr)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("default_exprs=")
|
||||
builder.WriteString(_m.DefaultExprs)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("drop_optional=")
|
||||
builder.WriteString(_m.DropOptional)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Users is a parsable slice of User.
|
||||
type Users []*User
|
||||
1415
entc/integration/migrate/entv2/user/mutation.go
Normal file
1415
entc/integration/migrate/entv2/user/mutation.go
Normal file
File diff suppressed because it is too large
Load Diff
398
entc/integration/migrate/entv2/user/user.go
Normal file
398
entc/integration/migrate/entv2/user/user.go
Normal file
@@ -0,0 +1,398 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package user
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the user type in the database.
|
||||
Label = "user"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "oid"
|
||||
// FieldMixedString holds the string denoting the mixed_string field in the database.
|
||||
FieldMixedString = "mixed_string"
|
||||
// FieldMixedEnum holds the string denoting the mixed_enum field in the database.
|
||||
FieldMixedEnum = "mixed_enum"
|
||||
// FieldActive holds the string denoting the active field in the database.
|
||||
FieldActive = "active"
|
||||
// FieldAge holds the string denoting the age field in the database.
|
||||
FieldAge = "age"
|
||||
// FieldName holds the string denoting the name field in the database.
|
||||
FieldName = "name"
|
||||
// FieldDescription holds the string denoting the description field in the database.
|
||||
FieldDescription = "description"
|
||||
// FieldNickname holds the string denoting the nickname field in the database.
|
||||
FieldNickname = "nickname"
|
||||
// FieldPhone holds the string denoting the phone field in the database.
|
||||
FieldPhone = "phone"
|
||||
// FieldBuffer holds the string denoting the buffer field in the database.
|
||||
FieldBuffer = "buffer"
|
||||
// FieldTitle holds the string denoting the title field in the database.
|
||||
FieldTitle = "title"
|
||||
// FieldNewName holds the string denoting the new_name field in the database.
|
||||
FieldNewName = "renamed"
|
||||
// FieldNewToken holds the string denoting the new_token field in the database.
|
||||
FieldNewToken = "new_token"
|
||||
// FieldBlob holds the string denoting the blob field in the database.
|
||||
FieldBlob = "blob"
|
||||
// FieldState holds the string denoting the state field in the database.
|
||||
FieldState = "state"
|
||||
// FieldStatus holds the string denoting the status field in the database.
|
||||
FieldStatus = "status"
|
||||
// FieldWorkplace holds the string denoting the workplace field in the database.
|
||||
FieldWorkplace = "workplace"
|
||||
// FieldRoles holds the string denoting the roles field in the database.
|
||||
FieldRoles = "roles"
|
||||
// FieldDefaultExpr holds the string denoting the default_expr field in the database.
|
||||
FieldDefaultExpr = "default_expr"
|
||||
// FieldDefaultExprs holds the string denoting the default_exprs field in the database.
|
||||
FieldDefaultExprs = "default_exprs"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldDropOptional holds the string denoting the drop_optional field in the database.
|
||||
FieldDropOptional = "drop_optional"
|
||||
// EdgeCar holds the string denoting the car edge name in mutations.
|
||||
EdgeCar = "car"
|
||||
// EdgePets holds the string denoting the pets edge name in mutations.
|
||||
EdgePets = "pets"
|
||||
// EdgeFriends holds the string denoting the friends edge name in mutations.
|
||||
EdgeFriends = "friends"
|
||||
// CarFieldID holds the string denoting the ID field of the Car.
|
||||
CarFieldID = "id"
|
||||
// PetFieldID holds the string denoting the ID field of the Pet.
|
||||
PetFieldID = "id"
|
||||
// Table holds the table name of the user in the database.
|
||||
Table = "users"
|
||||
// CarTable is the table that holds the car relation/edge.
|
||||
CarTable = "Car"
|
||||
// CarInverseTable is the table name for the Car entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "car" package.
|
||||
CarInverseTable = "Car"
|
||||
// CarColumn is the table column denoting the car relation/edge.
|
||||
CarColumn = "user_car"
|
||||
// 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"
|
||||
// FriendsTable is the table that holds the friends relation/edge. The primary key declared below.
|
||||
FriendsTable = "friends"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for user fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldMixedString,
|
||||
FieldMixedEnum,
|
||||
FieldActive,
|
||||
FieldAge,
|
||||
FieldName,
|
||||
FieldDescription,
|
||||
FieldNickname,
|
||||
FieldPhone,
|
||||
FieldBuffer,
|
||||
FieldTitle,
|
||||
FieldNewName,
|
||||
FieldNewToken,
|
||||
FieldBlob,
|
||||
FieldState,
|
||||
FieldStatus,
|
||||
FieldWorkplace,
|
||||
FieldRoles,
|
||||
FieldDefaultExpr,
|
||||
FieldDefaultExprs,
|
||||
FieldCreatedAt,
|
||||
FieldDropOptional,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "users"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"blog_admins",
|
||||
}
|
||||
|
||||
var (
|
||||
// FriendsPrimaryKey and FriendsColumn2 are the table columns denoting the
|
||||
// primary key for the friends relation (M2M).
|
||||
FriendsPrimaryKey = []string{"user", "friend"}
|
||||
)
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
if column == Columns[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for i := range ForeignKeys {
|
||||
if column == ForeignKeys[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultMixedString holds the default value on creation for the "mixed_string" field.
|
||||
DefaultMixedString string
|
||||
// DefaultActive holds the default value on creation for the "active" field.
|
||||
DefaultActive bool
|
||||
// NicknameValidator is a validator for the "nickname" field. It is called by the builders before save.
|
||||
NicknameValidator func(string) error
|
||||
// DefaultPhone holds the default value on creation for the "phone" field.
|
||||
DefaultPhone string
|
||||
// DefaultBuffer holds the default value on creation for the "buffer" field.
|
||||
DefaultBuffer func() []byte
|
||||
// DefaultTitle holds the default value on creation for the "title" field.
|
||||
DefaultTitle string
|
||||
// DefaultNewToken holds the default value on creation for the "new_token" field.
|
||||
DefaultNewToken func() string
|
||||
// BlobValidator is a validator for the "blob" field. It is called by the builders before save.
|
||||
BlobValidator func([]byte) error
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultDropOptional holds the default value on creation for the "drop_optional" field.
|
||||
DefaultDropOptional func() string
|
||||
)
|
||||
|
||||
// MixedEnum defines the type for the "mixed_enum" enum field.
|
||||
type MixedEnum string
|
||||
|
||||
// MixedEnumOn is the default value of the MixedEnum enum.
|
||||
const DefaultMixedEnum = MixedEnumOn
|
||||
|
||||
// MixedEnum values.
|
||||
const (
|
||||
MixedEnumOn MixedEnum = "on"
|
||||
MixedEnumOff MixedEnum = "off"
|
||||
)
|
||||
|
||||
func (me MixedEnum) String() string {
|
||||
return string(me)
|
||||
}
|
||||
|
||||
// MixedEnumValidator is a validator for the "mixed_enum" field enum values. It is called by the builders before save.
|
||||
func MixedEnumValidator(me MixedEnum) error {
|
||||
switch me {
|
||||
case MixedEnumOn, MixedEnumOff:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("user: invalid enum value for mixed_enum field: %q", me)
|
||||
}
|
||||
}
|
||||
|
||||
// State defines the type for the "state" enum field.
|
||||
type State string
|
||||
|
||||
// StateLoggedIn is the default value of the State enum.
|
||||
const DefaultState = StateLoggedIn
|
||||
|
||||
// State values.
|
||||
const (
|
||||
StateLoggedIn State = "logged_in"
|
||||
StateLoggedOut State = "logged_out"
|
||||
StateOnline State = "online"
|
||||
)
|
||||
|
||||
func (s State) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// StateValidator is a validator for the "state" field enum values. It is called by the builders before save.
|
||||
func StateValidator(s State) error {
|
||||
switch s {
|
||||
case StateLoggedIn, StateLoggedOut, StateOnline:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("user: invalid enum value for state field: %q", s)
|
||||
}
|
||||
}
|
||||
|
||||
// Status defines the type for the "status" enum field.
|
||||
type Status string
|
||||
|
||||
// Status values.
|
||||
const (
|
||||
StatusDone Status = "done"
|
||||
StatusPending Status = "pending"
|
||||
)
|
||||
|
||||
func (s Status) String() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// StatusValidator is a validator for the "status" field enum values. It is called by the builders before save.
|
||||
func StatusValidator(s Status) error {
|
||||
switch s {
|
||||
case StatusDone, StatusPending:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("user: invalid enum value for status field: %q", s)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the User queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByMixedString orders the results by the mixed_string field.
|
||||
func ByMixedString(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldMixedString, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByMixedEnum orders the results by the mixed_enum field.
|
||||
func ByMixedEnum(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldMixedEnum, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByActive orders the results by the active field.
|
||||
func ByActive(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldActive, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAge orders the results by the age field.
|
||||
func ByAge(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldAge, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDescription orders the results by the description field.
|
||||
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDescription, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByNickname orders the results by the nickname field.
|
||||
func ByNickname(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldNickname, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByPhone orders the results by the phone field.
|
||||
func ByPhone(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldPhone, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTitle orders the results by the title field.
|
||||
func ByTitle(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTitle, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByNewName orders the results by the new_name field.
|
||||
func ByNewName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldNewName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByNewToken orders the results by the new_token field.
|
||||
func ByNewToken(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldNewToken, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByState orders the results by the state field.
|
||||
func ByState(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldState, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByStatus orders the results by the status field.
|
||||
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByWorkplace orders the results by the workplace field.
|
||||
func ByWorkplace(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldWorkplace, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDefaultExpr orders the results by the default_expr field.
|
||||
func ByDefaultExpr(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDefaultExpr, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDefaultExprs orders the results by the default_exprs field.
|
||||
func ByDefaultExprs(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDefaultExprs, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDropOptional orders the results by the drop_optional field.
|
||||
func ByDropOptional(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDropOptional, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCarCount orders the results by car count.
|
||||
func ByCarCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newCarStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByCar orders the results by car terms.
|
||||
func ByCar(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newCarStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByPetsField orders the results by pets field.
|
||||
func ByPetsField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newPetsStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByFriendsCount orders the results by friends count.
|
||||
func ByFriendsCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newFriendsStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByFriends orders the results by friends terms.
|
||||
func ByFriends(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newFriendsStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newCarStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(CarInverseTable, CarFieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, CarTable, CarColumn),
|
||||
)
|
||||
}
|
||||
func newPetsStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(PetsInverseTable, PetFieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, PetsTable, PetsColumn),
|
||||
)
|
||||
}
|
||||
func newFriendsStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, FriendsTable, FriendsPrimaryKey...),
|
||||
)
|
||||
}
|
||||
1339
entc/integration/migrate/entv2/user/where.go
Normal file
1339
entc/integration/migrate/entv2/user/where.go
Normal file
File diff suppressed because it is too large
Load Diff
720
entc/integration/migrate/entv2/user_create.go
Normal file
720
entc/integration/migrate/entv2/user_create.go
Normal file
@@ -0,0 +1,720 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/pet"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// UserCreate is the builder for creating a User entity.
|
||||
type UserCreate struct {
|
||||
config
|
||||
mutation *UserMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetMixedString sets the "mixed_string" field.
|
||||
func (_c *UserCreate) SetMixedString(v string) *UserCreate {
|
||||
_c.mutation.SetMixedString(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableMixedString sets the "mixed_string" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableMixedString(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetMixedString(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetMixedEnum sets the "mixed_enum" field.
|
||||
func (_c *UserCreate) SetMixedEnum(v user.MixedEnum) *UserCreate {
|
||||
_c.mutation.SetMixedEnum(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableMixedEnum sets the "mixed_enum" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableMixedEnum(v *user.MixedEnum) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetMixedEnum(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetActive sets the "active" field.
|
||||
func (_c *UserCreate) SetActive(v bool) *UserCreate {
|
||||
_c.mutation.SetActive(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableActive sets the "active" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableActive(v *bool) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetActive(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetAge sets the "age" field.
|
||||
func (_c *UserCreate) SetAge(v int) *UserCreate {
|
||||
_c.mutation.SetAge(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *UserCreate) SetName(v string) *UserCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (_c *UserCreate) SetDescription(v string) *UserCreate {
|
||||
_c.mutation.SetDescription(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableDescription(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetDescription(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNickname sets the "nickname" field.
|
||||
func (_c *UserCreate) SetNickname(v string) *UserCreate {
|
||||
_c.mutation.SetNickname(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetPhone sets the "phone" field.
|
||||
func (_c *UserCreate) SetPhone(v string) *UserCreate {
|
||||
_c.mutation.SetPhone(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillablePhone sets the "phone" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillablePhone(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetPhone(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetBuffer sets the "buffer" field.
|
||||
func (_c *UserCreate) SetBuffer(v []byte) *UserCreate {
|
||||
_c.mutation.SetBuffer(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetTitle sets the "title" field.
|
||||
func (_c *UserCreate) SetTitle(v string) *UserCreate {
|
||||
_c.mutation.SetTitle(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableTitle sets the "title" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableTitle(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetTitle(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNewName sets the "new_name" field.
|
||||
func (_c *UserCreate) SetNewName(v string) *UserCreate {
|
||||
_c.mutation.SetNewName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableNewName sets the "new_name" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableNewName(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetNewName(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNewToken sets the "new_token" field.
|
||||
func (_c *UserCreate) SetNewToken(v string) *UserCreate {
|
||||
_c.mutation.SetNewToken(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableNewToken sets the "new_token" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableNewToken(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetNewToken(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetBlob sets the "blob" field.
|
||||
func (_c *UserCreate) SetBlob(v []byte) *UserCreate {
|
||||
_c.mutation.SetBlob(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetState sets the "state" field.
|
||||
func (_c *UserCreate) SetState(v user.State) *UserCreate {
|
||||
_c.mutation.SetState(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableState sets the "state" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableState(v *user.State) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetState(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_c *UserCreate) SetStatus(v user.Status) *UserCreate {
|
||||
_c.mutation.SetStatus(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableStatus(v *user.Status) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetStatus(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetWorkplace sets the "workplace" field.
|
||||
func (_c *UserCreate) SetWorkplace(v string) *UserCreate {
|
||||
_c.mutation.SetWorkplace(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableWorkplace sets the "workplace" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableWorkplace(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetWorkplace(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetRoles sets the "roles" field.
|
||||
func (_c *UserCreate) SetRoles(v []string) *UserCreate {
|
||||
_c.mutation.SetRoles(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetDefaultExpr sets the "default_expr" field.
|
||||
func (_c *UserCreate) SetDefaultExpr(v string) *UserCreate {
|
||||
_c.mutation.SetDefaultExpr(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableDefaultExpr sets the "default_expr" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableDefaultExpr(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetDefaultExpr(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetDefaultExprs sets the "default_exprs" field.
|
||||
func (_c *UserCreate) SetDefaultExprs(v string) *UserCreate {
|
||||
_c.mutation.SetDefaultExprs(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableDefaultExprs sets the "default_exprs" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableDefaultExprs(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetDefaultExprs(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_c *UserCreate) SetCreatedAt(v time.Time) *UserCreate {
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableCreatedAt(v *time.Time) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetCreatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetDropOptional sets the "drop_optional" field.
|
||||
func (_c *UserCreate) SetDropOptional(v string) *UserCreate {
|
||||
_c.mutation.SetDropOptional(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableDropOptional sets the "drop_optional" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableDropOptional(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetDropOptional(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *UserCreate) SetID(v int) *UserCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddCarIDs adds the "car" edge to the Car entity by IDs.
|
||||
func (_c *UserCreate) AddCarIDs(ids ...int) *UserCreate {
|
||||
_c.mutation.AddCarIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddCar adds the "car" edges to the Car entity.
|
||||
func (_c *UserCreate) AddCar(v ...*Car) *UserCreate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddCarIDs(ids...)
|
||||
}
|
||||
|
||||
// SetPetsID sets the "pets" edge to the Pet entity by ID.
|
||||
func (_c *UserCreate) SetPetsID(id int) *UserCreate {
|
||||
_c.mutation.SetPetsID(id)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillablePetsID sets the "pets" edge to the Pet entity by ID if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillablePetsID(id *int) *UserCreate {
|
||||
if id != nil {
|
||||
_c = _c.SetPetsID(*id)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetPets sets the "pets" edge to the Pet entity.
|
||||
func (_c *UserCreate) SetPets(v *Pet) *UserCreate {
|
||||
return _c.SetPetsID(v.ID)
|
||||
}
|
||||
|
||||
// AddFriendIDs adds the "friends" edge to the User entity by IDs.
|
||||
func (_c *UserCreate) AddFriendIDs(ids ...int) *UserCreate {
|
||||
_c.mutation.AddFriendIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddFriends adds the "friends" edges to the User entity.
|
||||
func (_c *UserCreate) AddFriends(v ...*User) *UserCreate {
|
||||
ids := make([]int, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddFriendIDs(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) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *UserCreate) SaveX(ctx context.Context) *User {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *UserCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *UserCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *UserCreate) defaults() {
|
||||
if _, ok := _c.mutation.MixedString(); !ok {
|
||||
v := user.DefaultMixedString
|
||||
_c.mutation.SetMixedString(v)
|
||||
}
|
||||
if _, ok := _c.mutation.MixedEnum(); !ok {
|
||||
v := user.DefaultMixedEnum
|
||||
_c.mutation.SetMixedEnum(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Active(); !ok {
|
||||
v := user.DefaultActive
|
||||
_c.mutation.SetActive(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Phone(); !ok {
|
||||
v := user.DefaultPhone
|
||||
_c.mutation.SetPhone(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Buffer(); !ok {
|
||||
v := user.DefaultBuffer()
|
||||
_c.mutation.SetBuffer(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Title(); !ok {
|
||||
v := user.DefaultTitle
|
||||
_c.mutation.SetTitle(v)
|
||||
}
|
||||
if _, ok := _c.mutation.NewToken(); !ok {
|
||||
v := user.DefaultNewToken()
|
||||
_c.mutation.SetNewToken(v)
|
||||
}
|
||||
if _, ok := _c.mutation.State(); !ok {
|
||||
v := user.DefaultState
|
||||
_c.mutation.SetState(v)
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
v := user.DefaultCreatedAt()
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := _c.mutation.DropOptional(); !ok {
|
||||
v := user.DefaultDropOptional()
|
||||
_c.mutation.SetDropOptional(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *UserCreate) check() error {
|
||||
if _, ok := _c.mutation.MixedString(); !ok {
|
||||
return &ValidationError{Name: "mixed_string", err: errors.New(`entv2: missing required field "User.mixed_string"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.MixedEnum(); !ok {
|
||||
return &ValidationError{Name: "mixed_enum", err: errors.New(`entv2: missing required field "User.mixed_enum"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.MixedEnum(); ok {
|
||||
if err := user.MixedEnumValidator(v); err != nil {
|
||||
return &ValidationError{Name: "mixed_enum", err: fmt.Errorf(`entv2: validator failed for field "User.mixed_enum": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.Active(); !ok {
|
||||
return &ValidationError{Name: "active", err: errors.New(`entv2: missing required field "User.active"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Age(); !ok {
|
||||
return &ValidationError{Name: "age", err: errors.New(`entv2: missing required field "User.age"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`entv2: missing required field "User.name"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Nickname(); !ok {
|
||||
return &ValidationError{Name: "nickname", err: errors.New(`entv2: missing required field "User.nickname"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Nickname(); ok {
|
||||
if err := user.NicknameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "nickname", err: fmt.Errorf(`entv2: validator failed for field "User.nickname": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.Phone(); !ok {
|
||||
return &ValidationError{Name: "phone", err: errors.New(`entv2: missing required field "User.phone"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Title(); !ok {
|
||||
return &ValidationError{Name: "title", err: errors.New(`entv2: missing required field "User.title"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.NewToken(); !ok {
|
||||
return &ValidationError{Name: "new_token", err: errors.New(`entv2: missing required field "User.new_token"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Blob(); ok {
|
||||
if err := user.BlobValidator(v); err != nil {
|
||||
return &ValidationError{Name: "blob", err: fmt.Errorf(`entv2: validator failed for field "User.blob": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _c.mutation.State(); ok {
|
||||
if err := user.StateValidator(v); err != nil {
|
||||
return &ValidationError{Name: "state", err: fmt.Errorf(`entv2: validator failed for field "User.state": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _c.mutation.Status(); ok {
|
||||
if err := user.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`entv2: validator failed for field "User.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`entv2: missing required field "User.created_at"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.DropOptional(); !ok {
|
||||
return &ValidationError{Name: "drop_optional", err: errors.New(`entv2: missing required field "User.drop_optional"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if _spec.ID.Value != _node.ID {
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
}
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &User{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
)
|
||||
if id, ok := _c.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
if value, ok := _c.mutation.MixedString(); ok {
|
||||
_spec.SetField(user.FieldMixedString, field.TypeString, value)
|
||||
_node.MixedString = value
|
||||
}
|
||||
if value, ok := _c.mutation.MixedEnum(); ok {
|
||||
_spec.SetField(user.FieldMixedEnum, field.TypeEnum, value)
|
||||
_node.MixedEnum = value
|
||||
}
|
||||
if value, ok := _c.mutation.Active(); ok {
|
||||
_spec.SetField(user.FieldActive, field.TypeBool, value)
|
||||
_node.Active = value
|
||||
}
|
||||
if value, ok := _c.mutation.Age(); ok {
|
||||
_spec.SetField(user.FieldAge, field.TypeInt, value)
|
||||
_node.Age = value
|
||||
}
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(user.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := _c.mutation.Description(); ok {
|
||||
_spec.SetField(user.FieldDescription, field.TypeString, value)
|
||||
_node.Description = value
|
||||
}
|
||||
if value, ok := _c.mutation.Nickname(); ok {
|
||||
_spec.SetField(user.FieldNickname, field.TypeString, value)
|
||||
_node.Nickname = value
|
||||
}
|
||||
if value, ok := _c.mutation.Phone(); ok {
|
||||
_spec.SetField(user.FieldPhone, field.TypeString, value)
|
||||
_node.Phone = value
|
||||
}
|
||||
if value, ok := _c.mutation.Buffer(); ok {
|
||||
_spec.SetField(user.FieldBuffer, field.TypeBytes, value)
|
||||
_node.Buffer = value
|
||||
}
|
||||
if value, ok := _c.mutation.Title(); ok {
|
||||
_spec.SetField(user.FieldTitle, field.TypeString, value)
|
||||
_node.Title = value
|
||||
}
|
||||
if value, ok := _c.mutation.NewName(); ok {
|
||||
_spec.SetField(user.FieldNewName, field.TypeString, value)
|
||||
_node.NewName = value
|
||||
}
|
||||
if value, ok := _c.mutation.NewToken(); ok {
|
||||
_spec.SetField(user.FieldNewToken, field.TypeString, value)
|
||||
_node.NewToken = value
|
||||
}
|
||||
if value, ok := _c.mutation.Blob(); ok {
|
||||
_spec.SetField(user.FieldBlob, field.TypeBytes, value)
|
||||
_node.Blob = value
|
||||
}
|
||||
if value, ok := _c.mutation.State(); ok {
|
||||
_spec.SetField(user.FieldState, field.TypeEnum, value)
|
||||
_node.State = value
|
||||
}
|
||||
if value, ok := _c.mutation.Status(); ok {
|
||||
_spec.SetField(user.FieldStatus, field.TypeEnum, value)
|
||||
_node.Status = value
|
||||
}
|
||||
if value, ok := _c.mutation.Workplace(); ok {
|
||||
_spec.SetField(user.FieldWorkplace, field.TypeString, value)
|
||||
_node.Workplace = value
|
||||
}
|
||||
if value, ok := _c.mutation.Roles(); ok {
|
||||
_spec.SetField(user.FieldRoles, field.TypeJSON, value)
|
||||
_node.Roles = value
|
||||
}
|
||||
if value, ok := _c.mutation.DefaultExpr(); ok {
|
||||
_spec.SetField(user.FieldDefaultExpr, field.TypeString, value)
|
||||
_node.DefaultExpr = value
|
||||
}
|
||||
if value, ok := _c.mutation.DefaultExprs(); ok {
|
||||
_spec.SetField(user.FieldDefaultExprs, field.TypeString, value)
|
||||
_node.DefaultExprs = value
|
||||
}
|
||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.DropOptional(); ok {
|
||||
_spec.SetField(user.FieldDropOptional, field.TypeString, value)
|
||||
_node.DropOptional = value
|
||||
}
|
||||
if nodes := _c.mutation.CarIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.CarTable,
|
||||
Columns: []string{user.CarColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(car.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.PetsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
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.FriendsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: user.FriendsTable,
|
||||
Columns: user.FriendsPrimaryKey,
|
||||
Bidi: true,
|
||||
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)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// UserCreateBulk is the builder for creating many User entities in bulk.
|
||||
type UserCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*UserCreate
|
||||
}
|
||||
|
||||
// Save creates the User entities in the database.
|
||||
func (_c *UserCreateBulk) Save(ctx context.Context) ([]*User, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*User, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*UserMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *UserCreateBulk) SaveX(ctx context.Context) []*User {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *UserCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *UserCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/migrate/entv2/user_delete.go
Normal file
92
entc/integration/migrate/entv2/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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/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)
|
||||
}
|
||||
}
|
||||
791
entc/integration/migrate/entv2/user_query.go
Normal file
791
entc/integration/migrate/entv2/user_query.go
Normal file
@@ -0,0 +1,791 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/car"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/pet"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/user"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// UserQuery is the builder for querying User entities.
|
||||
type UserQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []user.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.User
|
||||
withCar *CarQuery
|
||||
withPets *PetQuery
|
||||
withFriends *UserQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the UserQuery builder.
|
||||
func (_q *UserQuery) Where(ps ...predicate.User) *UserQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *UserQuery) Limit(limit int) *UserQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *UserQuery) Offset(offset int) *UserQuery {
|
||||
_q.ctx.Offset = &offset
|
||||
return _q
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (_q *UserQuery) Unique(unique bool) *UserQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *UserQuery) Order(o ...user.OrderOption) *UserQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// QueryCar chains the current query on the "car" edge.
|
||||
func (_q *UserQuery) QueryCar() *CarQuery {
|
||||
query := (&CarClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(car.Table, car.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.CarTable, user.CarColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryPets chains the current query on the "pets" edge.
|
||||
func (_q *UserQuery) QueryPets() *PetQuery {
|
||||
query := (&PetClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(pet.Table, pet.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.PetsTable, user.PetsColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryFriends chains the current query on the "friends" edge.
|
||||
func (_q *UserQuery) QueryFriends() *UserQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := _q.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, user.FriendsTable, user.FriendsPrimaryKey...),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(_q.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first User entity from the query.
|
||||
// Returns a *NotFoundError when no User was found.
|
||||
func (_q *UserQuery) First(ctx context.Context) (*User, error) {
|
||||
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{user.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *UserQuery) FirstX(ctx context.Context) *User {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first User ID from the query.
|
||||
// Returns a *NotFoundError when no User ID was found.
|
||||
func (_q *UserQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{user.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *UserQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single User entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one User entity is found.
|
||||
// Returns a *NotFoundError when no User entities are found.
|
||||
func (_q *UserQuery) Only(ctx context.Context) (*User, error) {
|
||||
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{user.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{user.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *UserQuery) OnlyX(ctx context.Context) *User {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only User ID in the query.
|
||||
// Returns a *NotSingularError when more than one User ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *UserQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = &NotSingularError{user.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *UserQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := _q.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Users.
|
||||
func (_q *UserQuery) All(ctx context.Context) ([]*User, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*User, *UserQuery]()
|
||||
return withInterceptors[[]*User](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *UserQuery) AllX(ctx context.Context) []*User {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of User IDs.
|
||||
func (_q *UserQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if _q.ctx.Unique == nil && _q.path != nil {
|
||||
_q.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
|
||||
if err = _q.Select(user.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *UserQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := _q.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (_q *UserQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, _q, querierCount[*UserQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *UserQuery) CountX(ctx context.Context) int {
|
||||
count, err := _q.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (_q *UserQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
|
||||
switch _, err := _q.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("entv2: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *UserQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the UserQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (_q *UserQuery) Clone() *UserQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &UserQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]user.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.User{}, _q.predicates...),
|
||||
withCar: _q.withCar.Clone(),
|
||||
withPets: _q.withPets.Clone(),
|
||||
withFriends: _q.withFriends.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithCar tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "car" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *UserQuery) WithCar(opts ...func(*CarQuery)) *UserQuery {
|
||||
query := (&CarClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withCar = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithPets tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "pets" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *UserQuery) WithPets(opts ...func(*PetQuery)) *UserQuery {
|
||||
query := (&PetClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withPets = query
|
||||
return _q
|
||||
}
|
||||
|
||||
// WithFriends tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "friends" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (_q *UserQuery) WithFriends(opts ...func(*UserQuery)) *UserQuery {
|
||||
query := (&UserClient{config: _q.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
_q.withFriends = 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 {
|
||||
// MixedString string `json:"mixed_string,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.User.Query().
|
||||
// GroupBy(user.FieldMixedString).
|
||||
// Aggregate(entv2.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &UserGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = user.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// MixedString string `json:"mixed_string,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.User.Query().
|
||||
// Select(user.FieldMixedString).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *UserQuery) Select(fields ...string) *UserSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &UserSelect{UserQuery: _q}
|
||||
sbuild.label = user.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a UserSelect configured with the given aggregations.
|
||||
func (_q *UserQuery) Aggregate(fns ...AggregateFunc) *UserSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *UserQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("entv2: uninitialized interceptor (forgotten import entv2/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !user.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("entv2: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if _q.path != nil {
|
||||
prev, err := _q.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_q.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, error) {
|
||||
var (
|
||||
nodes = []*User{}
|
||||
withFKs = _q.withFKs
|
||||
_spec = _q.querySpec()
|
||||
loadedTypes = [3]bool{
|
||||
_q.withCar != nil,
|
||||
_q.withPets != nil,
|
||||
_q.withFriends != nil,
|
||||
}
|
||||
)
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, user.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*User).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &User{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := _q.withCar; query != nil {
|
||||
if err := _q.loadCar(ctx, query, nodes,
|
||||
func(n *User) { n.Edges.Car = []*Car{} },
|
||||
func(n *User, e *Car) { n.Edges.Car = append(n.Edges.Car, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withPets; query != nil {
|
||||
if err := _q.loadPets(ctx, query, nodes, nil,
|
||||
func(n *User, e *Pet) { n.Edges.Pets = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := _q.withFriends; query != nil {
|
||||
if err := _q.loadFriends(ctx, query, nodes,
|
||||
func(n *User) { n.Edges.Friends = []*User{} },
|
||||
func(n *User, e *User) { n.Edges.Friends = append(n.Edges.Friends, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *UserQuery) loadCar(ctx context.Context, query *CarQuery, nodes []*User, init func(*User), assign func(*User, *Car)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*User)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.Car(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(user.CarColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.user_car
|
||||
if fk == nil {
|
||||
return fmt.Errorf(`foreign-key "user_car" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "user_car" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *UserQuery) loadPets(ctx context.Context, query *PetQuery, nodes []*User, init func(*User), assign func(*User, *Pet)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*User)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.Pet(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(user.PetsColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.owner_id
|
||||
if fk == nil {
|
||||
return fmt.Errorf(`foreign-key "owner_id" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "owner_id" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (_q *UserQuery) loadFriends(ctx context.Context, query *UserQuery, nodes []*User, init func(*User), assign func(*User, *User)) error {
|
||||
edgeIDs := make([]driver.Value, len(nodes))
|
||||
byID := make(map[int]*User)
|
||||
nids := make(map[int]map[*User]struct{})
|
||||
for i, node := range nodes {
|
||||
edgeIDs[i] = node.ID
|
||||
byID[node.ID] = node
|
||||
if init != nil {
|
||||
init(node)
|
||||
}
|
||||
}
|
||||
query.Where(func(s *sql.Selector) {
|
||||
joinT := sql.Table(user.FriendsTable)
|
||||
s.Join(joinT).On(s.C(user.FieldID), joinT.C(user.FriendsPrimaryKey[1]))
|
||||
s.Where(sql.InValues(joinT.C(user.FriendsPrimaryKey[0]), edgeIDs...))
|
||||
columns := s.SelectedColumns()
|
||||
s.Select(joinT.C(user.FriendsPrimaryKey[0]))
|
||||
s.AppendSelect(columns...)
|
||||
s.SetDistinct(false)
|
||||
})
|
||||
if err := query.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
||||
assign := spec.Assign
|
||||
values := spec.ScanValues
|
||||
spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
values, err := values(columns[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append([]any{new(sql.NullInt64)}, values...), nil
|
||||
}
|
||||
spec.Assign = func(columns []string, values []any) error {
|
||||
outValue := int(values[0].(*sql.NullInt64).Int64)
|
||||
inValue := int(values[1].(*sql.NullInt64).Int64)
|
||||
if nids[inValue] == nil {
|
||||
nids[inValue] = map[*User]struct{}{byID[outValue]: {}}
|
||||
return assign(columns[1:], values[1:])
|
||||
}
|
||||
nids[inValue][byID[outValue]] = struct{}{}
|
||||
return nil
|
||||
}
|
||||
})
|
||||
})
|
||||
neighbors, err := withInterceptors[[]*User](ctx, query, qr, query.inters)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected "friends" node returned %v`, n.ID)
|
||||
}
|
||||
for kn := range nodes {
|
||||
assign(kn, n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_q *UserQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := _q.querySpec()
|
||||
_spec.Node.Columns = _q.ctx.Fields
|
||||
if len(_q.ctx.Fields) > 0 {
|
||||
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
|
||||
}
|
||||
|
||||
func (_q *UserQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
_spec.From = _q.sql
|
||||
if unique := _q.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if _q.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := _q.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, user.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != user.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _q.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := _q.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (_q *UserQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(user.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = user.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if _q.sql != nil {
|
||||
selector = _q.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if _q.ctx.Unique != nil && *_q.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range _q.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range _q.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := _q.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := _q.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// UserGroupBy is the group-by builder for User entities.
|
||||
type UserGroupBy struct {
|
||||
selector
|
||||
build *UserQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *UserGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
|
||||
if err := _g.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*UserQuery, *UserGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *UserGroupBy) sqlScan(ctx context.Context, root *UserQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(_g.fns))
|
||||
for _, fn := range _g.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
|
||||
for _, f := range *_g.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*_g.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// UserSelect is the builder for selecting fields of User entities.
|
||||
type UserSelect struct {
|
||||
*UserQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *UserSelect) Aggregate(fns ...AggregateFunc) *UserSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *UserSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
|
||||
if err := _s.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*UserQuery, *UserSelect](ctx, _s.UserQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *UserSelect) sqlScan(ctx context.Context, root *UserQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(_s.fns))
|
||||
for _, fn := range _s.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*_s.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := _s.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
1569
entc/integration/migrate/entv2/user_update.go
Normal file
1569
entc/integration/migrate/entv2/user_update.go
Normal file
File diff suppressed because it is too large
Load Diff
95
entc/integration/migrate/entv2/zoo.go
Normal file
95
entc/integration/migrate/entv2/zoo.go
Normal file
@@ -0,0 +1,95 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package entv2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/zoo"
|
||||
)
|
||||
|
||||
// Zoo is the model entity for the Zoo schema.
|
||||
type Zoo struct {
|
||||
config
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Zoo) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case zoo.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 Zoo fields.
|
||||
func (_m *Zoo) 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 zoo.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = 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 Zoo.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (_m *Zoo) Value(name string) (ent.Value, error) {
|
||||
return _m.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Zoo.
|
||||
// Note that you need to call Zoo.Unwrap() before calling this method if this Zoo
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Zoo) Update() *ZooUpdateOne {
|
||||
return NewZooClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Zoo 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 *Zoo) Unwrap() *Zoo {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("entv2: Zoo is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Zoo) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Zoo(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v", _m.ID))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Zoos is a parsable slice of Zoo.
|
||||
type Zoos []*Zoo
|
||||
192
entc/integration/migrate/entv2/zoo/mutation.go
Normal file
192
entc/integration/migrate/entv2/zoo/mutation.go
Normal file
@@ -0,0 +1,192 @@
|
||||
// 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 zoo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// Mutation represents an operation that mutates the Zoo nodes in the graph.
|
||||
type Mutation struct {
|
||||
op ent.Op
|
||||
typ string
|
||||
clearedFields map[string]struct{}
|
||||
predicates []predicate.Zoo
|
||||
}
|
||||
|
||||
// NewMutation creates a new Mutation for the Zoo entity.
|
||||
func NewMutation(op ent.Op) *Mutation {
|
||||
return &Mutation{
|
||||
op: op,
|
||||
typ: "Zoo",
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// Predicates returns the list of predicates set on the mutation.
|
||||
func (m *Mutation) Predicates() []predicate.Zoo {
|
||||
return m.predicates
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the Mutation builder.
|
||||
func (m *Mutation) Where(ps ...predicate.Zoo) {
|
||||
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.Zoo, 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 (Zoo).
|
||||
func (m *Mutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *Mutation) Fields() []string {
|
||||
fields := make([]string, 0, 0)
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *Mutation) Field(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *Mutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
return nil, fmt.Errorf("unknown Zoo field %s", name)
|
||||
}
|
||||
|
||||
// SetField sets the value of a field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *Mutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
}
|
||||
return fmt.Errorf("unknown Zoo field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *Mutation) AddedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||
// with the given name. The second boolean return value indicates that this field
|
||||
// was not set, or was not defined in the schema.
|
||||
func (m *Mutation) AddedField(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// AddField adds the value to the field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *Mutation) AddField(name string, value ent.Value) error {
|
||||
return fmt.Errorf("unknown Zoo 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 Zoo nullable field %s", name)
|
||||
}
|
||||
|
||||
// ResetField resets all changes in the mutation for the field with the given name.
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *Mutation) ResetField(name string) error {
|
||||
return fmt.Errorf("unknown Zoo field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *Mutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *Mutation) AddedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *Mutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *Mutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *Mutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *Mutation) EdgeCleared(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *Mutation) ClearEdge(name string) error {
|
||||
return fmt.Errorf("unknown Zoo unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *Mutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown Zoo edge %s", name)
|
||||
}
|
||||
72
entc/integration/migrate/entv2/zoo/where.go
Normal file
72
entc/integration/migrate/entv2/zoo/where.go
Normal file
@@ -0,0 +1,72 @@
|
||||
// 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 zoo
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Zoo {
|
||||
return predicate.Zoo(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Zoo {
|
||||
return predicate.Zoo(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Zoo {
|
||||
return predicate.Zoo(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Zoo {
|
||||
return predicate.Zoo(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Zoo {
|
||||
return predicate.Zoo(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Zoo {
|
||||
return predicate.Zoo(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Zoo {
|
||||
return predicate.Zoo(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Zoo {
|
||||
return predicate.Zoo(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Zoo {
|
||||
return predicate.Zoo(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Zoo) predicate.Zoo {
|
||||
return predicate.Zoo(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Zoo) predicate.Zoo {
|
||||
return predicate.Zoo(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Zoo) predicate.Zoo {
|
||||
return predicate.Zoo(sql.NotPredicates(p))
|
||||
}
|
||||
43
entc/integration/migrate/entv2/zoo/zoo.go
Normal file
43
entc/integration/migrate/entv2/zoo/zoo.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.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package zoo
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the zoo type in the database.
|
||||
Label = "zoo"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// Table holds the table name of the zoo in the database.
|
||||
Table = "zoos"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for zoo fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
}
|
||||
|
||||
// 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 Zoo 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()
|
||||
}
|
||||
185
entc/integration/migrate/entv2/zoo_create.go
Normal file
185
entc/integration/migrate/entv2/zoo_create.go
Normal file
@@ -0,0 +1,185 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/zoo"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ZooCreate is the builder for creating a Zoo entity.
|
||||
type ZooCreate struct {
|
||||
config
|
||||
mutation *ZooMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *ZooCreate) SetID(v int) *ZooCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the ZooMutation object of the builder.
|
||||
func (_c *ZooCreate) Mutation() *ZooMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the Zoo in the database.
|
||||
func (_c *ZooCreate) Save(ctx context.Context) (*Zoo, error) {
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *ZooCreate) SaveX(ctx context.Context) *Zoo {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *ZooCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *ZooCreate) 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 *ZooCreate) check() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *ZooCreate) sqlSave(ctx context.Context) (*Zoo, 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 *ZooCreate) createSpec() (*Zoo, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Zoo{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(zoo.Table, sqlgraph.NewFieldSpec(zoo.FieldID, field.TypeInt))
|
||||
)
|
||||
if id, ok := _c.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// ZooCreateBulk is the builder for creating many Zoo entities in bulk.
|
||||
type ZooCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*ZooCreate
|
||||
}
|
||||
|
||||
// Save creates the Zoo entities in the database.
|
||||
func (_c *ZooCreateBulk) Save(ctx context.Context) ([]*Zoo, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*Zoo, 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.(*ZooMutation)
|
||||
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 *ZooCreateBulk) SaveX(ctx context.Context) []*Zoo {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *ZooCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *ZooCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
92
entc/integration/migrate/entv2/zoo_delete.go
Normal file
92
entc/integration/migrate/entv2/zoo_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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/zoo"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ZooDelete is the builder for deleting a Zoo entity.
|
||||
type ZooDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ZooMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ZooDelete builder.
|
||||
func (_d *ZooDelete) Where(ps ...predicate.Zoo) *ZooDelete {
|
||||
_d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (_d *ZooDelete) 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 *ZooDelete) ExecX(ctx context.Context) int {
|
||||
n, err := _d.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (_d *ZooDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(zoo.Table, sqlgraph.NewFieldSpec(zoo.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
|
||||
}
|
||||
|
||||
// ZooDeleteOne is the builder for deleting a single Zoo entity.
|
||||
type ZooDeleteOne struct {
|
||||
_d *ZooDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ZooDelete builder.
|
||||
func (_d *ZooDeleteOne) Where(ps ...predicate.Zoo) *ZooDeleteOne {
|
||||
_d._d.mutation.Where(ps...)
|
||||
return _d
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (_d *ZooDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := _d._d.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{zoo.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_d *ZooDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := _d.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
509
entc/integration/migrate/entv2/zoo_query.go
Normal file
509
entc/integration/migrate/entv2/zoo_query.go
Normal file
@@ -0,0 +1,509 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/zoo"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ZooQuery is the builder for querying Zoo entities.
|
||||
type ZooQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []zoo.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Zoo
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the ZooQuery builder.
|
||||
func (_q *ZooQuery) Where(ps ...predicate.Zoo) *ZooQuery {
|
||||
_q.predicates = append(_q.predicates, ps...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (_q *ZooQuery) Limit(limit int) *ZooQuery {
|
||||
_q.ctx.Limit = &limit
|
||||
return _q
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (_q *ZooQuery) Offset(offset int) *ZooQuery {
|
||||
_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 *ZooQuery) Unique(unique bool) *ZooQuery {
|
||||
_q.ctx.Unique = &unique
|
||||
return _q
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (_q *ZooQuery) Order(o ...zoo.OrderOption) *ZooQuery {
|
||||
_q.order = append(_q.order, o...)
|
||||
return _q
|
||||
}
|
||||
|
||||
// First returns the first Zoo entity from the query.
|
||||
// Returns a *NotFoundError when no Zoo was found.
|
||||
func (_q *ZooQuery) First(ctx context.Context) (*Zoo, 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{zoo.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (_q *ZooQuery) FirstX(ctx context.Context) *Zoo {
|
||||
node, err := _q.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Zoo ID from the query.
|
||||
// Returns a *NotFoundError when no Zoo ID was found.
|
||||
func (_q *ZooQuery) 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{zoo.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (_q *ZooQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := _q.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Zoo entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Zoo entity is found.
|
||||
// Returns a *NotFoundError when no Zoo entities are found.
|
||||
func (_q *ZooQuery) Only(ctx context.Context) (*Zoo, 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{zoo.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{zoo.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (_q *ZooQuery) OnlyX(ctx context.Context) *Zoo {
|
||||
node, err := _q.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Zoo ID in the query.
|
||||
// Returns a *NotSingularError when more than one Zoo ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (_q *ZooQuery) 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{zoo.Label}
|
||||
default:
|
||||
err = &NotSingularError{zoo.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (_q *ZooQuery) 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 Zoos.
|
||||
func (_q *ZooQuery) All(ctx context.Context) ([]*Zoo, error) {
|
||||
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
|
||||
if err := _q.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Zoo, *ZooQuery]()
|
||||
return withInterceptors[[]*Zoo](ctx, _q, qr, _q.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (_q *ZooQuery) AllX(ctx context.Context) []*Zoo {
|
||||
nodes, err := _q.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Zoo IDs.
|
||||
func (_q *ZooQuery) 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(zoo.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (_q *ZooQuery) 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 *ZooQuery) 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[*ZooQuery](), _q.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (_q *ZooQuery) 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 *ZooQuery) 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("entv2: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (_q *ZooQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := _q.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the ZooQuery 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 *ZooQuery) Clone() *ZooQuery {
|
||||
if _q == nil {
|
||||
return nil
|
||||
}
|
||||
return &ZooQuery{
|
||||
config: _q.config,
|
||||
ctx: _q.ctx.Clone(),
|
||||
order: append([]zoo.OrderOption{}, _q.order...),
|
||||
inters: append([]Interceptor{}, _q.inters...),
|
||||
predicates: append([]predicate.Zoo{}, _q.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: _q.sql.Clone(),
|
||||
path: _q.path,
|
||||
}
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
func (_q *ZooQuery) GroupBy(field string, fields ...string) *ZooGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &ZooGroupBy{build: _q}
|
||||
grbuild.flds = &_q.ctx.Fields
|
||||
grbuild.label = zoo.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
func (_q *ZooQuery) Select(fields ...string) *ZooSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &ZooSelect{ZooQuery: _q}
|
||||
sbuild.label = zoo.Label
|
||||
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a ZooSelect configured with the given aggregations.
|
||||
func (_q *ZooQuery) Aggregate(fns ...AggregateFunc) *ZooSelect {
|
||||
return _q.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (_q *ZooQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range _q.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("entv2: uninitialized interceptor (forgotten import entv2/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, _q); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range _q.ctx.Fields {
|
||||
if !zoo.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("entv2: 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 *ZooQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Zoo, error) {
|
||||
var (
|
||||
nodes = []*Zoo{}
|
||||
_spec = _q.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Zoo).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Zoo{config: _q.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (_q *ZooQuery) 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 *ZooQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(zoo.Table, zoo.Columns, sqlgraph.NewFieldSpec(zoo.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, zoo.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != zoo.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 *ZooQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(_q.driver.Dialect())
|
||||
t1 := builder.Table(zoo.Table)
|
||||
columns := _q.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = zoo.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
|
||||
}
|
||||
|
||||
// ZooGroupBy is the group-by builder for Zoo entities.
|
||||
type ZooGroupBy struct {
|
||||
selector
|
||||
build *ZooQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (_g *ZooGroupBy) Aggregate(fns ...AggregateFunc) *ZooGroupBy {
|
||||
_g.fns = append(_g.fns, fns...)
|
||||
return _g
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_g *ZooGroupBy) 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[*ZooQuery, *ZooGroupBy](ctx, _g.build, _g, _g.build.inters, v)
|
||||
}
|
||||
|
||||
func (_g *ZooGroupBy) sqlScan(ctx context.Context, root *ZooQuery, 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)
|
||||
}
|
||||
|
||||
// ZooSelect is the builder for selecting fields of Zoo entities.
|
||||
type ZooSelect struct {
|
||||
*ZooQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (_s *ZooSelect) Aggregate(fns ...AggregateFunc) *ZooSelect {
|
||||
_s.fns = append(_s.fns, fns...)
|
||||
return _s
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (_s *ZooSelect) 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[*ZooQuery, *ZooSelect](ctx, _s.ZooQuery, _s, _s.inters, v)
|
||||
}
|
||||
|
||||
func (_s *ZooSelect) sqlScan(ctx context.Context, root *ZooQuery, 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)
|
||||
}
|
||||
179
entc/integration/migrate/entv2/zoo_update.go
Normal file
179
entc/integration/migrate/entv2/zoo_update.go
Normal file
@@ -0,0 +1,179 @@
|
||||
// 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 entv2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/predicate"
|
||||
"entgo.io/ent/entc/integration/migrate/entv2/zoo"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ZooUpdate is the builder for updating Zoo entities.
|
||||
type ZooUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ZooMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ZooUpdate builder.
|
||||
func (_u *ZooUpdate) Where(ps ...predicate.Zoo) *ZooUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the ZooMutation object of the builder.
|
||||
func (_u *ZooUpdate) Mutation() *ZooMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *ZooUpdate) 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 *ZooUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *ZooUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *ZooUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *ZooUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(zoo.Table, zoo.Columns, sqlgraph.NewFieldSpec(zoo.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 _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{zoo.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// ZooUpdateOne is the builder for updating a single Zoo entity.
|
||||
type ZooUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *ZooMutation
|
||||
}
|
||||
|
||||
// Mutation returns the ZooMutation object of the builder.
|
||||
func (_u *ZooUpdateOne) Mutation() *ZooMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ZooUpdate builder.
|
||||
func (_u *ZooUpdateOne) Where(ps ...predicate.Zoo) *ZooUpdateOne {
|
||||
_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 *ZooUpdateOne) Select(field string, fields ...string) *ZooUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Zoo entity.
|
||||
func (_u *ZooUpdateOne) Save(ctx context.Context) (*Zoo, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *ZooUpdateOne) SaveX(ctx context.Context) *Zoo {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *ZooUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *ZooUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *ZooUpdateOne) sqlSave(ctx context.Context) (_node *Zoo, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(zoo.Table, zoo.Columns, sqlgraph.NewFieldSpec(zoo.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`entv2: missing "Zoo.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, zoo.FieldID)
|
||||
for _, f := range fields {
|
||||
if !zoo.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("entv2: invalid field %q for query", f)}
|
||||
}
|
||||
if f != zoo.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
_node = &Zoo{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{zoo.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
Reference in New Issue
Block a user