Ormlite or sqlite Which one is good for Android pe

2019-02-08 07:24发布

I am confused the which one good for android perspective either Ormlite or sqlite. please can you give me suggestion which one is better for use our android app. And makes easy to use and supported all android devices? I want to use the ormlite in our project but before i want to sure that it will be helfull for me and my app. So please guide me if any one used earlier this. I much appreciate your thought here.Thnaks

4条回答
三岁会撩人
2楼-- · 2019-02-08 07:57

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)

查看更多
时光不老,我们不散
3楼-- · 2019-02-08 08:04

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.

查看更多
地球回转人心会变
4楼-- · 2019-02-08 08:08

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!!

查看更多
我命由我不由天
5楼-- · 2019-02-08 08:13

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.

查看更多
登录 后发表回答