-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Supported for redis database modification and add jooq page util (#63)
* ✨ Supported for redis database modification * ✨ Add jooq page util * Format code * Optimize code and update gradle * Optimize code and update gradle * Fixed bug * Reformat code
- Loading branch information
Showing
4 changed files
with
36 additions
and
12 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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
22 changes: 22 additions & 0 deletions
22
middleware/sisyphus-jdbc/src/main/kotlin/com/bybutter/sisyphus/middleware/jdbc/utils/Page.kt
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,22 @@ | ||
package com.bybutter.sisyphus.middleware.jdbc.utils | ||
|
||
import com.bybutter.sisyphus.api.paging.OffsetPaging | ||
import com.bybutter.sisyphus.api.paging.invoke | ||
import com.bybutter.sisyphus.api.paging.nextPage | ||
import org.jooq.Record | ||
import org.jooq.SelectConditionStep | ||
|
||
data class Page<T>(var data: List<T>, var nextToken: String?, var total: Int? = null) | ||
|
||
inline fun <reified T : Record> SelectConditionStep<T>.withPaging(pageToken: String, pageSize: Int, needTotal: Boolean = true): Page<T> { | ||
val offset = OffsetPaging(pageToken)?.offset | ||
val size = if (pageSize in 1..30) { | ||
pageSize | ||
} else { | ||
30 | ||
} | ||
val count = if (needTotal) this.count() else null | ||
val data = this.offset(offset).limit(size).fetchInto(T::class.java) | ||
val next = OffsetPaging(pageToken).nextPage(data.size, size) | ||
return Page(data, next, 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