Commit 2abd0747 authored by Mathieu's avatar Mathieu
Browse files

Refactor queries

parent 7113f0b6
...@@ -70,13 +70,6 @@ object DB { ...@@ -70,13 +70,6 @@ object DB {
actions: _* actions: _*
).transactionally), Duration.Inf) ).transactionally), Duration.Inf)
def runQuery(query: TableQuery[DB.Users]) =
Await.result(
db.run(
query.result
), Duration.Inf
)
def initDB = { def initDB = {
runTransaction(userTable.schema.createIfNotExists) runTransaction(userTable.schema.createIfNotExists)
if (DB.users.isEmpty) { if (DB.users.isEmpty) {
...@@ -84,16 +77,21 @@ object DB { ...@@ -84,16 +77,21 @@ object DB {
} }
} }
def exists(email: Email) = { type UserQuery = Query[Users, (UUID, Email, Password, Role), Seq]
def runQuery(query: UserQuery) =
Await.result( Await.result(
db.run( db.run(
(for { query.result
), Duration.Inf
).map { case (u, e, p, r) => User(e, p, r, u) }
def exists(email: Email) = {
runQuery(
for {
u <- userTable if (u.email === email) u <- userTable if (u.email === email)
} yield (u)).result } yield (u)
).map { ).length != 0
_.length != 0
}, Duration.Inf
)
} }
def addUser(email: Email, password: Password, role: Role = simpleUser) = { def addUser(email: Email, password: Password, role: Role = simpleUser) = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment