...

/

Starting the Application

Starting the Application

Learn how to define the main entrypoint and interact with the pure implementation of the service.

Main application

Within our main entry point, we initialize all needed components and wire them together. We’ll step through each part in this section.

The first thing you’ll notice is that we use the IOApp provided by the Cats effect library.

Press + to interact
object Pure extends IOApp {
@SuppressWarnings(Array("org.wartremover.warts.Any"))
def run(args: List[String]): IO[ExitCode] = ???
}

We need to suppress a warning from wartremover (Line 2) here as well.

Database initialization

Let’s continue to initialize the database connection.

Press + to interact
val migrator: DatabaseMigrator[IO] = new FlywayDatabaseMigrator
val program = for {
(apiConfig, dbConfig) <- IO {
val cfg = ConfigFactory.load
(loadConfigOrThrow[ApiConfig](cfg, "api"),
loadConfigOrThrow[DatabaseConfig](cfg, "database"))
}
ms <- migrator.migrate(dbConfig.url, dbConfig.user, dbConfig.pass)
tx = Transactor
.fromDriverManager[IO](dbConfig.driver,
dbConfig.url,
dbConfig.user,
dbConfig.pass)
repo = new DoobieRepository(tx)

We create our database migrator explicitly wired to the IO data type.

Now, we ...

Access this course and 1400+ top-rated courses and projects.