SQLDelight Migration Guide: Room to Multiplatform
- Mobile Byte Sensei
- Mar 27
- 1 min read
Migrating from Room to SQLDelight is one of the most common steps when adopting Kotlin Multiplatform. At MBS, we've migrated three production apps. Here's the step-by-step guide we wish we had when we started.
Why SQLDelight?
Room is Android-only. SQLDelight generates Kotlin code from SQL statements and works across Android, iOS, Desktop, and Web. It gives you type-safe queries, automatic schema migrations, and coroutine/flow support — all shared across platforms.
Step 1: Map Your Room Entities
Start by listing all Room @Entity classes and their @Dao interfaces. For each entity, you'll create a .sq file with CREATE TABLE and query statements. Room annotations map directly to SQL: @PrimaryKey becomes PRIMARY KEY, @ColumnInfo maps to column names, and @Relation becomes a JOIN query.
Step 2: Write SQL Schemas
Create .sq files in src/commonMain/sqldelight/. Define your tables with explicit SQL types. SQLDelight generates Kotlin data classes from these schemas — no manual mapping needed. The generated code is type-safe and null-safe, catching errors at compile time.
Step 3: Platform Drivers
SQLDelight uses platform-specific drivers: AndroidSqliteDriver for Android, NativeSqliteDriver for iOS, and JdbcSqliteDriver for Desktop/tests. Configure these in your Koin modules using expect/actual. The shared code never knows which driver it's using.
Want a detailed walkthrough with real code examples? Our KMP Mastery Course covers SQLDelight migration in Module 5, including schema versioning, complex queries, and testing strategies.
.png)
Comments