Tuesday, October 23, 2012

ORM for android

     ORM – Object relational mapping has been around for quite some time now. Basically it’s a piece of software (regardless of targeted platform), which simplifies the connection between objects (as in OOP) and data in database (mostly used is tables based relational database), and it exists in order to help simplify bridging the gap between the two in our development process.

    Microsoft's Entity framework is a great example for a robust easy to use framework which allows creating and querying the database from an object’s point of view with classic object oriented programming paradigms while maintaining all DB construction’s needs such as relationships between objects (tables) such as one to many or many to many including all the indexing, optimization etc..

     In android, we have SQLite as a database platform, from simple to advanced application, it’s likely to assume that we’ll need some relational database to store and retrieve local data from the database using the basic CRUD operations. When developing any platform-agnostic app, dealing with the database is quite a hassle, because it is very sensitive to work with "string” based queries, and Occasionally we’ll have to write a lot of code in the Sqlite DB helper class. It’s absolutely a bottleneck when trying to concentrate on the logic itself rather than worrying about the data access layer.

     so what can we do in order to simplify the work the the local database? there are couple of open source projects such as:

ORMDroid 

OrmLite

activeandroid

all these ORM’s are simple to use and are quite lightweight and support the basic needs for databases in android application, but do not offer advanced features for performance optimizations and indexing etc.. hopefully some time in the near future Google will release a stable library to be included in the SDK in order to help us, the developers concentrate on build better apps quicker and better.

there are probably some more open source projects which do the work in terms of making everything simple and not working with the actual database in terms of querying it and looking after matters like cascading, updating, auto incrementing etc..

I’m currently working on an ORM library myself, hopefully will finish it soon enough to publish to github.