mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 13:37:35 +00:00
implementation done
This commit is contained in:
@@ -10,9 +10,10 @@ func WithCondition(condition Condition) QueryOption {
|
||||
}
|
||||
|
||||
// WithOrderBy sets the columns to order the results by.
|
||||
func WithOrderBy(orderBy ...Column) QueryOption {
|
||||
func WithOrderBy(descending bool, orderBy ...Column) QueryOption {
|
||||
return func(opts *QueryOpts) {
|
||||
opts.OrderBy = orderBy
|
||||
opts.OrderByDescending = descending
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +70,9 @@ type QueryOpts struct {
|
||||
// OrderBy is the columns to order the results by.
|
||||
// It is used to build the ORDER BY clause of the SQL statement.
|
||||
OrderBy Columns
|
||||
// OrderByDescending indicates if the results should be ordered in descending order.
|
||||
// default is ascending order.
|
||||
OrderByDescending bool
|
||||
// Limit is the maximum number of results to return.
|
||||
// It is used to build the LIMIT clause of the SQL statement.
|
||||
Limit uint32
|
||||
@@ -105,7 +109,15 @@ func (opts *QueryOpts) WriteOrderBy(builder *StatementBuilder) {
|
||||
return
|
||||
}
|
||||
builder.WriteString(" ORDER BY ")
|
||||
opts.OrderBy.Write(builder)
|
||||
for i, col := range opts.OrderBy {
|
||||
if i > 0 {
|
||||
builder.WriteString(", ")
|
||||
}
|
||||
col.Write(builder)
|
||||
if opts.OrderByDescending {
|
||||
builder.WriteString(" DESC")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (opts *QueryOpts) WriteLimit(builder *StatementBuilder) {
|
||||
|
@@ -538,7 +538,7 @@ func TestListInstance(t *testing.T) {
|
||||
// check instance values
|
||||
returnedInstances, err := instanceRepo.List(ctx,
|
||||
database.WithCondition(condition),
|
||||
database.WithOrderBy(instanceRepo.CreatedAtColumn(true)),
|
||||
database.WithOrderBy(false, instanceRepo.CreatedAtColumn(true)),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
if tt.noInstanceReturned {
|
||||
|
@@ -785,7 +785,7 @@ func TestListOrganization(t *testing.T) {
|
||||
// check organization values
|
||||
returnedOrgs, err := organizationRepo.List(ctx,
|
||||
database.WithCondition(condition),
|
||||
database.WithOrderBy(organizationRepo.CreatedAtColumn(true)),
|
||||
database.WithOrderBy(false, organizationRepo.CreatedAtColumn(true)),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
if tt.noOrganizationReturned {
|
||||
|
Reference in New Issue
Block a user