Friday, September 13, 2013

Android ORM

Well, I came to the point that nearly all apps arrive at:  the need for persistence. I'll admit it, I am not a database guy.  They don't excite me.  I don't like talking about indexes, query plans, triggers, schemas, etc.  None of that shit.  I'm a coder, and storage is a necessary evil that I would prefer to have abstracted away.

So my needs for this project (AR) are that I will be creating a Ticket object, which consists of one or more Game objects.  Think parlay ticket if you are a sports bettor, or a single game "straight bet".  My business objects are fairly straightforward.  For the last Android app that I wrote, Tapster, I wrote the data access layer "by hand".  Some people contend that ORM frameworks are evil and afford you less control, and they are probably right.  But I don't want to mange table creation nor write tedious sql.

What are my options?  I could use a traditional sql relational database.  I could use a NoSql option like Mongo or Couch.  I can persist locally.  I can persist to the cloud.  I can do both.  I should probably go read a best practices document for android storage patterns.

I've decided to start with a local SqlLite db.  I also went looking for an ORM framework for Android, because like I said, I'd prefer the CRUD to be magically taken care of for me.  I found a couple, Green DAO and OrmLite.  I settled on OrmLite after reading one testimony on StackOverflow.  Pretty diligent on the research eh?  It really came down to quality of documentation and abundance of sample code.

So, one thing that bugs me in the Android world, and I've seen quite a bit of it, is that every framework wants you to inherit from their base classes.  OrmLite is no different.  I don't like to "commit" to a framework like that, so I don't want to intertwine my code with theirs.  When I decide later to swap it out, I'd like it to be painless.  I guess this is where programmers prove their worth, by going the extra mile to isolate things.

Anyway, I'm looking forward to spending some time this weekend on the app and hopefully get a preliminary version working.

Adios amigos!

No comments:

Post a Comment