write-local-datasource

Implements SQLDelight local data layers with DAOs, mappers, migrations, and DI registration.

1.6k|163|Updated Jan 10, 2018
One-click install
npx skills add https://github.com/igorescodro/alkaa --skill write-local-datasource
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: write-local-datasource
Source: https://github.com/igorescodro/alkaa/tree/main/.claude/skills/write-local-datasource
Command: npx skills add https://github.com/igorescodro/alkaa --skill write-local-datasource

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

Adding local persistence to a Kotlin Multiplatform feature requires coordinating eight distinct phases — DataSource interface, SQLDelight schema, migrations, DAO, mapper, LocalDataSource, and DI — each with strict conventions that are easy to get wrong.

Core Features & Use Cases

  • Eight-Phase Workflow: Guides creation of the DataSource interface, .sq schema, .sqm migrations, DAO interface and implementation, local mapper, LocalDataSource implementation, and Koin DI registration.
  • Convention Enforcement: Codifies rules such as Flow vs. suspend returns, executeAsOneOrNull() for single reads, mandatory cleanTable: queries, and singleOf/factoryOf DI scoping.
  • Migration Safety: Details .sqm file numbering, immutability, NOT NULL DEFAULT requirements, and verification via verifySqlDelightMigration.
  • Use Case: When adding a new entity like a Category table to the Alkaa app, follow the phases to produce a complete, convention-compliant local data layer ready for repository and E2E test integration.

Quick Start

Ask the AI to add local database persistence for a new entity in the Alkaa project using SQLDelight.

Frequently Asked Questions about write-local-datasource

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new SQLDelight table in a Kotlin Multiplatform project?

Create a `.sq` schema file with prefixed column names and named queries including `cleanTable:`, then build the DAO interface, DAO implementation, local mapper, LocalDataSource, and register everything in the Koin module. If the app has existing users, also add a `.sqm` migration file.

When should a DAO method return Flow versus suspend?

Use `Flow<List<T>>` without suspend for reactive, observable reads that update over time. Use `suspend` for mutations and point-in-time single reads. Never call `.first()` inside the DAO implementation for a Flow return type.

How do SQLDelight migrations work with .sqm files?

SQLDelight derives the database version from the count of `.sqm` files, where file N.sqm upgrades version N to N+1. Always update the `.sq` schema first, then add a new numbered `.sqm` file — existing `.sqm` files are immutable and must never be edited.

Why does adding a NOT NULL column fail in a SQLite migration?

SQLite rejects `ALTER TABLE ADD COLUMN` with `NOT NULL` on tables containing existing rows unless a `DEFAULT` value is provided. Always write the migration as `ALTER TABLE X ADD COLUMN col TYPE NOT NULL DEFAULT value`.

Should DataSources and DAOs use singleOf or factoryOf in Koin?

Use `singleOf` for DataSources, DAOs, and DatabaseProvider because they hold or share database state. Use `factoryOf` only for mappers, which are stateless and cheap to create. Registering a DataSource as `factoryOf` or duplicating DatabaseProvider causes Koin conflicts.