SQLDelight in Android: Getting Started

In this course, we will introduce you to SQLDelight, a generator for typesafe Kotlin code based on SQL database statements, with built-in support for migrations, schema validation and IDE integrations. From initial installation all the way to customization, you’ll learn everything there is to know about this latest invention from Square. By Marcel Schnelle.

Leave a rating/review
Download materials
Save for later

Learning path

This is part of the Advanced Android Data & Networking learning path. View path.

Who is this for?

This course is for Android developers with an existing knowledge of and interest in SQLite, and those eager to learn about a new library to assist with the data persistence layer of their applications. If they have prior experience with comparable solutions for data persistence (e.g. Room, Realm), this course will be of value to them as well.

Covered concepts

  • Installation
  • Database Configuration
  • Model Creation & Relationships
  • CRUD Functions
  • Column Types
  • SQL Views
  • Grouping
  • Migrations
  • Testing & Schema Validation
  • RxJava Integration
  • Coroutines Integration
  • Paging Integration

Part 1: Preparation & Setup

Toggle description

Learn how SQLDelight is constructed and how it works on a high level on a multitude of platforms. Afterwards, install the required IDE and Gradle plugins to your environment and add the Android-specific driver library as a new dependency to the provided sample project used in this course.

Toggle description

Learn how to deviate from SQLDelight’s default configuration and tailor it to your specific needs via the domain-specific language exposed by its Gradle plugin.

Toggle description

Familiarize yourself with the .sq file format, used by SQLDelight to describe a table in the generated database. From the scope of the sample app, introduce the intended database relationships and construct the CREATE TABLE statements that make up these models.

Toggle description

Instantiate the Database object generated by SQLDelight and connect it to the existing sample app. Learn about how SQL Drivers are the backbone of the library and how to configure the Android driver specifically. Check out how the underlying AndroidX database can be surfaced for customization and fine-grained configuration.

Toggle description

Learn how SQLDelight stores the columns of generated tables in the underlying SQLite database. Show how different type aliases can affect the generated model classes. For advanced users, show how the library supports custom types through imports and column adapters.

Toggle description

Familiarize yourself with the syntax of functions in SQLDelight and how they add methods to the generated model classes. Using an exemplary workflow of the sample app, create code to insert data into the database and query it with a different function. Furthermore, learn how to get notified whenever the underlying dataset is changed.

Toggle description

Learn about a feature in SQLDelight called grouping statements, wherein multiple SQL statements can be combined under a single name to reduce complexity of the calling Kotlin code.

Toggle description

Learn about the Transaction API in SQLDelight, which allows you to execute multiple statements in Kotlin and commit them all at once. Furthermore, explore how the transaction can be rolled back in case of errors and how to be notified of events related to the ongoing transaction.

Toggle description

Learn how SQL migrations are supported in SQLDelight. This episode introduces the .sqm file format with which the database schema can be migrated to a later version.

Toggle description

Explore how the CREATE VIEW syntax can be used to add SQL Views to your database for common queries. Learn how this can help reduce the amount of types generated by SQLDelight.

Toggle description

Learn about some best practices for unit testing a database schema generated by SQLDelight. Furthermore, familiarize yourself with some ways to automatically validate SQL migrations by means of the Gradle plugin.

Part 2: Advanced SQLDelight Integrations

Toggle description

Learn about the integration library with RxJava 2 and 3, which allow SQLDelight’s Query type to be observed as RxJava Observables. Apply this extension to the core API of the sample app.

Toggle description

Learn about the integration library with Kotlin Coroutines, which allow SQLDelight’s Query type to be converted into Flows or suspending functions. Apply this extension to the core API of the sample app.

Toggle description

Learn about the integration library with Android Paging, which allows SQLDelight to provide a DataSource implementation that automatically pulls data from a table in a paginated fashion. Refactor the lists of the app to allow for potentially infinite scrolling, powered by Android Paging.

Up next

Android & Kotlin
Jetpack Navigation: Getting Started
In this course, learn how to use the Navigation Architecture Component provided by Android Jetpack Library to simplify navigation in your app. It also helps you visualize your app’s navigation flow. You will also learn how to add Animations and Deep links to your navigation flow.



Over 300 content creators. Join our team.