Skip to content

Commit 8c7bcfd

Browse files
committed
feat(kotlin): provide operators through extension functions
To use a more fluent syntax, we provide some extension functions in the kotlin context. All the code is just a bridge with real java implementation. Closes #11
1 parent 463900a commit 8c7bcfd

File tree

3 files changed

+248
-0
lines changed

3 files changed

+248
-0
lines changed

jooq-postgresql-json/pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,22 @@
1212
<name>jooq-postgresql-json</name>
1313
<description>jOOQ support for PostgreSQL json &amp; jsonb</description>
1414

15+
<properties>
16+
<kotlin.version>1.4.20</kotlin.version>
17+
</properties>
18+
1519
<dependencies>
1620
<dependency>
1721
<groupId>org.jooq</groupId>
1822
<artifactId>jooq</artifactId>
1923
</dependency>
24+
25+
<dependency>
26+
<groupId>org.jetbrains.kotlin</groupId>
27+
<artifactId>kotlin-stdlib</artifactId>
28+
<version>${kotlin.version}</version>
29+
<optional>true</optional>
30+
</dependency>
2031
</dependencies>
2132

2233
<build>
@@ -27,6 +38,42 @@
2738
<version>3.1.2</version>
2839
</plugin>
2940

41+
<plugin>
42+
<!-- Based on instructions here - https://kotlinlang.org/docs/reference/using-maven.html -->
43+
<groupId>org.jetbrains.kotlin</groupId>
44+
<artifactId>kotlin-maven-plugin</artifactId>
45+
<version>${kotlin.version}</version>
46+
<configuration>
47+
<jvmTarget>1.8</jvmTarget>
48+
</configuration>
49+
<executions>
50+
<execution>
51+
<id>compile</id>
52+
<goals>
53+
<goal>compile</goal>
54+
</goals>
55+
<configuration>
56+
<sourceDirs>
57+
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
58+
<sourceDir>${project.basedir}/src/main/java</sourceDir>
59+
</sourceDirs>
60+
</configuration>
61+
</execution>
62+
<execution>
63+
<id>test-compile</id>
64+
<goals>
65+
<goal>test-compile</goal>
66+
</goals>
67+
<configuration>
68+
<sourceDirs>
69+
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
70+
<sourceDir>${project.basedir}/src/test/java</sourceDir>
71+
</sourceDirs>
72+
</configuration>
73+
</execution>
74+
</executions>
75+
</plugin>
76+
3077
<plugin>
3178
<groupId>org.apache.maven.plugins</groupId>
3279
<artifactId>maven-source-plugin</artifactId>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.github.t9t.jooq.json
2+
3+
import org.jooq.Field
4+
import org.jooq.JSON
5+
6+
7+
/**
8+
* @see JsonDSL.arrayElement
9+
*/
10+
fun Field<JSON?>?.arrayElement(index: Int): Field<JSON?>? = JsonDSL.arrayElement(this, index)
11+
12+
/**
13+
* @see JsonDSL.arrayElementText
14+
*/
15+
fun Field<JSON?>?.arrayElementText(index: Int): Field<String?>? = JsonDSL.arrayElementText(this, index)
16+
17+
/**
18+
* @see JsonDSL.fieldByKey
19+
*/
20+
fun Field<JSON?>?.fieldByKey(key: String?): Field<JSON?>? = JsonDSL.fieldByKey(this, key)
21+
22+
/**
23+
* @see JsonDSL.fieldByKeyText
24+
*/
25+
fun Field<JSON?>?.fieldByKeyText(key: String?): Field<String?>? = JsonDSL.fieldByKeyText(this, key)
26+
27+
/**
28+
* @see JsonDSL.objectAtPath
29+
*/
30+
fun Field<JSON?>?.objectAtPath(vararg path: String?): Field<JSON?>? = JsonDSL.objectAtPath(this, *path)
31+
32+
/**
33+
* @see JsonDSL.objectAtPath
34+
*/
35+
fun Field<JSON?>?.objectAtPath(path: Collection<String>): Field<JSON?>? = JsonDSL.objectAtPath(this, path)
36+
37+
/**
38+
* @see JsonDSL.objectAtPathText
39+
*/
40+
fun Field<JSON?>?.objectAtPathText(vararg path: String?): Field<String?>? = JsonDSL.objectAtPathText(this, *path)
41+
42+
/**
43+
* @see JsonDSL.objectAtPathText
44+
*/
45+
fun Field<JSON?>?.objectAtPathText(path: Collection<String>): Field<String?>? = JsonDSL.objectAtPathText(this, path)
46+
47+
/**
48+
* @see JsonDSL.arrayLength
49+
*/
50+
fun arrayLength(jsonField: Field<JSON?>?): Field<Int?>? = JsonDSL.arrayLength(jsonField)
51+
52+
/**
53+
* @see JsonDSL.extractPath
54+
*/
55+
fun extractPath(jsonField: Field<JSON?>?, vararg path: String?): Field<JSON?>? = JsonDSL.extractPath(jsonField, *path)
56+
57+
/**
58+
* @see JsonDSL.extractPath
59+
*/
60+
fun extractPath(jsonField: Field<JSON?>?, path: Collection<String>): Field<JSON?>? = JsonDSL.extractPath(jsonField, path)
61+
62+
/**
63+
* @see JsonDSL.extractPathText
64+
*/
65+
fun extractPathText(jsonField: Field<JSON?>?, vararg path: String?): Field<String?>? = JsonDSL.extractPathText(jsonField, *path)
66+
67+
/**
68+
* @see JsonDSL.extractPathText
69+
*/
70+
fun extractPathText(jsonField: Field<JSON?>?, path: Collection<String>): Field<String?>? = JsonDSL.extractPathText(jsonField, path)
71+
72+
/**
73+
* @see JsonDSL.typeOf
74+
*/
75+
fun typeOf(jsonField: Field<JSON?>?): Field<String?>? = JsonDSL.typeOf(jsonField)
76+
77+
/**
78+
* @see JsonDSL.stripNulls
79+
*/
80+
fun stripNulls(jsonField: Field<JSON?>?): Field<JSON?>? = JsonDSL.stripNulls(jsonField)
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
@file:Suppress("unused")
2+
3+
package com.github.t9t.jooq.json
4+
5+
import org.jooq.Condition
6+
import org.jooq.Field
7+
import org.jooq.JSONB
8+
9+
/**
10+
* @see JsonbDSL.arrayElement
11+
*/
12+
fun Field<JSONB?>?.arrayElement(index: Int): Field<JSONB?>? = JsonbDSL.arrayElement(this, index)
13+
/**
14+
* @see JsonbDSL.arrayElementText
15+
*/
16+
fun Field<JSONB?>?.arrayElementText(index: Int): Field<String?>? = JsonbDSL.arrayElementText(this, index)
17+
/**
18+
* @see JsonbDSL.fieldByKey
19+
*/
20+
fun Field<JSONB?>?.fieldByKey(key: String?): Field<JSONB?>? = JsonbDSL.fieldByKey(this, key)
21+
/**
22+
* @see JsonbDSL.fieldByKeyText
23+
*/
24+
fun Field<JSONB?>?.fieldByKeyText(key: String?): Field<String?>? = JsonbDSL.fieldByKeyText(this, key)
25+
/**
26+
* @see JsonbDSL.objectAtPath
27+
*/
28+
fun Field<JSONB?>?.objectAtPath(vararg path: String?): Field<JSONB?>? = JsonbDSL.objectAtPath(this, *path)
29+
/**
30+
* @see JsonbDSL.objectAtPath
31+
*/
32+
fun Field<JSONB?>?.objectAtPath(path: Collection<String>): Field<JSONB?>? = JsonbDSL.objectAtPath(this, path)
33+
/**
34+
* @see JsonbDSL.objectAtPathText
35+
*/
36+
fun Field<JSONB?>?.objectAtPathText(vararg path: String?): Field<String?>? = JsonbDSL.objectAtPathText(this, *path)
37+
/**
38+
* @see JsonbDSL.objectAtPathText
39+
*/
40+
fun Field<JSONB?>?.objectAtPathText(path: Collection<String>): Field<String?>? = JsonbDSL.objectAtPathText(this, path)
41+
/**
42+
* @see JsonbDSL.contains
43+
*/
44+
fun Field<JSONB?>?.contains(other: Field<JSONB?>?): Condition? = JsonbDSL.contains(this, other)
45+
/**
46+
* @see JsonbDSL.containedIn
47+
*/
48+
fun Field<JSONB?>?.containedIn(other: Field<JSONB?>?): Condition? = JsonbDSL.containedIn(this, other)
49+
/**
50+
* @see JsonbDSL.hasKey
51+
*/
52+
fun Field<JSONB?>?.hasKey(key: String?): Condition? = JsonbDSL.hasKey(this, key)
53+
/**
54+
* @see JsonbDSL.hasAnyKey
55+
*/
56+
fun Field<JSONB?>?.hasAnyKey(vararg keys: String?): Condition? = JsonbDSL.hasAnyKey(this, *keys)
57+
/**
58+
* @see JsonbDSL.hasAnyKey
59+
*/
60+
fun Field<JSONB?>?.hasAnyKey(keys: Collection<String>): Condition? = JsonbDSL.hasAnyKey(this, keys)
61+
/**
62+
* @see JsonbDSL.hasAllKeys
63+
*/
64+
fun Field<JSONB?>?.hasAllKeys(vararg keys: String?): Condition? = JsonbDSL.hasAllKeys(this, *keys)
65+
/**
66+
* @see JsonbDSL.hasAllKeys
67+
*/
68+
fun Field<JSONB?>?.hasAllKeys(keys: Collection<String>): Condition? = JsonbDSL.hasAllKeys(this, keys)
69+
/**
70+
* @see JsonbDSL.concat
71+
*/
72+
fun Field<JSONB?>?.concat(field2: Field<JSONB?>?): Field<JSONB?>? = JsonbDSL.concat(this, field2)
73+
/**
74+
* @see JsonbDSL.delete
75+
*/
76+
fun Field<JSONB?>?.delete(keyOrElement: String?): Field<JSONB?>? = JsonbDSL.delete(this, keyOrElement)
77+
/**
78+
* @see JsonbDSL.delete
79+
*/
80+
fun Field<JSONB?>?.delete(vararg keysOrElements: String?): Field<JSONB?>? = JsonbDSL.delete(this, *keysOrElements)
81+
/**
82+
* @see JsonbDSL.deleteElement
83+
*/
84+
fun Field<JSONB?>?.deleteElement(index: Int): Field<JSONB?>? = JsonbDSL.deleteElement(this, index)
85+
/**
86+
* @see JsonbDSL.deletePath
87+
*/
88+
fun Field<JSONB?>?.deletePath(vararg path: String?): Field<JSONB?>? = JsonbDSL.deletePath(this, *path)
89+
90+
/**
91+
* @see JsonbDSL.arrayLength
92+
*/
93+
fun arrayLength(jsonField: Field<JSONB?>?): Field<Int?>? = JsonbDSL.arrayLength(jsonField)
94+
/**
95+
* @see JsonbDSL.extractPath
96+
*/
97+
fun extractPath(jsonField: Field<JSONB?>?, vararg path: String?): Field<JSONB?>? = JsonbDSL.extractPath(jsonField, *path)
98+
/**
99+
* @see JsonbDSL.extractPath
100+
*/
101+
fun extractPath(jsonField: Field<JSONB?>?, path: Collection<String>): Field<JSONB?> ? = JsonbDSL.extractPath(jsonField, *path.toTypedArray())
102+
/**
103+
* @see JsonbDSL.extractPathText
104+
*/
105+
fun extractPathText(jsonField: Field<JSONB?>?, vararg path: String?): Field<String?>? = JsonbDSL.extractPathText(jsonField, *path)
106+
/**
107+
* @see JsonbDSL.extractPathText
108+
*/
109+
fun extractPathText(jsonField: Field<JSONB?>?, path: Collection<String>): Field<String?>? = JsonbDSL.extractPathText(jsonField, *path.toTypedArray())
110+
/**
111+
* @see JsonbDSL.typeOf
112+
*/
113+
fun typeOf(jsonField: Field<JSONB?>?): Field<String?>? = JsonbDSL.typeOf(jsonField)
114+
/**
115+
* @see JsonbDSL.stripNulls
116+
*/
117+
fun stripNulls(jsonField: Field<JSONB?>?): Field<JSONB?>? = JsonbDSL.stripNulls(jsonField)
118+
/**
119+
* @see JsonbDSL.pretty
120+
*/
121+
fun pretty(jsonField: Field<JSONB?>?): Field<String?>? = JsonbDSL.pretty(jsonField)

0 commit comments

Comments
 (0)