aist
unknown
scala
4 years ago
1.4 kB
5
Indexable
package repository import org.scalatest.flatspec.AnyFlatSpec import cats.effect._ import cats.implicits._ import doobie._ import doobie.implicits._ import doobie.h2._ import doobie.util.ExecutionContexts import cats.syntax.apply._ class H2Spec extends AnyFlatSpec { "Given H2 connection" should "write and read from the connection" in { val transactor: Resource[IO, H2Transactor[IO]] = for { ce <- ExecutionContexts.fixedThreadPool[IO](32) // our connect EC xa <- H2Transactor.newH2Transactor[IO]( "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", // connect URL "sa", // username "", // password ce, // await connection here ) } yield xa def run(args: List[String]): IO[ExitCode] = transactor.use { xa => // Construct and run your server here! for { n <- sql"select 42".query[Int].unique.transact(xa) } yield ExitCode.Success } val drop: Update0 = sql""" DROP TABLE IF EXISTS person """.update val create: Update0 = sql""" CREATE TABLE person ( id SERIAL, name VARCHAR NOT NULL UNIQUE, age SMALLINT ) """.update (drop, create).mapN(_ + _).transact(transactor).unsafeRunSync } }
Editor is loading...