database

Manage Postgres JDBC in Kotlin with Migrator, DAO, and transactions.

1|1|Updated Apr 9, 2024
One-click install
npx skills add https://github.com/navikt/helved-utbetaling --skill database-navikt
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: database
Source: https://github.com/navikt/helved-utbetaling/tree/main/.agents/skills/database
Command: npx skills add https://github.com/navikt/helved-utbetaling --skill database-navikt

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Solves the complexity of JDBC usage in Kotlin by providing Migrator, Dao<T>, and transactional utilities.

Core Features & Use Cases

  • Custom Migrator for managing versioned SQL migrations under main/migrations using V<n>__<description>.sql files.
  • DAO pattern via a companion object : Dao<T> on row types, enabling type-safe queries and updates without an ORM.
  • Transactional work with transaction { } to ensure atomic multi-statement operations and safe rollback on failure.
  • CoroutineDatasource (jdbcCtx) to carry a DataSource through the coroutine context and enable per-app DB access.
  • Easy wiring at startup with Jdbc.initialize and .context() to obtain a jdbcCtx for service layers.

Quick Start

Define your data models and companion object DAOs, initialize the JDBC at startup, and run DB tasks inside transaction blocks using the provided jdbcCtx.

Frequently Asked Questions about database

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

FAQPage Schema
How do I manage JDBC transactions in Kotlin coroutine contexts?

Kotlin JDBC transaction scoping is managed using transaction { } blocks to ensure atomic multi-statement operations and safe rollback on failure. A CoroutineDatasource carries the DataSource through the coroutine context to enable per-app DB access.

What is the best way to run type-safe database queries in Kotlin without an ORM?

Type-safe database queries without an ORM are achieved by implementing a companion object : Dao<T> on row types. This DAO pattern enables type-safe queries and updates directly via JDBC, avoiding the overhead of full object-relational mapping frameworks.

How do I execute versioned SQL migrations in a Kotlin application?

Versioned SQL migrations are executed using a custom Migrator that manages SQL files under main/migrations. You structure your files as V<n>__<description>.sql, and the Migrator workflow applies them to the Postgres database.

Can I use this JDBC pattern with Kotlin services managing Postgres data?

Yes, this JDBC pattern targets Kotlin services managing Postgres data with coroutine-bound contexts. It is explicitly designed for modules that require robust data access, transaction scoping, and per-context JDBC datasource initialization.

How do I initialize a JDBC datasource for service layers at startup?

JDBC datasource initialization at startup is performed using Jdbc.initialize and .context() methods. This wiring obtains a jdbcCtx for service layers, establishing the database connection required for subsequent DAO queries and transactional work.