diff options
Diffstat (limited to 'src/main/scala/xyz/driver')
-rw-r--r-- | src/main/scala/xyz/driver/core/database/database.scala | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/core/database/database.scala b/src/main/scala/xyz/driver/core/database/database.scala index 8426309..7df44ba 100644 --- a/src/main/scala/xyz/driver/core/database/database.scala +++ b/src/main/scala/xyz/driver/core/database/database.scala @@ -6,9 +6,12 @@ import xyz.driver.core.date.Date import xyz.driver.core.time.Time import scala.concurrent.Future +import scala.concurrent.ExecutionContext package database { + import java.nio.file.{Files, Paths} + import com.typesafe.config.Config trait Database { @@ -136,6 +139,29 @@ package database { def dropSchema(): Unit = { Await.result(slickDal.execute(tables.schema.drop >> tables.dropNamespaceSchema), Duration.Inf) } + + def insertTestData(database: xyz.driver.core.database.Database, filePath: String)( + implicit executionContext: ExecutionContext): Future[Seq[Int]] = { + + import database.profile.api.{DBIO => _, _} + + val file = Paths.get(filePath) + val sqlLine = new String(Files.readAllBytes(file), "UTF-8") + + val createInsertProcedure = + sqlu"""CREATE PROCEDURE INSERT_TEST_DATA() + MODIFIES SQL DATA + BEGIN ATOMIC + #$sqlLine + END; + """ + + val callInserts = sqlu"""{call INSERT_TEST_DATA()}""" + + val dropInsertProcedure = sqlu"""drop PROCEDURE INSERT_TEST_DATA;""" + + Future.sequence(Seq(createInsertProcedure, callInserts, dropInsertProcedure).map(slickDal.execute)) + } } trait DatabaseObject extends ColumnTypes { |