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.

Comments

Unknown said…
Hi thanks a lot for your artitcle.
What
about remote db? mysql for example.
how can i use it without php wrapper? in c# exist very fine library,and in android?
Israel Tabadi said…
Thanks Leonid,
Mysql is just another DBMS, it could be any other one.
by php you mean the server side code which communicates with the database itself, you could use any other server side "wrapper" like C#, ruby or python for example, or even JavaScript.
you can't and shouldn't be able to communicate with a remote database straight from the android application.

if you have any more questions, please feel free to ask, i'll be happy to answer.
Unknown said…
Hi
see this article :
http://www.codeproject.com/Tips/423233/How-to-Connect-to-MySQL-Using-Csharp

It what i want :-) connect to mysql server, without any wrappers on server side :-)
Israel Tabadi said…
Hi,
it seems that you are missing the point in the communication methods between an app to the remote database.
the article which you've mentioned is a wrapper for C# to communicate with MySQL database , both are done on a server.

this current post talks about making it easy and convenient to manage a LOCAL SQLite database which is present on the local app on your android device.

there are also many convenient ways to manage the communication to and from the database on server platforms, I've mentioned Entity framework for C# (can be done even on console application or any other .Net based application)

In order to build a client-server application like most android apps, you need to expose some web services with an API to enable you to send data back and forth with the server. These services will implement the data transfer back and forth with the database itself.

Unknown said…
Israel
I understand your point.
Connect to to local DB is easy enough without any additional tools, at least for me.
But connect to remote DB in android may be better.
Israel Tabadi said…
Due to 2 reasons it's not possible and not recommended:
1. Security - imagine that your database will be exposed to attacks.
2. technology - you connect with your android to a server most likely over http (port 80), databases work with other ports and for the most part with other protocols (TCP).

in conclusion, it's common practice to work with a mediator on server to allow easy and secure access to a database.
Unknown said…
I have gone through Siminov Android ORM, it is open source framework with proper user guide and documentation. It is easily configurable, handle application deployment, support multiple schemas and many more. I found it very useful and easy to use.Good thing is same available on other platforms also e.g iOS, Windows 8. I suggest you to try this, you will definitely find it useful and this ORM may solve your problems.

You can check this link "http://siminov.github.io/android-orm/".
MB said…
You might like AndroYiid, not an open source but developed as no other. Try it yourself - https://androyiid.com

Popular posts from this blog

Spinner VS AutoCompleteTextView

Utilizing Http response cache