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

评论

  • CheplanovaGergo回复

    actu viagra

    [url=http://viagralms.com/]buy generic viagra[/url]

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

    generic viagra acces rx

  • Luiz Gastão Bittencourt da Silva回复

    I am extremely inspired along with your writing skills and also with the structure for your weblog. Is this a paid subject matter or did you customize it your self? Anyway stay up the excellent quality writing, it's rare to peer a great blog like this one these days..|

  • Educator回复

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

  • adidas yeezy回复

    I together with my buddies were found to be going through the best strategies from your web page and immediately got a terrible feeling I never thanked the site owner for those strategies. Those young men happened to be so joyful to see all of them and already have certainly been using those things. I appreciate you for truly being quite thoughtful and also for having this form of essential subject areas millions of individuals are really desirous to understand about. My honest regret for not expressing gratitude to you sooner.

  • find home security回复

    Way cool! Some extremely valid points! I appreciate
    you writing this post and also the rest of the site
    is also very good.

  • CheplanovaGergo回复

    viagra levitra same day

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

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

    wo viagra online

  • Lélio Vieira Carneiro Junio回复

    Just wish to say your article is as surprising. The clarity in your post is simply great and i can assume you're an expert on this subject. Well with your permission allow me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please keep up the enjoyable work.|

  • VladilenGergo回复

    viagra 100mg erection

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

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

    viagra kaufen gran canaria

  • Jose Wilame Araujo Rodrigues回复

    Great weblog here! Also your website quite a bit up fast! What web host are you the use of? Can I get your affiliate hyperlink to your host? I desire my website loaded up as quickly as yours lol|

  • kelleher international回复

    Great post. I was checking constantly this blog and I'm inspired!

    Very helpful information particularly the last phase
    😊 I care for such information a lot. I was seeking this particular info for a
    very lengthy time. Thanks and best of luck.

  • Adidas NMD New Camouflage Main Dark Blue回复

    I am just writing to make you know of the useful experience my wife's child went through checking your web site. She realized many things, with the inclusion of what it is like to have a very effective helping character to make most people quite simply know various complicated topics. You actually exceeded our own expectations. Thank you for rendering those valuable, dependable, revealing and cool guidance on this topic to Evelyn.

  • AdamGergo回复

    only here cialis overnite

    [url=http://canadianiucialis.com/]cialis cheap[/url]

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

    cialis e levitra impotenza

  • www.alpq.me回复

    If you're an expert within a certain field, it is possible to provide tutorial or
    services to those who wish to learn or know
    a little more about that field, too. They could
    be turned from your trailer into a child stroller with no tools.
    Firstly, a youngster not only sleeps at nighttime,
    but in addition at working day.

  • Vitamix 5300 Review回复

    The conical frustum will have opening for filling materials and taking it out.
    * Some great ingredients to try adding to your nut milks (in moderation. Poplawski, received patents for a machine that would reduce vegetables and fruits into a liquid form.

  • child shopping cart回复

    You can use those to swaddle a baby, act as being a burp cloth
    after feeding, protect a bed when changing a diaper, cover little legs when it's chilly -- their email list goes on as well as on. If and
    once you decide to acquire one the kids they would possibly not thank you
    however hhours of a good times and playing is going to be thanks
    enough. It is the most suitable then to teach your little one
    to crunches all enough time.

  • Top 10 Best Vacuum Cleaners回复

    To take care of the machine away from harms method it is possible to utilize the inbuilt alerts.
    Nevertheless because of this, you will find suggestions that
    guide one in purchasing a vacuum cleaner on-line. Be sure to
    subscribe to receive email notifications of further publications.

  • microwave safe containers回复

    Take those left over items of veg,ham,bacon and then for
    any other left overs within your fridge. Simple, raw and peeled carrots make an incredible diet snack through the day as well as their calorie content is generally
    afound 30 per carrot. The sun is often a clean and inexhaustible source and
    there vary types of technologies involving solar energy to
    make other fforms of energy (electricity, heat,
    light etc).

  • best anti puffiness eye cream回复

    They may be hereditary; if a person or both of the folks are, you probably have the crooks to.
    Pink eye or conjunctivitis happens if the white part of the becomes inflamed and irritated.

    ' The top anti-wrinkle eye creams comprise Keratin, an average protein identified
    inside physique that plays an integral structural
    function in pores and skin.

  • TV Screen Protectors & Cleaners回复

    As I web site possessor I believe the content matter here is rattling excellent , appreciate it for your efforts. You should keep it up forever! Good Luck.

  • Shoes and Sandals回复

    Thank you, I have recently been searching for info approximately this subject for a long time and yours is the best I've came upon till now. But, what about the conclusion? Are you certain concerning the source?

  • Adult Acne skin care回复

    Well I sincerely liked studying it. This information procured by you is very constructive for accurate planning.

  • Hp Color Laserjet Pro Mfp M476Dw回复

    Instead, it has allowed for business expansion on such a scale that service and retail sectors have grown, along
    with their need for flyers and correspondence on a large scale.
    Depending on what is wrong with the device, printer repair may save even more money.
    Most paper jams are usually caused by improper placement of papers or leftovers or pieces of paper
    that has been left from previous paper jam can cause this too.

  • online shopping for women回复

    It¡¦s actually a great and helpful piece of information. I¡¦m happy that you just shared this useful info with us. Please keep us informed like this. Thank you for sharing.

  • cheap homeowner insurance回复

    Thanks a bunch for sharing this with all of us you really recognise what you are talking about!
    Bookmarked. Kindly also visit my web site =). We can have
    a link change agreement among us

  • Black & Decker Dcm18S Brew 'N Go Personal Coffeemaker With Travel Mug Review回复

    Today, Melitta continues to generate coffee filters, and makes a speciality of gourmet coffee both in ground and whole bean.
    But let's be truthful; there are many to pick from available, so how
    does one know those are the top. I may use all types of loose leaf teas which
    I much prefer over bags while using Coffee a la Carte and also good coffee which is the
    very best feature.

  • Electric Toothbrush Reviews回复

    Although you could possibly brush your teeth once or perhaps twice daily, high chances
    are that food particles that cling below the
    gum line will cement there, resulting in bad breath, and a a lot of extra other
    unwanted conditions for example periodontitis, gingivitis and tartar.
    It is safe on thhe gums and yes it is better to use by peopole who
    have bad brushing techniques. The Sonicare Electric toothbrush can be
    a good illustration of how older folks have product choices today
    that could cater on their needs.

  • adidas nmd回复

    I'm writing to make you be aware of what a beneficial encounter my wife's princess found visiting yuor web blog. She realized plenty of issues, which included what it's like to have an excellent helping spirit to get the rest effortlessly grasp specific impossible matters. You actually surpassed our desires. I appreciate you for rendering these essential, trustworthy, revealing and as well as unique tips on the topic to Gloria.

  • https://wiki.open-empire.org回复

    Just like using the enjoy, these units make it possible
    with the person for getting golf program info using their
    company personal computer in the GPS system,
    making the knowledge very accurate. Its scorecard features will include
    a score of approximately fourr golfers, simple
    score entry, rotated full-round traditional scorecard view, and stableford scoring.
    But I've tried it for six months and yes it's performed flawlessly.

  • kelleher international回复

    Hello, I enjoy reading all of your article post. I wanted to write a little comment to support you.

  • VladilenGergo回复

    customs generic viagra

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

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

    viagra 8cpr 50mg

  • Bagless Vacuum Cleaner Reviews回复

    Most vacuums have a series of attachments for these sorts of jobs.
    Believe it or not, you could save a lot of money when you purchase those vacuums that do not
    requires any bags. Although a bit loud for a residential machine, this compact
    Hoover model is a good value for under $100 dollars considering the amount of overall power, the allergen filtration and the included tool
    kit.

  • PDS Mauritius回复

    I absolutely love your site. I found it a few weeks ago while searching Google and can’t get enough of it. If you have the time, I think you would like my marketing website.

  • stationary cycle回复

    If you want from simply no exercise in any reslect to for being able to Ten minute fiyness bike workouts using little weight, you could
    be more inclined to avoid harm, pain, and quite several coming of all, early sensations related to wipe out.
    This unique Proform stationary bike is a lots of fun and
    will consider the tedious element from stationary bike workout routines.
    While the essential use of an stationary bike in Phoenix
    is fairly easy, shopping for any home fitness bike
    can be very intimidating.

  • Teeth Whitening Hydrogen Peroxide回复

    Peolle notice smiles if teeth are dull, stained or discolored, it could
    cause you to be look less groomed as well as, believe it or you cannot, less qualified.

    Another good strategy for covering or disguising discolored tooth are porcelain veneers
    which is often a thin layer of porcelain which is paste into the surface from the teeth.
    These toothpastes can be obtained over the counter and value only a pound or two more
    compared to the regular toothpastes.

  • AlyonaGergo回复

    cialis mexico sin receta

    [url=http://cialisnorxonlinez.com/]generic cialis[/url]

    <a href="http://cialisnorxonlinez.com/">cialis cheap</a>

    cialis 40 mg forum

  • Malinda回复

    If water is leaking from around the larger water
    urn, get rid of the nut holding the fauucet then turnaround for the washer then return the faucet into position. You’re kitchen will
    probably possess a nice salad smell as it’s brewing
    you could possibly even like. So if you have a tendency to brew a pot then drink it during the entire morning the carafe can be a real plus.

  • Best Rated Leaf Blower回复

    Both homeoners and commercial lawn and garden companies start using thise models,
    even though the professionals prefer the electric
    and gas powered backpack style leaf blowers because from
    the convenience they supply. The BR380 Stihl backpack blower is
    reasonably all to easy to start. Once you receive to the end on the driveway, take a pace toward the inside you were blowing (e.

  • Best Wet Dry Electric Shaver回复

    If it's going to take a while, work out how much you really feel your time is worth and should you will really save money by
    doing the repair yourself. These varieties of units are perfect for guys on the go plus
    case you are in a very hurry, you are able to simply
    carfy your shaver and perform the shaving within your car on your
    way to work. There are a number of points about this particular shaver that I think will probably be of
    interest to those of you which can be thinking of getting it to your own personal circumstances.

  • Relevantrankings.Com回复

    Let's say for example you are photographing old furniture.
    This lets one set up the shutter speed and aperture size.

    Well, our Panasonic Lumix TZ10 Review talks about how this camera
    is being produced.

  • KarolinaGergo回复

    brand name cialis cheap

    [url=http://orderdascialis.com/]generic cialis online[/url]

    <a href="http://orderdascialis.com/">cialis cheap</a>

    cheap legitimate cialis