Skip to content

Commit

Permalink
feat: simple app spring jooq (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillKurdyukov authored Sep 5, 2024
1 parent 33c903f commit ecc569f
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 15 deletions.
6 changes: 3 additions & 3 deletions jdbc/spring-jooq/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<properties>
<maven.compiler.release>17</maven.compiler.release>
<kotlin.version>1.9.22</kotlin.version>
<jooq.ydb.version>1.0.0-RC1</jooq.ydb.version>
<jooq.ydb.version>1.0.0</jooq.ydb.version>
<flyway.version>10.7.1</flyway.version>
</properties>
<dependencies>
Expand Down Expand Up @@ -106,6 +106,7 @@
<configuration>
<environmentVariables>
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
<YDB_DOCKER_IMAGE>cr.yandex/yc/yandex-docker-local-ydb:trunk</YDB_DOCKER_IMAGE>
</environmentVariables>
</configuration>
</plugin>
Expand Down Expand Up @@ -151,8 +152,7 @@

<!-- <database>-->
<!-- <name>tech.ydb.jooq.codegen.YdbDatabase</name>-->
<!-- <includes>.*</includes>-->
<!-- <excludes/>-->
<!-- <excludes>.sys.*</excludes>-->
<!-- </database>-->

<!-- <target>-->
Expand Down
26 changes: 26 additions & 0 deletions jdbc/spring-jooq/src/main/java/ydb/default_schema/Indexes.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package tech.ydb.jooq.repository

import org.springframework.stereotype.Repository
import tech.ydb.jooq.YdbDSLContext
import ydb.default_schema.Indexes
import ydb.default_schema.Tables.SERIES

/**
* @author Kirill Kurdyukov
*/
@Repository
class SeriesRepository(val ydbDSLContext: YdbDSLContext) {

fun findByTitle(title: String) = ydbDSLContext.selectFrom(SERIES.useIndex(Indexes.TITLE_NAME.name))
.where(SERIES.TITLE.eq(title))
.fetchOne()
}
25 changes: 13 additions & 12 deletions jdbc/spring-jooq/src/main/resources/db/migration/V1__schema.sql
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
CREATE TABLE series
(
series_id Int64,
title Utf8,
series_info Utf8,
series_id Int64,
title Text,
series_info Text,
release_date Date,
PRIMARY KEY (series_id)
PRIMARY KEY (series_id),
INDEX title_name GLOBAL ON (title)
);

CREATE TABLE seasons
(
series_id Int64,
season_id Int64,
title Utf8,
series_id Int64,
season_id Int64,
title Text,
first_aired Date,
last_aired Date,
last_aired Date,
PRIMARY KEY (series_id, season_id)
);

CREATE TABLE episodes
(
series_id Int64,
season_id Int64,
series_id Int64,
season_id Int64,
episode_id Int64,
title Utf8,
air_date Date,
title Text,
air_date Date,
PRIMARY KEY (series_id, season_id, episode_id)
);
10 changes: 10 additions & 0 deletions jdbc/spring-jooq/src/test/kotlin/tech/ydb/jooq/JooqTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.springframework.test.context.DynamicPropertyRegistry
import org.springframework.test.context.DynamicPropertySource
import tech.ydb.jooq.repository.EpisodesRepository
import tech.ydb.jooq.repository.SeasonsRepository
import tech.ydb.jooq.repository.SeriesRepository
import tech.ydb.test.junit5.YdbHelperExtension
import ydb.default_schema.tables.records.EpisodesRecord
import java.time.LocalDate
Expand Down Expand Up @@ -43,6 +44,9 @@ class JooqTest {
@Autowired
lateinit var ydbDSLContext: YdbDSLContext

@Autowired
lateinit var seriesRepository: SeriesRepository

@Test
fun findAllTest() {
assertEquals(70, episodesRepository.findAll().size)
Expand Down Expand Up @@ -136,4 +140,10 @@ class JooqTest {
assertEquals("IT Crowd", titles[i - 1].second)
}
}

@Test
fun findByTitleViewIndex() {
val record = seriesRepository.findByTitle("IT Crowd")!!
assertEquals(LocalDate.parse("2006-02-03"), record.releaseDate)
}
}

0 comments on commit ecc569f

Please sign in to comment.