MobileUI LogoMobileUI

🔌 ORMLite

Use object relational mapping for SQLite on Android and iOS

The ORMLite Plugin PURPLE brings object relational mapping on the basis of ORMLite to your app. This Plugin brings special ORMLite bindings for the SQLite database on iOS to make the cross-platform magic happen. Additionally, you get a unified way of configuring ORMLite and the underlying database. You don't have to write platform-specific code.

Plugin Infos
Api Docsio.nevernull.mobileui.ormlite
Main Interfaceio.nevernull.mobileui.ormlite.DaoFactory

Configuring ORMLite and the database

To configure ORMLite and the underlying SQLite database for your project, you need to create an OrmLiteConfiguration bean. To accomplish this, you can create a Bean Factory by annotating a class with the @Factory annotation. Then, add a method annotated with @Singleton that returns the OrmLiteConfiguration as shown below:
import io.micronaut.context.annotation.Factory;
import io.nevernull.mobileui.ormlite.OrmLiteConfiguration;
import javax.inject.Singleton;

public class Config {

    public OrmLiteConfiguration ormLiteConfiguration() {
        return OrmLiteConfiguration
                // The data classes that are annotated with ORMLite annotations (entities)
                .entities(Person.class, Team.class, Project.class)
                // The name of the SQLite file within you app's private database dir
                // Migration version differentiating database versions
                // Let the ORMLite Plugin manage table creation based on the entities (true)
                .onCreate(s -> {
                    // Optionally: Run script to create the database schema
                .onUpgrade((connection, oldVersion, newVersion) -> {
                    // Optionally: Run script to migrate

Note: To learn more about entities and ORMLite's annotation to map object into the database, please refer to the ORMLite documentation.

Using ORMLite to manage data

As soon as the configuration is available, you can simply inject the DaoFactory into your code. You can obtain a Dao (Data Access Object) with the getDao(<class>) method as shown below. Make sure, you are running this code after injection has taken place. This can be done within a method annotated with the javax.annotation.PostConstruct annotation.
public class PersonController {

    private DaoFactory daoFactory;    private Dao<Person, Object> personDao;
    public List<Person> personList;

    public void init() {
        try {
            personDao = daoFactory.getDao(Person.class);            personList = dao.queryForAll();
        } catch (SQLException e) {
            throw new RuntimeException(e);

    public void onAddChuckClicked(){
        Person chuck = new Person("Chuck", "Norris");
        personList = dao.queryForAll();
        MobileUI.firePropertyChanged(this, "personList");

Further Reading