Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
pilgr authored Aug 25, 2016
1 parent c4cb0fb commit 1838aac
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ Paper is a [fast](#benchmark-results) NoSQL data storage for Android that lets y

![Paper icon](/paper_icon.png)

#### What's [new](/CHANGELOG.md) in 1.5
### What's [new](/CHANGELOG.md) in 1.5
* Save all the things! No more restriction to use classes only having no-arg constructor.
* Custom serializers can be added using `Paper.addSerializer()`.
* Kotlin is fully supported now, including saving `data class`es. Obviously saving lambdas is not supported.

#### Add dependency
### Add dependency
```groovy
compile 'io.paperdb:paperdb:1.5'
```

#### Initialize Paper
### Initialize Paper
Should be initialized one time in onCreate() in Application or Activity.

```java
Expand All @@ -24,7 +24,7 @@ Paper.init(context);

It's OK to call it in UI thread. All other methods should be used in background thread.

#### Save
### Save
Save data object.
Paper creates separate data file for each key.

Expand All @@ -34,7 +34,7 @@ Paper.book().write("task-queue", queue); // LinkedList
Paper.book().write("countries", countryCodeMap); // HashMap
```

#### Read
### Read
Read data objects. Paper instantiates exactly the classes which has been used in saved data. The limited backward and forward compatibility is supported. See [Handle data class changes](#handle-data-structure-changes).

```java
Expand All @@ -51,7 +51,7 @@ LinkedList queue = Paper.book().read("task-queue", new LinkedList());
HashMap countryCodeMap = Paper.book().read("countries", new HashMap());
```

#### Delete
### Delete
Delete data for one key.

```java
Expand All @@ -64,22 +64,22 @@ Completely destroys Paper storage. Requires to call ```Paper.init()``` before us
Paper.book().destroy();
```

#### Use custom book
### Use custom book
You can create custom Book with separate storage using

```java
Paper.book("custom-book")...;
```
Each book is located in separate file folder.

#### Get all keys
### Get all keys
Returns all keys for objects in the book.

```
List<String> allKeys = Paper.book().getAllKeys();
```

#### Handle data structure changes
### Handle data structure changes
Class fields which has been removed will be ignored on restore and new fields will have their default values. For example, if you have following data class saved in Paper storage:

```java
Expand All @@ -101,13 +101,13 @@ class Volcano {

Then on restore the _isActive_ field will be ignored and new _location_ field will have its default value _null_.

#### Exclude fields
### Exclude fields
Use _transient_ keyword for fields which you want to exclude from saving process.

```java
public transient String tempId = "default"; // Won't be saved
```
#### Proguard config
### Proguard config
* Keep data classes:

```
Expand All @@ -120,7 +120,7 @@ alternatively you can implement _Serializable_ for all your data classes and kee
-keep class * implements java.io.Serializable { *; }
```

#### How it works
### How it works
Paper is based on the following assumptions:
- Saved data on mobile are relatively small;
- Random file access on flash storage is very fast.
Expand All @@ -129,7 +129,7 @@ So each data object is saved in separate file and write/read operations write/re

The [Kryo](https://github.com/EsotericSoftware/kryo) is used for object graph serialization and to provide data compatibility support.

#### Benchmark results
### Benchmark results
Running [Benchmark](https://github.com/pilgr/Paper/blob/master/paperdb/src/androidTest/java/io/paperdb/benchmark/Benchmark.java) on Nexus 4, in ms:

| Benchmark | Paper | [Hawk](https://github.com/orhanobut/hawk) | [sqlite](http://developer.android.com/reference/android/database/sqlite/package-summary.html) |
Expand All @@ -138,8 +138,10 @@ Running [Benchmark](https://github.com/pilgr/Paper/blob/master/paperdb/src/andro
| Write 500 contacts | 108 | 221 | |
| Read 500 contacts | 79 | 155 | |

### Limitations
* Circular references not supported

#### Apps using Paper
### Apps using Paper
- [AppDialer](https://play.google.com/store/apps/details?id=name.pilgr.appdialer) – Paper _initially_ has been developed to reduce start up time for AppDialer. Currently AppDialer has the best start up time in its class. And simple no-sql-pain data storage layer like a bonus.

### License
Expand Down

0 comments on commit 1838aac

Please sign in to comment.