{"id":13604705,"url":"https://github.com/pilgr/Paper","last_synced_at":"2025-04-12T02:31:21.720Z","repository":{"id":33633381,"uuid":"37285717","full_name":"pilgr/Paper","owner":"pilgr","description":"Paper is a fast NoSQL-like storage for Java/Kotlin objects on Android with automatic schema migration support.","archived":false,"fork":false,"pushed_at":"2023-01-06T22:00:05.000Z","size":386,"stargazers_count":2346,"open_issues_count":19,"forks_count":234,"subscribers_count":61,"default_branch":"master","last_synced_at":"2024-11-05T03:42:40.780Z","etag":null,"topics":["android","database","mobile-database","nosql","paper","performace"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pilgr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-11T20:55:15.000Z","updated_at":"2024-11-02T04:34:25.000Z","dependencies_parsed_at":"2023-01-15T01:45:51.808Z","dependency_job_id":null,"html_url":"https://github.com/pilgr/Paper","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilgr%2FPaper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilgr%2FPaper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilgr%2FPaper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilgr%2FPaper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pilgr","download_url":"https://codeload.github.com/pilgr/Paper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223489623,"owners_count":17153790,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","database","mobile-database","nosql","paper","performace"],"created_at":"2024-08-01T19:00:50.318Z","updated_at":"2024-11-07T09:30:46.456Z","avatar_url":"https://github.com/pilgr.png","language":"Java","funding_links":[],"categories":["Java","数据库"],"sub_categories":[],"readme":"# Paper\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Paper-blue.svg?style=flat)](http://android-arsenal.com/details/1/2080)   [![Build Status](https://travis-ci.org/pilgr/Paper.svg?branch=master)](https://travis-ci.org/pilgr/Paper)\n\nPaper's aim is to provide a simple yet [fast](#benchmark-results) object storage option for Android. It allows to use Java/Kotlin classes as is: without annotations, factory methods, mandatory class extensions etc. Moreover adding or removing fields to data classes is no longer a pain – all data structure changes are handled automatically.\n\n![Paper icon](/paper_icon.png)\n\n### Migration to Maven Central\n**Library has been moved to Maven Central since service ends for JCenter. Note that group id\nhas been changed to `io.github.pilgr`. See the updated section below.**  \n\n### Add dependency\n```groovy\nimplementation 'io.github.pilgr:paperdb:2.7.2'\n```\n\nRxJava wrapper for Paper is available as a separate lib [RxPaper2](https://github.com/pakoito/RxPaper2). Thanks [@pakoito](https://github.com/pakoito) for it!\n\n### Initialize Paper\nShould be initialized once in `Application.onCreate()`:\n\n```java\nPaper.init(context);\n```\n\n### Threading\n* `Paper.init()` should be called in UI thread; \n* All other APIs (`write`, `read` etc.) are thread-safe and obviously must be called outside of UI thread. Reading/writing for different `key`s can be done in parallel. \n \n### Save\nSave any object, Map, List, HashMap etc. including all internal objects. Use your existing data classes as is. Note that key is used as file name to store the data and so *cannot* contain symbols like `/`.\n\n```java\nList\u003cPerson\u003e contacts = ...\nPaper.book().write(\"contacts\", contacts);\n```\n\n### Read\nRead data objects is as easy as\n\n```java\nList\u003cPerson\u003e = Paper.book().read(\"contacts\");\n```\nthe instantiated class is exactly the one used to save data. Limited changes to the class structure are handled automatically. See [Handle data class changes](#handle-data-structure-changes).\n\nUse default values if object doesn't exist in the storage.\n\n```java\nList\u003cPerson\u003e = Paper.book().read(\"contacts\", new ArrayList\u003c\u003e());\n```\n\n### Delete\nDelete data for one key.\n\n```java\nPaper.book().delete(\"contacts\");\n```\n\nRemove all keys for the given Book. ```Paper.init()``` must be called prior calling `destroy()`.\n\n```java\nPaper.book().destroy();\n```\n\n### Use custom book\nYou can create custom Book with separate storage using\n\n```java\nPaper.book(\"for-user-1\").write(\"contacts\", contacts);\nPaper.book(\"for-user-2\").write(\"contacts\", contacts);\n```\nEach book is located in a separate file folder.\n\n### Get all keys \nReturns all keys for objects in the book.\n\n```java\nList\u003cString\u003e allKeys = Paper.book().getAllKeys();\n```\n\n### Handle data structure changes\nYou can add or remove fields to the class. Then on next read attempt of a new class:\n* Newly added fields will have their default values. \n* Removed field will be ignored. \n\n*Note:* field type changes are not supported.\n\nFor example, if you have following data class saved in Paper storage:\n\n```java\nclass Volcano {\n    public String name;\n    public boolean isActive;\n}\n```\n\nAnd then you realized you need to change the class like:\n\n```java\nclass Volcano {\n    public String name;\n    // public boolean isActive; removed field\n    public Location location; // New field\n}\n```\n\nthe _isActive_ field will be ignored on next read and new _location_ field will have its default value as _null_.\n\n### Exclude fields\nUse _transient_ keyword for fields which you want to exclude from saving process.\n\n```java\npublic transient String tempId = \"default\"; // Won't be saved\n```\n\n### Set storage location for Book instances\nBy default, all the Paper data files are located with all files belonging to your app, at `../you-app-package-name/files`. To save data on SDCard or at any other location you can use new API:\n* `Paper.bookOn(\"/path/to/the/new/location\")`\n* or `Paper.bookOn(\"path/to/the/new/location\", \"book-for-user-1\")` to create custom book. \n\n### Export/Import\n* Use `Paper.book().getPath()` to get path for a folder containing all *.pt files for a given book.\n* Use `Paper.book().getPath(key)` to get path for a particular *.pt file containing saved object for a given key.\n Feel free to copy/rewrite those files for export/import purposes. It's your responsibility to finalize file's export/import operations prior accessing data over Paper API.\n\n### Proguard config\n* Keep your data classes from modification by Proguard:\n\n```\n-keep class your.app.data.model.** { *; }\n```\n\nalso you can implement _Serializable_ for all your data classes and keep all of them using:\n\n```\n-keep class * implements java.io.Serializable { *; }\n```\n* If your data models use enums, you should also keep them:\n\n```\n-keep enum your.app.data.model.** { *; }\n```\n* And if you rely on Kotlin's `emptyList()`/`emptyMap()`/`emptySet` to assign values to your data models, it is relevant to keep `EmptyList`/`EmptyMap`/`EmptySet` as well:\n```\n-keep class kotlin.collections.* { *; }\n```\n### How it works\nPaper is based on the following assumptions:\n- Datasets on mobile devices are small and usually don't have relations in between; \n- Random file access on flash storage is very fast;\n\nPaper saves each object for given key in a separate file and every write/read operations write/read the whole file.\n\nThe [Kryo](https://github.com/EsotericSoftware/kryo) is used for object graph serialization and to provide data compatibility support.\n\n### Benchmark results\nRunning [Benchmark](https://github.com/pilgr/Paper/blob/master/paperdb/src/androidTest/java/io/paperdb/benchmark/Benchmark.java) on Nexus 4, in ms:\n\n| Benchmark                 | Paper    | [Hawk](https://github.com/orhanobut/hawk) |\n|---------------------------|----------|----------|\n| Read/write 500 contacts   | 187      | 447      |\n| Write 500 contacts        | 108      | 221      |\n| Read 500 contacts         | 79       | 155      |\n\n### Limitations\n* Circular references are not supported\n\n### Apps using Paper\n- [AppDialer](https://play.google.com/store/apps/details?id=name.pilgr.appdialer) – Paper initially has been developed as internal lib 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.\n- [Busmap](https://play.google.com/store/apps/details?id=com.t7.busmap\u0026hl=en) - This application provide all things you need for travelling by bus in Ho Chi Minh city, Vietnam. While the source code is not opened, it is found that the application use Paper internally to manange the bus stop data, route data, time data,... and more.\n\n### License\n    Copyright 2015 Aleksey Masny\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpilgr%2FPaper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpilgr%2FPaper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpilgr%2FPaper/lists"}