mirror of
https://github.com/versia-pub/versia-go.git
synced 2025-12-06 06:28:18 +01:00
527 lines
14 KiB
Go
527 lines
14 KiB
Go
|
|
// Code generated by ent, DO NOT EDIT.
|
||
|
|
|
||
|
|
package ent
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
"math"
|
||
|
|
|
||
|
|
"entgo.io/ent/dialect/sql"
|
||
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||
|
|
"entgo.io/ent/schema/field"
|
||
|
|
"github.com/lysand-org/versia-go/ent/image"
|
||
|
|
"github.com/lysand-org/versia-go/ent/predicate"
|
||
|
|
)
|
||
|
|
|
||
|
|
// ImageQuery is the builder for querying Image entities.
|
||
|
|
type ImageQuery struct {
|
||
|
|
config
|
||
|
|
ctx *QueryContext
|
||
|
|
order []image.OrderOption
|
||
|
|
inters []Interceptor
|
||
|
|
predicates []predicate.Image
|
||
|
|
// intermediate query (i.e. traversal path).
|
||
|
|
sql *sql.Selector
|
||
|
|
path func(context.Context) (*sql.Selector, error)
|
||
|
|
}
|
||
|
|
|
||
|
|
// Where adds a new predicate for the ImageQuery builder.
|
||
|
|
func (iq *ImageQuery) Where(ps ...predicate.Image) *ImageQuery {
|
||
|
|
iq.predicates = append(iq.predicates, ps...)
|
||
|
|
return iq
|
||
|
|
}
|
||
|
|
|
||
|
|
// Limit the number of records to be returned by this query.
|
||
|
|
func (iq *ImageQuery) Limit(limit int) *ImageQuery {
|
||
|
|
iq.ctx.Limit = &limit
|
||
|
|
return iq
|
||
|
|
}
|
||
|
|
|
||
|
|
// Offset to start from.
|
||
|
|
func (iq *ImageQuery) Offset(offset int) *ImageQuery {
|
||
|
|
iq.ctx.Offset = &offset
|
||
|
|
return iq
|
||
|
|
}
|
||
|
|
|
||
|
|
// 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 (iq *ImageQuery) Unique(unique bool) *ImageQuery {
|
||
|
|
iq.ctx.Unique = &unique
|
||
|
|
return iq
|
||
|
|
}
|
||
|
|
|
||
|
|
// Order specifies how the records should be ordered.
|
||
|
|
func (iq *ImageQuery) Order(o ...image.OrderOption) *ImageQuery {
|
||
|
|
iq.order = append(iq.order, o...)
|
||
|
|
return iq
|
||
|
|
}
|
||
|
|
|
||
|
|
// First returns the first Image entity from the query.
|
||
|
|
// Returns a *NotFoundError when no Image was found.
|
||
|
|
func (iq *ImageQuery) First(ctx context.Context) (*Image, error) {
|
||
|
|
nodes, err := iq.Limit(1).All(setContextOp(ctx, iq.ctx, "First"))
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
if len(nodes) == 0 {
|
||
|
|
return nil, &NotFoundError{image.Label}
|
||
|
|
}
|
||
|
|
return nodes[0], nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// FirstX is like First, but panics if an error occurs.
|
||
|
|
func (iq *ImageQuery) FirstX(ctx context.Context) *Image {
|
||
|
|
node, err := iq.First(ctx)
|
||
|
|
if err != nil && !IsNotFound(err) {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return node
|
||
|
|
}
|
||
|
|
|
||
|
|
// FirstID returns the first Image ID from the query.
|
||
|
|
// Returns a *NotFoundError when no Image ID was found.
|
||
|
|
func (iq *ImageQuery) FirstID(ctx context.Context) (id int, err error) {
|
||
|
|
var ids []int
|
||
|
|
if ids, err = iq.Limit(1).IDs(setContextOp(ctx, iq.ctx, "FirstID")); err != nil {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if len(ids) == 0 {
|
||
|
|
err = &NotFoundError{image.Label}
|
||
|
|
return
|
||
|
|
}
|
||
|
|
return ids[0], nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||
|
|
func (iq *ImageQuery) FirstIDX(ctx context.Context) int {
|
||
|
|
id, err := iq.FirstID(ctx)
|
||
|
|
if err != nil && !IsNotFound(err) {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return id
|
||
|
|
}
|
||
|
|
|
||
|
|
// Only returns a single Image entity found by the query, ensuring it only returns one.
|
||
|
|
// Returns a *NotSingularError when more than one Image entity is found.
|
||
|
|
// Returns a *NotFoundError when no Image entities are found.
|
||
|
|
func (iq *ImageQuery) Only(ctx context.Context) (*Image, error) {
|
||
|
|
nodes, err := iq.Limit(2).All(setContextOp(ctx, iq.ctx, "Only"))
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
switch len(nodes) {
|
||
|
|
case 1:
|
||
|
|
return nodes[0], nil
|
||
|
|
case 0:
|
||
|
|
return nil, &NotFoundError{image.Label}
|
||
|
|
default:
|
||
|
|
return nil, &NotSingularError{image.Label}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnlyX is like Only, but panics if an error occurs.
|
||
|
|
func (iq *ImageQuery) OnlyX(ctx context.Context) *Image {
|
||
|
|
node, err := iq.Only(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return node
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnlyID is like Only, but returns the only Image ID in the query.
|
||
|
|
// Returns a *NotSingularError when more than one Image ID is found.
|
||
|
|
// Returns a *NotFoundError when no entities are found.
|
||
|
|
func (iq *ImageQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||
|
|
var ids []int
|
||
|
|
if ids, err = iq.Limit(2).IDs(setContextOp(ctx, iq.ctx, "OnlyID")); err != nil {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
switch len(ids) {
|
||
|
|
case 1:
|
||
|
|
id = ids[0]
|
||
|
|
case 0:
|
||
|
|
err = &NotFoundError{image.Label}
|
||
|
|
default:
|
||
|
|
err = &NotSingularError{image.Label}
|
||
|
|
}
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||
|
|
func (iq *ImageQuery) OnlyIDX(ctx context.Context) int {
|
||
|
|
id, err := iq.OnlyID(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return id
|
||
|
|
}
|
||
|
|
|
||
|
|
// All executes the query and returns a list of Images.
|
||
|
|
func (iq *ImageQuery) All(ctx context.Context) ([]*Image, error) {
|
||
|
|
ctx = setContextOp(ctx, iq.ctx, "All")
|
||
|
|
if err := iq.prepareQuery(ctx); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
qr := querierAll[[]*Image, *ImageQuery]()
|
||
|
|
return withInterceptors[[]*Image](ctx, iq, qr, iq.inters)
|
||
|
|
}
|
||
|
|
|
||
|
|
// AllX is like All, but panics if an error occurs.
|
||
|
|
func (iq *ImageQuery) AllX(ctx context.Context) []*Image {
|
||
|
|
nodes, err := iq.All(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return nodes
|
||
|
|
}
|
||
|
|
|
||
|
|
// IDs executes the query and returns a list of Image IDs.
|
||
|
|
func (iq *ImageQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||
|
|
if iq.ctx.Unique == nil && iq.path != nil {
|
||
|
|
iq.Unique(true)
|
||
|
|
}
|
||
|
|
ctx = setContextOp(ctx, iq.ctx, "IDs")
|
||
|
|
if err = iq.Select(image.FieldID).Scan(ctx, &ids); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
return ids, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// IDsX is like IDs, but panics if an error occurs.
|
||
|
|
func (iq *ImageQuery) IDsX(ctx context.Context) []int {
|
||
|
|
ids, err := iq.IDs(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return ids
|
||
|
|
}
|
||
|
|
|
||
|
|
// Count returns the count of the given query.
|
||
|
|
func (iq *ImageQuery) Count(ctx context.Context) (int, error) {
|
||
|
|
ctx = setContextOp(ctx, iq.ctx, "Count")
|
||
|
|
if err := iq.prepareQuery(ctx); err != nil {
|
||
|
|
return 0, err
|
||
|
|
}
|
||
|
|
return withInterceptors[int](ctx, iq, querierCount[*ImageQuery](), iq.inters)
|
||
|
|
}
|
||
|
|
|
||
|
|
// CountX is like Count, but panics if an error occurs.
|
||
|
|
func (iq *ImageQuery) CountX(ctx context.Context) int {
|
||
|
|
count, err := iq.Count(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return count
|
||
|
|
}
|
||
|
|
|
||
|
|
// Exist returns true if the query has elements in the graph.
|
||
|
|
func (iq *ImageQuery) Exist(ctx context.Context) (bool, error) {
|
||
|
|
ctx = setContextOp(ctx, iq.ctx, "Exist")
|
||
|
|
switch _, err := iq.FirstID(ctx); {
|
||
|
|
case IsNotFound(err):
|
||
|
|
return false, nil
|
||
|
|
case err != nil:
|
||
|
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||
|
|
default:
|
||
|
|
return true, nil
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// ExistX is like Exist, but panics if an error occurs.
|
||
|
|
func (iq *ImageQuery) ExistX(ctx context.Context) bool {
|
||
|
|
exist, err := iq.Exist(ctx)
|
||
|
|
if err != nil {
|
||
|
|
panic(err)
|
||
|
|
}
|
||
|
|
return exist
|
||
|
|
}
|
||
|
|
|
||
|
|
// Clone returns a duplicate of the ImageQuery builder, including all associated steps. It can be
|
||
|
|
// used to prepare common query builders and use them differently after the clone is made.
|
||
|
|
func (iq *ImageQuery) Clone() *ImageQuery {
|
||
|
|
if iq == nil {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
return &ImageQuery{
|
||
|
|
config: iq.config,
|
||
|
|
ctx: iq.ctx.Clone(),
|
||
|
|
order: append([]image.OrderOption{}, iq.order...),
|
||
|
|
inters: append([]Interceptor{}, iq.inters...),
|
||
|
|
predicates: append([]predicate.Image{}, iq.predicates...),
|
||
|
|
// clone intermediate query.
|
||
|
|
sql: iq.sql.Clone(),
|
||
|
|
path: iq.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 {
|
||
|
|
// URL string `json:"url,omitempty"`
|
||
|
|
// Count int `json:"count,omitempty"`
|
||
|
|
// }
|
||
|
|
//
|
||
|
|
// client.Image.Query().
|
||
|
|
// GroupBy(image.FieldURL).
|
||
|
|
// Aggregate(ent.Count()).
|
||
|
|
// Scan(ctx, &v)
|
||
|
|
func (iq *ImageQuery) GroupBy(field string, fields ...string) *ImageGroupBy {
|
||
|
|
iq.ctx.Fields = append([]string{field}, fields...)
|
||
|
|
grbuild := &ImageGroupBy{build: iq}
|
||
|
|
grbuild.flds = &iq.ctx.Fields
|
||
|
|
grbuild.label = image.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 {
|
||
|
|
// URL string `json:"url,omitempty"`
|
||
|
|
// }
|
||
|
|
//
|
||
|
|
// client.Image.Query().
|
||
|
|
// Select(image.FieldURL).
|
||
|
|
// Scan(ctx, &v)
|
||
|
|
func (iq *ImageQuery) Select(fields ...string) *ImageSelect {
|
||
|
|
iq.ctx.Fields = append(iq.ctx.Fields, fields...)
|
||
|
|
sbuild := &ImageSelect{ImageQuery: iq}
|
||
|
|
sbuild.label = image.Label
|
||
|
|
sbuild.flds, sbuild.scan = &iq.ctx.Fields, sbuild.Scan
|
||
|
|
return sbuild
|
||
|
|
}
|
||
|
|
|
||
|
|
// Aggregate returns a ImageSelect configured with the given aggregations.
|
||
|
|
func (iq *ImageQuery) Aggregate(fns ...AggregateFunc) *ImageSelect {
|
||
|
|
return iq.Select().Aggregate(fns...)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (iq *ImageQuery) prepareQuery(ctx context.Context) error {
|
||
|
|
for _, inter := range iq.inters {
|
||
|
|
if inter == nil {
|
||
|
|
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||
|
|
}
|
||
|
|
if trv, ok := inter.(Traverser); ok {
|
||
|
|
if err := trv.Traverse(ctx, iq); err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
for _, f := range iq.ctx.Fields {
|
||
|
|
if !image.ValidColumn(f) {
|
||
|
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if iq.path != nil {
|
||
|
|
prev, err := iq.path(ctx)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
iq.sql = prev
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (iq *ImageQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Image, error) {
|
||
|
|
var (
|
||
|
|
nodes = []*Image{}
|
||
|
|
_spec = iq.querySpec()
|
||
|
|
)
|
||
|
|
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||
|
|
return (*Image).scanValues(nil, columns)
|
||
|
|
}
|
||
|
|
_spec.Assign = func(columns []string, values []any) error {
|
||
|
|
node := &Image{config: iq.config}
|
||
|
|
nodes = append(nodes, node)
|
||
|
|
return node.assignValues(columns, values)
|
||
|
|
}
|
||
|
|
for i := range hooks {
|
||
|
|
hooks[i](ctx, _spec)
|
||
|
|
}
|
||
|
|
if err := sqlgraph.QueryNodes(ctx, iq.driver, _spec); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
if len(nodes) == 0 {
|
||
|
|
return nodes, nil
|
||
|
|
}
|
||
|
|
return nodes, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (iq *ImageQuery) sqlCount(ctx context.Context) (int, error) {
|
||
|
|
_spec := iq.querySpec()
|
||
|
|
_spec.Node.Columns = iq.ctx.Fields
|
||
|
|
if len(iq.ctx.Fields) > 0 {
|
||
|
|
_spec.Unique = iq.ctx.Unique != nil && *iq.ctx.Unique
|
||
|
|
}
|
||
|
|
return sqlgraph.CountNodes(ctx, iq.driver, _spec)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (iq *ImageQuery) querySpec() *sqlgraph.QuerySpec {
|
||
|
|
_spec := sqlgraph.NewQuerySpec(image.Table, image.Columns, sqlgraph.NewFieldSpec(image.FieldID, field.TypeInt))
|
||
|
|
_spec.From = iq.sql
|
||
|
|
if unique := iq.ctx.Unique; unique != nil {
|
||
|
|
_spec.Unique = *unique
|
||
|
|
} else if iq.path != nil {
|
||
|
|
_spec.Unique = true
|
||
|
|
}
|
||
|
|
if fields := iq.ctx.Fields; len(fields) > 0 {
|
||
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||
|
|
_spec.Node.Columns = append(_spec.Node.Columns, image.FieldID)
|
||
|
|
for i := range fields {
|
||
|
|
if fields[i] != image.FieldID {
|
||
|
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if ps := iq.predicates; len(ps) > 0 {
|
||
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
||
|
|
for i := range ps {
|
||
|
|
ps[i](selector)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if limit := iq.ctx.Limit; limit != nil {
|
||
|
|
_spec.Limit = *limit
|
||
|
|
}
|
||
|
|
if offset := iq.ctx.Offset; offset != nil {
|
||
|
|
_spec.Offset = *offset
|
||
|
|
}
|
||
|
|
if ps := iq.order; len(ps) > 0 {
|
||
|
|
_spec.Order = func(selector *sql.Selector) {
|
||
|
|
for i := range ps {
|
||
|
|
ps[i](selector)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return _spec
|
||
|
|
}
|
||
|
|
|
||
|
|
func (iq *ImageQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||
|
|
builder := sql.Dialect(iq.driver.Dialect())
|
||
|
|
t1 := builder.Table(image.Table)
|
||
|
|
columns := iq.ctx.Fields
|
||
|
|
if len(columns) == 0 {
|
||
|
|
columns = image.Columns
|
||
|
|
}
|
||
|
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||
|
|
if iq.sql != nil {
|
||
|
|
selector = iq.sql
|
||
|
|
selector.Select(selector.Columns(columns...)...)
|
||
|
|
}
|
||
|
|
if iq.ctx.Unique != nil && *iq.ctx.Unique {
|
||
|
|
selector.Distinct()
|
||
|
|
}
|
||
|
|
for _, p := range iq.predicates {
|
||
|
|
p(selector)
|
||
|
|
}
|
||
|
|
for _, p := range iq.order {
|
||
|
|
p(selector)
|
||
|
|
}
|
||
|
|
if offset := iq.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 := iq.ctx.Limit; limit != nil {
|
||
|
|
selector.Limit(*limit)
|
||
|
|
}
|
||
|
|
return selector
|
||
|
|
}
|
||
|
|
|
||
|
|
// ImageGroupBy is the group-by builder for Image entities.
|
||
|
|
type ImageGroupBy struct {
|
||
|
|
selector
|
||
|
|
build *ImageQuery
|
||
|
|
}
|
||
|
|
|
||
|
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||
|
|
func (igb *ImageGroupBy) Aggregate(fns ...AggregateFunc) *ImageGroupBy {
|
||
|
|
igb.fns = append(igb.fns, fns...)
|
||
|
|
return igb
|
||
|
|
}
|
||
|
|
|
||
|
|
// Scan applies the selector query and scans the result into the given value.
|
||
|
|
func (igb *ImageGroupBy) Scan(ctx context.Context, v any) error {
|
||
|
|
ctx = setContextOp(ctx, igb.build.ctx, "GroupBy")
|
||
|
|
if err := igb.build.prepareQuery(ctx); err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
return scanWithInterceptors[*ImageQuery, *ImageGroupBy](ctx, igb.build, igb, igb.build.inters, v)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (igb *ImageGroupBy) sqlScan(ctx context.Context, root *ImageQuery, v any) error {
|
||
|
|
selector := root.sqlQuery(ctx).Select()
|
||
|
|
aggregation := make([]string, 0, len(igb.fns))
|
||
|
|
for _, fn := range igb.fns {
|
||
|
|
aggregation = append(aggregation, fn(selector))
|
||
|
|
}
|
||
|
|
if len(selector.SelectedColumns()) == 0 {
|
||
|
|
columns := make([]string, 0, len(*igb.flds)+len(igb.fns))
|
||
|
|
for _, f := range *igb.flds {
|
||
|
|
columns = append(columns, selector.C(f))
|
||
|
|
}
|
||
|
|
columns = append(columns, aggregation...)
|
||
|
|
selector.Select(columns...)
|
||
|
|
}
|
||
|
|
selector.GroupBy(selector.Columns(*igb.flds...)...)
|
||
|
|
if err := selector.Err(); err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
rows := &sql.Rows{}
|
||
|
|
query, args := selector.Query()
|
||
|
|
if err := igb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
defer rows.Close()
|
||
|
|
return sql.ScanSlice(rows, v)
|
||
|
|
}
|
||
|
|
|
||
|
|
// ImageSelect is the builder for selecting fields of Image entities.
|
||
|
|
type ImageSelect struct {
|
||
|
|
*ImageQuery
|
||
|
|
selector
|
||
|
|
}
|
||
|
|
|
||
|
|
// Aggregate adds the given aggregation functions to the selector query.
|
||
|
|
func (is *ImageSelect) Aggregate(fns ...AggregateFunc) *ImageSelect {
|
||
|
|
is.fns = append(is.fns, fns...)
|
||
|
|
return is
|
||
|
|
}
|
||
|
|
|
||
|
|
// Scan applies the selector query and scans the result into the given value.
|
||
|
|
func (is *ImageSelect) Scan(ctx context.Context, v any) error {
|
||
|
|
ctx = setContextOp(ctx, is.ctx, "Select")
|
||
|
|
if err := is.prepareQuery(ctx); err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
return scanWithInterceptors[*ImageQuery, *ImageSelect](ctx, is.ImageQuery, is, is.inters, v)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (is *ImageSelect) sqlScan(ctx context.Context, root *ImageQuery, v any) error {
|
||
|
|
selector := root.sqlQuery(ctx)
|
||
|
|
aggregation := make([]string, 0, len(is.fns))
|
||
|
|
for _, fn := range is.fns {
|
||
|
|
aggregation = append(aggregation, fn(selector))
|
||
|
|
}
|
||
|
|
switch n := len(*is.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 := is.driver.Query(ctx, query, args, rows); err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
defer rows.Close()
|
||
|
|
return sql.ScanSlice(rows, v)
|
||
|
|
}
|