Android目前流行三方数据库ORM分析及对比

Android 平台上的数据库框架非常多,但是有一个共同特点就是基于对象关系映射(ORM)模型的。实现的目标也都是不需要写SQL语句,通过对对象的操作保存和操作数据。要是从语法的简洁性来说都有自己的特点,总的来说不相上下,因此只能从数据的性能上来抉择了。

首先我们先看看目前最常用的数据库框架介绍(排名不分先后)

  • GreenDao
    简单介绍:GreenDao是为Android设计的对象关系映射(ORM)工具。它提供了对象到关系型数据库SQLite的相应接口。为了在Android工程中使用greenDao,需要创建另一个“生成器”工程,它的任务是在你的工程域里生成具体的代码。因此相比与其它ORM框架具有出众性能。
    使用方法:GreenDao:3.2.0用方法

  • LitePal
    简单介绍:LitePal是对象关系映射(ORM)模型。它使开发者使用SQLite数据库变得非常容易。 你可以不用写一句SQL语句就可以完成大部分数据库操作,包括创建表,更新表,约束操作,聚合功能等等。
    使用方法:(懒人必备)Android开源数据库LitePal

  • Afinal
    简单介绍:是一个android的sqlite orm 和 ioc 框架。同时封装了android中的http框架,使其更加简单易用。FinalDB模块,android中的orm框架,一行代码就可以进行增删改查。支持一对多,多对一等查询。
    使用方法:FinalDb操作sqlite的数据库(增删改查)

  • ORMLite
    简单介绍:(Object Relational Mapping Lite)提供了一些轻量级持久化Java对象到SQL数据库,同时也避免了复杂性和更多的标准的ORM包的开销功能。它支持的SQL数据库使用JDBC的数量,还支持原生的Android操作系统数据库API调用sqlite。
    使用方法:Android 数据库框架ormlite使用精要

  • SugarORM
    简单介绍:是对象关系映射模式。不用写复杂的sql语句,而用简单的API即可完成创建和操纵数据;可以在原有的Bean上仅仅添加小的修改而复用Bean;简化而明了的数据库设计和创建过程,同时提供表的一对多的支持。
    使用方法:Android SugerORM框架的使用

  • Realm
    简单介绍:是用来替代sqlite的一种解决方案,它有一套自己的数据库存储引擎,比sqlite更轻量级,拥有更快的速度,并且具有很多现代数据库的特性,比如支持JSON,流式api,数据变更通知,自动数据同步,简单身份验证,访问控制,事件处理,最重要的是跨平台,目前已有Java,Objective C,Swift,React-Native,Xamarin这五种实现。
    使用方法:Realm for Android详细教程

  • LiteOrm
    简单介绍:是android上的一款数据库(ORM)框架库。速度快、体积小、性能高。开发者基本一行代码实现数据库的增删改查操作,以及实体关系的持久化和自动映射。设计原则:轻量、专注、性能优先、线程无关,专注数据及其关系存储和操作;无需工具辅助,不需要无参构造,不需要繁多注解,约定优于配置;使用极致简约,例如:db.save(u); db.query(U.class); db.deleteAll(U.class);。
    使用方法:Android 数据库框架LiteOrm使用

  • DBFlow
    简单介绍:综合了 ActiveAndroid, Schematic, Ollie,Sprinkles 等库的优点。同时不是基于反射,所以性能也是非常高,效率紧跟greenDAO其后。基于注解,使用apt技术,在编译过程中生成操作类,使用方式和ActiveAndroid高度相似,使用简单。无缝支持多个数据库,使用annotation processing提高速度,ModelContainer类库可以直接解析像JSON这样的数据,增加灵活性的丰富接口。
    使用方法:Android技术前沿:DBFlow的实践

数据库性能比较

具体对比仔细查看下列图表
Android 数据库框架性能测试

LiteOrm 和 系统原生SQLiteDatabase API 测试数据

LiteOrm 和 greenDAO 的性能表现
greenDAO vs LiteOrm 循环测试

greenDAO vs LiteOrm 批量测试

总结

从图中可以看出 Realm 的性能应该是最好的,同时它执行跨平台,且并不是采用 SQLite 的持久化引擎。但是也有不少的缺点(具体查看文章为什么我不再使用Realm)。

greenDAO 是基于AndroidSQLite的最快、性能最强悍的数据库框架,因为他不涉及反射,靠的是代码辅助生成。

当然,不论哪款ORM或数据库框架,都各有利弊,至于该选用哪一款,可自行斟酌,开发者最好自己亲身体验下,毕竟绝知此事需躬行,只听或者看别人的言论和结果,无异于直接吃别人嚼过的东西,没有味道不重要,变了味会影响个人判断。

本文原创发布于公众号【AndroidParks】,微信搜索androidparks或者扫一扫关注

