tasklog_query.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "context"
  5. "fmt"
  6. "math"
  7. "entgo.io/ent/dialect/sql"
  8. "entgo.io/ent/dialect/sql/sqlgraph"
  9. "entgo.io/ent/schema/field"
  10. "github.com/suyuan32/simple-admin-job/ent/predicate"
  11. "github.com/suyuan32/simple-admin-job/ent/task"
  12. "github.com/suyuan32/simple-admin-job/ent/tasklog"
  13. )
  14. // TaskLogQuery is the builder for querying TaskLog entities.
  15. type TaskLogQuery struct {
  16. config
  17. ctx *QueryContext
  18. order []tasklog.OrderOption
  19. inters []Interceptor
  20. predicates []predicate.TaskLog
  21. withTasks *TaskQuery
  22. withFKs bool
  23. // intermediate query (i.e. traversal path).
  24. sql *sql.Selector
  25. path func(context.Context) (*sql.Selector, error)
  26. }
  27. // Where adds a new predicate for the TaskLogQuery builder.
  28. func (tlq *TaskLogQuery) Where(ps ...predicate.TaskLog) *TaskLogQuery {
  29. tlq.predicates = append(tlq.predicates, ps...)
  30. return tlq
  31. }
  32. // Limit the number of records to be returned by this query.
  33. func (tlq *TaskLogQuery) Limit(limit int) *TaskLogQuery {
  34. tlq.ctx.Limit = &limit
  35. return tlq
  36. }
  37. // Offset to start from.
  38. func (tlq *TaskLogQuery) Offset(offset int) *TaskLogQuery {
  39. tlq.ctx.Offset = &offset
  40. return tlq
  41. }
  42. // Unique configures the query builder to filter duplicate records on query.
  43. // By default, unique is set to true, and can be disabled using this method.
  44. func (tlq *TaskLogQuery) Unique(unique bool) *TaskLogQuery {
  45. tlq.ctx.Unique = &unique
  46. return tlq
  47. }
  48. // Order specifies how the records should be ordered.
  49. func (tlq *TaskLogQuery) Order(o ...tasklog.OrderOption) *TaskLogQuery {
  50. tlq.order = append(tlq.order, o...)
  51. return tlq
  52. }
  53. // QueryTasks chains the current query on the "tasks" edge.
  54. func (tlq *TaskLogQuery) QueryTasks() *TaskQuery {
  55. query := (&TaskClient{config: tlq.config}).Query()
  56. query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
  57. if err := tlq.prepareQuery(ctx); err != nil {
  58. return nil, err
  59. }
  60. selector := tlq.sqlQuery(ctx)
  61. if err := selector.Err(); err != nil {
  62. return nil, err
  63. }
  64. step := sqlgraph.NewStep(
  65. sqlgraph.From(tasklog.Table, tasklog.FieldID, selector),
  66. sqlgraph.To(task.Table, task.FieldID),
  67. sqlgraph.Edge(sqlgraph.M2O, true, tasklog.TasksTable, tasklog.TasksColumn),
  68. )
  69. fromU = sqlgraph.SetNeighbors(tlq.driver.Dialect(), step)
  70. return fromU, nil
  71. }
  72. return query
  73. }
  74. // First returns the first TaskLog entity from the query.
  75. // Returns a *NotFoundError when no TaskLog was found.
  76. func (tlq *TaskLogQuery) First(ctx context.Context) (*TaskLog, error) {
  77. nodes, err := tlq.Limit(1).All(setContextOp(ctx, tlq.ctx, "First"))
  78. if err != nil {
  79. return nil, err
  80. }
  81. if len(nodes) == 0 {
  82. return nil, &NotFoundError{tasklog.Label}
  83. }
  84. return nodes[0], nil
  85. }
  86. // FirstX is like First, but panics if an error occurs.
  87. func (tlq *TaskLogQuery) FirstX(ctx context.Context) *TaskLog {
  88. node, err := tlq.First(ctx)
  89. if err != nil && !IsNotFound(err) {
  90. panic(err)
  91. }
  92. return node
  93. }
  94. // FirstID returns the first TaskLog ID from the query.
  95. // Returns a *NotFoundError when no TaskLog ID was found.
  96. func (tlq *TaskLogQuery) FirstID(ctx context.Context) (id uint64, err error) {
  97. var ids []uint64
  98. if ids, err = tlq.Limit(1).IDs(setContextOp(ctx, tlq.ctx, "FirstID")); err != nil {
  99. return
  100. }
  101. if len(ids) == 0 {
  102. err = &NotFoundError{tasklog.Label}
  103. return
  104. }
  105. return ids[0], nil
  106. }
  107. // FirstIDX is like FirstID, but panics if an error occurs.
  108. func (tlq *TaskLogQuery) FirstIDX(ctx context.Context) uint64 {
  109. id, err := tlq.FirstID(ctx)
  110. if err != nil && !IsNotFound(err) {
  111. panic(err)
  112. }
  113. return id
  114. }
  115. // Only returns a single TaskLog entity found by the query, ensuring it only returns one.
  116. // Returns a *NotSingularError when more than one TaskLog entity is found.
  117. // Returns a *NotFoundError when no TaskLog entities are found.
  118. func (tlq *TaskLogQuery) Only(ctx context.Context) (*TaskLog, error) {
  119. nodes, err := tlq.Limit(2).All(setContextOp(ctx, tlq.ctx, "Only"))
  120. if err != nil {
  121. return nil, err
  122. }
  123. switch len(nodes) {
  124. case 1:
  125. return nodes[0], nil
  126. case 0:
  127. return nil, &NotFoundError{tasklog.Label}
  128. default:
  129. return nil, &NotSingularError{tasklog.Label}
  130. }
  131. }
  132. // OnlyX is like Only, but panics if an error occurs.
  133. func (tlq *TaskLogQuery) OnlyX(ctx context.Context) *TaskLog {
  134. node, err := tlq.Only(ctx)
  135. if err != nil {
  136. panic(err)
  137. }
  138. return node
  139. }
  140. // OnlyID is like Only, but returns the only TaskLog ID in the query.
  141. // Returns a *NotSingularError when more than one TaskLog ID is found.
  142. // Returns a *NotFoundError when no entities are found.
  143. func (tlq *TaskLogQuery) OnlyID(ctx context.Context) (id uint64, err error) {
  144. var ids []uint64
  145. if ids, err = tlq.Limit(2).IDs(setContextOp(ctx, tlq.ctx, "OnlyID")); err != nil {
  146. return
  147. }
  148. switch len(ids) {
  149. case 1:
  150. id = ids[0]
  151. case 0:
  152. err = &NotFoundError{tasklog.Label}
  153. default:
  154. err = &NotSingularError{tasklog.Label}
  155. }
  156. return
  157. }
  158. // OnlyIDX is like OnlyID, but panics if an error occurs.
  159. func (tlq *TaskLogQuery) OnlyIDX(ctx context.Context) uint64 {
  160. id, err := tlq.OnlyID(ctx)
  161. if err != nil {
  162. panic(err)
  163. }
  164. return id
  165. }
  166. // All executes the query and returns a list of TaskLogs.
  167. func (tlq *TaskLogQuery) All(ctx context.Context) ([]*TaskLog, error) {
  168. ctx = setContextOp(ctx, tlq.ctx, "All")
  169. if err := tlq.prepareQuery(ctx); err != nil {
  170. return nil, err
  171. }
  172. qr := querierAll[[]*TaskLog, *TaskLogQuery]()
  173. return withInterceptors[[]*TaskLog](ctx, tlq, qr, tlq.inters)
  174. }
  175. // AllX is like All, but panics if an error occurs.
  176. func (tlq *TaskLogQuery) AllX(ctx context.Context) []*TaskLog {
  177. nodes, err := tlq.All(ctx)
  178. if err != nil {
  179. panic(err)
  180. }
  181. return nodes
  182. }
  183. // IDs executes the query and returns a list of TaskLog IDs.
  184. func (tlq *TaskLogQuery) IDs(ctx context.Context) (ids []uint64, err error) {
  185. if tlq.ctx.Unique == nil && tlq.path != nil {
  186. tlq.Unique(true)
  187. }
  188. ctx = setContextOp(ctx, tlq.ctx, "IDs")
  189. if err = tlq.Select(tasklog.FieldID).Scan(ctx, &ids); err != nil {
  190. return nil, err
  191. }
  192. return ids, nil
  193. }
  194. // IDsX is like IDs, but panics if an error occurs.
  195. func (tlq *TaskLogQuery) IDsX(ctx context.Context) []uint64 {
  196. ids, err := tlq.IDs(ctx)
  197. if err != nil {
  198. panic(err)
  199. }
  200. return ids
  201. }
  202. // Count returns the count of the given query.
  203. func (tlq *TaskLogQuery) Count(ctx context.Context) (int, error) {
  204. ctx = setContextOp(ctx, tlq.ctx, "Count")
  205. if err := tlq.prepareQuery(ctx); err != nil {
  206. return 0, err
  207. }
  208. return withInterceptors[int](ctx, tlq, querierCount[*TaskLogQuery](), tlq.inters)
  209. }
  210. // CountX is like Count, but panics if an error occurs.
  211. func (tlq *TaskLogQuery) CountX(ctx context.Context) int {
  212. count, err := tlq.Count(ctx)
  213. if err != nil {
  214. panic(err)
  215. }
  216. return count
  217. }
  218. // Exist returns true if the query has elements in the graph.
  219. func (tlq *TaskLogQuery) Exist(ctx context.Context) (bool, error) {
  220. ctx = setContextOp(ctx, tlq.ctx, "Exist")
  221. switch _, err := tlq.FirstID(ctx); {
  222. case IsNotFound(err):
  223. return false, nil
  224. case err != nil:
  225. return false, fmt.Errorf("ent: check existence: %w", err)
  226. default:
  227. return true, nil
  228. }
  229. }
  230. // ExistX is like Exist, but panics if an error occurs.
  231. func (tlq *TaskLogQuery) ExistX(ctx context.Context) bool {
  232. exist, err := tlq.Exist(ctx)
  233. if err != nil {
  234. panic(err)
  235. }
  236. return exist
  237. }
  238. // Clone returns a duplicate of the TaskLogQuery builder, including all associated steps. It can be
  239. // used to prepare common query builders and use them differently after the clone is made.
  240. func (tlq *TaskLogQuery) Clone() *TaskLogQuery {
  241. if tlq == nil {
  242. return nil
  243. }
  244. return &TaskLogQuery{
  245. config: tlq.config,
  246. ctx: tlq.ctx.Clone(),
  247. order: append([]tasklog.OrderOption{}, tlq.order...),
  248. inters: append([]Interceptor{}, tlq.inters...),
  249. predicates: append([]predicate.TaskLog{}, tlq.predicates...),
  250. withTasks: tlq.withTasks.Clone(),
  251. // clone intermediate query.
  252. sql: tlq.sql.Clone(),
  253. path: tlq.path,
  254. }
  255. }
  256. // WithTasks tells the query-builder to eager-load the nodes that are connected to
  257. // the "tasks" edge. The optional arguments are used to configure the query builder of the edge.
  258. func (tlq *TaskLogQuery) WithTasks(opts ...func(*TaskQuery)) *TaskLogQuery {
  259. query := (&TaskClient{config: tlq.config}).Query()
  260. for _, opt := range opts {
  261. opt(query)
  262. }
  263. tlq.withTasks = query
  264. return tlq
  265. }
  266. // GroupBy is used to group vertices by one or more fields/columns.
  267. // It is often used with aggregate functions, like: count, max, mean, min, sum.
  268. //
  269. // Example:
  270. //
  271. // var v []struct {
  272. // StartedAt time.Time `json:"started_at,omitempty"`
  273. // Count int `json:"count,omitempty"`
  274. // }
  275. //
  276. // client.TaskLog.Query().
  277. // GroupBy(tasklog.FieldStartedAt).
  278. // Aggregate(ent.Count()).
  279. // Scan(ctx, &v)
  280. func (tlq *TaskLogQuery) GroupBy(field string, fields ...string) *TaskLogGroupBy {
  281. tlq.ctx.Fields = append([]string{field}, fields...)
  282. grbuild := &TaskLogGroupBy{build: tlq}
  283. grbuild.flds = &tlq.ctx.Fields
  284. grbuild.label = tasklog.Label
  285. grbuild.scan = grbuild.Scan
  286. return grbuild
  287. }
  288. // Select allows the selection one or more fields/columns for the given query,
  289. // instead of selecting all fields in the entity.
  290. //
  291. // Example:
  292. //
  293. // var v []struct {
  294. // StartedAt time.Time `json:"started_at,omitempty"`
  295. // }
  296. //
  297. // client.TaskLog.Query().
  298. // Select(tasklog.FieldStartedAt).
  299. // Scan(ctx, &v)
  300. func (tlq *TaskLogQuery) Select(fields ...string) *TaskLogSelect {
  301. tlq.ctx.Fields = append(tlq.ctx.Fields, fields...)
  302. sbuild := &TaskLogSelect{TaskLogQuery: tlq}
  303. sbuild.label = tasklog.Label
  304. sbuild.flds, sbuild.scan = &tlq.ctx.Fields, sbuild.Scan
  305. return sbuild
  306. }
  307. // Aggregate returns a TaskLogSelect configured with the given aggregations.
  308. func (tlq *TaskLogQuery) Aggregate(fns ...AggregateFunc) *TaskLogSelect {
  309. return tlq.Select().Aggregate(fns...)
  310. }
  311. func (tlq *TaskLogQuery) prepareQuery(ctx context.Context) error {
  312. for _, inter := range tlq.inters {
  313. if inter == nil {
  314. return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
  315. }
  316. if trv, ok := inter.(Traverser); ok {
  317. if err := trv.Traverse(ctx, tlq); err != nil {
  318. return err
  319. }
  320. }
  321. }
  322. for _, f := range tlq.ctx.Fields {
  323. if !tasklog.ValidColumn(f) {
  324. return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
  325. }
  326. }
  327. if tlq.path != nil {
  328. prev, err := tlq.path(ctx)
  329. if err != nil {
  330. return err
  331. }
  332. tlq.sql = prev
  333. }
  334. return nil
  335. }
  336. func (tlq *TaskLogQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*TaskLog, error) {
  337. var (
  338. nodes = []*TaskLog{}
  339. withFKs = tlq.withFKs
  340. _spec = tlq.querySpec()
  341. loadedTypes = [1]bool{
  342. tlq.withTasks != nil,
  343. }
  344. )
  345. if tlq.withTasks != nil {
  346. withFKs = true
  347. }
  348. if withFKs {
  349. _spec.Node.Columns = append(_spec.Node.Columns, tasklog.ForeignKeys...)
  350. }
  351. _spec.ScanValues = func(columns []string) ([]any, error) {
  352. return (*TaskLog).scanValues(nil, columns)
  353. }
  354. _spec.Assign = func(columns []string, values []any) error {
  355. node := &TaskLog{config: tlq.config}
  356. nodes = append(nodes, node)
  357. node.Edges.loadedTypes = loadedTypes
  358. return node.assignValues(columns, values)
  359. }
  360. for i := range hooks {
  361. hooks[i](ctx, _spec)
  362. }
  363. if err := sqlgraph.QueryNodes(ctx, tlq.driver, _spec); err != nil {
  364. return nil, err
  365. }
  366. if len(nodes) == 0 {
  367. return nodes, nil
  368. }
  369. if query := tlq.withTasks; query != nil {
  370. if err := tlq.loadTasks(ctx, query, nodes, nil,
  371. func(n *TaskLog, e *Task) { n.Edges.Tasks = e }); err != nil {
  372. return nil, err
  373. }
  374. }
  375. return nodes, nil
  376. }
  377. func (tlq *TaskLogQuery) loadTasks(ctx context.Context, query *TaskQuery, nodes []*TaskLog, init func(*TaskLog), assign func(*TaskLog, *Task)) error {
  378. ids := make([]uint64, 0, len(nodes))
  379. nodeids := make(map[uint64][]*TaskLog)
  380. for i := range nodes {
  381. if nodes[i].task_task_logs == nil {
  382. continue
  383. }
  384. fk := *nodes[i].task_task_logs
  385. if _, ok := nodeids[fk]; !ok {
  386. ids = append(ids, fk)
  387. }
  388. nodeids[fk] = append(nodeids[fk], nodes[i])
  389. }
  390. if len(ids) == 0 {
  391. return nil
  392. }
  393. query.Where(task.IDIn(ids...))
  394. neighbors, err := query.All(ctx)
  395. if err != nil {
  396. return err
  397. }
  398. for _, n := range neighbors {
  399. nodes, ok := nodeids[n.ID]
  400. if !ok {
  401. return fmt.Errorf(`unexpected foreign-key "task_task_logs" returned %v`, n.ID)
  402. }
  403. for i := range nodes {
  404. assign(nodes[i], n)
  405. }
  406. }
  407. return nil
  408. }
  409. func (tlq *TaskLogQuery) sqlCount(ctx context.Context) (int, error) {
  410. _spec := tlq.querySpec()
  411. _spec.Node.Columns = tlq.ctx.Fields
  412. if len(tlq.ctx.Fields) > 0 {
  413. _spec.Unique = tlq.ctx.Unique != nil && *tlq.ctx.Unique
  414. }
  415. return sqlgraph.CountNodes(ctx, tlq.driver, _spec)
  416. }
  417. func (tlq *TaskLogQuery) querySpec() *sqlgraph.QuerySpec {
  418. _spec := sqlgraph.NewQuerySpec(tasklog.Table, tasklog.Columns, sqlgraph.NewFieldSpec(tasklog.FieldID, field.TypeUint64))
  419. _spec.From = tlq.sql
  420. if unique := tlq.ctx.Unique; unique != nil {
  421. _spec.Unique = *unique
  422. } else if tlq.path != nil {
  423. _spec.Unique = true
  424. }
  425. if fields := tlq.ctx.Fields; len(fields) > 0 {
  426. _spec.Node.Columns = make([]string, 0, len(fields))
  427. _spec.Node.Columns = append(_spec.Node.Columns, tasklog.FieldID)
  428. for i := range fields {
  429. if fields[i] != tasklog.FieldID {
  430. _spec.Node.Columns = append(_spec.Node.Columns, fields[i])
  431. }
  432. }
  433. }
  434. if ps := tlq.predicates; len(ps) > 0 {
  435. _spec.Predicate = func(selector *sql.Selector) {
  436. for i := range ps {
  437. ps[i](selector)
  438. }
  439. }
  440. }
  441. if limit := tlq.ctx.Limit; limit != nil {
  442. _spec.Limit = *limit
  443. }
  444. if offset := tlq.ctx.Offset; offset != nil {
  445. _spec.Offset = *offset
  446. }
  447. if ps := tlq.order; len(ps) > 0 {
  448. _spec.Order = func(selector *sql.Selector) {
  449. for i := range ps {
  450. ps[i](selector)
  451. }
  452. }
  453. }
  454. return _spec
  455. }
  456. func (tlq *TaskLogQuery) sqlQuery(ctx context.Context) *sql.Selector {
  457. builder := sql.Dialect(tlq.driver.Dialect())
  458. t1 := builder.Table(tasklog.Table)
  459. columns := tlq.ctx.Fields
  460. if len(columns) == 0 {
  461. columns = tasklog.Columns
  462. }
  463. selector := builder.Select(t1.Columns(columns...)...).From(t1)
  464. if tlq.sql != nil {
  465. selector = tlq.sql
  466. selector.Select(selector.Columns(columns...)...)
  467. }
  468. if tlq.ctx.Unique != nil && *tlq.ctx.Unique {
  469. selector.Distinct()
  470. }
  471. for _, p := range tlq.predicates {
  472. p(selector)
  473. }
  474. for _, p := range tlq.order {
  475. p(selector)
  476. }
  477. if offset := tlq.ctx.Offset; offset != nil {
  478. // limit is mandatory for offset clause. We start
  479. // with default value, and override it below if needed.
  480. selector.Offset(*offset).Limit(math.MaxInt32)
  481. }
  482. if limit := tlq.ctx.Limit; limit != nil {
  483. selector.Limit(*limit)
  484. }
  485. return selector
  486. }
  487. // TaskLogGroupBy is the group-by builder for TaskLog entities.
  488. type TaskLogGroupBy struct {
  489. selector
  490. build *TaskLogQuery
  491. }
  492. // Aggregate adds the given aggregation functions to the group-by query.
  493. func (tlgb *TaskLogGroupBy) Aggregate(fns ...AggregateFunc) *TaskLogGroupBy {
  494. tlgb.fns = append(tlgb.fns, fns...)
  495. return tlgb
  496. }
  497. // Scan applies the selector query and scans the result into the given value.
  498. func (tlgb *TaskLogGroupBy) Scan(ctx context.Context, v any) error {
  499. ctx = setContextOp(ctx, tlgb.build.ctx, "GroupBy")
  500. if err := tlgb.build.prepareQuery(ctx); err != nil {
  501. return err
  502. }
  503. return scanWithInterceptors[*TaskLogQuery, *TaskLogGroupBy](ctx, tlgb.build, tlgb, tlgb.build.inters, v)
  504. }
  505. func (tlgb *TaskLogGroupBy) sqlScan(ctx context.Context, root *TaskLogQuery, v any) error {
  506. selector := root.sqlQuery(ctx).Select()
  507. aggregation := make([]string, 0, len(tlgb.fns))
  508. for _, fn := range tlgb.fns {
  509. aggregation = append(aggregation, fn(selector))
  510. }
  511. if len(selector.SelectedColumns()) == 0 {
  512. columns := make([]string, 0, len(*tlgb.flds)+len(tlgb.fns))
  513. for _, f := range *tlgb.flds {
  514. columns = append(columns, selector.C(f))
  515. }
  516. columns = append(columns, aggregation...)
  517. selector.Select(columns...)
  518. }
  519. selector.GroupBy(selector.Columns(*tlgb.flds...)...)
  520. if err := selector.Err(); err != nil {
  521. return err
  522. }
  523. rows := &sql.Rows{}
  524. query, args := selector.Query()
  525. if err := tlgb.build.driver.Query(ctx, query, args, rows); err != nil {
  526. return err
  527. }
  528. defer rows.Close()
  529. return sql.ScanSlice(rows, v)
  530. }
  531. // TaskLogSelect is the builder for selecting fields of TaskLog entities.
  532. type TaskLogSelect struct {
  533. *TaskLogQuery
  534. selector
  535. }
  536. // Aggregate adds the given aggregation functions to the selector query.
  537. func (tls *TaskLogSelect) Aggregate(fns ...AggregateFunc) *TaskLogSelect {
  538. tls.fns = append(tls.fns, fns...)
  539. return tls
  540. }
  541. // Scan applies the selector query and scans the result into the given value.
  542. func (tls *TaskLogSelect) Scan(ctx context.Context, v any) error {
  543. ctx = setContextOp(ctx, tls.ctx, "Select")
  544. if err := tls.prepareQuery(ctx); err != nil {
  545. return err
  546. }
  547. return scanWithInterceptors[*TaskLogQuery, *TaskLogSelect](ctx, tls.TaskLogQuery, tls, tls.inters, v)
  548. }
  549. func (tls *TaskLogSelect) sqlScan(ctx context.Context, root *TaskLogQuery, v any) error {
  550. selector := root.sqlQuery(ctx)
  551. aggregation := make([]string, 0, len(tls.fns))
  552. for _, fn := range tls.fns {
  553. aggregation = append(aggregation, fn(selector))
  554. }
  555. switch n := len(*tls.selector.flds); {
  556. case n == 0 && len(aggregation) > 0:
  557. selector.Select(aggregation...)
  558. case n != 0 && len(aggregation) > 0:
  559. selector.AppendSelect(aggregation...)
  560. }
  561. rows := &sql.Rows{}
  562. query, args := selector.Query()
  563. if err := tls.driver.Query(ctx, query, args, rows); err != nil {
  564. return err
  565. }
  566. defer rows.Close()
  567. return sql.ScanSlice(rows, v)
  568. }