0PricingLogin
Scala for Backend Engineering & Functional Programming · Lesson

Connecting with a Transactor

Set up database access.

What Is a Transactor?

Doobie is a pure functional JDBC layer for Scala. A Transactor[F] is the bridge between Doobie's pure programs and a real database connection.

A Transactor knows how to acquire a JDBC Connection, run your program inside a transaction, and release resources safely.

It is parameterized by an effect type F[_] such as cats.effect.IO.

import doobie._
import cats.effect.IO

val xa: Transactor[IO] = ???

The ConnectionIO Program

Doobie queries are values of type ConnectionIO[A]. They describe a computation that needs a JDBC connection but do not run yet.

You build these programs purely, then hand them to a Transactor to execute them. Nothing touches the database until you run it.

import doobie.implicits._

val program: ConnectionIO[Int] =
  sql"select 42".query[Int].unique

All lessons in this course

  1. Connecting with a Transactor
  2. Running Queries
  3. Inserts and Updates
  4. Composing Transactions
← Back to Scala for Backend Engineering & Functional Programming