@@ -25,19 +25,20 @@ realm.where(Person.class).equalTo(PersonFieldNames.FIRST_NAME, "Sally").findFirs
25
25
RealmTypeSafeQuery . with(realm). where(Person . class). equalTo(PersonFields . FIRST_NAME , " Sally" ). findFirst();
26
26
```
27
27
28
- ## How to include
28
+ ## How to include _ JavaOnly project _
29
29
30
30
#### In your top level build file, add the jitpack repository along with realm
31
31
``` groovy
32
32
buildscript {
33
33
dependencies {
34
- classpath "io.realm:realm-gradle-plugin:4.3.1 " // supported version of realm
34
+ classpath "io.realm:realm-gradle-plugin:4.3.4 " // supported version of realm
35
35
}
36
36
}
37
37
38
38
allprojects {
39
39
repositories {
40
40
jcenter()
41
+ google()
41
42
maven { url "https://jitpack.io" } // RTSQ is hosted on jitpack
42
43
}
43
44
}
@@ -46,17 +47,23 @@ allprojects {
46
47
#### App module build file dependencies:
47
48
``` groovy
48
49
apply plugin: 'realm-android' // realm setup at top of file
49
-
50
- // requires java 8
51
- compileOptions {
52
- sourceCompatibility JavaVersion.VERSION_1_8
53
- targetCompatibility JavaVersion.VERSION_1_8
50
+ android {
51
+ ...[elided]...
52
+ // requires java 8
53
+ compileOptions {
54
+ sourceCompatibility JavaVersion.VERSION_1_8
55
+ targetCompatibility JavaVersion.VERSION_1_8
56
+ }
57
+ ...[elided]...
54
58
}
55
59
56
60
dependencies {
57
- compileOnly 'com.github.quarkworks.RealmTypeSafeQuery-Android:annotations:{{version_number}}' // annotations
58
- annotationProcessor 'com.github.quarkworks.RealmTypeSafeQuery-Android:annotationprocessor:{{version_number}}' // annotation processor
59
- implementation 'com.github.quarkworks.RealmTypeSafeQuery-Android:query:{{version_number}}' // query dsl
61
+ ...[elided]...
62
+ compileOnly "com.github.quarkworks.RealmTypeSafeQuery-Android:annotations:$RTSQ_version" // annotations
63
+ annotationProcessor "com.github.quarkworks.RealmTypeSafeQuery-Android:annotationprocessor:$RTSQ_version" // annotation processor
64
+ implementation "com.github.quarkworks.RealmTypeSafeQuery-Android:query:$RTSQ_version" // query dsl
65
+ ...[elided]...
66
+ }
60
67
```
61
68
62
69
#### Example Model
@@ -72,7 +79,7 @@ class Person extends RealmObject {
72
79
73
80
// If what pops out of the code generator doesn't compile add these annotations.
74
81
// Realm constantly updates their api and RTSQ might be a little behind.
75
- @SkipGenerationOfRealmFieldNames
82
+ @SkipGenerationOfRealmFieldName
76
83
@SkipGenerationOfRealmField
77
84
RealmList<String > website;
78
85
}
@@ -103,20 +110,96 @@ RealmResults<Person> peopleWithHeavyPets = RealmTypeSafeQuery.with(realm).where(
103
110
.greaterThan(PersonFields . PETS. link(PetFields . WEIGHT ), 9000 ). findAll();
104
111
```
105
112
106
- #### Bonus
107
-
108
- ``` java
113
+ ## How to include _ KotlinOnly project_
109
114
110
- final Realm realm = ...
115
+ #### In your top level build file, add the jitpack repository along with realm
116
+ ``` groovy
117
+ buildscript {
118
+ dependencies {
119
+ classpath "io.realm:realm-gradle-plugin:4.3.4" // supported version of realm
120
+ }
121
+ }
122
+
123
+ allprojects {
124
+ repositories {
125
+ jcenter()
126
+ google()
127
+ maven { url "https://jitpack.io" } // RTSQ is hosted on jitpack
128
+ }
129
+ }
130
+ ```
131
+
132
+ #### App module build file dependencies:
133
+ ``` groovy
134
+ apply plugin: 'kotlin-android'
135
+ apply plugin: 'kotlin-kapt'
136
+ apply plugin: 'realm-android' // realm setup at top of file but below 'kotlin-kapt'
137
+
138
+ android {
139
+ ...[elided]...
140
+ // requires java 8 (android build issue)
141
+ compileOptions {
142
+ sourceCompatibility JavaVersion.VERSION_1_8
143
+ targetCompatibility JavaVersion.VERSION_1_8
144
+ }
145
+ ...[elided]...
146
+ }
111
147
112
- // For chainable sorting
113
- RealmTypeSafeQuery . with(realm). where(ExampleModel . class). sort(field1). sort(field3). sort(field2). findAll();
148
+ dependencies {
149
+ ...[elided]...
150
+ compileOnly "com.github.quarkworks.RealmTypeSafeQuery-Android:annotations:$RTSQ_version" // annotations
151
+ // use kapt not annotationProcessor
152
+ kapt "com.github.quarkworks.RealmTypeSafeQuery-Android:annotationprocessor:$RTSQ_version" // annotation processor
153
+ implementation "com.github.quarkworks.RealmTypeSafeQuery-Android:query:$RTSQ_version" // query dsl
154
+ ...[elided]...
155
+ }
156
+ ```
157
+
158
+ #### Example Model
159
+ ``` kotlin
160
+ @GenerateRealmFields // Generates a file called PersonFields.java. This is a RTSQ annotation.
161
+ @GenerateRealmFieldNames // Generates a file called PersonFieldNames.java This is a RTSQ annotation.
162
+ // Kotlin classes are final by default (notice open)
163
+ open class Person : RealmObject () {
164
+ var firstName: String? = null
165
+ var lastName: String? = null
166
+ var birthday: Date ? = null
114
167
115
- // For creating query groups with lambdas
116
- RealmTypeSafeQuery . with(realm). where(ExampleModel . class). group((query) - > {}). findAll();
117
- RealmTypeSafeQuery . with(realm). where(ExampleModel . class). or((query) - > {}). findAll();
118
-
119
- // For those pesky CSV fields that have a delimiter
120
- final String delimiter = " ," ;
121
- RealmTypeSafeQuery . with(realm). where(ExampleModel . class). contains(field, value, delimiter). findAll();
168
+ var pets: RealmList <Pet >? = null
169
+
170
+ // If what pops out of the code generator doesn't compile add these annotations.
171
+ // Realm constantly updates their api and RTSQ might be a little behind.
172
+ @SkipGenerationOfRealmFieldName
173
+ @SkipGenerationOfRealmField
174
+ var website: RealmList <String >? = null
175
+ }
176
+
177
+ @GenerateRealmFields // Generates a file called PetFields.java.
178
+ @GenerateRealmFieldNames // Generates a file called PetFieldNames.java.
179
+ open class Pet : RealmObject () {
180
+ var name: String? = null
181
+ var weight: Int? = null
182
+ }
183
+ ```
184
+
185
+ #### Example Queries
186
+
187
+ ``` kotlin
188
+ Realm .init (this .applicationContext)
189
+
190
+ Realm .getDefaultInstance().use { realm ->
191
+ realm.executeTransaction { realm ->
192
+
193
+ val sallyNotSmiths = RealmTypeSafeQuery .with (realm).where(Person ::class .java)
194
+ .equalTo(PersonFields .FIRST_NAME , " Sally" )
195
+ .notEqualTo(PersonFields .LAST_NAME , " Smith" , Case .INSENSITIVE )
196
+ .lessThan(PersonFields .BIRTHDAY , Date ())
197
+ .findAllSorted(PersonFields .BIRTHDAY , Sort .ASCENDING )
198
+
199
+ // Link queries also work too
200
+
201
+ val peopleWithHeavyPets = RealmTypeSafeQuery .with (realm).where(Person ::class .java)
202
+ .greaterThan(PersonFields .PETS .link(PetFields .WEIGHT ), 9000 ).findAll()
203
+ }
204
+ }
122
205
```
0 commit comments