SQlite数据库VS Room持久性库 [英] SQlite Database VS Room persistence library

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

问题描述

我需要为我的考试项目提供帮助,以发现ROOM数据库的不同之处和优势: 我试图在android开发文档中进行搜索,以了解这两个数据库之间的区别,但是我不清楚. 我也没有在堆栈溢出中找到任何答案. 我还想知道与SQLite数据库相比使用Room Persistence的好处.

I need help for my exam project to find differences and benefit of ROOM database: I tried to search in android development documentation to understand the difference between these two databases, but i couldn't clearly understand. I did not find any answer in stack overflow either. I also want to know the benefit of using Room persistence compared to SQLite database.

希望有人可以给我明确的答案.

Hope someone can give me clear answer.

推荐答案

Room是一个ORM(对象关系映射)库.换句话说,Room会将我们的数据库对象映射到Java对象. Room在SQLite上提供了一个抽象层,以允许流利的数据库访问,同时利用SQLite的全部功能.

Room is an ORM, Object Relational Mapping library. In other words, Room will map our database objects to Java objects. Room provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite.

SQLite和Room持久性库之间的区别:-

Difference between SQLite and Room persistence library:-

  • 对于SQLite,没有原始SQLite查询的编译时验证.但是在Room中,在编译时会进行SQL验证.
  • 随着架构的更改,您需要手动更新受影响的SQL查询.房间解决了这个问题.
  • 您需要使用大量样板代码在SQL查询和 Java数据对象.但是,Room可以将我们的数据库对象映射到Java对象,而无需样板代码.
  • Room可以与LiveData和RxJava一起使用来进行数据观察,而SQLite则不能.
  • In case of SQLite, There is no compile time verification of raw SQLite queries. But in Room there is SQL validation at compile time.
  • As your schema changes, you need to update the affected SQL queries manually. Room solves this problem.
  • You need to use lots of boilerplate code to convert between SQL queries and Java data objects. But, Room maps our database objects to Java Object without boilerplate code.
  • Room is built to work with LiveData and RxJava for data observation, while SQLite does not.

房间注释和主要组成部分:

Room annotations and main components:

  1. @Entity-定义我们的数据库表
  2. @DAO —提供用于读取和写入数据的API
  3. @Database-代表数据库所有者

这是链接其中详细说明了Room Persistence库的用法和优点. 我希望这会有所帮助.

Here is the link to the medium article which explains in detail the usage and benefits of Room persistence library. I hope this helps.

您可以参考Google开发者文档,其中明确说明了如何使用Room将数据保存到本地数据库中. 链接到Google Developer Docs

Edit 1: You can refer to Google developer docs, which clearly explains how to save data in a local database using room. Link to Google Developer Docs

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

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