ldbc Tutorial

ldbc is a type-safe MySQL database client written in Scala 3. It allows you to write SQL safely and concisely while leveraging Scala's powerful type system to reduce database operation errors.

Key Features of ldbc

Quick Start

Let's first take a look at the basic usage of ldbc. Here's a simple example of retrieving user information from the database and adding a new user:

import cats.effect.*
import cats.syntax.all.*
import ldbc.connector.*
import ldbc.dsl.*

// Database connection configuration
val provider =
  ConnectionProvider
    .default[IO]("127.0.0.1", 3306, "ldbc", "password", "ldbc")
    .setSSL(SSL.Trusted)

// Executing queries
val program = for
  // Retrieving user list
  users <- sql"SELECT id, name FROM user".query[(Int, String)].to[List]
  
  // Adding a new user
  _ <- sql"INSERT INTO user (name, email) VALUES ('Taro Yamada', 'yamada@example.com')".update
  
  // Checking user count after update
  count <- sql"SELECT COUNT(*) FROM user".query[Int].unsafe
yield (users, count)

// Executing the program
provider.use { conn =>
  program.transaction(conn)
}

How to Proceed with this Tutorial

This tutorial series is structured to help you learn ldbc step by step. We recommend proceeding in the following order:

1. Setup

First, let's prepare the environment for using ldbc.

2. Basic Operations

Next, let's learn frequently used features for everyday tasks.

3. Advanced Operations

After understanding the basics, let's move on to more advanced features.

Why Choose ldbc?

Now, let's start with Setup!

Detailed Navigation