Loading Data – SQLite DB vs. ObjectBox DB

Loading Data – SQLite DB vs. ObjectBox DB

Code Example n°1

Beautiful
Code

Loading data.
In just 2 lines.

LOADING DATA FROM A MOBILE DATABASE

Loading data in a Mobile App can be lenghty… if you work with SQLite directly. That’s why we built the fastest ORM on the market: greenDAO. With greenDAO its only 2 lines of code. With ObjectBox, our Mobile Database, its also 2 lines of code. Objectbox simply gives you additional speed out of the box. If you are already working with greenDAO, you can switch to using ObjectBox almost seamlessly. Check out our greenDAO CompatLayer to learn how you can easily switch and boost your app performance with minimal effort.

CODE COMPARISON

SQlite / greenDAO / ObjectBox

SQLITE DATABASE

String[] columns = { “note”, “date_changed” };

String[] idArgs = { String.valueOf(id) };

SQLiteCursor cursor = (SQLiteCursor) db.query(“notes”, columns, “_id=?”, idArgs, null, null, “note”);

try {

if (cursor.getCount() != 1) {

throw new Exception(“Unexpected count: ” +cursor.getCount());

}

cursor.moveToNext();

String note = cursor.getString(0);

String date = cursor.getString(1);

updateUi(note, date);

} finally {

cursor.close();

}

GREENDAO ORM

Note note = noteDao.load(id);

updateUi(note.getNote(), note.getDate());

OBJECTBOX DB

Note note = noteBox.get(id);

updateUi(note.getNote(), note.getDate());