pcmt/ent/searchquery.go
surtur 74546f996b
All checks were successful
continuous-integration/drone/push Build is passing
ent: add/extend entities, tests, validation
2023-08-19 04:52:15 +02:00

161 lines
5.1 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"git.dotya.ml/mirre-mt/pcmt/ent/searchquery"
"git.dotya.ml/mirre-mt/pcmt/ent/user"
"github.com/google/uuid"
)
// SearchQuery is the model entity for the SearchQuery schema.
type SearchQuery struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// Query holds the value of the "query" field.
Query string `json:"query,omitempty"`
// Created holds the value of the "created" field.
Created time.Time `json:"created,omitempty"`
// id of the user that's done the search query
Owner uuid.UUID `json:"owner,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the SearchQueryQuery when eager-loading is set.
Edges SearchQueryEdges `json:"edges"`
selectValues sql.SelectValues
}
// SearchQueryEdges holds the relations/edges for other nodes in the graph.
type SearchQueryEdges struct {
// User holds the value of the user edge.
User *User `json:"user,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// UserOrErr returns the User value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e SearchQueryEdges) UserOrErr() (*User, error) {
if e.loadedTypes[0] {
if e.User == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: user.Label}
}
return e.User, nil
}
return nil, &NotLoadedError{edge: "user"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*SearchQuery) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case searchquery.FieldQuery:
values[i] = new(sql.NullString)
case searchquery.FieldCreated:
values[i] = new(sql.NullTime)
case searchquery.FieldID, searchquery.FieldOwner:
values[i] = new(uuid.UUID)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the SearchQuery fields.
func (sq *SearchQuery) 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 searchquery.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
sq.ID = *value
}
case searchquery.FieldQuery:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field query", values[i])
} else if value.Valid {
sq.Query = value.String
}
case searchquery.FieldCreated:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created", values[i])
} else if value.Valid {
sq.Created = value.Time
}
case searchquery.FieldOwner:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field owner", values[i])
} else if value != nil {
sq.Owner = *value
}
default:
sq.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the SearchQuery.
// This includes values selected through modifiers, order, etc.
func (sq *SearchQuery) Value(name string) (ent.Value, error) {
return sq.selectValues.Get(name)
}
// QueryUser queries the "user" edge of the SearchQuery entity.
func (sq *SearchQuery) QueryUser() *UserQuery {
return NewSearchQueryClient(sq.config).QueryUser(sq)
}
// Update returns a builder for updating this SearchQuery.
// Note that you need to call SearchQuery.Unwrap() before calling this method if this SearchQuery
// was returned from a transaction, and the transaction was committed or rolled back.
func (sq *SearchQuery) Update() *SearchQueryUpdateOne {
return NewSearchQueryClient(sq.config).UpdateOne(sq)
}
// Unwrap unwraps the SearchQuery 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 (sq *SearchQuery) Unwrap() *SearchQuery {
_tx, ok := sq.config.driver.(*txDriver)
if !ok {
panic("ent: SearchQuery is not a transactional entity")
}
sq.config.driver = _tx.drv
return sq
}
// String implements the fmt.Stringer.
func (sq *SearchQuery) String() string {
var builder strings.Builder
builder.WriteString("SearchQuery(")
builder.WriteString(fmt.Sprintf("id=%v, ", sq.ID))
builder.WriteString("query=")
builder.WriteString(sq.Query)
builder.WriteString(", ")
builder.WriteString("created=")
builder.WriteString(sq.Created.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("owner=")
builder.WriteString(fmt.Sprintf("%v", sq.Owner))
builder.WriteByte(')')
return builder.String()
}
// SearchQueries is a parsable slice of SearchQuery.
type SearchQueries []*SearchQuery