-
Notifications
You must be signed in to change notification settings - Fork 12
/
WithHandler.scala
98 lines (90 loc) · 3.53 KB
/
WithHandler.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package acolyte.reactivemongo
import scala.concurrent.{ ExecutionContext, Future }
import reactivemongo.api.{ MongoConnection, MongoDriver }
/** Functions to work with handler (provided driver functions). */
trait WithHandler { up: WithDriver ⇒
/**
* Works with a Mongo driver handling only queries,
* using given query `handler`.
* Driver and associated resources are released
* after the function `f` the result `Future` is completed.
*
* {{{
* import reactivemongo.api.MongoDriver
* import acolyte.reactivemongo.{ AcolyteDSL, Request }
*
* AcolyteDSL.withQueryHandler({ req: Request ⇒ aResponse }) { d =>
* val driver: MongoDriver = d
* "aResult"
* }
* }}}
*
* @see [[AcolyteDSL.withDriver]]
* @see [[AcolyteDSL.handleQuery]]
* @see [[AcolyteDSL.withQueryResult]]
*/
def withQueryHandler[T](handler: Request ⇒ PreparedResponse)(f: MongoDriver ⇒ T)(implicit m: DriverManager[ConnectionHandler], c: ExecutionContext): Future[T] = withDriver(AcolyteDSL handleQuery QueryHandler(handler))(f)
/**
* Works with a Mongo driver handling only queries,
* using given query `handler`.
* Driver and associated resources are released
* after the function `f` the result `Future` is completed.
*
* {{{
* import reactivemongo.api.MongoDriver
* import acolyte.reactivemongo.{ AcolyteDSL, Request }
*
* AcolyteDSL.withFlatQueryHandler({ req: Request ⇒ aResponse }) { d =>
* val driver: MongoDriver = d
* Future(1+2)
* }
* }}}
*
* @see [[AcolyteDSL.withFlatDriver]]
* @see [[AcolyteDSL.handleQuery]]
* @see [[AcolyteDSL.withQueryResult]]
*/
def withFlatQueryHandler[T](handler: Request ⇒ PreparedResponse)(f: MongoDriver ⇒ Future[T])(implicit m: DriverManager[ConnectionHandler], c: ExecutionContext): Future[T] = withFlatDriver(AcolyteDSL handleQuery QueryHandler(handler))(f)
/**
* Works with a Mongo driver handling only write operations,
* using given write `handler`.
* Driver and associated resources are released
* after the function `f` the result `Future` is completed.
*
* {{{
* import reactivemongo.api.MongoDriver
* import acolyte.reactivemongo.{ AcolyteDSL, Request, WriteOp }
*
* AcolyteDSL.withWriteHandler({ cmd: (WriteOp, Request) ⇒ aResp }) { d =>
* val driver: MongoDriver = d
* "aResult"
* }
* }}}
*
* @see [[AcolyteDSL.withDriver]]
* @see [[AcolyteDSL.handleWrite]]
* @see [[AcolyteDSL.withWriteResult]
*/
def withWriteHandler[T](handler: (WriteOp, Request) ⇒ PreparedResponse)(f: MongoDriver ⇒ T)(implicit m: DriverManager[ConnectionHandler], c: ExecutionContext): Future[T] = withDriver(AcolyteDSL handleWrite handler)(f)
/**
* Works with a Mongo driver handling only write operations,
* using given write `handler`.
* Driver and associated resources are released
* after the function `f` the result `Future` is completed.
*
* {{{
* import reactivemongo.api.MongoDriver
* import acolyte.reactivemongo.{ AcolyteDSL, Request, WriteOp }
*
* AcolyteDSL.withWriteHandler({ cmd: (WriteOp, Request) ⇒ aResp }) { d =>
* val driver: MongoDriver = d
* Future(1+2)
* }
* }}}
*
* @see [[AcolyteDSL.withFlatDriver]]
* @see [[AcolyteDSL.handleWrite]]
* @see [[AcolyteDSL.withFlatWriteResult]
*/
def withFlatWriteHandler[T](handler: (WriteOp, Request) ⇒ PreparedResponse)(f: MongoDriver ⇒ Future[T])(implicit m: DriverManager[ConnectionHandler], c: ExecutionContext): Future[T] = withFlatDriver(AcolyteDSL handleWrite handler)(f)
}