Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jun-labs/async-paging
π λΉλκΈ° νμ΄μ§ μμ μ½λ.
https://github.com/jun-labs/async-paging
async cursor limit offset page pagination paging sync
Last synced: about 15 hours ago
JSON representation
π λΉλκΈ° νμ΄μ§ μμ μ½λ.
- Host: GitHub
- URL: https://github.com/jun-labs/async-paging
- Owner: jun-labs
- Created: 2024-04-24T07:01:03.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-06-11T12:51:30.000Z (5 months ago)
- Last Synced: 2024-06-12T13:44:29.039Z (5 months ago)
- Topics: async, cursor, limit, offset, page, pagination, paging, sync
- Language: Kotlin
- Homepage:
- Size: 69.3 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Async Paging
νμ΄μ§ **`μΉ΄μ΄νΈ`**, **`λ°μ΄ν° νμΉ`** 쿼리 λΆλ¦¬ μμ .
## π» νλ‘κ·Έλ¨ μ€ν
λΉλ ν, νλ‘μ νΈ μ€ν ν©λλ€. μ ν리μΌμ΄μ μ€ν ν, λ°μ΄ν° μ΄κΈ°ν μμ μ΄ μκΈ° λλ¬Έμ μ κΉ λκΈ°ν©λλ€.
```shell
./gradlew build
``````shell
java -jar build/libs/paging-async-0.0.1.jar
```
## π Content
νμ΄μ§μμ **`μΉ΄μ΄νΈ`** μ **`λ°μ΄ν° νμΉ`** λ μΏΌλ¦¬κ° μμ°¨μ μΌλ‘ μ€νλ©λλ€. μ΄λ₯Ό λΆλ¦¬ν ν, λΉλκΈ°λ‘ μ‘°ννλ©΄ μ‘°ν μ±λ₯μ μ‘°κΈ λ ν₯μμν¬ μ μμ΅λλ€.
```kotlin
@Repository
class UserEntityReadRepository(
private val queryFactory: JPAQueryFactory,
) : UserReadRepository {companion object {
private val totalCountExpression = numberTemplate(Long::class.java, "count(1)")
}override suspend fun findUsers(
page: Int,
size: Int,
): Pair> = coroutineScope {
val totalCount = async {
queryFactory.select(totalCountExpression)
.from(user)
.fetchOne() ?: 0L
}val findUsers = async {
queryFactory.selectFrom(user)
.offset((page) * size.toLong())
.limit(10)
.fetch()
}
Pair(totalCount.await(), findUsers.await())
}
}
```> λ¨, μ΄λ offset λ°©μμ νκ³λ λ²μ΄λμ§ λͺ»νλ―λ‘, λ°μ΄ν°κ° λ§μ μλ‘ μλκ° λλ €μ§λλ€.