Skip to content

Commit 063f56a

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 063f56a

File tree

3 files changed

+273
-0
lines changed

3 files changed

+273
-0
lines changed

jooq-postgresql-json/pom.xml

Lines changed: 46 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,41 @@
2738
<version>3.1.2</version>
2839
</plugin>
2940

41+
<plugin>
42+
<groupId>org.jetbrains.kotlin</groupId>
43+
<artifactId>kotlin-maven-plugin</artifactId>
44+
<version>${kotlin.version}</version>
45+
<configuration>
46+
<jvmTarget>1.8</jvmTarget>
47+
</configuration>
48+
<executions>
49+
<execution>
50+
<id>compile</id>
51+
<goals>
52+
<goal>compile</goal>
53+
</goals>
54+
<configuration>
55+
<sourceDirs>
56+
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
57+
<sourceDir>${project.basedir}/src/main/java</sourceDir>
58+
</sourceDirs>
59+
</configuration>
60+
</execution>
61+
<execution>
62+
<id>test-compile</id>
63+
<goals>
64+
<goal>test-compile</goal>
65+
</goals>
66+
<configuration>
67+
<sourceDirs>
68+
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
69+
<sourceDir>${project.basedir}/src/test/java</sourceDir>
70+
</sourceDirs>
71+
</configuration>
72+
</execution>
73+
</executions>
74+
</plugin>
75+
3076
<plugin>
3177
<groupId>org.apache.maven.plugins</groupId>
3278
<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: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
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+
/**
15+
* @see JsonbDSL.arrayElementText
16+
*/
17+
fun Field<JSONB>.arrayElementText(index: Int): Field<String> = JsonbDSL.arrayElementText(this, index)
18+
19+
/**
20+
* @see JsonbDSL.fieldByKey
21+
*/
22+
fun Field<JSONB>.fieldByKey(key: String): Field<JSONB> = JsonbDSL.fieldByKey(this, key)
23+
24+
/**
25+
* @see JsonbDSL.fieldByKeyText
26+
*/
27+
fun Field<JSONB>.fieldByKeyText(key: String): Field<String> = JsonbDSL.fieldByKeyText(this, key)
28+
29+
/**
30+
* @see JsonbDSL.objectAtPath
31+
*/
32+
fun Field<JSONB>.objectAtPath(vararg path: String): Field<JSONB> = JsonbDSL.objectAtPath(this, *path)
33+
34+
/**
35+
* @see JsonbDSL.objectAtPath
36+
*/
37+
fun Field<JSONB>.objectAtPath(path: Collection<String>): Field<JSONB> = JsonbDSL.objectAtPath(this, path)
38+
39+
/**
40+
* @see JsonbDSL.objectAtPathText
41+
*/
42+
fun Field<JSONB>.objectAtPathText(vararg path: String): Field<String> = JsonbDSL.objectAtPathText(this, *path)
43+
44+
/**
45+
* @see JsonbDSL.objectAtPathText
46+
*/
47+
fun Field<JSONB>.objectAtPathText(path: Collection<String>): Field<String> = JsonbDSL.objectAtPathText(this, path)
48+
49+
/**
50+
* @see JsonbDSL.contains
51+
*/
52+
fun Field<JSONB>.contains(other: Field<JSONB>): Condition = JsonbDSL.contains(this, other)
53+
54+
/**
55+
* @see JsonbDSL.containedIn
56+
*/
57+
fun Field<JSONB>.containedIn(other: Field<JSONB>): Condition = JsonbDSL.containedIn(this, other)
58+
59+
/**
60+
* @see JsonbDSL.hasKey
61+
*/
62+
fun Field<JSONB>.hasKey(key: String): Condition = JsonbDSL.hasKey(this, key)
63+
64+
/**
65+
* @see JsonbDSL.hasAnyKey
66+
*/
67+
fun Field<JSONB>.hasAnyKey(vararg keys: String): Condition = JsonbDSL.hasAnyKey(this, *keys)
68+
69+
/**
70+
* @see JsonbDSL.hasAnyKey
71+
*/
72+
fun Field<JSONB>.hasAnyKey(keys: Collection<String>): Condition = JsonbDSL.hasAnyKey(this, keys)
73+
74+
/**
75+
* @see JsonbDSL.hasAllKeys
76+
*/
77+
fun Field<JSONB>.hasAllKeys(vararg keys: String): Condition = JsonbDSL.hasAllKeys(this, *keys)
78+
79+
/**
80+
* @see JsonbDSL.hasAllKeys
81+
*/
82+
fun Field<JSONB>.hasAllKeys(keys: Collection<String>): Condition = JsonbDSL.hasAllKeys(this, keys)
83+
84+
/**
85+
* @see JsonbDSL.concat
86+
*/
87+
fun Field<JSONB>.concat(field2: Field<JSONB>): Field<JSONB> = JsonbDSL.concat(this, field2)
88+
89+
/**
90+
* @see JsonbDSL.delete
91+
*/
92+
fun Field<JSONB>.delete(keyOrElement: String): Field<JSONB> = JsonbDSL.delete(this, keyOrElement)
93+
94+
/**
95+
* @see JsonbDSL.delete
96+
*/
97+
fun Field<JSONB>.delete(vararg keysOrElements: String): Field<JSONB> = JsonbDSL.delete(this, *keysOrElements)
98+
99+
/**
100+
* @see JsonbDSL.deleteElement
101+
*/
102+
fun Field<JSONB>.deleteElement(index: Int): Field<JSONB> = JsonbDSL.deleteElement(this, index)
103+
104+
/**
105+
* @see JsonbDSL.deletePath
106+
*/
107+
fun Field<JSONB>.deletePath(vararg path: String): Field<JSONB> = JsonbDSL.deletePath(this, *path)
108+
109+
/**
110+
* @see JsonbDSL.arrayLength
111+
*/
112+
fun arrayLength(jsonField: Field<JSONB>): Field<Int> = JsonbDSL.arrayLength(jsonField)
113+
114+
/**
115+
* @see JsonbDSL.extractPath
116+
*/
117+
fun extractPath(jsonField: Field<JSONB>, vararg path: String): Field<JSONB> = JsonbDSL.extractPath(jsonField, *path)
118+
119+
/**
120+
* @see JsonbDSL.extractPath
121+
*/
122+
fun extractPath(jsonField: Field<JSONB>, path: Collection<String>): Field<JSONB> = JsonbDSL.extractPath(jsonField, *path.toTypedArray())
123+
124+
/**
125+
* @see JsonbDSL.extractPathText
126+
*/
127+
fun extractPathText(jsonField: Field<JSONB>, vararg path: String): Field<String> = JsonbDSL.extractPathText(jsonField, *path)
128+
129+
/**
130+
* @see JsonbDSL.extractPathText
131+
*/
132+
fun extractPathText(jsonField: Field<JSONB>, path: Collection<String>): Field<String> = JsonbDSL.extractPathText(jsonField, *path.toTypedArray())
133+
134+
/**
135+
* @see JsonbDSL.typeOf
136+
*/
137+
fun typeOf(jsonField: Field<JSONB>): Field<String> = JsonbDSL.typeOf(jsonField)
138+
139+
/**
140+
* @see JsonbDSL.stripNulls
141+
*/
142+
fun stripNulls(jsonField: Field<JSONB>): Field<JSONB> = JsonbDSL.stripNulls(jsonField)
143+
144+
/**
145+
* @see JsonbDSL.pretty
146+
*/
147+
fun pretty(jsonField: Field<JSONB>): Field<String> = JsonbDSL.pretty(jsonField)

0 commit comments

Comments
 (0)