realm

How to store [String] or [Int] in react-native realm

青春壹個敷衍的年華 提交于 2019-12-04 14:12:46
I've read online where in Android/iOS I should inherit from RealmObject and create my own RealmString to use as my objectType in a list. What's the approach in react-native? I can't find any code samples on how to handle this issue. Thanks You can use the same strategy in react-native: var intObject = { name: 'intObject', properties: { value: 'int' } }; var intListObject = { name: 'intListObject', properties: { 'intList': { type: 'list', objectType: 'intObject' } } }; var realm = new Realm({schema: [intObject, intListObject]}); var listObject = realm.create('intListObject', { intList: [{value:

Realm and Retrofit2: sending auto-managed objects

本小妞迷上赌 提交于 2019-12-04 14:03:15
When using Realm and Retrofit2 for sending auto-managed RealmObjects to our server, Retrofit2 (using Gson) only sends the ints in the RealmObject. It completely ignores the Strings and other fields, and does not put these in the json. No errors are logged. If I however, disconnect the RealmObject from Realm: realm.copyFromRealm(myRealmObject) then it does send all fields. What could be the problem? Is there a proper solution? Before we dive in In one of my posts here on Stackoverflow, I have explained what's happening when using Gson and Realm together (Retrofit is just using Gson as a data

exclude a Realm model class

人盡茶涼 提交于 2019-12-04 13:24:05
I have two Realm files configured in my app. I want to store my Log model to a separate file from the rest of my models. My problem is that I also see my Log model class in my default Realm file, which I don't want. How can I exclude a particular model class from a given Realm file? I use the default configuration for my main Realm file, and I want to store the Log model only in another database file, but when I default.realm in the Realm Browser it also shows the Log model. bdash You can explicitly list the classes a given Realm can store via the objectTypes property on Realm.Configuration :

Shiro权限验证说明

百般思念 提交于 2019-12-04 13:20:06
1、简介 shiro是一个安全框架,是Apache的一个子项目。shiro提供了:认证、授权、加密、会话管理、与web集成、缓存等模块。 1.1、模块介绍 Authentication:用户身份识别,可以认为是登录; Authorization:授权,即权限验证,验证某个已认证的用户是否拥有某个权限;即判断用户是否能做事情,常见的如:验证某个用户是否拥有某个角色。或者细粒度的验证某个用户对某个资源是否具有某个权限。 Session Manager:会话管理,即用户登录后就是一次会话,在没有退出之前,它的所有信息都在会话中;会话可以是普通 JavaSE 环境的,也可以是如 Web 环境的。 Cryptography:加密,保护数据的安全性,如密码加密存储到数据库,而不是明文存储。 Web Support:Web支持,可以非常容易的集成到 web 环境。 Caching:缓存,比如用户登录后,其用户信息、拥有的角色/权限不必每次去查,这样可以提高效率。 Concurrency:shiro 支持多线程应用的并发验证,即如在一个线程中开启另一个线程,能把权限自动传播过去。 Testing:提供测试支持。 Run As:允许一个用户假装为另一个用户(如果他们允许)的身份进行访问。 Remember Me:记住我,这个是非常常见的功能,即一次登录后,下次再来的话不用登录了。 注意

Swift 3: Property observer for singleton

邮差的信 提交于 2019-12-04 12:52:58
I wonder if there's any way to observe singleton class for changes in ony of its property In my case, with Realm I have something like this class User: Object { dynamic var name:String = "" dynamic var email:String = "" dynamic var id:String = "" dynamic var picURL:String = "" dynamic var pic:Data = Data() static let currentUser = User() { didSet { try! realm.write { realm.add(currentUser, update: true) } } } } What I want to achieve is I want to have only one user object in my app, and anytime any of its properties gets modified, I would like to save it to Realm. However, the example above

Correct flow in RxJava with Retrofit and Realm

こ雲淡風輕ζ 提交于 2019-12-04 12:51:21
问题 I'm implementing network API with the combination of RxJava and Retrofit, and I use Realm as my database. I got it pretty much working but I'm wondering if it is the correct approach and flow of events. So, here is the RetrofitApiManager . public class RetrofitApiManager { private static final String BASE_URL = "***"; private final ShopApi shopApi; public RetrofitApiManager(OkHttpClient okHttpClient) { // GSON INITIALIZATION Retrofit retrofit = new Retrofit.Builder() .client(okHttpClient)

Android: Change old primary key in realm migration

六眼飞鱼酱① 提交于 2019-12-04 11:57:40
Can I change old primary key with new primary key in realm migration script? Yes, it is possible. RealmObjectSchema objectSchema = schema.get("MyObject"); objectSchema.addField("newId", long.class) .transform(new RealmObjectSchema.Function() { @Override public void apply(DynamicRealmObject obj) { obj.setLong("newId", getNewId(obj)); } }) .removeField("id") .renameField("newId", "id") .addPrimaryKey("id"); However, you can't directly create the field as objectSchema.addField("newId", long.class, FieldAttribute.PRIMARY_KEY) because the values are initialized to 0 in your database, which means

Deleting with one-to-many relationship

眉间皱痕 提交于 2019-12-04 11:49:49
I have a one-to-many relationship: class GameSystem: Object { dynamic var gameSystemName = "" } class games: Object { dynamic var gameSystemName = gameSystemName().name dynamic var gameTitle = "" dynamic var gameGenre = "" } The gameSystemName s are currently displayed on a TableView. If the user deletes a gameSystemName , I want that gameSystemName along with all of that system's games deleted. The code I'm currently using will only delete the GameSystem , but leaves all the games. func deleteRowAtIndexPath(indexPath: NSIndexPath) { let realm = Realm() let objectToDelete = gameSystems

Realm write performed on background thread still blocks Main UI

血红的双手。 提交于 2019-12-04 10:59:34
问题 Periodically in my app, I need to perform large writes to Realm, anywhere between 100 to 10,000 objects. Obviously this is a large write, so I'm attempting to perform this write in the background so that the user can perform other operations and not even notice the write. Unfortunately, even though I thought my write was being performed on a background thread, the main UI still gets blocked. Here is the jist of the method that I call to perform the writes to realm. This method is called

Avoid Adding Repeat Object to Realm

岁酱吖の 提交于 2019-12-04 10:49:41
问题 I query down the data from Parse.com and save them in the local Realm database (iOS/swift). Each object has a unique property(A) but also a might-be-same property(B). What is the most efficient way to avoid adding objects with same property B into the realm database? Thanks in advance. 回答1: You can set a primary key on an object so that Realm guarantees that there is only one of each object in the DB. class Person: RLMObject { dynamic var id = 0 dynamic var name = "" override class func