-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(query): added LimitedResult/LimitedQuery
- Loading branch information
Showing
11 changed files
with
188 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package sqle | ||
|
||
// LimitedQueryOption is a function type that modifies a LimitedQuery. | ||
type LimitedQueryOption func(q *LimitedQuery) | ||
|
||
// LimitedQuery represents a query with pagination and ordering options. | ||
type LimitedQuery struct { | ||
Offset int64 // PageIndex represents the index of the page to retrieve. | ||
Limit int64 // PageSize represents the number of items per page. | ||
OrderBy *OrderByBuilder // OrderBy represents the ordering of the query. | ||
} | ||
|
||
// WithPageSize is a LimitedQueryOption that sets the page size of the LimitedQuery. | ||
func WithPageSize(size int64) LimitedQueryOption { | ||
return func(q *LimitedQuery) { | ||
q.Limit = size | ||
} | ||
} | ||
|
||
// WithOrderBy is a LimitedQueryOption that sets the ordering of the LimitedQuery. | ||
func WithOrderBy(ob *OrderByBuilder) LimitedQueryOption { | ||
return func(q *LimitedQuery) { | ||
q.OrderBy = ob | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package sqle | ||
|
||
// LimitedResult represents a limited result set with items and total count. | ||
type LimitedResult[T any] struct { | ||
Items []T `json:"items,omitempty"` // Items contains the limited result items. | ||
Total int64 `json:"total,omitempty"` // Total represents the total count. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.