-
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.
Store feedback in PostgresSql
- Loading branch information
Showing
7 changed files
with
205 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package quizz.db | ||
|
||
import cats.effect.IO | ||
|
||
object DatabaseInitializer { | ||
|
||
def initDatabase(cfg: DatabaseConfig): IO[Int] = { | ||
import doobie._ | ||
import doobie.implicits._ | ||
import doobie.util.ExecutionContexts | ||
import cats.effect._ | ||
implicit val cs: ContextShift[IO] = IO.contextShift(ExecutionContexts.synchronous) | ||
|
||
val xa = Transactor.fromDriverManager[IO]( | ||
"org.postgresql.Driver", // driver classname | ||
s"jdbc:postgresql://${cfg.host}:${cfg.port}/${cfg.database}", // connect URL (driver-specific) | ||
cfg.user, // user | ||
cfg.password // password | ||
) | ||
val create = | ||
sql""" CREATE TABLE IF NOT EXISTS feedback | ||
( | ||
id SERIAL PRIMARY KEY, | ||
timestamp timestamp NOT NULL, | ||
quizzId varchar(300) NOT NULL, | ||
path varchar(2000) NOT NULL, | ||
comment varchar(5000) NOT NULL, | ||
rate INT NOT NULL | ||
); | ||
""".update.run | ||
create.transact(xa) | ||
} | ||
|
||
} |
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,12 @@ | ||
package quizz.db | ||
|
||
import java.util.Date | ||
|
||
case class Feedback( | ||
id: Int, | ||
timestamp: Date, | ||
quizzId: String, | ||
path: String, | ||
comment: String, | ||
rate: Int | ||
) |
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,24 @@ | ||
package quizz | ||
|
||
import com.typesafe.config.Config | ||
|
||
package object db { | ||
|
||
case class DatabaseConfig( | ||
host: String, | ||
port: Int, | ||
database: String, | ||
user: String, | ||
password: String | ||
) | ||
|
||
def databaseConfig(config: Config): DatabaseConfig = | ||
DatabaseConfig( | ||
host = config.getString("database.host"), | ||
port = config.getInt("database.port"), | ||
database = config.getString("database.dbname"), | ||
user = config.getString("database.user"), | ||
password = config.getString("database.password") | ||
) | ||
|
||
} |
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
Oops, something went wrong.