Add cursor / toList functions and methods

This commit is contained in:
Daniel J. Summers 2022-06-14 09:31:37 -04:00
parent 8030d81f96
commit a8af285cae
4 changed files with 239 additions and 20 deletions

View File

@ -473,6 +473,43 @@ type RethinkBuilder<'T> () =
conn : IConnection) = conn : IConnection) =
this.ResultOption (expr, opts, cancelToken) conn this.ResultOption (expr, opts, cancelToken) conn
/// Execute the query, returning a cursor for the type specified using the given cancellation token
[<CustomOperation "resultCursor">]
member _.ResultCursor (expr : ReqlExpr, cancelToken : CancellationToken) = runCursorWithCancel<'T> cancelToken expr
/// Execute the query, returning a cursor for the type specified using the given cancellation token
[<CustomOperation "resultCursor">]
member this.ResultCursor (expr : ReqlExpr, cancelToken : CancellationToken, conn : IConnection) =
this.ResultCursor (expr, cancelToken) conn
/// Execute the query, returning a cursor for the type specified
[<CustomOperation "resultCursor">]
member _.ResultCursor (expr : ReqlExpr) = runCursor<'T> expr
/// Execute the query, returning a cursor for the type specified
[<CustomOperation "resultCursor">]
member this.ResultCursor (expr : ReqlExpr, conn : IConnection) = this.ResultCursor expr conn
/// Execute the query, returning a cursor for the type specified, using optional arguments
[<CustomOperation "resultCursor">]
member _.ResultCursor (expr : ReqlExpr, args : RunOptArg list) = runCursorWithOptArgs<'T> args expr
/// Execute the query, returning a cursor for the type specified
[<CustomOperation "resultCursor">]
member this.ResultCursor (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) =
this.ResultCursor (expr, args) conn
/// Execute the query, returning a cursor for the type specified, using optional arguments and a cancellation token
[<CustomOperation "resultCursor">]
member _.ResultCursor (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken) =
runCursorWithOptArgsAndCancel<'T> args cancelToken expr
/// Execute the query, returning a cursor for the type specified, using optional arguments and a cancellation token
[<CustomOperation "resultCursor">]
member this.ResultCursor (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken,
conn : IConnection) =
this.ResultCursor (expr, args, cancelToken) conn
/// Execute the query, returning the result of the type specified using the given cancellation token /// Execute the query, returning the result of the type specified using the given cancellation token
[<CustomOperation "asyncResult">] [<CustomOperation "asyncResult">]
member _.AsyncResult (expr : ReqlExpr, cancelToken : CancellationToken) = asyncResultWithCancel<'T> cancelToken expr member _.AsyncResult (expr : ReqlExpr, cancelToken : CancellationToken) = asyncResultWithCancel<'T> cancelToken expr
@ -494,7 +531,7 @@ type RethinkBuilder<'T> () =
[<CustomOperation "asyncResult">] [<CustomOperation "asyncResult">]
member _.AsyncResult (expr : ReqlExpr, args : RunOptArg list) = asyncResultWithOptArgs<'T> args expr member _.AsyncResult (expr : ReqlExpr, args : RunOptArg list) = asyncResultWithOptArgs<'T> args expr
/// Execute the query, returning the result of the type specified /// Execute the query, returning the result of the type specified, using optional arguments
[<CustomOperation "asyncResult">] [<CustomOperation "asyncResult">]
member this.AsyncResult (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) = member this.AsyncResult (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) =
this.AsyncResult (expr, args) conn this.AsyncResult (expr, args) conn
@ -554,6 +591,43 @@ type RethinkBuilder<'T> () =
conn : IConnection) = conn : IConnection) =
this.AsyncOption (expr, opts, cancelToken) conn this.AsyncOption (expr, opts, cancelToken) conn
/// Execute the query, returning a cursor for the type specified using the given cancellation token
[<CustomOperation "asyncCursor">]
member _.AsyncCursor (expr : ReqlExpr, cancelToken : CancellationToken) = asyncCursorWithCancel<'T> cancelToken expr
/// Execute the query, returning a cursor for the type specified using the given cancellation token
[<CustomOperation "asyncCursor">]
member this.AsyncCursor (expr : ReqlExpr, cancelToken : CancellationToken, conn : IConnection) =
this.AsyncCursor (expr, cancelToken) conn
/// Execute the query, returning a cursor for the type specified
[<CustomOperation "asyncCursor">]
member _.AsyncCursor (expr : ReqlExpr) = asyncCursor<'T> expr
/// Execute the query, returning a cursor for the type specified
[<CustomOperation "asyncCursor">]
member this.AsyncCursor (expr : ReqlExpr, conn : IConnection) = this.AsyncCursor expr conn
/// Execute the query, returning a cursor for the type specified, using optional arguments
[<CustomOperation "asyncCursor">]
member _.AsyncCursor (expr : ReqlExpr, args : RunOptArg list) = asyncCursorWithOptArgs<'T> args expr
/// Execute the query, returning a cursor for the type specified, using optional arguments
[<CustomOperation "asyncCursor">]
member this.AsyncCursor (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) =
this.AsyncCursor (expr, args) conn
/// Execute the query, returning a cursor for the type specified, using optional arguments and a cancellation token
[<CustomOperation "asyncCursor">]
member _.AsyncCursor (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken) =
asyncCursorWithOptArgsAndCancel<'T> args cancelToken expr
/// Execute the query, returning a cursor for the type specified, using optional arguments and a cancellation token
[<CustomOperation "asyncCursor">]
member this.AsyncCursor (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken,
conn : IConnection) =
this.AsyncCursor (expr, args, cancelToken) conn
/// Execute the query synchronously, returning the result of the type specified /// Execute the query synchronously, returning the result of the type specified
[<CustomOperation "syncResult">] [<CustomOperation "syncResult">]
member _.SyncResult (expr : ReqlExpr) = syncResult<'T> expr member _.SyncResult (expr : ReqlExpr) = syncResult<'T> expr
@ -566,7 +640,7 @@ type RethinkBuilder<'T> () =
[<CustomOperation "syncResult">] [<CustomOperation "syncResult">]
member _.SyncResult (expr : ReqlExpr, args : RunOptArg list) = syncResultWithOptArgs<'T> args expr member _.SyncResult (expr : ReqlExpr, args : RunOptArg list) = syncResultWithOptArgs<'T> args expr
/// Execute the query synchronously, returning the result of the type specified /// Execute the query synchronously, returning the result of the type specified, using optional arguments
[<CustomOperation "syncResult">] [<CustomOperation "syncResult">]
member this.SyncResult (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) = member this.SyncResult (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) =
this.SyncResult (expr, args) conn this.SyncResult (expr, args) conn
@ -590,6 +664,23 @@ type RethinkBuilder<'T> () =
member this.SyncOption (expr : ReqlExpr, opts : RunOptArg list, conn : IConnection) = member this.SyncOption (expr : ReqlExpr, opts : RunOptArg list, conn : IConnection) =
this.SyncOption (expr, opts) conn this.SyncOption (expr, opts) conn
/// Execute the query synchronously, returning a cursor for the type specified
[<CustomOperation "syncCursor">]
member _.SyncCursor (expr : ReqlExpr) = syncCursor<'T> expr
/// Execute the query synchronously, returning a cursor for the type specified
[<CustomOperation "syncCursor">]
member this.SyncCursor (expr : ReqlExpr, conn : IConnection) = this.SyncCursor expr conn
/// Execute the query synchronously, returning a cursor for the type specified, using optional arguments
[<CustomOperation "syncCursor">]
member _.SyncCursor (expr : ReqlExpr, args : RunOptArg list) = syncCursorWithOptArgs<'T> args expr
/// Execute the query synchronously, returning a cursor for the type specified, using optional arguments
[<CustomOperation "syncCursor">]
member this.SyncCursor (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) =
this.SyncCursor (expr, args) conn
/// Perform a write operation /// Perform a write operation
[<CustomOperation "write">] [<CustomOperation "write">]
member _.Write (expr : ReqlExpr) = runWrite expr member _.Write (expr : ReqlExpr) = runWrite expr
@ -799,6 +890,30 @@ type RethinkBuilder<'T> () =
[<CustomOperation "ignoreSync">] [<CustomOperation "ignoreSync">]
member this.IgnoreSync (f : IConnection -> 'T, conn) = this.IgnoreSync f conn member this.IgnoreSync (f : IConnection -> 'T, conn) = this.IgnoreSync f conn
/// Convert the items in a cursor to a list
[<CustomOperation "toList">]
member _.ToList (f : IConnection -> Task<Cursor<'T>>) = toList<'T> f
/// Convert the items in a cursor to a list
[<CustomOperation "toList">]
member this.ToList (f : IConnection -> Task<Cursor<'T>>, conn) = this.ToList f conn
/// Convert the items in a cursor to a list
[<CustomOperation "toListAsync">]
member _.ToListAsync (f : IConnection -> Async<Cursor<'T>>) = toListAsync f
/// Convert the items in a cursor to a list
[<CustomOperation "toListAsync">]
member this.ToListAsync (f : IConnection -> Async<Cursor<'T>>, conn) = this.ToListAsync f conn
/// Convert the items in a cursor to a list
[<CustomOperation "toListSync">]
member _.ToListSync (f : IConnection -> Cursor<'T>) = toListSync f
/// Convert the items in a cursor to a list
[<CustomOperation "toListSync">]
member this.ToListSync (f : IConnection -> Cursor<'T>, conn) = this.ToListSync f conn
// Reconnection // Reconnection
/// Retries a variable number of times, waiting each time for the seconds specified /// Retries a variable number of times, waiting each time for the seconds specified

View File

@ -2,6 +2,7 @@
module RethinkDb.Driver.FSharp.Functions module RethinkDb.Driver.FSharp.Functions
open System.Threading open System.Threading
open System.Threading.Tasks
open RethinkDb.Driver open RethinkDb.Driver
open RethinkDb.Driver.Ast open RethinkDb.Driver.Ast
open RethinkDb.Driver.Net open RethinkDb.Driver.Net
@ -14,13 +15,6 @@ module private Helpers =
/// Create a Javascript object from a string (used mostly for type inference) /// Create a Javascript object from a string (used mostly for type inference)
let toJS (js : string) = Javascript js let toJS (js : string) = Javascript js
// ~~ EXECUTION ~~
/// Get a cursor with the results of an expression
let asyncCursor<'T> (expr : ReqlExpr) conn =
expr.RunCursorAsync<'T> conn
|> Async.AwaitTask
// ~~ WRITES ~~ // ~~ WRITES ~~
/// Write a ReQL command with a cancellation token, always returning a result /// Write a ReQL command with a cancellation token, always returning a result
@ -111,12 +105,13 @@ let syncWriteWithOptArgs args expr = fun conn ->
// ~~ QUERY RESULTS AND MANIPULATION ~~ // ~~ QUERY RESULTS AND MANIPULATION ~~
// ~~ Full results (atom / sequence) ~~
/// Run the ReQL command using a cancellation token, returning the result as the type specified /// Run the ReQL command using a cancellation token, returning the result as the type specified
let runResultWithCancel<'T> cancelToken (expr : ReqlExpr) = fun conn -> let runResultWithCancel<'T> cancelToken (expr : ReqlExpr) = fun conn ->
expr.RunResultAsync<'T> (conn, cancelToken) expr.RunResultAsync<'T> (conn, cancelToken)
/// Run the ReQL command using optional arguments and a cancellation token, returning the result as the type /// Run the ReQL command using optional arguments and a cancellation token, returning the result as the type specified
/// specified
let runResultWithOptArgsAndCancel<'T> args cancelToken (expr : ReqlExpr) = fun conn -> let runResultWithOptArgsAndCancel<'T> args cancelToken (expr : ReqlExpr) = fun conn ->
expr.RunResultAsync<'T> (conn, RunOptArg.create args, cancelToken) expr.RunResultAsync<'T> (conn, RunOptArg.create args, cancelToken)
@ -138,8 +133,7 @@ let asyncResultWithOptArgs<'T> args expr = fun conn ->
let asyncResultWithCancel<'T> cancelToken expr = fun conn -> let asyncResultWithCancel<'T> cancelToken expr = fun conn ->
runResultWithCancel<'T> cancelToken expr conn |> Async.AwaitTask runResultWithCancel<'T> cancelToken expr conn |> Async.AwaitTask
/// Run the ReQL command using optional arguments and a cancellation token, returning the result as the type /// Run the ReQL command using optional arguments and a cancellation token, returning the result as the type specified
/// specified
let asyncResultWithOptArgsAndCancel<'T> args cancelToken expr = fun conn -> let asyncResultWithOptArgsAndCancel<'T> args cancelToken expr = fun conn ->
runResultWithOptArgsAndCancel<'T> args cancelToken expr conn |> Async.AwaitTask runResultWithOptArgsAndCancel<'T> args cancelToken expr conn |> Async.AwaitTask
@ -176,6 +170,75 @@ let ignoreResult<'T> (f : IConnection -> Tasks.Task<'T>) conn = task {
() ()
} }
// ~~ Cursors / partial results (sequence / partial) ~~
/// Run the ReQL command using a cancellation token, returning a cursor for the type specified
let runCursorWithCancel<'T> cancelToken (expr : ReqlExpr) = fun conn ->
expr.RunCursorAsync<'T> (conn, cancelToken)
/// Run the ReQL command using optional arguments and a cancellation token, returning a cursor for the type specified
let runCursorWithOptArgsAndCancel<'T> args cancelToken (expr : ReqlExpr) = fun conn ->
expr.RunCursorAsync<'T> (conn, RunOptArg.create args, cancelToken)
/// Run the ReQL command, returning a cursor for the type specified
let runCursor<'T> expr = runCursorWithCancel<'T> CancellationToken.None expr
/// Run the ReQL command using optional arguments, returning a cursor for the type specified
let runCursorWithOptArgs<'T> args expr = runCursorWithOptArgsAndCancel<'T> args CancellationToken.None expr
/// Run the ReQL command, returning a cursor for the type specified
let asyncCursor<'T> expr = fun conn ->
runCursor<'T> expr conn |> Async.AwaitTask
/// Run the ReQL command using optional arguments, returning a cursor for the type specified
let asyncCursorWithOptArgs<'T> args expr = fun conn ->
runCursorWithOptArgs<'T> args expr conn |> Async.AwaitTask
/// Run the ReQL command using a cancellation token, returning a cursor for the type specified
let asyncCursorWithCancel<'T> cancelToken expr = fun conn ->
runCursorWithCancel<'T> cancelToken expr conn |> Async.AwaitTask
/// Run the ReQL command using optional arguments and a cancellation token, returning a cursor for the type specified
let asyncCursorWithOptArgsAndCancel<'T> args cancelToken expr = fun conn ->
runCursorWithOptArgsAndCancel<'T> args cancelToken expr conn |> Async.AwaitTask
/// Run the ReQL command, returning a cursor for the type specified
let syncCursor<'T> expr = fun conn ->
asyncCursor<'T> expr conn |> Async.RunSynchronously
/// Run the ReQL command using optional arguments, returning a cursor for the type specified
let syncCursorWithOptArgs<'T> args expr = fun conn ->
asyncCursorWithOptArgs<'T> args expr conn |> Async.RunSynchronously
/// Convert a cursor to a list (once the cursor has been obtained)
let cursorToList<'T> (cursor : Cursor<'T>) = backgroundTask {
let! hasNext = cursor.MoveNextAsync ()
let mutable hasData = hasNext
let mutable items = []
while hasData do
items <- cursor.Current :: items
let! hasNext = cursor.MoveNextAsync ()
hasData <- hasNext
return items
}
/// Convert a cursor to a list of items
let toList<'T> (f : IConnection -> Task<Cursor<'T>>) = fun conn -> backgroundTask {
use! cursor = f conn
return! cursorToList cursor
}
/// Convert a cursor to a list of items
let toListAsync<'T> (f : IConnection -> Async<Cursor<'T>>) = fun conn -> async {
use! cursor = f conn
return! cursorToList<'T> cursor |> Async.AwaitTask
}
/// Convert a cursor to a list of items
let toListSync<'T> (f : IConnection -> Cursor<'T>) = fun conn ->
use cursor = f conn
cursorToList cursor |> Async.AwaitTask |> Async.RunSynchronously
/// Apply a connection to the query pipeline (typically the final step) /// Apply a connection to the query pipeline (typically the final step)
let withConn<'T> conn (f : IConnection -> 'T) = f conn let withConn<'T> conn (f : IConnection -> 'T) = f conn

