Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsJul 2, 2026·3 min de lectura

SQLDelight — Type-Safe SQL for Kotlin Multiplatform

SQLDelight generates type-safe Kotlin APIs from SQL statements, enabling compile-time verified database queries across Android, iOS, JVM, and JavaScript targets.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
SQLDelight Overview
Comando de instalación directa
npx -y tokrepo@latest install 5772c14d-75f0-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

Introduction

SQLDelight turns your SQL statements into type-safe Kotlin APIs. Instead of writing an ORM abstraction, you write real SQL and let the compiler generate the data classes and query functions, catching errors at build time rather than runtime.

What SQLDelight Does

  • Generates type-safe Kotlin code from plain SQL statements in .sq files
  • Validates SQL syntax and schema at compile time
  • Supports Kotlin Multiplatform: Android, iOS, JVM, JS, and Native targets
  • Provides coroutines-based reactive queries that re-emit on data changes
  • Handles database migrations with versioned .sqm files

Architecture Overview

SQLDelight operates as a Gradle plugin that parses .sq files containing SQL statements and schema definitions. It resolves types against the declared schema, generates Kotlin data classes matching query result columns, and produces a database interface with suspend functions. At runtime, a platform-specific driver (AndroidSqliteDriver, NativeSqliteDriver, or JdbcSqliteDriver) connects the generated code to the actual database engine.

Self-Hosting & Configuration

  • Add the Gradle plugin to your build configuration
  • Create a sqldelight block specifying the database name and package
  • Place .sq files in src/commonMain/sqldelight for shared queries
  • Configure platform-specific drivers in each target's source set
  • Use the generateSqlDelightInterface Gradle task to produce code

Key Features

  • SQL-first approach: write real SQL, not a DSL or annotations
  • Compile-time schema validation catches typos and type mismatches before runtime
  • Multiplatform support with a single set of SQL files shared across targets
  • Reactive queries via Flow integration for automatic UI updates
  • Built-in migration tooling with verification and testing support

Comparison with Similar Tools

  • Room — Android-only annotation processor; SQLDelight is multiplatform and SQL-first
  • Exposed — Kotlin DSL that abstracts SQL; SQLDelight keeps you writing raw SQL with type safety
  • Realm — object-oriented mobile database; SQLDelight uses standard SQLite with generated code
  • JOOQ — JVM-only with a Java-centric DSL; SQLDelight targets Kotlin Multiplatform
  • Drift (Moor) — Dart/Flutter equivalent; SQLDelight serves the Kotlin ecosystem

FAQ

Q: Which databases does SQLDelight support? A: SQLDelight supports SQLite (all platforms), MySQL (JVM), PostgreSQL (JVM), and HSQL/H2 (JVM). SQLite is the primary target for multiplatform projects.

Q: Can I use SQLDelight with existing databases? A: Yes. Point SQLDelight at your existing schema and it generates code for your queries. Migration files handle schema evolution.

Q: How does SQLDelight handle migrations? A: Numbered .sqm files contain ALTER TABLE and other DDL statements. SQLDelight verifies that each migration produces the expected schema at compile time.

Q: Does SQLDelight work with Jetpack Compose? A: Yes. SQLDelight queries return Kotlin Flow objects that integrate directly with Compose state collection via collectAsState.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados