Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
openmole
openmole-connect
Commits
2abd0747
Commit
2abd0747
authored
Nov 14, 2019
by
Mathieu
Browse files
Refactor queries
parent
7113f0b6
Changes
1
Show whitespace changes
Inline
Side-by-side
server/src/main/scala/org/openmole-connect/server/DB.scala
View file @
2abd0747
...
@@ -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
)
=
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment