Android中的Realm VS Room [英] Realm VS Room in Android

查看:367
本文介绍了Android中的Realm VS Room的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序,我需要在其中使用数据库.我正在考虑使用Room,因为它现在很新而且很热.但是我也听说过很多有关Realm的好东西.有人可以指出使用每种方法的可能优势吗?

I'm building an app and I need to use a database in it. I'm considering using Room as it's new and hot right now. But I've heard a lot of great stuff about Realm too. Can someone point out the possible advantages of using each?

我进行了研究并阅读了文档,但是我自己没有经验来理解

I did my research and read the docs but I have no experience to understand it myself

房间文档

领域文档

编辑:

已经有一段时间了,我可以指出使用Room的另一个原因.尽管您可以使用Realm和Transformations将内容与LiveData关联起来,但是使用Room可以直接为数据库返回LiveData(以及使用插件的RXJava类型),这将为您节省一些样板代码和麻烦.

It's been some time and and I can point out another reason to use Room. Although you can use Realm and Transformations to tie things up with LiveData but with Room you can directly return LiveData (and also RXJava types using a plugin) for the DB, which will save you some boilerplate code and headache.

除了第一个编辑内容外,Room现在在Kotlin中对协程有一流的支持,因此,如果您打算使用它们,那将是一个不错的选择->

In addition to the first edit, Room now has a first class support for coroutines in Kotlin so if you are planning to use those it will be a nice-have -> https://medium.com/androiddevelopers/room-coroutines-422b786dc4c5

推荐答案

领域

一个相对快速和方便的库,所有链接都简单实现了,这与数据库的面向对象有关.优秀的文档.也许这是目前在移动设备上存储数据的最佳选择之一,它的减号只能是apk文件大小增加2.5 MB.

A relatively fast and convenient library, all links are simply implemented, which is related to the object orientation of the database. Excellent documentation. Is, perhaps, one of the best option for storing data on a mobile device at the moment, the minus can only be an increase in the size of the apk-file by 2.5 MB.

房间

Google I/O 2017上提出了一个有趣的解决方案,是在Android OS上使用数据库的最佳解决方案.尽管有必要使用显式的sql请求,但事实证明该库非常方便,我个人喜欢它.性能方面处于领先地位,所以我建议您选择这个特定的库.这样做的最大优势是基于内置的SQLite数据库.由于此解决方案是由Google提交的,因此很快就会流行起来,因此,找到随之而来的问题的解决方案将没有任何问题.

An interesting solution presented on Google I / O 2017 as optimal for working with the database on Android OS. Despite the fact that it is necessary to use explicit sql-requests, the library turned out to be quite convenient and I liked it personally. On performance is in the lead, so I would advise you to choose this particular library. Big advantage of this is based on build-in SQLite database. Since this solution, submitted by Google, it will quickly become popular, and, therefore, there will be no problems with finding solutions to problems that occur along with it.

Realm使用更多的RAM并增加apk大小和构建时间.所以我更喜欢Room.

Realm uses more RAM and increases the apk size, build time. So I prefer Room.

有比较: https://github.com/AlexeyZatsepin/Android-ORM-benchmark

这篇关于Android中的Realm VS Room的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