snapshot of https://github.com/ent/ent.git (master, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
188
entc/integration/gremlin/ent/pet.go
Normal file
188
entc/integration/gremlin/ent/pet.go
Normal file
@@ -0,0 +1,188 @@
|
||||
// Copyright 2019-present Facebook Inc. All rights reserved.
|
||||
// This source code is licensed under the Apache 2.0 license found
|
||||
// in the LICENSE file in the root directory of this source tree.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/gremlin"
|
||||
"entgo.io/ent/entc/integration/gremlin/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Pet is the model entity for the Pet schema.
|
||||
type Pet struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID string `json:"id,omitempty"`
|
||||
// Age holds the value of the "age" field.
|
||||
Age float64 `json:"age,omitempty"`
|
||||
// Name holds the value of the "name" field.
|
||||
Name string `json:"name,omitempty"`
|
||||
// UUID holds the value of the "uuid" field.
|
||||
UUID uuid.UUID `json:"uuid,omitempty"`
|
||||
// Nickname holds the value of the "nickname" field.
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
// Trained holds the value of the "trained" field.
|
||||
Trained bool `json:"trained,omitempty"`
|
||||
// OptionalTime holds the value of the "optional_time" field.
|
||||
OptionalTime time.Time `json:"optional_time,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"`
|
||||
}
|
||||
|
||||
// PetEdges holds the relations/edges for other nodes in the graph.
|
||||
type PetEdges struct {
|
||||
// Team holds the value of the team edge.
|
||||
Team *User `json:"team,omitempty"`
|
||||
// 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 [2]bool
|
||||
}
|
||||
|
||||
// TeamOrErr returns the Team value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e PetEdges) TeamOrErr() (*User, error) {
|
||||
if e.Team != nil {
|
||||
return e.Team, nil
|
||||
} else if e.loadedTypes[0] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "team"}
|
||||
}
|
||||
|
||||
// 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[1] {
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "owner"}
|
||||
}
|
||||
|
||||
// FromResponse scans the gremlin response data into Pet.
|
||||
func (_m *Pet) FromResponse(res *gremlin.Response) error {
|
||||
vmap, err := res.ReadValueMap()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var scan_m struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Age float64 `json:"age,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
UUID uuid.UUID `json:"uuid,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
Trained bool `json:"trained,omitempty"`
|
||||
OptionalTime int64 `json:"optional_time,omitempty"`
|
||||
}
|
||||
if err := vmap.Decode(&scan_m); err != nil {
|
||||
return err
|
||||
}
|
||||
_m.ID = scan_m.ID
|
||||
_m.Age = scan_m.Age
|
||||
_m.Name = scan_m.Name
|
||||
_m.UUID = scan_m.UUID
|
||||
_m.Nickname = scan_m.Nickname
|
||||
_m.Trained = scan_m.Trained
|
||||
_m.OptionalTime = time.Unix(0, scan_m.OptionalTime)
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryTeam queries the "team" edge of the Pet entity.
|
||||
func (_m *Pet) QueryTeam() *UserQuery {
|
||||
return NewPetClient(_m.config).QueryTeam(_m)
|
||||
}
|
||||
|
||||
// QueryOwner queries the "owner" edge of the Pet entity.
|
||||
func (_m *Pet) QueryOwner() *UserQuery {
|
||||
return NewPetClient(_m.config).QueryOwner(_m)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Pet.
|
||||
// Note that you need to call Pet.Unwrap() before calling this method if this Pet
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (_m *Pet) Update() *PetUpdateOne {
|
||||
return NewPetClient(_m.config).UpdateOne(_m)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Pet entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (_m *Pet) Unwrap() *Pet {
|
||||
_tx, ok := _m.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Pet is not a transactional entity")
|
||||
}
|
||||
_m.config.driver = _tx.drv
|
||||
return _m
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (_m *Pet) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Pet(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("age=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Age))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(_m.Name)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("uuid=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.UUID))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("nickname=")
|
||||
builder.WriteString(_m.Nickname)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("trained=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Trained))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("optional_time=")
|
||||
builder.WriteString(_m.OptionalTime.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Pets is a parsable slice of Pet.
|
||||
type Pets []*Pet
|
||||
|
||||
// FromResponse scans the gremlin response data into Pets.
|
||||
func (_m *Pets) FromResponse(res *gremlin.Response) error {
|
||||
vmap, err := res.ReadValueMap()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var scan_m []struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Age float64 `json:"age,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
UUID uuid.UUID `json:"uuid,omitempty"`
|
||||
Nickname string `json:"nickname,omitempty"`
|
||||
Trained bool `json:"trained,omitempty"`
|
||||
OptionalTime int64 `json:"optional_time,omitempty"`
|
||||
}
|
||||
if err := vmap.Decode(&scan_m); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, v := range scan_m {
|
||||
node := &Pet{ID: v.ID}
|
||||
node.Age = v.Age
|
||||
node.Name = v.Name
|
||||
node.UUID = v.UUID
|
||||
node.Nickname = v.Nickname
|
||||
node.Trained = v.Trained
|
||||
node.OptionalTime = time.Unix(0, v.OptionalTime)
|
||||
*_m = append(*_m, node)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user