Skip to content

Commit

Permalink
feat(query): add direct property setters for query elements (#1127)
Browse files Browse the repository at this point in the history
refactor(query): add direct property setters for query elements

- Add direct setter methods for pagination, projection, condition, and sort
- Simplify DSL usage by allowing direct property setting
- Improve code readability and flexibility in constructing queries
  • Loading branch information
Ahoo-Wang authored Jan 15, 2025
1 parent 15b7948 commit ea2d488
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ import me.ahoo.wow.api.query.Pagination
class PagedQueryDsl : QueryableDsl<IPagedQuery>() {
private var pagination: Pagination = Pagination.DEFAULT

fun pagination(pagination: Pagination) {
this.pagination = pagination
}

fun pagination(block: PaginationDsl.() -> Unit) {
val dsl = PaginationDsl()
dsl.block()
pagination = dsl.build()
pagination(dsl.build())
}

override fun build(): IPagedQuery {
Expand Down
19 changes: 16 additions & 3 deletions wow-query/src/main/kotlin/me/ahoo/wow/query/dsl/QueryableDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,35 @@ abstract class QueryableDsl<Q : Queryable<Q>> {
protected var projection: Projection = Projection.ALL
protected var condition: Condition = Condition.all()
protected var sort: List<Sort> = emptyList()

fun projection(projection: Projection) {
this.projection = projection
}

fun projection(block: ProjectionDsl.() -> Unit) {
val dsl = ProjectionDsl()
dsl.block()
projection = dsl.build()
projection(dsl.build())
}

fun condition(condition: Condition) {
this.condition = condition
}

fun condition(block: ConditionDsl.() -> Unit) {
val dsl = ConditionDsl()
dsl.block()
condition = dsl.build()
condition(dsl.build())
}

fun sort(sort: List<Sort>) {
this.sort = sort
}

fun sort(block: SortDsl.() -> Unit) {
val dsl = SortDsl()
dsl.block()
sort = dsl.build()
sort(dsl.build())
}

abstract fun build(): Q
Expand Down

0 comments on commit ea2d488

Please sign in to comment.