Raise exn on write error
This commit is contained in:
parent
711855037b
commit
20a9ea461c
@ -11,6 +11,9 @@ open System.Threading.Tasks
|
|||||||
/// Computation Expression builder for RethinkDB queries
|
/// Computation Expression builder for RethinkDB queries
|
||||||
type RethinkBuilder<'T> () =
|
type RethinkBuilder<'T> () =
|
||||||
|
|
||||||
|
/// Await a Task (avoids using the task CE when we may raise exceptions)
|
||||||
|
let await = Async.AwaitTask >> Async.RunSynchronously
|
||||||
|
|
||||||
/// Create a RethinkDB hash map of the given field/value pairs
|
/// Create a RethinkDB hash map of the given field/value pairs
|
||||||
let fieldsToMap (fields : (string * obj) list) =
|
let fieldsToMap (fields : (string * obj) list) =
|
||||||
fields
|
fields
|
||||||
@ -211,9 +214,11 @@ type RethinkBuilder<'T> () =
|
|||||||
/// Perform a write operation
|
/// Perform a write operation
|
||||||
[<CustomOperation "write">]
|
[<CustomOperation "write">]
|
||||||
member _.Write (expr : ReqlExpr) : IConnection -> Task<Model.Result> =
|
member _.Write (expr : ReqlExpr) : IConnection -> Task<Model.Result> =
|
||||||
fun conn -> task {
|
fun conn ->
|
||||||
return! expr.RunWriteAsync conn
|
let result = expr.RunWriteAsync conn |> await
|
||||||
}
|
match result.Errors with
|
||||||
|
| 0UL -> Task.FromResult result
|
||||||
|
| _ -> raise <| ReqlRuntimeError result.FirstError
|
||||||
|
|
||||||
/// Perform a write operation
|
/// Perform a write operation
|
||||||
[<CustomOperation "write">]
|
[<CustomOperation "write">]
|
||||||
|
Loading…
Reference in New Issue
Block a user