Skip to content

Commit

Permalink
dep v bump
Browse files Browse the repository at this point in the history
  • Loading branch information
mvysny committed Jan 23, 2024
1 parent cf0ae09 commit d87f6ea
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tasks.withType<KotlinCompile> {
dependencies {
api(kotlin("stdlib-jdk8"))
api("com.github.mvysny.vokdataloader:vok-dataloader:0.9.1")
api("com.gitlab.mvysny.jdbiorm:jdbi-orm:2.1")
api("com.gitlab.mvysny.jdbiorm:jdbi-orm:2.4")

// logging
implementation("org.slf4j:slf4j-api:$slf4jVersion")
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/github/vokorm/Dao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public fun <T : Any> DaoOfAny<T>.count(filter: Filter<T>): Long {
* db { con.createQuery("delete from Foo where name = :name").addParameter("name", name).executeUpdate() }
* ```
*/
public fun <T : Any> DaoOfAny<T>.deleteBy2(block: FilterBuilder<T>.() -> Filter<T>) {
public fun <T : Any> DaoOfAny<T>.deleteBy(block: FilterBuilder<T>.() -> Filter<T>) {
deleteBy(FilterBuilder<T>(entityClass).block())
}

Expand All @@ -118,7 +118,7 @@ public fun <T : Any> DaoOfAny<T>.deleteBy(filter: Filter<T>) {
* @param range use LIMIT+OFFSET to fetch given page of data. Defaults to all data.
* @param block the filter to use.
*/
public fun <T : Any> DaoOfAny<T>.findAllBy2(
public fun <T : Any> DaoOfAny<T>.findAllBy(
vararg orderBy: SortClause = arrayOf(),
range: IntRange = IntRange(0, Int.MAX_VALUE),
block: FilterBuilder<T>.() -> Filter<T>
Expand Down Expand Up @@ -181,7 +181,7 @@ public fun <T : Any> DaoOfAny<T>.findAllBy(
* ```
* @param block the filter to use.
*/
public fun <T : Any> DaoOfAny<T>.existsBy2(block: FilterBuilder<T>.() -> Filter<T>): Boolean =
public fun <T : Any> DaoOfAny<T>.existsBy(block: FilterBuilder<T>.() -> Filter<T>): Boolean =
existsBy(block(FilterBuilder(entityClass)))

/**
Expand Down
17 changes: 9 additions & 8 deletions src/test/kotlin/com/github/vokorm/DaoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.time.Instant
import java.time.LocalDate
import java.util.*
import kotlin.test.expect
import com.github.vokorm.deleteBy

@DynaTestDsl
fun DynaNodeGroup.dbDaoTests() {
Expand Down Expand Up @@ -87,9 +88,9 @@ fun DynaNodeGroup.dbDaoTests() {
}
test("DeleteBy") {
listOf("Albedo", "Nigredo", "Rubedo").forEach { Person(name = it, age = 129).save() }
Person.deleteBy2 { "name = :name"("name" to "Albedo") } // raw sql where
Person.deleteBy { "name = :name"("name" to "Albedo") } // raw sql where
expect(listOf("Nigredo", "Rubedo")) { Person.findAll().map { it.name } }
Person.deleteBy2 { Person::name eq "Rubedo" } // fancy type-safe criteria
Person.deleteBy { Person::name eq "Rubedo" } // fancy type-safe criteria
expect(listOf("Nigredo")) { Person.findAll().map { it.name } }
}
group("findOneBy() tests") {
Expand Down Expand Up @@ -130,21 +131,21 @@ fun DynaNodeGroup.dbDaoTests() {
test("returns false on empty table") {
expect(false) { Person.existsAny() }
expect(false) { Person.existsById(25) }
expect(false) { Person.existsBy2 { Person::age le 26 } }
expect(false) { Person.existsBy { Person::age le 26 } }
}
test("returns true on matching entity") {
val p = Person(name = "Albedo", age = 134)
p.save()
expect(true) { Person.existsAny() }
expect(true) { Person.existsById(p.id!!) }
expect(true) { Person.existsBy2 { Person::age ge 26 } }
expect(true) { Person.existsBy { Person::age ge 26 } }
}
test("returns false on non-matching entity") {
val p = Person(name = "Albedo", age = 135)
p.save()
expect(true) { Person.existsAny() }
expect(false) { Person.existsById(p.id!! + 1) }
expect(false) { Person.existsBy2 { Person::age le 26 } }
expect(false) { Person.existsBy { Person::age le 26 } }
}
}
test("sql92 filter works") {
Expand Down Expand Up @@ -205,7 +206,7 @@ fun DynaNodeGroup.dbDaoTests() {
}
test("DeleteBy") {
listOf("Albedo", "Nigredo", "Rubedo").forEach { EntityWithAliasedId(name = it).save() }
EntityWithAliasedId.deleteBy2 { "name = :name"("name" to "Albedo") } // raw sql where
EntityWithAliasedId.deleteBy { "name = :name"("name" to "Albedo") } // raw sql where
expect(listOf("Nigredo", "Rubedo")) { EntityWithAliasedId.findAll().map { it.name } }
}
group("findOneBy() tests") {
Expand All @@ -219,14 +220,14 @@ fun DynaNodeGroup.dbDaoTests() {
test("returns false on empty table") {
expect(false) { EntityWithAliasedId.existsAny() }
expect(false) { EntityWithAliasedId.existsById(25) }
expect(false) { EntityWithAliasedId.existsBy2 { EntityWithAliasedId::name le "a" } }
expect(false) { EntityWithAliasedId.existsBy { EntityWithAliasedId::name le "a" } }
}
test("returns true on matching entity") {
val p = EntityWithAliasedId(name = "Albedo")
p.save()
expect(true) { EntityWithAliasedId.existsAny() }
expect(true) { EntityWithAliasedId.existsById(p.id!!) }
expect(true) { EntityWithAliasedId.existsBy2 { EntityWithAliasedId::name eq "Albedo" } }
expect(true) { EntityWithAliasedId.existsBy { EntityWithAliasedId::name eq "Albedo" } }
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/test/kotlin/com/github/vokorm/FiltersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,67 +48,67 @@ fun DynaNodeGroup.dbFiltersTest(info: DatabaseInfo) {

test("eq filter test") {
expectList() {
Person.findAllBy2 { Person::age eq 40 }.map { it.name }
Person.findAllBy { Person::age eq 40 }.map { it.name }
}
expectList("Jerry") {
Person.findAllBy2 { Person::age eq 26 }.map { it.name }
Person.findAllBy { Person::age eq 26 }.map { it.name }
}
}

test("ne filter test") {
expectList("Moby", "Jerry", "Paul") {
Person.findAllBy2 { Person::age ne 40 }.map { it.name }
Person.findAllBy { Person::age ne 40 }.map { it.name }
}
expectList("Jerry", "Paul") {
Person.findAllBy2 { Person::age ne 25 }.map { it.name }
Person.findAllBy { Person::age ne 25 }.map { it.name }
}
}

test("le filter test") {
expectList("Moby", "Jerry", "Paul") {
Person.findAllBy2 { Person::age le 40 }.map { it.name }
Person.findAllBy { Person::age le 40 }.map { it.name }
}
expectList("Moby", "Jerry") {
Person.findAllBy2 { Person::age le 26 }.map { it.name }
Person.findAllBy { Person::age le 26 }.map { it.name }
}
}

test("lt filter test") {
expectList("Moby", "Jerry", "Paul") {
Person.findAllBy2 { Person::age lt 40 }.map { it.name }
Person.findAllBy { Person::age lt 40 }.map { it.name }
}
expectList("Moby") {
Person.findAllBy2 { Person::age lt 26 }.map { it.name }
Person.findAllBy { Person::age lt 26 }.map { it.name }
}
}

test("ge filter test") {
expectList() {
Person.findAllBy2 { Person::age ge 40 }.map { it.name }
Person.findAllBy { Person::age ge 40 }.map { it.name }
}
expectList("Jerry", "Paul") {
Person.findAllBy2 { Person::age ge 26 }.map { it.name }
Person.findAllBy { Person::age ge 26 }.map { it.name }
}
}

test("gt filter test") {
expectList() {
Person.findAllBy2 { Person::age gt 40 }.map { it.name }
Person.findAllBy { Person::age gt 40 }.map { it.name }
}
expectList("Paul") {
Person.findAllBy2 { Person::age gt 26 }.map { it.name }
Person.findAllBy { Person::age gt 26 }.map { it.name }
}
}

test("not filter test") {
expectList("Moby", "Paul") {
Person.findAllBy2 { !(Person::age eq 26) }.map { it.name }
Person.findAllBy { !(Person::age eq 26) }.map { it.name }
}
}

test("in filter test") {
expectList("Moby", "Jerry") {
Person.findAllBy2 { Person::age `in` listOf(25, 26, 28) }.map { it.name }
Person.findAllBy { Person::age `in` listOf(25, 26, 28) }.map { it.name }
}
}
}
Expand Down

0 comments on commit d87f6ea

Please sign in to comment.