Skip to content

Commit 7e09647

Browse files
committed
setup template
1 parent b617203 commit 7e09647

File tree

7 files changed

+73
-20
lines changed

7 files changed

+73
-20
lines changed

README.md

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1-
# Scala starter
1+
# Doobie Quick Start
2+
3+
This is a template to help you get started playing with doobie (or to reproduce doobie bugs 🫣)
4+
5+
## Getting started
6+
7+
1. Clone this repository
8+
1. Edit `build.sbt` to set the Scala/doobie version you're using
9+
1. Run `docker-compose up -d --force-recreate` to start the DB container
10+
1. `sbt run`
11+
12+
## Next steps
13+
14+
Once you have the example running
15+
16+
- Edit `docker_db_init/setup.sql` to change the set of your database schema and data. Don't forget to to run `docker-compose up -d --force-recreate` to make sure the database is recreated with your updated setup.sql!
17+
- Edit the Scala code. The entry point of the application is `src/main/scala/example/Main.scala`
218

3-
Quick starter project for scala

build.sbt

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1+
val doobieVersion = "<SET_THIS_DOOBIE_VERSION>"
2+
// val doobieVersion = "1.0.0-RC2"
3+
14
lazy val root = Project("root", file("."))
25
.settings(commonSettings)
36
.settings(
4-
name := "Scala Starter",
7+
name := "Doobie",
58
libraryDependencies ++= Seq(
6-
"org.typelevel" %% "cats-core" % "2.9.0",
7-
"org.scalameta" %% "munit" % "0.7.29" % Test,
9+
"org.tpolecat" %% "doobie-core" % doobieVersion,
10+
"org.tpolecat" %% "doobie-postgres" % doobieVersion,
11+
"org.postgresql" % "postgresql" % "42.5.3",
812
),
913
)
1014

1115
lazy val commonSettings = Seq(
1216
version := "0.1.0",
13-
scalaVersion := "3.2.1",
17+
scalaVersion := "<SET_THIS_SCALA_VERSION>",
18+
// scalaVersion := "3.2.2",
19+
// scalaVersion := "2.13.10",
1420
scalacOptions --= {
1521
if (sys.env.get("CI").isDefined) {
1622
Seq.empty
1723
} else {
1824
Seq("-Xfatal-warnings")
1925
}
2026
},
27+
scalacOptions ++= Seq("-Xsource:3"),
2128
)

docker-compose.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: '3.8'
2+
3+
services:
4+
5+
postgres:
6+
image: postgis/postgis:15-3.3
7+
environment:
8+
POSTGRES_USER: postgres
9+
POSTGRES_PASSWORD: postgres
10+
POSTGRES_DB: repro
11+
ports:
12+
- 5432:5432
13+
volumes:
14+
- ./docker_db_init/:/docker-entrypoint-initdb.d/
15+
16+
# mysql:
17+
# image: mysql:8
18+
# environment:
19+
# MYSQL_ROOT_PASSWORD: root
20+
# MYSQL_DATABASE: repro
21+
# ports:
22+
# - 3306:3306
23+
# volumes:
24+
# - ./docker_db_init/:/docker-entrypoint-initdb.d/

docker_db_init/setup.sql

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
create table person(name TEXT, age INT);
2+
3+
insert into person (name, age) values ('Alice', 30), ('Bob', 30);

project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.6.2
1+
sbt.version=1.8.2

src/main/scala/example/Main.scala

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
package example
22

3-
object Main {
3+
import cats.effect.{IO, IOApp}
4+
import doobie.Transactor
5+
import doobie.implicits.*
46

5-
def main(args: Array[String]): Unit =
6-
println("Hello com.example.Empty Project!")
7+
object Main extends IOApp.Simple {
8+
9+
override def run: IO[Unit] = {
10+
val transactor: Transactor[IO] = Transactor.fromDriverManager[IO](
11+
"org.postgresql.Driver", // driver classname
12+
"jdbc:postgresql:repro", // connect URL (driver-specific)
13+
"postgres", // user
14+
"postgres", // password
15+
)
16+
17+
sql"SELECT name FROM person".query[String].to[List].transact(transactor).map { names =>
18+
println(names)
19+
}
20+
}
721

822
}

src/test/scala/example/ExampleSpec.scala

-10
This file was deleted.

0 commit comments

Comments
 (0)