diff options
author | Jakob Odersky <jakob@odersky.com> | 2018-10-27 18:45:06 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2018-10-27 18:45:06 -0700 |
commit | de095d377859887352c7380e52ea89bcabf662a0 (patch) | |
tree | 6cee6eb17c1977b85e01078e926499b33854047d /src/main/scala/byspel/app/modules.scala | |
download | byspel-de095d377859887352c7380e52ea89bcabf662a0.tar.gz byspel-de095d377859887352c7380e52ea89bcabf662a0.tar.bz2 byspel-de095d377859887352c7380e52ea89bcabf662a0.zip |
Initial commit
Diffstat (limited to 'src/main/scala/byspel/app/modules.scala')
-rw-r--r-- | src/main/scala/byspel/app/modules.scala | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/main/scala/byspel/app/modules.scala b/src/main/scala/byspel/app/modules.scala new file mode 100644 index 0000000..a4b85ae --- /dev/null +++ b/src/main/scala/byspel/app/modules.scala @@ -0,0 +1,51 @@ +package byspel +package app + +import akka.http.scaladsl.Http +import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport +import akka.http.scaladsl.server.{Directives, Route} +import spray.json.DefaultJsonProtocol +import scala.concurrent.Await +import scala.concurrent.duration._ + +trait HttpApi + extends Directives + with SprayJsonSupport + with DefaultJsonProtocol { + def route: Route +} + +trait HttpApp extends App { self: HttpApi => + + override def start() = { + super.start() + log("binding to interface") + val future = + Http().bindAndHandle(route, config.http.address, config.http.port) + Await.result(future, 2.seconds) + } + +} + +trait DatabaseApi extends Tables { + val profile = Tables.profile + import profile.api._ + + def database: Database + +} + +trait DatabaseApp extends App { self: DatabaseApi => + import profile.api.Database + + lazy val database: Database = Database.forURL( + s"jdbc:sqlite:${config.database.file}", + driver = "org.sqlite.JDBC" + ) + + override def start() = { + super.start() + log("initializing database") + database + } +} |