View File

@ -7,9 +7,6 @@ open RethinkDb.Driver
open RethinkDb.Driver.Ast open RethinkDb.Driver.Ast
open RethinkDb.Driver.Net open RethinkDb.Driver.Net
/// Get a cursor with the results of an expression
val asyncCursor<'T> : ReqlExpr -> IConnection -> Async<Cursor<'T>>
// ~~ WRITE, ALWAYS RETURNING A RESULT ~~ // ~~ WRITE, ALWAYS RETURNING A RESULT ~~
/// Write a ReQL command with a cancellation token, always returning a result /// Write a ReQL command with a cancellation token, always returning a result
@ -80,6 +77,8 @@ val syncWriteWithOptArgs : RunOptArg list -> ReqlExpr -> (IConnection -> Model.R
// ~~ RUNNING QUERIES AND MANIPULATING RESULTS ~~ // ~~ RUNNING QUERIES AND MANIPULATING RESULTS ~~
// ~~ Full results ~~
/// Run the ReQL command using a cancellation token, returning the result as the type specified /// Run the ReQL command using a cancellation token, returning the result as the type specified
val runResultWithCancel<'T> : CancellationToken -> ReqlExpr -> (IConnection -> Task<'T>) val runResultWithCancel<'T> : CancellationToken -> ReqlExpr -> (IConnection -> Task<'T>)
@ -122,6 +121,49 @@ val asSyncOption : (IConnection -> 'T) -> IConnection -> 'T option
/// Ignore the result of a task-based execution /// Ignore the result of a task-based execution
val ignoreResult<'T> : (IConnection -> Task<'T>) -> IConnection -> Task<unit> val ignoreResult<'T> : (IConnection -> Task<'T>) -> IConnection -> Task<unit>
// ~~ Cursors / Partial results ~~
/// Run the ReQL command using a cancellation token, returning a cursor for the type specified
val runCursorWithCancel<'T> : CancellationToken -> ReqlExpr -> (IConnection -> Task<Cursor<'T>>)
/// Run the ReQL command using optional arguments and a cancellation token, returning a cursor for the type specified
val runCursorWithOptArgsAndCancel<'T> :
RunOptArg list -> CancellationToken -> ReqlExpr -> (IConnection -> Task<Cursor<'T>>)
/// Run the ReQL command, returning a cursor for the type specified
val runCursor<'T> : ReqlExpr -> (IConnection -> Task<Cursor<'T>>)
/// Run the ReQL command using optional arguments, returning a cursor for the type specified
val runCursorWithOptArgs<'T> : RunOptArg list -> ReqlExpr -> (IConnection -> Task<Cursor<'T>>)
/// Run the ReQL command, returning a cursor for type specified
val asyncCursor<'T> : ReqlExpr -> (IConnection -> Async<Cursor<'T>>)
/// Run the ReQL command using optional arguments, returning a cursor for the type specified
val asyncCursorWithOptArgs<'T> : RunOptArg list -> ReqlExpr -> (IConnection -> Async<Cursor<'T>>)
/// Run the ReQL command using a cancellation token, returning a cursor for the type specified
val asyncCursorWithCancel<'T> : CancellationToken -> ReqlExpr -> (IConnection -> Async<Cursor<'T>>)
/// Run the ReQL command using optional arguments and a cancellation token, returning a cursor for the type specified
val asyncCursorWithOptArgsAndCancel<'T> :
RunOptArg list -> CancellationToken -> ReqlExpr -> (IConnection -> Async<Cursor<'T>>)
/// Run the ReQL command, returning a cursor for the type specified
val syncCursor<'T> : ReqlExpr -> (IConnection -> Cursor<'T>)
/// Run the ReQL command using optional arguments, returning a cursor for the type specified
val syncCursorWithOptArgs<'T> : RunOptArg list -> ReqlExpr -> (IConnection -> Cursor<'T>)
/// Convert a cursor to a list of items
val toList<'T> : (IConnection -> Task<Cursor<'T>>) -> IConnection -> Task<'T list>
/// Convert a cursor to a list of items
val toListAsync<'T> : (IConnection -> Async<Cursor<'T>>) -> IConnection -> Async<'T list>
/// Convert a cursor to a list of items
val toListSync<'T> : (IConnection -> Cursor<'T>) -> IConnection -> 'T list
/// Apply a connection to the query pipeline (typically the final step) /// Apply a connection to the query pipeline (typically the final step)
val withConn<'T> : IConnection -> (IConnection -> 'T) -> 'T val withConn<'T> : IConnection -> (IConnection -> 'T) -> 'T

View File

@ -14,10 +14,9 @@
<Copyright>See LICENSE</Copyright> <Copyright>See LICENSE</Copyright>
<PackageTags>RethinkDB document F#</PackageTags> <PackageTags>RethinkDB document F#</PackageTags>
<VersionPrefix>0.9.0</VersionPrefix> <VersionPrefix>0.9.0</VersionPrefix>
<VersionSuffix>beta-03</VersionSuffix> <VersionSuffix>beta-04</VersionSuffix>
<PackageReleaseNotes> <PackageReleaseNotes>
Retry logic now works with functions; added signature for function moduel and explicit type annotations to the Add cursor / toList functions and DSL operations
DSL builder
</PackageReleaseNotes> </PackageReleaseNotes>
</PropertyGroup> </PropertyGroup>