Created
April 16, 2024 12:22
-
-
Save nemoo/36071f5c8b05ecce38a26e12ebdd65bb to your computer and use it in GitHub Desktop.
Revisions
-
nemoo created this gist
Apr 16, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ //> using dep com.github.takezoe::blocking-slick:0.0.15-RC1 //> using dep org.postgresql:postgresql:42.7.3 // To run, first start a database: docker run -it -p 5432:5432 -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=playslickexample postgres import com.github.takezoe.slick.blocking.BlockingPostgresDriver.blockingApi.* import slick.jdbc.JdbcBackend case class Project(id: Long, name: String) val Projects: TableQuery[ProjectsTable] = TableQuery[ProjectsTable] class ProjectsTable(tag: Tag) extends Table[Project](tag, "project") { def id = column[Long]("id", O.AutoInc, O.PrimaryKey) def name = column[String]("name") def * = (id, name) <> (Project.apply.tupled, Project.unapply) } @main def main = println("Hello World!") val db = Database.forURL( url="jdbc:postgresql://localhost:5432/playslickexample", driver="org.postgresql.Driver", user="postgres", password="secret", ) def allProjects(implicit session: JdbcBackend#Session): List[Project] = Projects.list db.withSession { implicit session => // Projects.schema.create val project = Project(0, "Hello") val id = (Projects returning Projects.map(_.id)).insert(project) // val res = Projects.list val res = allProjects println(res.mkString("\n")) println(s"End of World! Just created id: $id") }