You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "minjibir (via GitHub)" <gi...@apache.org> on 2025/01/12 22:32:51 UTC
[PR] Slick - Add slick flow functions with error handling using try. [pekko-connectors]
minjibir opened a new pull request, #949:
URL: https://github.com/apache/pekko-connectors/pull/949
(no comment)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Slick - Add slick flow functions with error handling using try. [pekko-connectors]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #949:
URL: https://github.com/apache/pekko-connectors/pull/949#issuecomment-2585957885
My preference would be not to change the 'Slick' object. Could you just create just create a 2nd 'SlickWithTryResult' or something like that?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Slick - Add slick flow functions with error handling using try. [pekko-connectors]
Posted by "minjibir (via GitHub)" <gi...@apache.org>.
minjibir commented on code in PR #949:
URL: https://github.com/apache/pekko-connectors/pull/949#discussion_r1928044154
##########
slick/src/test/scala/docs/scaladsl/SlickWithTryResultSpec.scala:
##########
@@ -0,0 +1,355 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+/*
+ * Copyright (C) since 2016 Lightbend Inc. <https://www.lightbend.com>
+ */
+
+package docs.scaladsl
+
+import org.apache.pekko
+import pekko.Done
+import pekko.actor.ActorSystem
+import pekko.stream.connectors.slick.scaladsl.{ Slick, SlickSession, SlickWithTryResult }
+import pekko.stream.connectors.testkit.scaladsl.LogCapturing
+import pekko.stream.scaladsl._
+import pekko.testkit.TestKit
+
+import org.scalatest._
+import org.scalatest.concurrent.ScalaFutures
+import org.scalatest.matchers.must.Matchers
+import org.scalatest.wordspec.AnyWordSpec
+
+import slick.dbio.DBIOAction
+import slick.jdbc.GetResult
+
+import scala.concurrent.duration._
+import scala.concurrent.{ Await, ExecutionContext, Future }
+import scala.util.{ Failure, Success }
+
+class SlickWithTryResultSpec extends AnyWordSpec
+ with ScalaFutures
+ with BeforeAndAfterEach
+ with BeforeAndAfterAll
+ with Matchers
+ with LogCapturing {
+ // #init-mat
+ implicit val system: ActorSystem = ActorSystem()
+ // #init-mat
+
+ // #init-session
+ implicit val session: SlickSession = SlickSession.forConfig("slick-h2")
+ // #init-session
+
+ import session.profile.api._
+
+ case class User(id: Int, name: String)
+ class Users(tag: Tag) extends Table[(Int, String)](tag, "PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS") {
+ def id = column[Int]("ID", O.PrimaryKey)
+ def name = column[String]("NAME")
+ def * = (id, name)
+ }
+
+ implicit val ec: ExecutionContext = system.dispatcher
+ implicit val defaultPatience: PatienceConfig = PatienceConfig(timeout = 3.seconds, interval = 50.millis)
+ implicit val getUserResult: GetResult[User] = GetResult(r => User(r.nextInt(), r.nextString()))
+
+ val users = (1 to 40).map(i => User(i, s"Name$i")).toSet
+ val duplicateUser = scala.collection.immutable.Seq(users.head, users.head)
+
+ val createTable =
+ sqlu"""CREATE TABLE PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS(ID INTEGER PRIMARY KEY, NAME VARCHAR(50))"""
+ val dropTable = sqlu"""DROP TABLE PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS"""
+ val selectAllUsers = sql"SELECT ID, NAME FROM PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS".as[User]
+ val typedSelectAllUsers = TableQuery[Users].result
+
+ def insertUser(user: User): DBIO[Int] =
+ sqlu"INSERT INTO PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS VALUES(${user.id}, ${user.name})"
+
+ def getAllUsersFromDb: Future[Set[User]] = Slick.source(selectAllUsers).runWith(Sink.seq).map(_.toSet)
+ def populate(): Unit = {
+ val actions = users.map(insertUser)
+
+ // This uses the standard Slick API exposed by the Slick session
+ // on purpose, just to double-check that inserting data through
+ // our Pekko connectors is equivalent to inserting it the Slick way.
+ session.db.run(DBIO.seq(actions.toList: _*)).futureValue
+ }
+
+ override def beforeEach(): Unit = session.db.run(createTable).futureValue
+ override def afterEach(): Unit = session.db.run(dropTable).futureValue
+
+ override def afterAll(): Unit = {
+ // #close-session
+ system.registerOnTermination(() => session.close())
+ // #close-session
+
+ TestKit.shutdownActorSystem(system)
+ }
+
+ "SlickSession.forDbAndProfile" must {
+ "create a slick session able to talk to the db" in {
+ // #init-session-from-db-and-profile
+ val db = Database.forConfig("slick-h2.db")
+ val profile = slick.jdbc.H2Profile
+ val slickSessionCreatedForDbAndProfile: SlickSession = SlickSession.forDbAndProfile(db, profile)
+ // #init-session-from-db-and-profile
+ try {
+ val q = sql"select true".as[Boolean]
+ val result = Slick
Review Comment:
Ok, I will do so.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Slick - Add slick flow functions with error handling using try. [pekko-connectors]
Posted by "minjibir (via GitHub)" <gi...@apache.org>.
minjibir commented on PR #949:
URL: https://github.com/apache/pekko-connectors/pull/949#issuecomment-2594413662
@pjfanning file headers updated. Thank you for pointing that out.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Slick - Add slick flow functions with error handling using try. [pekko-connectors]
Posted by "minjibir (via GitHub)" <gi...@apache.org>.
minjibir commented on code in PR #949:
URL: https://github.com/apache/pekko-connectors/pull/949#discussion_r1927787321
##########
slick/src/test/scala/docs/scaladsl/SlickWithTryResultSpec.scala:
##########
@@ -0,0 +1,355 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+/*
+ * Copyright (C) since 2016 Lightbend Inc. <https://www.lightbend.com>
+ */
+
+package docs.scaladsl
+
+import org.apache.pekko
+import pekko.Done
+import pekko.actor.ActorSystem
+import pekko.stream.connectors.slick.scaladsl.{ Slick, SlickSession, SlickWithTryResult }
+import pekko.stream.connectors.testkit.scaladsl.LogCapturing
+import pekko.stream.scaladsl._
+import pekko.testkit.TestKit
+
+import org.scalatest._
+import org.scalatest.concurrent.ScalaFutures
+import org.scalatest.matchers.must.Matchers
+import org.scalatest.wordspec.AnyWordSpec
+
+import slick.dbio.DBIOAction
+import slick.jdbc.GetResult
+
+import scala.concurrent.duration._
+import scala.concurrent.{ Await, ExecutionContext, Future }
+import scala.util.{ Failure, Success }
+
+class SlickWithTryResultSpec extends AnyWordSpec
+ with ScalaFutures
+ with BeforeAndAfterEach
+ with BeforeAndAfterAll
+ with Matchers
+ with LogCapturing {
+ // #init-mat
+ implicit val system: ActorSystem = ActorSystem()
+ // #init-mat
+
+ // #init-session
+ implicit val session: SlickSession = SlickSession.forConfig("slick-h2")
+ // #init-session
+
+ import session.profile.api._
+
+ case class User(id: Int, name: String)
+ class Users(tag: Tag) extends Table[(Int, String)](tag, "PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS") {
+ def id = column[Int]("ID", O.PrimaryKey)
+ def name = column[String]("NAME")
+ def * = (id, name)
+ }
+
+ implicit val ec: ExecutionContext = system.dispatcher
+ implicit val defaultPatience: PatienceConfig = PatienceConfig(timeout = 3.seconds, interval = 50.millis)
+ implicit val getUserResult: GetResult[User] = GetResult(r => User(r.nextInt(), r.nextString()))
+
+ val users = (1 to 40).map(i => User(i, s"Name$i")).toSet
+ val duplicateUser = scala.collection.immutable.Seq(users.head, users.head)
+
+ val createTable =
+ sqlu"""CREATE TABLE PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS(ID INTEGER PRIMARY KEY, NAME VARCHAR(50))"""
+ val dropTable = sqlu"""DROP TABLE PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS"""
+ val selectAllUsers = sql"SELECT ID, NAME FROM PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS".as[User]
+ val typedSelectAllUsers = TableQuery[Users].result
+
+ def insertUser(user: User): DBIO[Int] =
+ sqlu"INSERT INTO PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS VALUES(${user.id}, ${user.name})"
+
+ def getAllUsersFromDb: Future[Set[User]] = Slick.source(selectAllUsers).runWith(Sink.seq).map(_.toSet)
+ def populate(): Unit = {
+ val actions = users.map(insertUser)
+
+ // This uses the standard Slick API exposed by the Slick session
+ // on purpose, just to double-check that inserting data through
+ // our Pekko connectors is equivalent to inserting it the Slick way.
+ session.db.run(DBIO.seq(actions.toList: _*)).futureValue
+ }
+
+ override def beforeEach(): Unit = session.db.run(createTable).futureValue
+ override def afterEach(): Unit = session.db.run(dropTable).futureValue
+
+ override def afterAll(): Unit = {
+ // #close-session
+ system.registerOnTermination(() => session.close())
+ // #close-session
+
+ TestKit.shutdownActorSystem(system)
+ }
+
+ "SlickSession.forDbAndProfile" must {
+ "create a slick session able to talk to the db" in {
+ // #init-session-from-db-and-profile
+ val db = Database.forConfig("slick-h2.db")
+ val profile = slick.jdbc.H2Profile
+ val slickSessionCreatedForDbAndProfile: SlickSession = SlickSession.forDbAndProfile(db, profile)
+ // #init-session-from-db-and-profile
+ try {
+ val q = sql"select true".as[Boolean]
+ val result = Slick
Review Comment:
I was trying to keep it DRY by using the source from `Slick` to setup the test since the implimentation is identical, and that the main purpose of the `SlickWithTryResult` is during the write operations. Would it be better if I have the same `source` function in `SlickWithTryResult` as well?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Slick - Add slick flow functions with error handling using try. [pekko-connectors]
Posted by "minjibir (via GitHub)" <gi...@apache.org>.
minjibir commented on code in PR #949:
URL: https://github.com/apache/pekko-connectors/pull/949#discussion_r1927695343
##########
slick/src/test/scala/docs/scaladsl/SlickWithTryResultSpec.scala:
##########
@@ -0,0 +1,355 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+/*
+ * Copyright (C) since 2016 Lightbend Inc. <https://www.lightbend.com>
+ */
+
+package docs.scaladsl
+
+import org.apache.pekko
+import pekko.Done
+import pekko.actor.ActorSystem
+import pekko.stream.connectors.slick.scaladsl.{ Slick, SlickSession, SlickWithTryResult }
+import pekko.stream.connectors.testkit.scaladsl.LogCapturing
+import pekko.stream.scaladsl._
+import pekko.testkit.TestKit
+
+import org.scalatest._
+import org.scalatest.concurrent.ScalaFutures
+import org.scalatest.matchers.must.Matchers
+import org.scalatest.wordspec.AnyWordSpec
+
+import slick.dbio.DBIOAction
+import slick.jdbc.GetResult
+
+import scala.concurrent.duration._
+import scala.concurrent.{ Await, ExecutionContext, Future }
+import scala.util.{ Failure, Success }
+
+class SlickWithTryResultSpec extends AnyWordSpec
+ with ScalaFutures
+ with BeforeAndAfterEach
+ with BeforeAndAfterAll
+ with Matchers
+ with LogCapturing {
+ // #init-mat
+ implicit val system: ActorSystem = ActorSystem()
+ // #init-mat
+
+ // #init-session
+ implicit val session: SlickSession = SlickSession.forConfig("slick-h2")
+ // #init-session
+
+ import session.profile.api._
+
+ case class User(id: Int, name: String)
+ class Users(tag: Tag) extends Table[(Int, String)](tag, "PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS") {
+ def id = column[Int]("ID", O.PrimaryKey)
+ def name = column[String]("NAME")
+ def * = (id, name)
+ }
+
+ implicit val ec: ExecutionContext = system.dispatcher
+ implicit val defaultPatience: PatienceConfig = PatienceConfig(timeout = 3.seconds, interval = 50.millis)
+ implicit val getUserResult: GetResult[User] = GetResult(r => User(r.nextInt(), r.nextString()))
+
+ val users = (1 to 40).map(i => User(i, s"Name$i")).toSet
+ val duplicateUser = scala.collection.immutable.Seq(users.head, users.head)
+
+ val createTable =
+ sqlu"""CREATE TABLE PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS(ID INTEGER PRIMARY KEY, NAME VARCHAR(50))"""
+ val dropTable = sqlu"""DROP TABLE PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS"""
+ val selectAllUsers = sql"SELECT ID, NAME FROM PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS".as[User]
+ val typedSelectAllUsers = TableQuery[Users].result
+
+ def insertUser(user: User): DBIO[Int] =
+ sqlu"INSERT INTO PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS VALUES(${user.id}, ${user.name})"
+
+ def getAllUsersFromDb: Future[Set[User]] = Slick.source(selectAllUsers).runWith(Sink.seq).map(_.toSet)
+ def populate(): Unit = {
+ val actions = users.map(insertUser)
+
+ // This uses the standard Slick API exposed by the Slick session
+ // on purpose, just to double-check that inserting data through
+ // our Pekko connectors is equivalent to inserting it the Slick way.
+ session.db.run(DBIO.seq(actions.toList: _*)).futureValue
+ }
+
+ override def beforeEach(): Unit = session.db.run(createTable).futureValue
+ override def afterEach(): Unit = session.db.run(dropTable).futureValue
+
+ override def afterAll(): Unit = {
+ // #close-session
+ system.registerOnTermination(() => session.close())
+ // #close-session
+
+ TestKit.shutdownActorSystem(system)
+ }
+
+ "SlickSession.forDbAndProfile" must {
+ "create a slick session able to talk to the db" in {
+ // #init-session-from-db-and-profile
+ val db = Database.forConfig("slick-h2.db")
+ val profile = slick.jdbc.H2Profile
+ val slickSessionCreatedForDbAndProfile: SlickSession = SlickSession.forDbAndProfile(db, profile)
+ // #init-session-from-db-and-profile
+ try {
+ val q = sql"select true".as[Boolean]
+ val result = Slick
Review Comment:
Let me check it out.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Slick - Add slick flow functions with error handling using try. [pekko-connectors]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #949:
URL: https://github.com/apache/pekko-connectors/pull/949#discussion_r1927807378
##########
slick/src/test/scala/docs/scaladsl/SlickWithTryResultSpec.scala:
##########
@@ -0,0 +1,355 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+/*
+ * Copyright (C) since 2016 Lightbend Inc. <https://www.lightbend.com>
+ */
+
+package docs.scaladsl
+
+import org.apache.pekko
+import pekko.Done
+import pekko.actor.ActorSystem
+import pekko.stream.connectors.slick.scaladsl.{ Slick, SlickSession, SlickWithTryResult }
+import pekko.stream.connectors.testkit.scaladsl.LogCapturing
+import pekko.stream.scaladsl._
+import pekko.testkit.TestKit
+
+import org.scalatest._
+import org.scalatest.concurrent.ScalaFutures
+import org.scalatest.matchers.must.Matchers
+import org.scalatest.wordspec.AnyWordSpec
+
+import slick.dbio.DBIOAction
+import slick.jdbc.GetResult
+
+import scala.concurrent.duration._
+import scala.concurrent.{ Await, ExecutionContext, Future }
+import scala.util.{ Failure, Success }
+
+class SlickWithTryResultSpec extends AnyWordSpec
+ with ScalaFutures
+ with BeforeAndAfterEach
+ with BeforeAndAfterAll
+ with Matchers
+ with LogCapturing {
+ // #init-mat
+ implicit val system: ActorSystem = ActorSystem()
+ // #init-mat
+
+ // #init-session
+ implicit val session: SlickSession = SlickSession.forConfig("slick-h2")
+ // #init-session
+
+ import session.profile.api._
+
+ case class User(id: Int, name: String)
+ class Users(tag: Tag) extends Table[(Int, String)](tag, "PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS") {
+ def id = column[Int]("ID", O.PrimaryKey)
+ def name = column[String]("NAME")
+ def * = (id, name)
+ }
+
+ implicit val ec: ExecutionContext = system.dispatcher
+ implicit val defaultPatience: PatienceConfig = PatienceConfig(timeout = 3.seconds, interval = 50.millis)
+ implicit val getUserResult: GetResult[User] = GetResult(r => User(r.nextInt(), r.nextString()))
+
+ val users = (1 to 40).map(i => User(i, s"Name$i")).toSet
+ val duplicateUser = scala.collection.immutable.Seq(users.head, users.head)
+
+ val createTable =
+ sqlu"""CREATE TABLE PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS(ID INTEGER PRIMARY KEY, NAME VARCHAR(50))"""
+ val dropTable = sqlu"""DROP TABLE PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS"""
+ val selectAllUsers = sql"SELECT ID, NAME FROM PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS".as[User]
+ val typedSelectAllUsers = TableQuery[Users].result
+
+ def insertUser(user: User): DBIO[Int] =
+ sqlu"INSERT INTO PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS VALUES(${user.id}, ${user.name})"
+
+ def getAllUsersFromDb: Future[Set[User]] = Slick.source(selectAllUsers).runWith(Sink.seq).map(_.toSet)
+ def populate(): Unit = {
+ val actions = users.map(insertUser)
+
+ // This uses the standard Slick API exposed by the Slick session
+ // on purpose, just to double-check that inserting data through
+ // our Pekko connectors is equivalent to inserting it the Slick way.
+ session.db.run(DBIO.seq(actions.toList: _*)).futureValue
+ }
+
+ override def beforeEach(): Unit = session.db.run(createTable).futureValue
+ override def afterEach(): Unit = session.db.run(dropTable).futureValue
+
+ override def afterAll(): Unit = {
+ // #close-session
+ system.registerOnTermination(() => session.close())
+ // #close-session
+
+ TestKit.shutdownActorSystem(system)
+ }
+
+ "SlickSession.forDbAndProfile" must {
+ "create a slick session able to talk to the db" in {
+ // #init-session-from-db-and-profile
+ val db = Database.forConfig("slick-h2.db")
+ val profile = slick.jdbc.H2Profile
+ val slickSessionCreatedForDbAndProfile: SlickSession = SlickSession.forDbAndProfile(db, profile)
+ // #init-session-from-db-and-profile
+ try {
+ val q = sql"select true".as[Boolean]
+ val result = Slick
Review Comment:
why not delete this test case if the test is already in the SlickSpec?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Slick - Add slick flow functions with error handling using try. [pekko-connectors]
Posted by "minjibir (via GitHub)" <gi...@apache.org>.
minjibir commented on PR #949:
URL: https://github.com/apache/pekko-connectors/pull/949#issuecomment-2585977209
Absolutely. That's my first implementation, but later settled with this. I will change it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Slick - Add slick flow functions with error handling using try. [pekko-connectors]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #949:
URL: https://github.com/apache/pekko-connectors/pull/949#issuecomment-2598582118
I have committed some code changes but I'm not sure if they work yet.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Slick - Add slick flow functions with error handling using try. [pekko-connectors]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #949:
URL: https://github.com/apache/pekko-connectors/pull/949#issuecomment-2598085540
the code doesn't compile in scala 2.12
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Slick - Add slick flow functions with error handling using try. [pekko-connectors]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #949:
URL: https://github.com/apache/pekko-connectors/pull/949
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Slick - Add slick flow functions with error handling using try. [pekko-connectors]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #949:
URL: https://github.com/apache/pekko-connectors/pull/949#discussion_r1920347934
##########
slick/src/test/scala/docs/scaladsl/SlickWithTryResultSpec.scala:
##########
@@ -0,0 +1,355 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+/*
+ * Copyright (C) since 2016 Lightbend Inc. <https://www.lightbend.com>
+ */
+
+package docs.scaladsl
+
+import org.apache.pekko
+import pekko.Done
+import pekko.actor.ActorSystem
+import pekko.stream.connectors.slick.scaladsl.{ Slick, SlickSession, SlickWithTryResult }
+import pekko.stream.connectors.testkit.scaladsl.LogCapturing
+import pekko.stream.scaladsl._
+import pekko.testkit.TestKit
+
+import org.scalatest._
+import org.scalatest.concurrent.ScalaFutures
+import org.scalatest.matchers.must.Matchers
+import org.scalatest.wordspec.AnyWordSpec
+
+import slick.dbio.DBIOAction
+import slick.jdbc.GetResult
+
+import scala.concurrent.duration._
+import scala.concurrent.{ Await, ExecutionContext, Future }
+import scala.util.{ Failure, Success }
+
+class SlickWithTryResultSpec extends AnyWordSpec
+ with ScalaFutures
+ with BeforeAndAfterEach
+ with BeforeAndAfterAll
+ with Matchers
+ with LogCapturing {
+ // #init-mat
+ implicit val system: ActorSystem = ActorSystem()
+ // #init-mat
+
+ // #init-session
+ implicit val session: SlickSession = SlickSession.forConfig("slick-h2")
+ // #init-session
+
+ import session.profile.api._
+
+ case class User(id: Int, name: String)
+ class Users(tag: Tag) extends Table[(Int, String)](tag, "PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS") {
+ def id = column[Int]("ID", O.PrimaryKey)
+ def name = column[String]("NAME")
+ def * = (id, name)
+ }
+
+ implicit val ec: ExecutionContext = system.dispatcher
+ implicit val defaultPatience: PatienceConfig = PatienceConfig(timeout = 3.seconds, interval = 50.millis)
+ implicit val getUserResult: GetResult[User] = GetResult(r => User(r.nextInt(), r.nextString()))
+
+ val users = (1 to 40).map(i => User(i, s"Name$i")).toSet
+ val duplicateUser = scala.collection.immutable.Seq(users.head, users.head)
+
+ val createTable =
+ sqlu"""CREATE TABLE PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS(ID INTEGER PRIMARY KEY, NAME VARCHAR(50))"""
+ val dropTable = sqlu"""DROP TABLE PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS"""
+ val selectAllUsers = sql"SELECT ID, NAME FROM PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS".as[User]
+ val typedSelectAllUsers = TableQuery[Users].result
+
+ def insertUser(user: User): DBIO[Int] =
+ sqlu"INSERT INTO PEKKO_CONNECTORS_SLICK_SCALADSL_TEST_USERS VALUES(${user.id}, ${user.name})"
+
+ def getAllUsersFromDb: Future[Set[User]] = Slick.source(selectAllUsers).runWith(Sink.seq).map(_.toSet)
+ def populate(): Unit = {
+ val actions = users.map(insertUser)
+
+ // This uses the standard Slick API exposed by the Slick session
+ // on purpose, just to double-check that inserting data through
+ // our Pekko connectors is equivalent to inserting it the Slick way.
+ session.db.run(DBIO.seq(actions.toList: _*)).futureValue
+ }
+
+ override def beforeEach(): Unit = session.db.run(createTable).futureValue
+ override def afterEach(): Unit = session.db.run(dropTable).futureValue
+
+ override def afterAll(): Unit = {
+ // #close-session
+ system.registerOnTermination(() => session.close())
+ // #close-session
+
+ TestKit.shutdownActorSystem(system)
+ }
+
+ "SlickSession.forDbAndProfile" must {
+ "create a slick session able to talk to the db" in {
+ // #init-session-from-db-and-profile
+ val db = Database.forConfig("slick-h2.db")
+ val profile = slick.jdbc.H2Profile
+ val slickSessionCreatedForDbAndProfile: SlickSession = SlickSession.forDbAndProfile(db, profile)
+ // #init-session-from-db-and-profile
+ try {
+ val q = sql"select true".as[Boolean]
+ val result = Slick
Review Comment:
@minjibir why is this testing the 'Slick' object and not the new SlickWithTryResult object?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Slick - Add slick flow functions with error handling using try. [pekko-connectors]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #949:
URL: https://github.com/apache/pekko-connectors/pull/949#issuecomment-2598589428
seeing test failure in `insert 40 records into a table (no parallelism)` (new Slick with try support test)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org