Migrating Android apps to Room is just a couple of clicks away

Room is a new library that provides an abstraction layer on top of SQLite. It makes interactions with databases simpler, less error-prone by reducing the amount of code we write, in addition to checking our SQL statements at compile-time. Room was first introduced at Google I/O 2017. It reached production-ready status in November 2017.

Migrating our existing Android apps to Room is possible with a few manual steps:

(For more details about manual migration to Room, please read “7 Steps to Room”, by Florina Muntenescu).

Wouldn’t it be convenient and efficient to generate Room classes from our existing database schemas automatically? …

Enter SQLScout

SQLScout is a plugin for Android Studio and IntelliJ IDEA that provides support for SQLite databases, including:

The ability to connect to databases in Android devices and the file system

A database schema explorer that displays the structure of databases

A SQL editor that provides all the features you’d expect from an IDE (syntax highlighting, code completion, reference navigation and refactoring) and the ability to execute SQL statements

A database console to view query results, edit table data, and export data to different formats (including Excel)

Database diagrams

Figure 1. SQLScout’s seamless integration with Android Studio

Introducing SQLScout 3.2.0! This version of SQLScout is dedicated to provide support for generating Room Entity, DAO and Database classes from existing database schemas.

Automating Migration to Room — With SQLScout

With 3 clicks as shown in figure 2, SQLScout’s “Room Migration” wizard will handle the heavy-lifting, manual work for you.

Figure 2. SQLScout’s “Room Migration” wizard

After clicking the “Finish” button in the wizard, SQLScout will automatically:

Add the Google Maven repository to your project, if needed Add the Room libraries as dependencies, if needed Generate Entity, DAO, Migration and Database classes from your existing database schema (the generated DAOs contain basic CRUD operations, which is a pretty good start) Generate a TypeConverter for java.util.Date , if needed Generate a detailed report explaining the changes made to your project and the classes that were generated

SQLScout generates 100% Kotlin code if your app is already using Kotlin.

Figure 3. SQLScout’s code generation in action

A Closer Look at the Generated Code

SQLScout generates code using the IDE’s own mechanism for generating Java and Kotlin code: code templates (for new classes and interfaces), and PSI (for fields, methods and functions), ensuring that the generated code follows your own coding style and preferences.

Figure 4. Room code generated by SQLScout

The followings are some examples of SQLScout’s generated code: