realm

Making GSON & Realm play nice

☆樱花仙子☆ 提交于 2019-11-29 17:08:16
问题 I'm trying to use Realm + GSON. If they would work together well, it would be a match made in heaven. However, when I extend my model objects with "extends RealmObject" I get this: 10-08 17:00:19.578 12492-12492/appwise.be.gsontestproject E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: appwise.be.gsontestproject, PID: 12492 java.lang.StackOverflowError at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:372) at com.google.gson.internal.$Gson$Types.resolve($Gson$Types.java:376)

Multiple Realm Tables of same Class

帅比萌擦擦* 提交于 2019-11-29 16:29:12
问题 I have a RealmObject Class. I want multiple tables of the same class. Can I do that in a single Realm(Database) or I need to have multiple Realms(One table per each Realm). If it has to be multiple Realms, how fast is the Realm switching process? 回答1: I want multiple tables of the same class. Well you have two reasonable options: 1.) add a discriminator field that determines which "table" this current object instance belongs to public class MyObject extends RealmObject { @PrimaryKey private

Sharing Realm fields on Android

我与影子孤独终老i 提交于 2019-11-29 16:08:50
Realm on Android doesn't support model inheritance/polymorphism . So is there any way to share fields on Android? We have 5 models that all share the same synchronization-related fields and code. We use inheritance in our current SQLite models; if we switch to Realm, is our only choice to duplicate the sync fields across each of the 5 model classes? As a workaround, I'm thinking about having those classes implement a Syncable interface with getters and setters for the shared fields, which at least let me share sync functionality. Is there a better way? To share sync functionality, my best

How to set primary key in Swift for Realm model

末鹿安然 提交于 2019-11-29 15:55:20
问题 I'm using Realm in a new iOS Swift project. I'm using Xcode 6.0.1 with iOS SDK 8.0 and Realm 0.85.0 I'm trying to use the new Realm primary key feature so I can do an addOrUpdateObject . Here is a sample model: import Foundation import Realm class Foo: RLMObject { dynamic var id = 0 dynamic var title = "" func primaryKey() -> Int { return id } } And how I'm trying to add/update a new object: let foo = Foo() foo.title = titleField.text foo.id = 1 // Get the default Realm let realm = RLMRealm

Refreshing multiple Realm instances at once?

落花浮王杯 提交于 2019-11-29 15:34:01
I'm using a setup in which every Presenter that is a retained Fragment has its own Realm instance. However, this essentially means that these Realms are all on the main thread. Now that also means, if I want to modify the Realm, I either need to do that on the main thread (which is okay for small data sets, but I don't really want to do that with large data sets), or I need to do it on a background thread, and refresh every Realm instance at once (which is possible with a simple event to the event bus). public enum SingletonBus { INSTANCE; private static String TAG = SingletonBus.class

Usage of parceler (@Parcel) with Realm.io (Android)

谁都会走 提交于 2019-11-29 15:25:36
问题 I have the following code which produces the error: Error:Parceler: Unable to find read/write generator for type io.realm.Realm for io.realm.RealmObject.realm It was working all fine without extends RealmObject , however I want to use Realm to put to database easily. Is there a way to exlcude the RealmObject fields and just use the basic pojo fields for @Parcel? @Parcel public class Feed extends RealmObject{ int id; public String text; public String time_created; String time_modified; int

“Object” is not part of the schema for this Realm

前提是你 提交于 2019-11-29 15:01:13
When I call the realm.where(MessageEventModel::class.java).findAll() it throws excepiton: this is error java.lang.IllegalArgumentException: MessageEventModel is not part of the schema for this Realm at io.realm.internal.modules.CompositeMediator.getMediator(CompositeMediator.java:172) at io.realm.internal.modules.CompositeMediator.getTableName(CompositeMediator.java:90) this is my Application class class MyApp : Application() { override fun onCreate() { super.onCreate() Realm.init(this) val realmConfiguration = RealmConfiguration.Builder() .deleteRealmIfMigrationNeeded() .name("my_db") .build(

Swift Realm, load the pre-populated database the right way?

风格不统一 提交于 2019-11-29 14:45:59
问题 I'm pretty new to ios development. I follow this migration example to use pre-populated database and change the code a little bit here is the final code I use on AppDelegate -> func application let defaultPath = Realm.Configuration.defaultConfiguration.path! let path = NSBundle.mainBundle().pathForResource("default", ofType: "realm") if let bundledPath = path { print("use pre-populated database") do { try NSFileManager.defaultManager().removeItemAtPath(defaultPath) try NSFileManager

Find path for Realm file with Realm React Native to use with Realm Browser

寵の児 提交于 2019-11-29 14:20:42
问题 On iOS, it is possible to inspect the contents of a Realm database by opening the corresponding file with the Realm Browser. The path to that file can be printed by using the following line of code (as noted here): print(Realm.Configuration.defaultConfiguration.path) Is it possible to do the same when using the React Native version of Realm? 回答1: Just found the answer myself by digging through the docs: console.log('create db:', db.path) 回答2: Just in case you can't get the above to work. Here

Realm Cleaning Up Old Objects

杀马特。学长 韩版系。学妹 提交于 2019-11-29 14:20:24
I've just started using Realm for caching in my iOS app. The app is a store, with merchandise. As the user browses merchandise, I'm adding the items to the database. However, as these items do not stay available forever, it does not make sense to keep them in the database past a certain point, let's say 24hrs. Is there a preferred way to batch expire objects after an amount of time? Or would it be best to add a date property and query these objects on each app launch? There's no default cache expiration mechanism in Realm itself, but like you said, it's a relatively trivial matter of adding an