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

Refactor queries

parent 7113f0b6
......@@ -70,13 +70,6 @@ object DB {
actions: _*
).transactionally), Duration.Inf)
def runQuery(query: TableQuery[DB.Users]) =
Await.result(
db.run(
query.result
), Duration.Inf
)
def initDB = {
runTransaction(userTable.schema.createIfNotExists)
if (DB.users.isEmpty) {
......@@ -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(
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)
} yield (u)).result
).map {
_.length != 0
}, Duration.Inf
)
} yield (u)
).length != 0
}
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