评论

  • a fantastic read回复

    I just want to say I am beginner to blogging and site-building and definitely savored your website. Most likely I’m want to bookmark your blog post . You amazingly have great articles. Regards for revealing your blog site.

  • tercio borlenghi junior回复

    What's Going down i'm new to this, I stumbled upon this I have found It positively helpful and it has helped me out loads. I am hoping to give a contribution & help other users like its helped me. Great job.|

  • why not try here回复

    I simply want to say I am just newbie to blogs and truly loved this web site. Likely I’m planning to bookmark your blog post . You absolutely have incredible writings. Appreciate it for sharing with us your web-site.

  • click for more info回复

    I just want to say I'm very new to blogging and site-building and definitely savored your page. Almost certainly I’m want to bookmark your website . You certainly come with terrific posts. Many thanks for sharing with us your blog site.

  • click for more回复

    I just want to tell you that I am beginner to blogging and site-building and honestly enjoyed your page. Almost certainly I’m planning to bookmark your blog post . You certainly have exceptional article content. Many thanks for sharing your webpage.

  • adidas yeezy boost回复

    I would like to show my appreciation to you just for rescuing me from this type of scenario. As a result of exploring through the internet and finding proposals which are not helpful, I was thinking my life was well over. Living without the presence of approaches to the problems you have sorted out by means of this guide is a crucial case, and the ones that would have in a wrong way affected my career if I hadn't discovered your site. Your own personal competence and kindness in controlling everything was important. I don't know what I would've done if I hadn't come across such a point like this. I can also at this point relish my future. Thanks a lot very much for the impressive and sensible help. I will not hesitate to propose your blog post to any individual who ought to have care about this subject matter.

  • hop over to this website回复

    I just want to mention I'm new to blogs and truly loved you're web-site. Most likely I’m likely to bookmark your website . You absolutely come with outstanding posts. Thank you for sharing your website page.

  • click to read回复

    I simply want to tell you that I am very new to weblog and absolutely enjoyed you're blog. Most likely I’m planning to bookmark your website . You surely have tremendous writings. Many thanks for sharing your web page.

  • my response回复

    I just want to mention I'm new to blogging and site-building and actually enjoyed your blog. Likely I’m planning to bookmark your blog . You surely have wonderful posts. Bless you for sharing your webpage.

  • click回复

    I simply want to mention I am beginner to weblog and really enjoyed your blog. More than likely I’m want to bookmark your blog . You actually have very good well written articles. Thanks for sharing with us your website.

  • AlyonaGergo回复

    viagra online apotheke holland

    [url=http://viagralak.com/]cheap viagra[/url]

    <a href="http://viagralak.com/">generic viagra online</a>

    100mg viagra didnt work

  • you could check here回复

    I simply want to say I am just new to blogging and site-building and truly enjoyed you're web-site. Almost certainly I’m planning to bookmark your blog . You really have great articles. Thanks a bunch for revealing your blog.

  • kd shoes回复

    Oh my goodness! an incredible article dude. Thank you Nevertheless I'm experiencing subject with ur rss . Don抰 know why Unable to subscribe to it. Is there anybody getting an identical rss downside? Anyone who is aware of kindly respond. Thnkx

  • Umanizzare presídios回复

    Howdy! I could have sworn I've visited this site before but after looking at a few of the posts I realized it's new to me. Nonetheless, I'm definitely happy I stumbled upon it and I'll be bookmarking it and checking back frequently!|

  • navigate to these guys回复

    I just want to say I am beginner to blogging and definitely loved this page. Almost certainly I’m likely to bookmark your blog . You absolutely have remarkable posts. Regards for revealing your blog.

  • more回复

    I just want to mention I am just beginner to blogs and seriously loved your web-site. More than likely I’m going to bookmark your website . You really have exceptional article content. Appreciate it for sharing your web page.

  • browse around this site回复

    I simply want to tell you that I am just newbie to blogging and site-building and really liked your blog site. Very likely I’m planning to bookmark your website . You really come with good stories. Appreciate it for sharing with us your blog site.

  • view回复

    I just want to mention I'm beginner to weblog and truly savored this page. Very likely I’m planning to bookmark your blog . You definitely come with awesome articles. Bless you for sharing with us your website.

  • StanislavaGergo回复

    viagra for men benefits

    [url=http://viagrafxz.com/]online viagra[/url]

    <a href="http://viagrafxz.com/">viagra cheap</a>

    viagra vs cialis online

  • look at this site回复

    I just want to say I'm very new to blogs and seriously savored you're page. Almost certainly I’m planning to bookmark your blog . You surely come with tremendous article content. Many thanks for sharing with us your web page.

  • recommended you read回复

    I just want to tell you that I am beginner to weblog and seriously enjoyed you're web blog. Probably I’m likely to bookmark your blog post . You amazingly come with awesome articles and reviews. Many thanks for sharing your website page.

  • Hiram回复

    Have been taking little over a month.

  • Hardware News回复

    magnificent submit, very informative. I ponder why the opposite specialists of this sector don't notice this. You should continue your writing. I am confident, you have a huge readers' base already!

  • ShamkinaGergo回复

    cialis y la diabetes

    [url=http://cialisokl.com/]buy cialis[/url]

    <a href="http://cialisokl.com/">order cialis online</a>

    cialis 20mg tablets prices

  • Vitamin D回复

    Hi there very nice website!! Man .. Excellent .. Wonderful .. I will bookmark your blog and take the feeds additionally¡KI am happy to search out a lot of useful info here in the publish, we want develop extra techniques in this regard, thanks for sharing. . . . . .

  • Handbags and luggages回复

    As I site possessor I believe the content material here is rattling fantastic , appreciate it for your hard work. You should keep it up forever! Best of luck.

  • Racing回复

    Just desire to say your article is as surprising. The clarity in your post is just cool and i can assume you're an expert on this subject. Well with your permission let me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please keep up the gratifying work.

  • Bedroom home design回复

    I¡¦ll right away snatch your rss as I can not to find your email subscription hyperlink or newsletter service. Do you have any? Please let me recognise in order that I may subscribe. Thanks.

  • AlyonaGergo回复

    acheter viagra ligne quebec

    [url=http://viagralak.com/]cheap viagra[/url]

    <a href="http://viagralak.com/">cheap viagra</a>

    viagra online with mastercard

  • yeezy shoes回复

    I in addition to my friends were found to be following the excellent tips and tricks located on your site then immediately got a horrible feeling I had not expressed respect to the site owner for those techniques. All the men were as a consequence thrilled to read all of them and have in truth been tapping into them. We appreciate you turning out to be really accommodating and also for choosing such helpful information millions of individuals are really wanting to be informed on. My personal honest regret for not expressing gratitude to you sooner.

  • tinder dating site free回复

    Great post however I was wanting to know if you could write a litte more on this topic?
    I'd be very grateful if you could elaborate a
    little bit more. Many thanks!

  • Itamar Serp回复

    Have you ever considered about adding a little bit more than just your articles? I mean, what you say is fundamental and all. But think about if you added some great visuals or video clips to give your posts more, "pop"! Your content is excellent but with images and video clips, this site could undeniably be one of the most beneficial in its niche. Great blog!|

  • StanislavaGergo回复

    comprar viagra la plata

    [url=http://viagrafxz.com/]generic viagra online[/url]

    <a href="http://viagrafxz.com/">online viagra</a>

    viagra sales us company

  • tinder回复

    Excellent post. I was checking continuously this blog
    and I am impressed! Very helpful info specially the last part 😊 I care for such info a lot.
    I was looking for this particular information for a
    very long time. Thank you and best of luck.

  • tinder dating回复

    Hi there, just became alert to your blog through Google, and found that it's truly informative.
    I am going to watch out for brussels. I'll appreciate if you continue this
    in future. A lot of people will be benefited from your writing.
    Cheers!

  • Restaurants回复

    Great tremendous things here. I am very glad to see your article. Thanks a lot and i am having a look ahead to contact you. Will you kindly drop me a mail?

  • tinder dating site free回复

    Just want to say your article is as astonishing.
    The clearness in your post is just great and i can assume you're an expert on this subject.
    Well with your permission let me to grab your feed to keep up to date with
    forthcoming post. Thanks a million and please carry on the gratifying work.

  • yeezy shoes回复

    Aw, this was a really nice post. In thought I wish to put in writing like this moreover ?taking time and actual effort to make an excellent article?however what can I say?I procrastinate alot and in no way seem to get one thing done.

  • tinder dating site free回复

    I just couldn't go away your website prior to suggesting
    that I extremely enjoyed the standard information an individual provide in your guests?

    Is gonna be again ceaselessly to check out new posts

  • negative service回复

    Great weblog right here! Also your web site loads up very fast! What web host are you the use of? Can I am getting your affiliate link in your host? I desire my site loaded up as fast as yours lol|

  • Umanizzare Gestão Prisional Ltda回复

    You really make it seem so easy with your presentation but I find this matter to be actually something that I think I would never understand. It seems too complex and very broad for me. I'm looking forward for your next post, I will try to get the hang of it!|

  • tinder dating site free回复

    Thank you for the auspicious writeup. It in fact was a
    amusement account it. Look advanced to more added agreeable from you!
    However, how can we communicate?

  • tinder回复

    Wonderful website. Plenty of useful info here. I'm
    sending it to several friends ans also sharing in delicious.
    And naturally, thanks to your effort!

  • StanislavaGergo回复

    viagra order usa

    [url=http://viagrafxz.com/]cheap viagra online[/url]

    <a href="http://viagrafxz.com/">online viagra</a>

    viagra e un farmac

  • paper writing help回复

    It's awesome to visit this website and reading the views of all mates about this article, while I am also keen of getting experience.

  • tinder回复

    Excellent post. I absolutely love this site.
    Keep it up!