Skip to content

Commit

Permalink
test refs
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentlauvlwj committed Jul 16, 2023
1 parent 8934336 commit 3bf7c08
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.ktorm.ksp.compiler.generator

import org.junit.Test
import org.ktorm.ksp.compiler.BaseKspTest

/**
* Created by vince at Jul 16, 2023.
*/
class RefsClassGeneratorTest : BaseKspTest() {

@Test
fun testRefs() = runKotlin(
"""
@Table
interface Employee: Entity<Employee> {
@PrimaryKey
var id: Int
var name: String
var job: String
var managerId: Int?
var hireDate: LocalDate
var salary: Long
@References
var department: Department
}
@Table
interface Department: Entity<Department> {
@PrimaryKey
var id: Int
var name: String
var location: String
}
fun run() {
val employees = database.employees
.filter { it.refs.department.name eq "tech" }
.filter { it.refs.department.location eq "Guangzhou" }
.sortedBy { it.id }
.toList()
assert(employees.size == 2)
assert(employees[0].name == "vince")
assert(employees[1].name == "marry")
}
""".trimIndent())
}
1 change: 1 addition & 0 deletions ktorm-ksp-compiler/src/test/resources/drop-ksp-data.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
drop table if exists "user";
drop table if exists "employee";
drop table if exists "department";
drop table if exists "province";
10 changes: 10 additions & 0 deletions ktorm-ksp-compiler/src/test/resources/init-ksp-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ values ('vince', 'engineer', null, '2018-01-01', 100, 1),
('tom', 'director', null, '2018-01-01', 200, 2),
('penny', 'assistant', 3, '2019-01-01', 100, 2);

create table "department"(
"id" int not null primary key auto_increment,
"name" varchar(128) not null,
"location" varchar(128) not null,
"mixedCase" varchar(128)
);

insert into "department"("name", "location") values ('tech', 'Guangzhou');
insert into "department"("name", "location") values ('finance', 'Beijing');

create table "province"
(
"country" varchar(128) not null,
Expand Down

0 comments on commit 3bf7c08

Please sign in to comment.