Ormlite or sqlite Which one is good for Android perspective? [closed]

↘锁芯ラ 提交于 2019-11-30 17:27:40
Android Fanatic

ORMLite is an open source software framework that provides lightweight object relational mapping (ORM) between Java classes and SQL databases.

if you use this framework you are ultimately using sqlite database (ORMLite is no database),it allows you to implemet a good architecture to your application, I always prefer using ORMLite

Here is my blog on ORMLite if you want to get started with it!!

ORMLite has two .jar files : ormlite-core.jar (275KB) and ormlite-android (50KB) libraries

Advantages :-

  1. Use for complicated database operations

  2. No need to remember to SQL queries

  3. Prefer for big size application

Disadvantages :-

  1. Unnecessarily increase size of application

  2. Little bit slow with compare to greenDao(another ORM)

Although other answers are perfect but I want to mention another aspect about using ORMs such as Ormlite vs SQlite.

ORMs (such as Ormlite) are good to use because they reduce amount of work and code but I've read this and I mention the opinion here:

We generally do not recommend using an Object-Relation Mapping library unless you have unusually complex data and you have a dire need. They tend to be complex and require time to learn. If you decide to go with an ORM you should pay attention to whether or not it is process safe if your application requires it, as many of the existing ORM solutions surprisingly are not.

Cubestack Labs

You can also choose to look at Storm (https://github.com/supaldubey/storm/)

It provides neat interface and does not asks to override or implement any base classes for the Models.

It also would auto create and auto upgrade your models

You can add to Gradle and start using easily

In parent:

maven { url "http://dl.bintray.com/cubestack/maven" }

In project Gradle:

 dependencies {
        compile 'in.cubestack.android.lib:storm:1.0g'
    }

Step 1: Define tables:

    @Table(name = "DEMO_ENTITY")
    class Entity {
   @PrimaryKey
   @Column(name="ID", type = FieldType.INTEGER)
   private int id;
    }

Step Two (Define the Database)

Database also have their annotation which can be applied, there can be multiple databases defined.

@Database(name="MY_DB", tables = {Entity.class, AnotherEntity.class}, version = 2)
class Database {}

Step Three (Start Using)

With database ready for us, we may start using it as below:

Retrieval

StormService service = new BaseService(getContext(), Database.class);
List<Entity> savedEntities  = service.findAll(Entity.class);

Similarly it has methods to save, delete etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!