Higher level database layer for Android?

女生的网名这么多〃 提交于 2019-12-29 03:03:45

问题


Are there any good database abstraction layers/object relational mappers/ActiveRecord implementations/whatever they are called for Android? I'm aware that db4o is officially supported, but it has quite a large footprint and I'd rather use a more conventional database (SQLite).


回答1:


I am the main author of ORMLite which was designed to be small[ish] but still provide higher level functionality. ORMLite makes calls to the native Android OS database APIs to support its ORM functionality. See the following for general information

http://ormlite.com/sqlite_java_android_orm.shtml

Here are some Android example applications:

http://ormlite.com/docs/android-examples




回答2:


I tried the Sugar ORM, which is very basic (and easy to use) but it worked for my needs.

Sugar website




回答3:


There is an 'android-active-record' project which provides ActiveRecord abstraction for accessing Android SQLite database. It's available here: http://code.google.com/p/android-active-record

It allows to eliminate most of boilerplate coding when performing CRUD operations on database entities and also minimizes efforts for creating/maintaining a database structure




回答4:


Try ActiveAndroid. It is free and open source (Apache Version 2.0).

From the website:

ActiveAndroid is an active record style ORM (object relational mapper). [...] ActiveAndroid allows you to save and retrieve SQLite database records without ever writing a single SQL statement. Each database record is wrapped neatly into a class with methods like save() and delete().

[...] Accessing the database is a hassle, to say the least, in Android. ActiveAndroid takes care of all the setup and messy stuff, and all with just a few simple steps of configuration.




回答5:


If performance and size matter, you should have a look at our open source ORM tool greenDAO. We wrote it because we did not want to compromise on speed. Other tools heavily rely on reflection, which is very slow on Android. Despite the tiny size (<100k), it supports relations, query builders, etc.




回答6:


Shameless plug, but I've been working on a new open source Android framework called Infinitum. One of its main features is an ORM which has a criteria API similar to Hibernate and a few other nifty features (associations, lazy loading, etc.). It's still in its early stages, but I think it's coming along pretty nicely.




回答7:


I have written a new ORM, for android, that's aimed and being as easy as possible to implement. It support lists and SQL free migration a couple things which I always found had an overhead in other libraries.

http://www.rushorm.com/




回答8:


I faced the same problem and looked at both android-active-record and ActiveAndroid. I found android-active-record didn't handle the things I cared about (relationships for example), and ActiveAndroid isn't free. Therefore, I decided to write my own library. It's called AndroidRecord and it's hosted on GitHub and you're free to do with it what you want (I think I'm going to go with the MIT license). I use this every day and I'm content with it, but I'd love to get feedback.

If you need to know how to use it, I'm working on the documentation. If you need it right away, you can check out this lame example project which should be enough to dip your toes in. You can also email me of course.




回答9:


There's also Neodatis and Perst (Lite).
I've toyed with Perst a year ago and concluded it's not worth it.
After all, a) Android runs on a rather restricted device with ~16mb of heap space per app and b) You customers would really appreciate performance and low power consumption.
So my advice is to go with SQLite and hand-written SQL. It's not hard at all and the wrappers provided by Android SDK are really nice.

EDIT: In 2012 the advice would be to use the ORM component of DroidParts (which is my project).




回答10:


I was comparing basics of ormlite and greendao some time ago. You might want to take a look there. I plan to write some follow up with more advanced stuff in the near future but for now it's only a basic stuff. In my own project I'm using GreenDAO.




回答11:


Have a look at Androrm. It is open source and well documented (see here). If you ever worked with django, you will notice, that the syntax is very similar.

Androrm also supports abstraction classes for the most common field types, plus relational fields. This way it enables you to query for your data in an very easy manner with only very little effort on your side.




回答12:


SQLite is explicitly part of Android:

http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

However you might have to create your own abstraction layer (query builder for simple queries), or otherwise deal with SQL.

Maybe http://developer.android.com/reference/android/database/sqlite/SQLiteQueryBuilder.html is what you need?



来源:https://stackoverflow.com/questions/1842357/higher-level-database-layer-for-android

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