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或者扫一扫关注

评论

  • MoisesGergo回复

    safe viagra stores online

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

    <a href="http://buycxviagra.com/">order viagra</a>

    viagra kaufen aus deutschland,

  • GoloaGergo回复

    cialis de descuento de canada

    <a href=http://canadianfdcialis.com/>generic cialis</a>

    <a href="http://canadianfdcialis.com/">buy cialis</a>

    vendita on line cialis

  • universalsitesupplies.co.uk回复

    I am not sure where you're getting your info, but good topic. I needs to spend some time learning more or understanding more. Thanks for wonderful info I was looking for this information for my mission.

  • cartier bracelet回复

    Can I just say what a aid to find somebody who really knows what theyre speaking about on the internet. You definitely know how you can bring a difficulty to light and make it important. More folks need to read this and understand this facet of the story. I cant believe youre not more well-liked because you undoubtedly have the gift.

  • Viagra回复

    I am really enjoying the theme/design of your blog. Do you ever run into any internet browser compatibility problems? A handful of my blog visitors have complained about my site not working correctly in Explorer but looks great in Firefox. Do you have any tips to help fix this problem?|

  • Business Development回复

    Thank you so much for giving everyone a very splendid opportunity to read in detail from this website. It's usually so beneficial and packed with amusement for me and my office colleagues to visit your website more than 3 times in one week to study the latest things you have. Of course, I'm so certainly motivated with your staggering tactics served by you. Some two tips in this post are basically the most efficient we've ever had.

  • AlenaGergo回复

    price check cialis

    http://buycialiskj.com/ - buy cialis

    <a href="http://buycialiskj.com/">buy cialis</a>

    generio cialis 10mg

  • Designer Bedding回复

    Wow! At last I got a website from where I be capable of really take valuable data concerning my study and
    knowledge.

  • MoisesGergo回复

    try it buying online viagra

    [url=http://buycxviagra.com/]order viagra[/url]

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

    viagra effet photo

  • XXX回复

    Hey, you used to write fantastic, but the last several posts have been kinda boring… I miss your super writings. Past few posts are just a little bit out of track! come on!

  • mathfel回复

    Now I am going to do my breakfast, afterward having my breakfast coming again to read further news.|

  • AlenaGergo回复

    i use it cialis sale

    [url=http://buycialiskj.com/]cialis online[/url]

    <a href="http://buycialiskj.com/">cialis coupon</a>

    cialis barato para venta

  • Get out from this Site回复

    Thanks for your personal marvelous posting! I really enjoyed reading it, you happen to be a great author.I will be sure to bookmark your blog and will often come back someday. I want to encourage you to ultimately continue your great job, have a nice day!

  • Viagra回复

    Fantastic blog! I really love how it’s easy on my eyes and also the information are well written. I am wondering how I could be notified whenever a new post has been made. I have subscribed to your rss feed which ought to do the trick! Have a nice day!

  • justbedding.com.au回复

    hey there and thank you for your information – I have certainly picked up anything new from right here. I did however expertise some technical issues using this site, since I experienced to reload the website a lot of times previous to I could get it to load properly. I had been wondering if your web host is OK? Not that I'm complaining, but slow loading instances times will sometimes affect your placement in google and can damage your quality score if ads and marketing with Adwords. Well I’m adding this RSS to my e-mail and can look out for a lot more of your respective exciting content. Make sure you update this again very soon..

  • burun estetigi回复

    I do not even know the way I ended up right here, but I assumed this put up used to be good. I do not recognise who you're however definitely you are going to a famous blogger should you are not already. Cheers!|

  • web design回复

    Hello, i think that i saw you visited my weblog thus i came to “return the favor”.I'm attempting to find things to enhance my website!I suppose its ok to use a few of your ideas!!

  • hamahdi.ir回复

    It's an remarkable post in favor of all the internet people; they will take advantage from it I am sure.

  • http://www.linux.ca回复

    ᏞІKE WHAT DADDY, TEᏞL US, TELL US.?
    Both boyus јumped up and down eager to knoᴡ find out how
    to maklе GoԀ happy.

  • porn movies回复

    It's difficult to find knowledgeable people in this particular topic, however, you seem like you know what you're talking about! Thanks|

  • michael jordan shoes回复

    I used to be more than happy to seek out this web-site.I needed to thanks on your time for this wonderful read!! I positively having fun with every little bit of it and I've you bookmarked to take a look at new stuff you blog post.

  • Tia回复

    Magnificent items from you, man. I've bear in mind your stuff previous to and you're simply too excellent.
    I actually like what you have received here, certainly like
    what you're saying and the way through which you
    are saying it. You are making it entertaining and you still care for to keep it smart.
    I can not wait to learn far more from you. That is actually a terrific
    site.

  • gambling回复

    Quality posts is the crucial to be a focus for the people to pay a visit the web site, that's what this site is providing.|

  • AlenaGergo回复

    low cost daily use cialis

    <a href=http://buycialiskj.com/>cialis online</a>

    <a href="http://buycialiskj.com/">buy cialis</a>

    buy cialis egypt

  • .linengallery回复

    Ahaa, its nice discussion about this piece of writing here at this webpage, I have read all that, so now me also commenting here.|

  • arnaque回复

    Marvelous, what a weblog it is! This webpage gives helpful facts to us, keep it up.|

  • www.vpstrust.com回复

    Wow! This blog looks just like my old one! It's on a totally different topic but it has
    pretty much the same layout and design. Great choice of colors!

  • MoisesGergo回复

    generic viagra for men blog

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

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

    how to buy real viagra online

  • cheap phones in india回复

    Hi, I think your blog might be having browser compatibility issues. When I look at your blog in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, great blog!|

  • yeezy sneakers回复

    I actually wanted to send a brief word so as to express gratitude to you for the magnificent points you are placing at this site. My time consuming internet look up has at the end been recognized with good quality ideas to exchange with my visitors. I 'd repeat that many of us website visitors are extremely lucky to be in a superb community with so many special individuals with great secrets. I feel really blessed to have encountered your entire webpages and look forward to tons of more cool moments reading here. Thank you again for everything.

  • reparacion lavadoras madrid回复

    You are so cool! I do not suppose I've read through something like this before. So great to discover somebody with some unique thoughts on this issue. Really.. thanks for starting this up. This web site is something that is needed on the web, someone with a little originality!|

  • mental health回复

    Great write-up, I am normal visitor of one¡¦s website, maintain up the excellent operate, and It is going to be a regular visitor for a long time.

  • Wheel chair van service回复

    Hey! I know this is kinda off topic however I'd figured I'd ask. Would you be interested in trading links or maybe guest writing a blog post or vice-versa? My site addresses a lot of the same subjects as yours and I believe we could greatly benefit from each other. If you're interested feel free to send me an email. I look forward to hearing from you! Wonderful blog by the way!|

  • fire door回复

    Hi i am kavin, its my first time to commenting anywhere, when i read this paragraph i thought i could also make
    comment due to this brilliant post.

  • auto insurance回复

    When someone writes an post he/she keeps the image of a user in his/her mind that how a user
    can know it. Therefore that's why this piece of writing is great.
    Thanks!

  • Check this out回复

    I love what you guys are usually up too. This type of clever work and coverage!

    Keep up the fantastic works guys I've you guys to blogroll.

  • Lucy回复

    You actually make it seem so easy with your presentation but
    I find this topic to be actually something which I think I would never understand.

    It seems too complex and very broad for me. I am looking forward for your next
    post, I'll try to get the hang of it!

  • AlenaGergo回复

    risks buying cialis online

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

    <a href="http://buycialiskj.com/">cialis coupon</a>

    lilly icos cialis

  • AlenaGergo回复

    cialis vente en pharmacie

    http://buycialiskj.com/ - buy cialis

    <a href="http://buycialiskj.com/">buy cialis</a>

    we choice cialis mail order

  • adidas ultra boost回复

    Spot on with this write-up, I really assume this website wants far more consideration. I抣l most likely be once more to read far more, thanks for that info.

  • M88回复

    I appreciate, cause I found just what I was looking for. You've ended my 4 day long hunt! God Bless you man. Have a great day. Bye

  • AlenaGergo回复

    cialis generica inghilterra

    <a href=http://buycialiskj.com/>buy cialis online</a>

    <a href="http://buycialiskj.com/">buy cialis</a>

    is there generic cialis

  • used computer recycling回复

    Pretty section of content. I just stumbled upon your web site and in accession capital to say that I get in fact loved account your weblog posts. Anyway I will be subscribing for your feeds or even I achievement you access persistently fast.