Skip to content

Commit

Permalink
tmp code of doobie integration
Browse files Browse the repository at this point in the history
  • Loading branch information
salamonpavel committed Dec 4, 2023
1 parent 264f510 commit 27fac52
Show file tree
Hide file tree
Showing 10 changed files with 353 additions and 176 deletions.
32 changes: 32 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version = "3.5.3"
runner.dialect = scala212

maxColumn = 120

align.preset = some
align.multiline = false

align.tokens = [
{
code = "<-"
},
{
code = "=>"
owners = [{
regex = "Case"
}]
}
]

indent.main = 2
indent.defnSite = 2

lineEndings = unix

docstrings.blankFirstLine = yes
docstrings.style = AsteriskSpace
docstrings.wrap = no
docstrings.removeEmpty = true

align.openParenDefnSite = false
align.openParenCallSite = false
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ lazy val commonJacocoExcludes: Seq[String] = Seq(
)

lazy val parent = (project in file("."))
.aggregate(faDbCore, faDBSlick, faDBExamples)
.aggregate(faDbCore, faDBSlick, faDBDoobie, faDBExamples)
.settings(
name := "root",
libraryDependencies ++= rootDependencies(scalaVersion.value),
Expand Down
3 changes: 0 additions & 3 deletions core/src/main/scala/za/co/absa/fadb/DBFunction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ import scala.language.higherKinds
abstract class DBFunction[I, R, E <: DBEngine[F], F[_]: Monad](functionNameOverride: Option[String] = None)
(implicit val schema: DBSchema, val dBEngine: E) extends DBFunctionFabric {

/* alternative constructors for different availability of input parameters */


/**
* Function to create the DB function call specific to the provided [[DBEngine]]. Expected to be implemented by the
* DBEngine specific mix-in.
Expand Down
132 changes: 69 additions & 63 deletions core/src/test/scala/za/co/absa/fadb/DBFunctionSuite.scala
Original file line number Diff line number Diff line change
@@ -1,63 +1,69 @@
///*
// * Copyright 2022 ABSA Group Limited
// *
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
//
//package za.co.absa.fadb
//
//import org.scalatest.funsuite.AnyFunSuite
//
//import scala.concurrent.{ExecutionContext, Future}
//import za.co.absa.fadb.naming.implementations.SnakeCaseNaming.Implicits.namingConvention
//
//class DBFunctionSuite extends AnyFunSuite {
//
// private def neverHappens: Nothing = {
// throw new Exception("Should never get here")
// }
//
// private implicit object EngineThrow extends DBEngine {
// override def run[R](query: QueryType[R]): Future[Seq[R]] = neverHappens
//
// override implicit val executor: ExecutionContext = ExecutionContext.Implicits.global
// }
//
// private object FooNamed extends DBSchema
// private object FooNameless extends DBSchema("")
//
// test("Function name check"){
// case class MyFunction(override val schema: DBSchema) extends DBFunction[Unit, Unit, DBEngine](schema) {
// override protected def query(values: Unit): dBEngine.QueryType[Unit] = neverHappens
// }
//
// val fnc1 = MyFunction(FooNamed)
// val fnc2 = MyFunction(FooNameless)
//
// assert(fnc1.functionName == "foo_named.my_function")
// assert(fnc2.functionName == "my_function")
// }
//
// test("Function name override check"){
// case class MyFunction(override val schema: DBSchema) extends DBFunction[Unit, Unit, DBEngine](schema, "bar") {
// override protected def query(values: Unit): dBEngine.QueryType[Unit] = neverHappens
// }
//
// val fnc1 = MyFunction(FooNamed)
// val fnc2 = MyFunction(FooNameless)
//
// assert(fnc1.functionName == "foo_named.bar")
// assert(fnc2.functionName == "bar")
// }
//
//}
/*
* Copyright 2022 ABSA Group Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package za.co.absa.fadb

import cats.implicits._
import org.scalatest.funsuite.AnyFunSuite
import za.co.absa.fadb.DBFunction.DBSingleResultFunction
import za.co.absa.fadb.naming.implementations.SnakeCaseNaming.Implicits.namingConvention

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

class DBFunctionSuite extends AnyFunSuite {

private def neverHappens: Nothing = {
throw new Exception("Should never get here")
}

class EngineThrow extends DBEngine[Future] {
override def run[R](query: QueryType[R]): Future[Seq[R]] = neverHappens
}

private object FooNamed extends DBSchema
private object FooNameless extends DBSchema("")

test("Function name check"){

class MyFunction(functionNameOverride: Option[String] = None)(implicit override val schema: DBSchema, val dbEngine: EngineThrow)
extends DBSingleResultFunction[Unit, Unit, EngineThrow, Future](None) {

override protected def query(values: Unit): dBEngine.QueryType[Unit] = neverHappens
}

val fnc1 = new MyFunction()(FooNamed, new EngineThrow)
val fnc2 = new MyFunction()(FooNameless, new EngineThrow)

assert(fnc1.functionName == "foo_named.my_function")
assert(fnc2.functionName == "my_function")
}

test("Function name override check"){
class MyFunction(implicit override val schema: DBSchema, val dbEngine: EngineThrow)
extends DBSingleResultFunction[Unit, Unit, EngineThrow, Future](Some("bar")) {

override protected def query(values: Unit): dBEngine.QueryType[Unit] = neverHappens
}

val fnc1 = new MyFunction()(FooNamed, new EngineThrow)
val fnc2 = new MyFunction()(FooNameless, new EngineThrow)

assert(fnc1.functionName == "foo_named.bar")
assert(fnc2.functionName == "bar")
}

}
Loading

0 comments on commit 27fac52

Please sign in to comment.