@@ -25,19 +25,20 @@ realm.where(Person.class).equalTo(PersonFieldNames.FIRST_NAME, "Sally").findFirs
2525RealmTypeSafeQuery . with(realm). where(Person . class). equalTo(PersonFields . FIRST_NAME , " Sally" ). findFirst();
2626```
2727
28- ## How to include
28+ ## How to include _ JavaOnly project _
2929
3030#### In your top level build file, add the jitpack repository along with realm
3131``` groovy
3232buildscript {
3333 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
3535 }
3636}
3737
3838allprojects {
3939 repositories {
4040 jcenter()
41+ google()
4142 maven { url "https://jitpack.io" } // RTSQ is hosted on jitpack
4243 }
4344}
@@ -46,17 +47,23 @@ allprojects {
4647#### App module build file dependencies:
4748``` groovy
4849apply 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]...
5458}
5559
5660dependencies {
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+ }
6067```
6168
6269#### Example Model
@@ -72,7 +79,7 @@ class Person extends RealmObject {
7279
7380 // If what pops out of the code generator doesn't compile add these annotations.
7481 // Realm constantly updates their api and RTSQ might be a little behind.
75- @SkipGenerationOfRealmFieldNames
82+ @SkipGenerationOfRealmFieldName
7683 @SkipGenerationOfRealmField
7784 RealmList<String > website;
7885}
@@ -103,20 +110,96 @@ RealmResults<Person> peopleWithHeavyPets = RealmTypeSafeQuery.with(realm).where(
103110 .greaterThan(PersonFields . PETS. link(PetFields . WEIGHT ), 9000 ). findAll();
104111```
105112
106- #### Bonus
107-
108- ``` java
113+ ## How to include _ KotlinOnly project_
109114
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+ }
111147
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
114167
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+ }
122205```
0 commit comments