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

评论

  • www.eliquid-depot.com回复

    This can be such a great position, plus took place sense very much exactly the same myself. Another fantastic keep posted.

  • MoisesGergo回复

    viagra pillen teuer

    [url=http://viagraferx.com/]buy cheap viagra[/url]

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

    viagra rezeptfrei schnel

  • Business回复

    I really wanted to post a brief note to say thanks to you for some of the magnificent concepts you are sharing on this site. My prolonged internet search has at the end been paid with incredibly good points to write about with my pals. I would admit that most of us readers actually are rather endowed to live in a superb network with very many special professionals with good tips and hints. I feel very much fortunate to have used your entire web site and look forward to many more entertaining times reading here. Thanks a lot once more for everything.

  • Health and Fitness回复

    But wanna tell that this is invaluable , Thanks for taking your time to write this.

  • Health and Fitness回复

    It's actually a great and helpful piece of info. I'm glad that you just shared this useful info with us. Please stay us informed like this. Thank you for sharing.

  • Health and Fitness回复

    excellent issues altogether, you simply received a brand new reader. What could you recommend about your publish that you just made a few days in the past? Any positive?

  • valeraGergo回复

    cialis schweiz ohne rezept

    [url=https://cialisols.com/]cialis coupon[/url]

    <a href="https://cialisols.com/">buy cialis</a>

    cialis 25 price

  • Health and Fitness回复

    I like what you guys are up too. Such intelligent work and reporting! Carry on the excellent works guys I have incorporated you guys to my blogroll. I think it will improve the value of my website :).

  • Health and Fitness回复

    Thanks for sharing excellent informations. Your web-site is so cool. I am impressed by the details that you have on this web site. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for extra articles. You, my pal, ROCK! I found just the info I already searched all over the place and just couldn't come across. What a perfect website.

  • Health and Fitness回复

    Hey there, You've done an excellent job. I’ll definitely digg it and personally recommend to my friends. I am sure they'll be benefited from this site.

  • Health and Fitness回复

    You actually make it seem so easy with your presentation however I find this topic to be actually one thing that I believe I might by no means understand. It seems too complex and extremely huge for me. I am looking forward to your next post, I¡¦ll try to get the hang of it!

  • Home Improvement回复

    Just wanna input that you have a very nice website , I love the style it really stands out.

  • Health and Fitness回复

    Some really nice and utilitarian information on this internet site, besides I believe the design contains superb features.

  • Health and Fitness回复

    Thanks for sharing superb informations. Your site is so cool. I am impressed by the details that you've on this blog. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for more articles. You, my pal, ROCK! I found just the information I already searched everywhere and just couldn't come across. What a perfect web-site.

  • Contact Us - Madden Mobile Hack Tool [2017]回复

    Test it your self: –

    When you attempt to establish the budget for madden mobile, your must always
    check it out yourself with your personal accounts, like that
    you will be sure certain system performs or otherwise not, don’t feel on somebody test
    anything yourself then just display if this has value to fairly share together with your family and friends, As various other people’s confidence both
    you and they don’t need fake claims.

    Very first time generate lowest information: –

    As you maybe once you understand many internet tend to be blocking the access
    to the internet generator due to bots and things hence they apply real
    person verification exams on their website, which has to be completed by the individual
    to confirm they truly are peoples, you understand exactly why is that happening?
    That’s because people exactly who got the accessibility the madden mobile on-line hack and cheats appliance overused
    it and tried to establish endless means each time, That’s why we'd advise
    you that, if you use the internet generator very first time next just
    make use of it to generate minimal quantities possible that way your account won’t get flagged or blocked through the program.

    To learn additional about maddenmobilehacktool and Madden Mobile Hack Tool [2017] - Online Cheats for FREE Coins, please check
    out our internet site Contact Us - Madden Mobile Hack Tool [2017].

    The game are cool that there are million subscriptions and players.

    The good thing about it is that this baseball online
    game contains members of the past additionally the gift so that the teams may be
    opted for while you wish.

    With Madden Mobile Hack you could be ensured you will get playing with all the current experience and method that will allow you
    to get the money and coins you'll want to get the then degree.

    Immediately this game awaits the participation very join in and acquire a possibility of accumulating madden coins, madden earnings and enjoy under the labels of this leading professionals all with the
    help of the hack.

    Thank you for visiting this site concerning the Madden Mobile Hack.

    1st, let’s mention exactly what the game from EA is about.
    Madden Mobile try a tremendously preferred online game in america.

    It is played by significantly more than 1 million people every month.
    This NATIONAL FOOTBALL LEAGUE game for mobiles video game is designed to getting starred best
    on smart phones. You're able to understand it from the term.
    That is available for Android os and iOS on the Bing

    Store and iOS Store. Its produced by EA Sporting events.
    You will need a wi-fi connections most likely because the game provides
    alone about 55MB, it is really not the smallest games but in addition perhaps not the greatest.
    Whether you want the activities or not the overall game will get you.
    Its very addicting that it's starred by loads of participants every day.
    It was probably one of the most performed activities games on yahoo Play.
    You can install the video game on iTunes right
    here at no cost.

  • Home Improvement回复

    Thanks for the sensible critique. Me & my neighbor were just preparing to do a little research on this. We got a grab a book from our local library but I think I learned more from this post. I'm very glad to see such great information being shared freely out there.

  • www.linux.ca回复

    Would Ᏼecoming A Freelance Paralegal Be A
    Goodd Рossіbility For You?

  • Education回复

    I do trust all the concepts you have offered to your post. They are really convincing and will certainly work. Nonetheless, the posts are very quick for newbies. Could you please lengthen them a bit from subsequent time? Thank you for the post.

  • Health and Fitness回复

    Hi, Neat post. There is an issue with your website in internet explorer, might check this¡K IE nonetheless is the marketplace chief and a large component to folks will leave out your excellent writing due to this problem.

  • stainless steel kitchens are回复

    Thanks for revealing your ideas right here. The other matter is that if a problem develops with a laptop or computer motherboard, persons should not consider the risk of repairing this themselves because if it is not done correctly it can lead to irreparable damage to the entire laptop. It is almost always safe just to approach the dealer of that laptop for your repair of motherboard. They've already technicians who may have an know-how in dealing with mobile computer motherboard issues and can make right prognosis and conduct repairs.

  • visit website回复

    It as nice to definitely arrive a web internet site in which the blogger is intelligent. Thanks for creating your web internet site.

  • coupon codes回复

    Major thankies for the blog post.Really thank you! Keep writing.

  • Health and Fitness回复

    I do agree with all of the ideas you've offered in your post. They're really convincing and can definitely work. Nonetheless, the posts are very brief for newbies. Could you please extend them a bit from next time? Thanks for the post.

  • house painters回复

    I am curious to find out what blog system you happen to be utilizing?
    I'm having some small security problems with my latest website and I'd like to find something more safe.
    Do you have any recommendations?

  • Health and Fitness回复

    We're a group of volunteers and starting a new scheme in our community. Your site provided us with valuable information to work on. You've done an impressive job and our whole community will be thankful to you.

  • Health and Fitness回复

    Hi my loved one! I wish to say that this post is amazing, nice written and include approximately all vital infos. I would like to peer more posts like this.

  • Health and Fitness回复

    I do not even know how I ended up here, but I thought this post was good. I don't know who you are but certainly you are going to a famous blogger if you are not already 😉 Cheers!

  • weed delivery回复

    I truly appreciate this post. I ave been looking everywhere for this! Thank God I found it on Bing. You ave made my day! Thx again

  • Health and Fitness回复

    I in addition to my guys were found to be viewing the best guides on your web blog and then unexpectedly developed an awful suspicion I never expressed respect to the web site owner for those techniques. All of the young men had been as a result passionate to study them and now have in truth been making the most of those things. Thank you for simply being indeed accommodating and then for obtaining certain decent ideas most people are really desirous to understand about. My personal sincere regret for not expressing appreciation to sooner.

  • Health and Fitness回复

    Some really excellent articles on this website, thanks for contribution. "We are always in search of the redeeming formula, the crystallizing thought." by Etty Hillesum.

  • short mens haircuts回复

    Too many times I passed over this link, and that was a tragedy. I am glad I will be back!

  • Ice packs回复

    Hi, i think that i saw you visited my website so i came to “return the favor”.I'm trying to find things to enhance my web site!I suppose its ok to use some of your ideas!!

  • Home Improvement回复

    My brother suggested I might like this blog. He was totally right. This post truly made my day. You cann't imagine just how much time I had spent for this info! Thanks!

  • payday loan store回复

    What’s Happening i'm new to this, I stumbled upon this I've found It positively helpful and it has helped me out loads. I hope to contribute & aid other users like its aided me. Good job.

  • www.pomeb.ru回复

    I know this site presents quality based content and additional information,
    is there any other website which provides these data in quality?

  • pro回复

    My brother recommended I might like this blog. He was entirely right. This post actually made my day. You can not imagine just how much time I had spent for this info! Thanks!

  • Health and Fitness回复

    Keep up the excellent work , I read few content on this website and I think that your website is rattling interesting and has got sets of fantastic info .

  • Health and Fitness回复

    Hello, you used to write excellent, but the last several posts have been kinda boring… I miss your great writings. Past several posts are just a bit out of track! come on!

  • Health and Fitness回复

    Hello there, You have done an incredible job. I will definitely digg it and personally suggest to my friends. I am confident they'll be benefited from this web site.

  • Game Maker回复

    I¡¦ve been exploring for a little bit for any high-quality articles or blog posts in this kind of area . Exploring in Yahoo I eventually stumbled upon this web site. Reading this information So i¡¦m satisfied to convey that I have an incredibly just right uncanny feeling I found out exactly what I needed. I such a lot certainly will make certain to do not put out of your mind this site and give it a look regularly.

  • Health and Fitness回复

    I have learn a few just right stuff here. Definitely value bookmarking for revisiting. I wonder how so much attempt you set to make one of these magnificent informative site.

  • Health and Fitness回复

    I am really impressed with your writing skills as well as with the layout on your weblog. Is this a paid theme or did you customize it yourself? Anyway keep up the excellent quality writing, it’s rare to see a nice blog like this one these days..

  • Digital Marketing回复

    Hi there to all, since I am actually keen of reading this
    weblog's post to be updated regularly. It contains good material.

  • Health and Fitness回复

    fantastic issues altogether, you simply gained a new reader. What could you suggest in regards to your put up that you just made a few days in the past? Any sure?