channelmonitorrequesttemplate_query.go 21 KB

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