Skip to content

Commit 773af6b

Browse files
authored
Update README.md
1 parent c430a01 commit 773af6b

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed

README.md

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@
44

55
### A type safe way to handle realm queries in Android.
66
Supports Realm query API 110% (there are some bonus features too 😉)
7+
8+
There are two big issues when working with Realm Queries.
9+
1) If a field name is spelled incorectly it failes at runtime instead of compile time.
10+
2) If an argument is an incorect type (Date instead of String) then the query fails at runtime instead of compile time.
11+
12+
If you have typesafe query paramaters that allows you to refactor your models without worry of breaking your queries.
13+
All the field descriptors are auto generated using annotatio proccess so you can't make a mistake.
14+
If you do, then it is caught at compile time and your app won't compile until you fix it.
15+
16+
### Here is some java code highlighting what the API looks like
717
```java
8-
// Bad, field name and type are checked at runtime.
18+
// Bad, field name and type are checked at runtime. This is using Relam the defualt way.
919
realm.where(Person.class).equalTo("firstName", "Sally").findFirst();
1020

1121
// Better, field name is checked at compile time, but type is still at runtime.
@@ -17,7 +27,7 @@ RealmTypeSafeQuery.with(realm).where(Person.class).equalTo(PersonFields.FIRST_NA
1727

1828
## How to include
1929

20-
#### In your top level build file, add the jitpack repository
30+
#### In your top level build file, add the jitpack repository along with realm
2131
```groovy
2232
buildscript {
2333
dependencies {
@@ -28,40 +38,47 @@ buildscript {
2838
allprojects {
2939
repositories {
3040
jcenter()
31-
maven { url "https://jitpack.io" } // needed to import RTSQ
41+
maven { url "https://jitpack.io" } // RTSQ is hosted on jitpack
3242
}
3343
}
3444
```
3545

3646
#### App module build file dependencies:
3747
```groovy
38-
apply plugin: 'realm-android' // realm setup
48+
apply plugin: 'realm-android' // realm setup at top of file
3949
40-
compileOnly 'com.github.quarkworks.RealmTypeSafeQuery-Android:annotations:{{version_number}}' // annotations
41-
annotationProcessor 'com.github.quarkworks.RealmTypeSafeQuery-Android:annotationprocessor:{{version_number}}' // annotation processor
42-
implementation 'com.github.quarkworks.RealmTypeSafeQuery-Android:query:{{version_number}}' // query dsl
50+
// requires java 8
51+
compileOptions {
52+
sourceCompatibility JavaVersion.VERSION_1_8
53+
targetCompatibility JavaVersion.VERSION_1_8
54+
}
55+
56+
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
4360
```
4461

4562
#### Example Model
4663
```java
47-
@GenerateRealmFields // Generates a file called PersonFields.java
48-
@GenerateRealmFieldNames // Generates a file called PersonFieldNames.java
64+
@GenerateRealmFields // Generates a file called PersonFields.java. This is a RTSQ annotation.
65+
@GenerateRealmFieldNames // Generates a file called PersonFieldNames.java This is a RTSQ annotation.
4966
class Person extends RealmObject {
5067
String firstName;
5168
String lastName;
5269
Date birthday;
5370

5471
RealmList<Pet> pets;
5572

56-
// If what pops out of the code generator doesn't compile add these annotations
57-
// Realm constantly updates their api and RTSQ might be a little behind
73+
// If what pops out of the code generator doesn't compile add these annotations.
74+
// Realm constantly updates their api and RTSQ might be a little behind.
5875
@SkipGenerationOfRealmFieldNames
5976
@SkipGenerationOfRealmField
6077
RealmList<String> website;
6178
}
6279

63-
@GenerateRealmFields // Generates a file called PetFields.java
64-
@GenerateRealmFieldNames // Generates a file called PetFieldNames.java
80+
@GenerateRealmFields // Generates a file called PetFields.java.
81+
@GenerateRealmFieldNames // Generates a file called PetFieldNames.java.
6582
class Pet extends RealmObject {
6683
String name;
6784
Integer weight;
@@ -72,7 +89,7 @@ class Pet extends RealmObject {
7289

7390
```java
7491

75-
Realm realm = Realm.getInstance();
92+
final Realm realm = ...
7693

7794
RealmResults<Person> sallyNotSmiths = RealmTypeSafeQuery.with(realm).where(Person.class)
7895
.equalTo(PersonFields.FIRST_NAME, "Sally")
@@ -89,13 +106,17 @@ RealmResults<Person> peopleWithHeavyPets = RealmTypeSafeQuery.with(realm).where(
89106
#### Bonus
90107

91108
```java
109+
110+
final Realm realm = ...
111+
92112
// For chainable sorting
93-
RealmTypeSafeQuery.with(realm).where(model).sort(field1).sort(field3).sort(field2).findAll();
113+
RealmTypeSafeQuery.with(realm).where(ExampleModel.class).sort(field1).sort(field3).sort(field2).findAll();
94114

95115
// For creating query groups with lambdas
96-
RealmTypeSafeQuery.with(realm).where(model).with(realm).where(model).group((query) -> {}).findAll();
97-
RealmTypeSafeQuery.with(realm).where(model).or((query) -> {}).findAll();
116+
RealmTypeSafeQuery.with(realm).where(ExampleModel.class).group((query) -> {}).findAll();
117+
RealmTypeSafeQuery.with(realm).where(ExampleModel.class).or((query) -> {}).findAll();
98118

99119
// For those pesky CSV fields that have a delimiter
100-
RealmTypeSafeQuery.with(realm).where(model).contains(field, value, delemiter).findAll();
120+
final String delemiter = ",";
121+
RealmTypeSafeQuery.with(realm).where(ExampleModel.class).contains(field, value, delemiter).findAll();
101122
```

0 commit comments

Comments
 (0)