1
1
package byos
2
2
3
3
import com.fasterxml.jackson.databind.ObjectMapper
4
- import db.jooq.generated.Tables.BOOK
5
- import db.jooq.generated.Tables.BOOK_TO_BOOKSTORE
6
- import db.jooq.generated.tables.Author
7
- import db.jooq.generated.tables.Book
8
- import db.jooq.generated.tables.BookToBookstore
9
- import db.jooq.generated.tables.Bookstore
4
+ import db.jooq.generated.Tables.FILM_ACTOR
5
+ import db.jooq.generated.Tables.FILM_CATEGORY
6
+ import db.jooq.generated.Tables.INVENTORY
7
+ import db.jooq.generated.tables.Actor
8
+ import db.jooq.generated.tables.Category
9
+ import db.jooq.generated.tables.Film
10
+ import db.jooq.generated.tables.Inventory
10
11
import db.jooq.generated.tables.Language
11
- import db.jooq.generated.tables.Shoporder
12
- import db.jooq.generated.tables.Shopuser
13
- import db.jooq.generated.tables.Tree
12
+ import db.jooq.generated.tables.Store
14
13
import graphql.language.Argument
15
14
import graphql.language.ArrayValue
16
15
import graphql.language.BooleanValue
@@ -31,21 +30,35 @@ import org.jooq.impl.DSL
31
30
object WhereCondition {
32
31
fun getForRelationship (relationshipName : String , left : Table <* >, right : Table <* >): Condition =
33
32
when {
34
- relationshipName == " author" && left is Book && right is Author -> left.AUTHORID .eq(right.ID )
35
- relationshipName == " books" && left is Author && right is Book -> right.AUTHORID .eq(left.ID )
36
- relationshipName == " user" && left is Shoporder && right is Shopuser -> right.USER_ID .eq(left.USER_ID )
37
- relationshipName == " orders" && left is Shopuser && right is Shoporder -> right.USER_ID .eq(left.USER_ID )
38
- relationshipName == " children" && left is Tree && right is Tree -> left.ID .eq(right.PARENT_ID )
39
- relationshipName == " parent" && left is Tree && right is Tree -> right.ID .eq(left.PARENT_ID )
40
- relationshipName == " books" && left is Bookstore && right is Book -> DSL .exists(
41
- DSL .selectOne().from(BOOK_TO_BOOKSTORE ).where(left.NAME .eq(BOOK_TO_BOOKSTORE .NAME ).and (BOOK_TO_BOOKSTORE .BOOKID .eq(right.ID )))
33
+ relationshipName == " actors" && left is Film && right is Actor -> DSL .exists(
34
+ DSL .selectOne().from(FILM_ACTOR ).where(left.FILM_ID .eq(FILM_ACTOR .FILM_ID ).and (FILM_ACTOR .ACTOR_ID .eq(right.ACTOR_ID )))
42
35
)
43
36
44
- relationshipName == " b2b" && left is Bookstore && right is BookToBookstore -> left.NAME .eq(right.NAME )
45
- relationshipName == " book" && left is BookToBookstore && right is Book -> left.BOOKID .eq(right.ID )
46
- relationshipName == " language" && left is Book && right is Language -> left.LANGUAGEID .eq(right.ID )
47
- relationshipName == " publicationLanguages" && left is Author && right is Language -> DSL .exists(
48
- DSL .selectOne().from(BOOK ).where(left.ID .eq(BOOK .AUTHORID ).and (BOOK .LANGUAGEID .eq(right.ID )))
37
+ relationshipName == " films" && left is Actor && right is Film -> DSL .exists(
38
+ DSL .selectOne().from(FILM_ACTOR ).where(left.ACTOR_ID .eq(FILM_ACTOR .ACTOR_ID ).and (FILM_ACTOR .FILM_ID .eq(right.FILM_ID )))
39
+ )
40
+
41
+ relationshipName == " stores" && left is Film && right is Store -> DSL .exists(
42
+ DSL .selectOne().from(INVENTORY ).where(left.FILM_ID .eq(INVENTORY .FILM_ID ).and (INVENTORY .STORE_ID .eq(right.STORE_ID )))
43
+ )
44
+
45
+ relationshipName == " films" && left is Store && right is Film -> DSL .exists(
46
+ DSL .selectOne().from(INVENTORY ).where(left.STORE_ID .eq(INVENTORY .STORE_ID ).and (INVENTORY .FILM_ID .eq(right.FILM_ID )))
47
+ )
48
+
49
+ relationshipName == " language" && left is Film && right is Language -> left.LANGUAGE_ID .eq(right.LANGUAGE_ID )
50
+ relationshipName == " original_language" && left is Film && right is Language -> left.ORIGINAL_LANGUAGE_ID .eq(right.LANGUAGE_ID )
51
+
52
+ relationshipName == " inventories" && left is Store && right is Inventory -> left.STORE_ID .eq(right.STORE_ID )
53
+
54
+ relationshipName == " film" && left is Inventory && right is Film -> left.FILM_ID .eq(right.FILM_ID )
55
+
56
+ relationshipName == " categories" && left is Film && right is Category -> DSL .exists(
57
+ DSL .selectOne().from(FILM_CATEGORY ).where(left.FILM_ID .eq(FILM_CATEGORY .FILM_ID ).and (FILM_CATEGORY .CATEGORY_ID .eq(right.CATEGORY_ID )))
58
+ )
59
+
60
+ relationshipName == " films" && left is Category && right is Film -> DSL .exists(
61
+ DSL .selectOne().from(FILM_CATEGORY ).where(left.CATEGORY_ID .eq(FILM_CATEGORY .CATEGORY_ID ).and (FILM_CATEGORY .FILM_ID .eq(right.FILM_ID )))
49
62
)
50
63
51
64
else -> error(" No relationship called $relationshipName found for tables $left and $right " )
0 commit comments