-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d12d96a
commit 804035d
Showing
11 changed files
with
110 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package za.co.absa.fadb.slick | ||
|
||
case class Actor(actorId: Int, firstName: String, lastName: String) |
17 changes: 17 additions & 0 deletions
17
slick/src/it/scala/za/co/absa/fadb/slick/ActorSlickConverter.scala
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package za.co.absa.fadb.slick | ||
|
||
import slick.jdbc.{GetResult, PositionedResult} | ||
|
||
/** | ||
* A trait representing a converter from a Slick PositionedResult to an Actor. | ||
* The trait is to be mixed into a SlickFunction returning an Actor. | ||
*/ | ||
trait ActorSlickConverter { | ||
|
||
protected def slickConverter: GetResult[Actor] = { | ||
def converter(r: PositionedResult): Actor = { | ||
Actor(r.<<, r.<<, r.<<) | ||
} | ||
GetResult(converter) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
slick/src/it/scala/za/co/absa/fadb/slick/SlickMultipleResultFunctionTest.scala
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package za.co.absa.fadb.slick | ||
|
||
import cats.implicits._ | ||
import org.scalatest.funsuite.AnyFunSuite | ||
import slick.jdbc.SQLActionBuilder | ||
import za.co.absa.fadb.DBFunction.DBMultipleResultFunction | ||
import za.co.absa.fadb.DBSchema | ||
import za.co.absa.fadb.slick.FaDbPostgresProfile.api._ | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import scala.concurrent.duration.DurationInt | ||
import scala.concurrent.{Await, Future} | ||
|
||
class SlickMultipleResultFunctionTest extends AnyFunSuite with SlickTest { | ||
|
||
class GetActors(implicit override val schema: DBSchema, val dbEngine: SlickPgEngine) | ||
extends DBMultipleResultFunction[GetActorsQueryParameters, Actor, SlickPgEngine, Future] | ||
with SlickFunction[GetActorsQueryParameters, Actor] | ||
with ActorSlickConverter { | ||
|
||
override def fieldsToSelect: Seq[String] = super.fieldsToSelect ++ Seq("actor_id", "first_name", "last_name") | ||
|
||
override protected def sql(values: GetActorsQueryParameters): SQLActionBuilder = { | ||
sql"""SELECT #$selectEntry FROM #$functionName(${values.firstName},${values.lastName}) #$alias;""" | ||
} | ||
} | ||
|
||
private val getActors = new GetActors()(Runs, new SlickPgEngine(db)) | ||
|
||
test("SlickTest") { | ||
val expectedResultElem = Actor(49, "Pavel", "Marek") | ||
val results = getActors.apply(GetActorsQueryParameters(Some("Pavel"), Some("Marek"))) | ||
assert(Await.result(results, 5.seconds).contains(expectedResultElem)) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
slick/src/it/scala/za/co/absa/fadb/slick/SlickOptionalResultFunctionTest.scala
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package za.co.absa.fadb.slick | ||
|
||
import cats.implicits._ | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import org.scalatest.funsuite.AnyFunSuite | ||
import slick.jdbc.SQLActionBuilder | ||
import za.co.absa.fadb.DBFunction.DBOptionalResultFunction | ||
import za.co.absa.fadb.DBSchema | ||
import za.co.absa.fadb.slick.FaDbPostgresProfile.api._ | ||
|
||
import scala.concurrent.{Await, Future} | ||
import scala.concurrent.duration.DurationInt | ||
|
||
class SlickOptionalResultFunctionTest extends AnyFunSuite with SlickTest { | ||
|
||
class GetActorById(implicit override val schema: DBSchema, val dbEngine: SlickPgEngine) | ||
extends DBOptionalResultFunction[Int, Actor, SlickPgEngine, Future] | ||
with SlickFunction[Int, Actor] | ||
with ActorSlickConverter { | ||
|
||
override def fieldsToSelect: Seq[String] = super.fieldsToSelect ++ Seq("actor_id", "first_name", "last_name") | ||
|
||
override protected def sql(values: Int): SQLActionBuilder = { | ||
sql"""SELECT #$selectEntry FROM #$functionName($values) #$alias;""" | ||
} | ||
} | ||
|
||
private val getActorById = new GetActorById()(Runs, new SlickPgEngine(db)) | ||
|
||
test("SlickTest") { | ||
val expectedResultElem = Some(Actor(49, "Pavel", "Marek")) | ||
val results = getActorById.apply(49) | ||
assert(Await.result(results, 5.seconds) == expectedResultElem) | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package za.co.absa.fadb.slick | ||
|
||
import slick.jdbc.JdbcBackend.Database | ||
import za.co.absa.fadb.DBSchema | ||
|
||
trait SlickTest { | ||
case class GetActorsQueryParameters(firstName: Option[String], lastName: Option[String]) | ||
|
||
import za.co.absa.fadb.naming.implementations.SnakeCaseNaming.Implicits._ | ||
object Runs extends DBSchema | ||
|
||
val db = Database.forConfig("postgrestestdb") | ||
} |