Add general queue
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
// Code generated by entc template, DO NOT EDIT.
|
||||
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// PaginateAfterID paginates GeneralQueue by monotonically increasing "id".
|
||||
// It preserves any existing filters/joins applied to the query, fetches up to "limit" items,
|
||||
// and returns the next cursor (last ID of this page) and whether a next page exists.
|
||||
func (q *GeneralQueueQuery) PaginateAfterID(ctx context.Context, afterID, limit int) ([]*GeneralQueue, int, bool, error) {
|
||||
if limit <= 0 {
|
||||
limit = 20
|
||||
}
|
||||
|
||||
qq := q.Clone().
|
||||
Order(func(s *sql.Selector) {
|
||||
s.OrderBy(s.C("id"))
|
||||
}).
|
||||
Limit(limit + 1) // fetch one extra to detect "has next"
|
||||
|
||||
if afterID > 0 {
|
||||
qq = qq.Where(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C("id"), afterID))
|
||||
})
|
||||
}
|
||||
|
||||
rows, err := qq.All(ctx)
|
||||
if err != nil {
|
||||
return nil, 0, false, err
|
||||
}
|
||||
|
||||
hasNext := len(rows) > limit
|
||||
if hasNext {
|
||||
rows = rows[:limit]
|
||||
}
|
||||
|
||||
next := 0
|
||||
if len(rows) > 0 {
|
||||
next = rows[len(rows)-1].ID
|
||||
}
|
||||
|
||||
return rows, next, hasNext, nil
|
||||
}
|
||||
|
||||
// PaginateAfterID paginates GeneralQueueState by monotonically increasing "id".
|
||||
// It preserves any existing filters/joins applied to the query, fetches up to "limit" items,
|
||||
// and returns the next cursor (last ID of this page) and whether a next page exists.
|
||||
func (q *GeneralQueueStateQuery) PaginateAfterID(ctx context.Context, afterID, limit int) ([]*GeneralQueueState, int, bool, error) {
|
||||
if limit <= 0 {
|
||||
limit = 20
|
||||
}
|
||||
|
||||
qq := q.Clone().
|
||||
Order(func(s *sql.Selector) {
|
||||
s.OrderBy(s.C("id"))
|
||||
}).
|
||||
Limit(limit + 1) // fetch one extra to detect "has next"
|
||||
|
||||
if afterID > 0 {
|
||||
qq = qq.Where(func(s *sql.Selector) {
|
||||
s.Where(sql.GT(s.C("id"), afterID))
|
||||
})
|
||||
}
|
||||
|
||||
rows, err := qq.All(ctx)
|
||||
if err != nil {
|
||||
return nil, 0, false, err
|
||||
}
|
||||
|
||||
hasNext := len(rows) > limit
|
||||
if hasNext {
|
||||
rows = rows[:limit]
|
||||
}
|
||||
|
||||
next := 0
|
||||
if len(rows) > 0 {
|
||||
next = rows[len(rows)-1].ID
|
||||
}
|
||||
|
||||
return rows, next, hasNext, nil
|
||||
}
|
||||
Reference in New Issue
Block a user