From 8030d81f961dabb2645ee68f28424463adcf5880 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Wed, 25 May 2022 14:34:37 -0400 Subject: [PATCH] Fix function retry (#2) / Add asOption (#1) - Add signature file for function module --- README.md | 14 +- src/RethinkDb.Driver.FSharp/Builder.fs | 532 +++++++++--------- src/RethinkDb.Driver.FSharp/Config.fs | 2 +- src/RethinkDb.Driver.FSharp/Functions.fs | 220 +++++--- src/RethinkDb.Driver.FSharp/Functions.fsi | 442 +++++++++++++++ src/RethinkDb.Driver.FSharp/README.md | 25 +- .../RethinkDb.Driver.FSharp.fsproj | 14 +- 7 files changed, 885 insertions(+), 364 deletions(-) create mode 100644 src/RethinkDb.Driver.FSharp/Functions.fsi diff --git a/README.md b/README.md index 3e34663..50ca87e 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,28 @@ # RethinkDb.Driver.FSharp Idiomatic F# extensions for the C# RethinkDB driver -[![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/RethinkDb.Driver.FSharp)](https://www.nuget.org/packages/RethinkDb.Driver.FSharp/) +[![Nuget (with prereleases)][pkg-img]][pkg-url] ## Using -Install the [NuGet](https://www.nuget.org/packages/RethinkDb.Driver.FSharp/) package `RethinkDb.Driver.FSharp`. You will need to specify pre-release, as the package currently has a beta designation. +Install the [NuGet][pkg-url] package `RethinkDb.Driver.FSharp`. You will need to specify pre-release, as the package currently has a beta designation. ## What It Provides +The full documentation is on [the project site][project]; TL;DR below. + ### A composable pipeline for creating ReQL statements ```fsharp open RethinkDb.Driver.FSharp.Functions -/// string -> (IConnection -> Task) +/// string -> (IConnection -> Task) let fetchPost (postId : string) = - fromDb "Blog" + db "Blog" |> table "Post" |> get postId |> runResult + |> asOption |> withRetryDefault ``` @@ -86,4 +89,7 @@ license on this project's dependencies. Please see [the heading on the C# driver If you are using the project, feel free to file issues about your pain points; there is no substitute for real-world feedback! +[pkg-img]: https://img.shields.io/nuget/vpre/RethinkDb.Driver.FSharp +[pkg-url]: https://www.nuget.org/packages/RethinkDb.Driver.FSharp/ +[project]: https://bitbadger.solutions/open-source/rethinkdb-driver-fsharp/ [license]: https://github.com/bchavez/RethinkDb.Driver#open-source-and-commercial-licensing diff --git a/src/RethinkDb.Driver.FSharp/Builder.fs b/src/RethinkDb.Driver.FSharp/Builder.fs index f7889d6..2a24b80 100644 --- a/src/RethinkDb.Driver.FSharp/Builder.fs +++ b/src/RethinkDb.Driver.FSharp/Builder.fs @@ -25,9 +25,6 @@ type RethinkBuilder<'T> () = Some parts[0], parts[1] | false -> None, table - /// Return None if the item is null, Some if it is not - let noneIfNull (it : 'T) = match (box >> isNull) it with true -> None | false -> Some it - member _.Bind (expr : ReqlExpr, f : ReqlExpr -> ReqlExpr) = f expr member this.For (expr, f) = this.Bind (expr, f) @@ -43,15 +40,15 @@ type RethinkBuilder<'T> () = /// Identify a table (of form "dbName.tableName"; if no db name, uses default database) [] - member this.Table (r, tableName) = + member this.Table (r : RethinkDB, tableName : string) = match dbAndTable tableName with | Some dbName, tblName -> this.Db (r, dbName) |> table tblName | None, _ -> fromTable tableName /// Create an equality join with another table [] - member _.EqJoin (expr : ReqlExpr, field : string, otherTable : string) = - expr.EqJoin (field, RethinkDB.R.Table otherTable) + member this.EqJoin (expr : ReqlExpr, field : string, otherTable : string) = + eqJoin field (this.Table (RethinkDB.R, otherTable)) expr // meta queries (tables, indexes, etc.) @@ -61,11 +58,11 @@ type RethinkBuilder<'T> () = /// Create a database [] - member _.DbCreate (_ : RethinkDB, dbName) = dbCreate dbName + member _.DbCreate (_ : RethinkDB, dbName : string) = dbCreate dbName /// Drop a database [] - member _.DbDrop (_ : RethinkDB, dbName) = dbDrop dbName + member _.DbDrop (_ : RethinkDB, dbName : string) = dbDrop dbName /// List all tables for the default database [] @@ -73,714 +70,718 @@ type RethinkBuilder<'T> () = /// List all tables for the specified database [] - member this.TableList (r, dbName) = + member this.TableList (r : RethinkDB, dbName : string) = match dbName with "" -> tableListFromDefault () | _ -> this.Db (r, dbName) |> tableList /// Create a table (of form "dbName.tableName"; if no db name, uses default database) [] - member this.TableCreate (r, tableName) = + member this.TableCreate (r : RethinkDB, tableName : string) = match dbAndTable tableName with | Some dbName, tblName -> this.Db (r, dbName) |> tableCreate tblName | None, _ -> tableCreateInDefault tableName /// Drop a table (of form "dbName.tableName"; if no db name, uses default database) [] - member this.TableDrop (r, tableName) = + member this.TableDrop (r : RethinkDB, tableName : string) = match dbAndTable tableName with | Some dbName, tblName -> this.Db (r, dbName) |> tableDrop tblName | None, _ -> tableDropFromDefault tableName /// List all indexes for a table [] - member _.IndexList tbl = indexList tbl + member _.IndexList (tbl : Table) = indexList tbl /// Create an index for a table [] - member _.IndexCreate (tbl, index) = indexCreate index tbl + member _.IndexCreate (tbl : Table, index : string) = indexCreate index tbl /// Create an index for a table, specifying an optional argument [] - member _.IndexCreate (tbl, index, opts) = indexCreateWithOptArgs index opts tbl + member _.IndexCreate (tbl : Table, index : string, opts : IndexCreateOptArg list) = + indexCreateWithOptArgs index opts tbl /// Create an index for a table, using a function to calculate the index [] - member _.IndexCreate (tbl, index, f) = indexCreateFunc index f tbl + member _.IndexCreate (tbl : Table, index : string, f : ReqlExpr -> obj) = indexCreateFunc index f tbl /// Create an index for a table, using a function to calculate the index [] - member _.IndexCreate (tbl, index, f, opts) = indexCreateFuncWithOptArgs index f opts tbl + member _.IndexCreate (tbl : Table, index : string, f : ReqlExpr -> obj, opts : IndexCreateOptArg list) = + indexCreateFuncWithOptArgs index f opts tbl /// Create an index for a table, using a JavaScript function to calculate the index [] - member _.IndexCreate (tbl, index, js) = indexCreateJS index js tbl + member _.IndexCreate (tbl : Table, index : string, js : string) = indexCreateJS index js tbl /// Create an index for a table, using a JavaScript function to calculate the index [] - member _.IndexCreate (tbl, index, js, opts) = indexCreateJSWithOptArgs index js opts tbl + member _.IndexCreate (tbl : Table, index : string, js : string, opts : IndexCreateOptArg list) = + indexCreateJSWithOptArgs index js opts tbl /// Drop an index for a table [] - member _.IndexDrop (tbl, index) = indexDrop index tbl + member _.IndexDrop (tbl : Table, index : string) = indexDrop index tbl /// Rename an index on a table [] - member _.IndexRename (tbl, oldName, newName) = indexRename oldName newName tbl + member _.IndexRename (tbl : Table, oldName : string, newName : string) = indexRename oldName newName tbl /// Rename an index on a table, specifying an overwrite option [] - member _.IndexRename (tbl, oldName, newName, opt) = indexRenameWithOptArg oldName newName opt tbl + member _.IndexRename (tbl : Table, oldName : string, newName : string, opt : IndexRenameOptArg) = + indexRenameWithOptArg oldName newName opt tbl /// Get the status of all indexes on a table [] - member _.IndexStatus tbl = indexStatusAll tbl + member _.IndexStatus (tbl : Table) = indexStatusAll tbl /// Get the status of specific indexes on a table [] - member _.IndexStatus (tbl, indexes) = indexStatus indexes tbl + member _.IndexStatus (tbl : Table, indexes : string list) = indexStatus indexes tbl /// Wait for all indexes on a table to become ready [] - member _.IndexWait tbl = indexWaitAll tbl + member _.IndexWait (tbl : Table) = indexWaitAll tbl /// Wait for specific indexes on a table to become ready [] - member _.IndexWait (tbl, indexes) = indexWait indexes tbl + member _.IndexWait (tbl : Table, indexes : string list) = indexWait indexes tbl // data retrieval / manipulation /// Get a document from a table by its ID [] - member _.Get (tbl, key : obj) = get key tbl + member _.Get (tbl : Table, key : obj) = get key tbl /// Get all documents matching the given primary key value [] - member _.GetAll (tbl, keys) = getAll (Seq.ofList keys) tbl + member _.GetAll (tbl : Table, keys : obj list) = getAll (Seq.ofList keys) tbl /// Get all documents matching the given index value [] - member _.GetAll (tbl, keys, index) = getAllWithIndex (Seq.ofList keys) index tbl + member _.GetAll (tbl : Table, keys : obj list, index : string) = getAllWithIndex (Seq.ofList keys) index tbl /// Skip a certain number of results [] - member _.Skip (expr, toSkip) = skip toSkip expr + member _.Skip (expr : ReqlExpr, toSkip : int) = skip toSkip expr /// Limit the results of this query [] - member _.Limit (expr, toLimit) = limit toLimit expr + member _.Limit (expr : ReqlExpr, toLimit : int) = limit toLimit expr /// Count documents for the current query [] - member _.Count expr = count expr + member _.Count (expr : ReqlExpr) = count expr /// Count documents for the current query [] - member _.Count (expr, f) = countFunc f expr + member _.Count (expr : ReqlExpr, f : ReqlExpr -> bool) = countFunc f expr /// Count documents for the current query [] - member _.Count (expr, js) = countJS js expr + member _.Count (expr : ReqlExpr, js : string) = countJS js expr /// Select distinct values from the sequence [] - member _.Distinct expr = distinct expr + member _.Distinct (expr : ReqlExpr) = distinct expr /// Select distinct values from the sequence using an index [] - member _.Distinct (expr, index) = distinctWithIndex expr index + member _.Distinct (expr : ReqlExpr, index : string) = distinctWithIndex index expr /// Filter a query by a single field value [] - member _.Filter (expr, field, value) = filter (fieldsToMap [ field, value ]) expr + member _.Filter (expr : ReqlExpr, field : string, value : obj) = filter (fieldsToMap [ field, value ]) expr /// Filter a query by a single field value, including an optional argument [] - member _.Filter (expr, field, value, opt) = filterWithOptArgs (fieldsToMap [ field, value ]) opt expr + member _.Filter (expr : ReqlExpr, field : string, value : obj, opt : FilterOptArg) = + filterWithOptArg (fieldsToMap [ field, value ]) opt expr /// Filter a query by multiple field values [] - member _.Filter (expr, filters) = filter (fieldsToMap filters) expr + member _.Filter (expr : ReqlExpr, filters : (string * obj) list) = filter (fieldsToMap filters) expr /// Filter a query by multiple field values, including an optional argument [] - member _.Filter (expr, filters, opt) = filterWithOptArgs (fieldsToMap filters) opt expr + member _.Filter (expr : ReqlExpr, filters : (string * obj) list, opt : FilterOptArg) = + filterWithOptArg (fieldsToMap filters) opt expr /// Filter a query by a function [] - member _.Filter (expr, f) = filterFunc f expr + member _.Filter (expr : ReqlExpr, f : ReqlExpr -> obj) = filterFunc f expr /// Filter a query by a function, including an optional argument [] - member _.Filter (expr, f, opt) = filterFuncWithOptArgs f opt expr + member _.Filter (expr : ReqlExpr, f : ReqlExpr -> obj, opt : FilterOptArg) = filterFuncWithOptArg f opt expr /// Filter a query by multiple functions (has the effect of ANDing them) [] - member _.Filter (expr, fs) = filterFuncAll fs expr + member _.Filter (expr : ReqlExpr, fs : (ReqlExpr -> obj) list) = filterFuncAll fs expr /// Filter a query by multiple functions (has the effect of ANDing them), including an optional argument [] - member _.Filter (expr, fs, opt) = filterFuncAllWithOptArgs fs opt expr + member _.Filter (expr : ReqlExpr, fs : (ReqlExpr -> obj) list, opt : FilterOptArg) = + filterFuncAllWithOptArg fs opt expr /// Filter a query using a JavaScript expression [] - member _.Filter (expr, js) = filterJS js expr + member _.Filter (expr : ReqlExpr, js : string) = filterJS js expr /// Filter a query using a JavaScript expression, including an optional argument [] - member _.Filter (expr, js, opt) = filterJSWithOptArgs js opt expr + member _.Filter (expr : ReqlExpr, js : string, opt : FilterOptArg) = filterJSWithOptArg js opt expr /// Filter a query by a range of values [] - member _.Between (expr, lower : obj, upper : obj) = between lower upper expr + member _.Between (expr : ReqlExpr, lower : obj, upper : obj) = between lower upper expr /// Filter a query by a range of values, using optional arguments [] - member _.Between (expr, lower : obj, upper : obj, opts) = betweenWithOptArgs lower upper opts expr + member _.Between (expr : ReqlExpr, lower : obj, upper : obj, opts : BetweenOptArg list) = + betweenWithOptArgs lower upper opts expr /// Map fields for the current query using a function [] - member _.Map (expr, f) = mapFunc f expr + member _.Map (expr : ReqlExpr, f : ReqlExpr -> obj) = mapFunc f expr /// Map fields for the current query using a JavaScript function [] - member _.Map (expr, js) = mapJS js expr + member _.Map (expr : ReqlExpr, js : string) = mapJS js expr /// Exclude the given fields from the output [] - member _.Without (expr, fields) = without (Seq.ofList fields) expr + member _.Without (expr : ReqlExpr, fields : string list) = without (Seq.ofList fields) expr /// Combine a left and right selection into a single record [] - member _.Zip expr = zip expr + member _.Zip (expr : ReqlExpr) = zip expr /// Merge a document into the current query [] - member _.Merge (expr, doc : obj) = merge doc expr + member _.Merge (expr : ReqlExpr, doc : obj) = merge doc expr /// Merge a document into the current query, constructed by a function [] - member _.Merge (expr, f) = mergeFunc f expr + member _.Merge (expr : ReqlExpr, f : ReqlExpr -> obj) = mergeFunc f expr /// Merge a document into the current query, constructed by a JavaScript function [] - member _.Merge (expr, js) = mergeJS js expr + member _.Merge (expr : ReqlExpr, js : string) = mergeJS js expr /// Pluck (select only) specific fields from the query [] - member _.Pluck (expr, fields) = pluck (Seq.ofList fields) expr + member _.Pluck (expr : ReqlExpr, fields : string list) = pluck (Seq.ofList fields) expr /// Order the results by the given field name (ascending) [] - member _.OrderBy (expr, field) = orderBy field expr + member _.OrderBy (expr : ReqlExpr, field : string) = orderBy field expr /// Order the results by the given field name (descending) [] - member _.OrderByDescending (expr, field) = orderByDescending field expr + member _.OrderByDescending (expr : ReqlExpr, field : string) = orderByDescending field expr /// Order the results by the given index name (ascending) [] - member _.OrderByIndex (expr, index) = orderByIndex index expr + member _.OrderByIndex (expr : ReqlExpr, index : string) = orderByIndex index expr /// Order the results by the given index name (descending) [] - member _.OrderByIndexDescending (expr, index) = orderByIndexDescending index expr + member _.OrderByIndexDescending (expr : ReqlExpr, index : string) = orderByIndexDescending index expr /// Order the results by the given function value (ascending) [] - member _.OrderByFunc (expr, f) = orderByFunc f expr + member _.OrderByFunc (expr : ReqlExpr, f : ReqlExpr -> obj) = orderByFunc f expr /// Order the results by the given function value (descending) [] - member _.OrderByFuncDescending (expr, f) = orderByFuncDescending f expr + member _.OrderByFuncDescending (expr : ReqlExpr, f : ReqlExpr -> obj) = orderByFuncDescending f expr /// Order the results by the given JavaScript function value (ascending) [] - member _.OrderByJS (expr, js) = orderByJS js expr + member _.OrderByJS (expr : ReqlExpr, js : string) = orderByJS js expr /// Order the results by the given JavaScript function value (descending) [] - member _.OrderByJSDescending (expr, js) = orderByJSDescending js expr + member _.OrderByJSDescending (expr : ReqlExpr, js : string) = orderByJSDescending js expr /// Insert a document into the given table [] - member _.Insert (tbl, doc : obj) = insert doc tbl + member _.Insert (tbl : Table, doc : obj) = insert doc tbl /// Insert multiple documents into the given table [] - member _.Insert (tbl, doc) = insertMany (Seq.ofList doc) tbl + member _.Insert (tbl : Table, doc : obj list) = insertMany (Seq.ofList doc) tbl /// Insert a document into the given table, using optional arguments [] - member _.Insert (tbl, docs : obj, opts) = insertWithOptArgs docs opts tbl + member _.Insert (tbl : Table, doc : obj, opts : InsertOptArg list) = insertWithOptArgs doc opts tbl /// Insert multiple documents into the given table, using optional arguments [] - member _.Insert (tbl, docs, opts) = insertManyWithOptArgs (Seq.ofList docs) opts tbl + member _.Insert (tbl : Table, docs : obj list, opts : InsertOptArg list) = + insertManyWithOptArgs (Seq.ofList docs) opts tbl - /// Update specific fields in a document + /// Update fields from the given object [] - member _.Update (expr, fields) = update (fieldsToMap fields) expr + member _.Update (expr : ReqlExpr, object : obj) = update object expr - /// Update specific fields in a document, using optional arguments + /// Update fields from the given object, using optional arguments [] - member _.Update (expr, fields, args) = updateWithOptArgs (fieldsToMap fields) args expr + member _.Update (expr : ReqlExpr, object : obj, args : UpdateOptArg list) = updateWithOptArgs object args expr - /// Update specific fields in a document using a function + /// Update specific fields [] - member _.Update (expr, f) = updateFunc f expr + member _.Update (expr : ReqlExpr, fields : (string * obj) list) = update (fieldsToMap fields) expr - /// Update specific fields in a document using a function, with optional arguments + /// Update specific fields, using optional arguments [] - member _.Update (expr, f, args) = updateFuncWithOptArgs f args expr + member _.Update (expr : ReqlExpr, fields : (string * obj) list, args : UpdateOptArg list) = + updateWithOptArgs (fieldsToMap fields) args expr - /// Update specific fields in a document using a JavaScript function + /// Update specific fields using a function [] - member _.Update (expr, js) = updateJS js expr + member _.Update (expr : ReqlExpr, f : ReqlExpr -> obj) = updateFunc f expr - /// Update specific fields in a document using a JavaScript function, with optional arguments + /// Update specific fields using a function, with optional arguments [] - member _.Update (expr, js, args) = updateJSWithOptArgs js args expr + member _.Update (expr : ReqlExpr, f : ReqlExpr -> obj, args : UpdateOptArg list) = updateFuncWithOptArgs f args expr + + /// Update specific fields using a JavaScript function + [] + member _.Update (expr : ReqlExpr, js : string) = updateJS js expr + + /// Update specific fields using a JavaScript function, with optional arguments + [] + member _.Update (expr : ReqlExpr, js : string, args : UpdateOptArg list) = updateJSWithOptArgs js args expr /// Replace the current query with the specified document [] - member _.Replace (expr, doc : obj) = replace doc expr + member _.Replace (expr : ReqlExpr, doc : obj) = replace doc expr /// Replace the current query with the specified document, using optional arguments [] - member _.Replace (expr, doc : obj, args) = replaceWithOptArgs doc args expr + member _.Replace (expr : ReqlExpr, doc : obj, args : ReplaceOptArg list) = replaceWithOptArgs doc args expr /// Replace the current query with document(s) created by a function [] - member _.Replace (expr, f) = replaceFunc f expr + member _.Replace (expr : ReqlExpr, f : ReqlExpr -> obj) = replaceFunc f expr /// Replace the current query with document(s) created by a function, using optional arguments [] - member _.Replace (expr, f, args) = replaceFuncWithOptArgs f args expr + member _.Replace (expr : ReqlExpr, f : ReqlExpr -> obj, args : ReplaceOptArg list) = + replaceFuncWithOptArgs f args expr /// Replace the current query with document(s) created by a JavaScript function [] - member _.Replace (expr, js) = replaceJS js expr + member _.Replace (expr : ReqlExpr, js : string) = replaceJS js expr /// Replace the current query with document(s) created by a JavaScript function, using optional arguments [] - member _.Replace (expr, js, args) = replaceJSWithOptArgs js args expr + member _.Replace (expr : ReqlExpr, js : string, args : ReplaceOptArg list) = replaceJSWithOptArgs js args expr /// Delete the document(s) identified by the current query [] - member _.Delete expr = delete expr + member _.Delete (expr : ReqlExpr) = delete expr /// Delete the document(s) identified by the current query [] - member _.Delete (expr, opts) = deleteWithOptArgs opts expr + member _.Delete (expr : ReqlExpr, opts : DeleteOptArg list) = deleteWithOptArgs opts expr /// Wait for updates to a table to be synchronized to disk [] - member _.Sync tbl = sync tbl + member _.Sync (tbl : Table) = sync tbl // executing queries /// Execute the query, returning the result of the type specified using the given cancellation token [] - member _.Result (expr, cancelToken) = fun conn -> backgroundTask { - return! runResultWithCancel<'T> cancelToken conn expr - } + member _.Result (expr : ReqlExpr, cancelToken : CancellationToken) = runResultWithCancel<'T> cancelToken expr /// Execute the query, returning the result of the type specified using the given cancellation token [] - member _.Result (expr, cancelToken, conn) = runResultWithCancel<'T> cancelToken conn expr + member this.Result (expr : ReqlExpr, cancelToken : CancellationToken, conn : IConnection) = + this.Result (expr, cancelToken) conn /// Execute the query, returning the result of the type specified [] - member _.Result expr = fun conn -> backgroundTask { - return! runResult<'T> conn expr - } + member _.Result (expr : ReqlExpr) = runResult<'T> expr /// Execute the query, returning the result of the type specified [] - member _.Result (expr, conn) = runResult<'T> conn expr + member this.Result (expr : ReqlExpr, conn : IConnection) = this.Result expr conn /// Execute the query, returning the result of the type specified, using optional arguments [] - member _.Result (expr, args) = fun conn -> backgroundTask { - return! runResultWithOptArgs<'T> args conn expr - } + member _.Result (expr : ReqlExpr, args : RunOptArg list) = runResultWithOptArgs<'T> args expr /// Execute the query, returning the result of the type specified [] - member _.Result (expr, args, conn) = runResultWithOptArgs<'T> args conn expr + member this.Result (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) = this.Result (expr, args) conn /// Execute the query, returning the result of the type specified, using optional arguments and a cancellation token [] - member _.Result (expr, args, cancelToken) = fun conn -> backgroundTask { - return! runResultWithOptArgsAndCancel<'T> args cancelToken conn expr - } + member _.Result (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken) = + runResultWithOptArgsAndCancel<'T> args cancelToken expr /// Execute the query, returning the result of the type specified, using optional arguments and a cancellation token [] - member _.Result (expr, args, cancelToken, conn) = - runResultWithOptArgsAndCancel<'T> args cancelToken conn expr + member this.Result (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken, conn : IConnection) = + this.Result (expr, args, cancelToken) conn /// Execute the query, returning the result of the type specified, or None if no result is found [] - member _.ResultOption expr = fun conn -> backgroundTask { - let! result = runResult<'T> conn expr - return noneIfNull result - } + member this.ResultOption (expr : ReqlExpr) = this.Result expr |> asOption /// Execute the query, returning the result of the type specified, or None if no result is found [] - member this.ResultOption (expr, conn) = - this.ResultOption expr conn + member this.ResultOption (expr : ReqlExpr, conn : IConnection) = this.ResultOption expr conn /// Execute the query with a cancellation token, returning the result of the type specified, or None if no result is /// found [] - member _.ResultOption (expr, cancelToken) = fun conn -> backgroundTask { - let! result = runResultWithCancel<'T> cancelToken conn expr - return noneIfNull result - } + member this.ResultOption (expr : ReqlExpr, cancelToken : CancellationToken) = + this.Result (expr, cancelToken) |> asOption /// Execute the query with a cancellation token, returning the result of the type specified, or None if no result is /// found [] - member this.ResultOption (expr : ReqlExpr, cancelToken : CancellationToken, conn) = + member this.ResultOption (expr : ReqlExpr, cancelToken : CancellationToken, conn : IConnection) = this.ResultOption (expr, cancelToken) conn /// Execute the query with optional arguments, returning the result of the type specified, or None if no result is /// found [] - member _.ResultOption (expr, opts) = fun conn -> backgroundTask { - let! result = runResultWithOptArgs<'T> opts conn expr - return noneIfNull result - } + member this.ResultOption (expr : ReqlExpr, opts : RunOptArg list) = this.Result (expr, opts) |> asOption /// Execute the query with optional arguments, returning the result of the type specified, or None if no result is /// found [] - member this.ResultOption (expr, opts : RunOptArg list, conn) = + member this.ResultOption (expr : ReqlExpr, opts : RunOptArg list, conn : IConnection) = this.ResultOption (expr, opts) conn /// Execute the query with optional arguments and a cancellation token, returning the result of the type specified, /// or None if no result is found [] - member _.ResultOption (expr, opts, cancelToken) = fun conn -> backgroundTask { - let! result = runResultWithOptArgsAndCancel<'T> opts cancelToken conn expr - return noneIfNull result - } + member this.ResultOption (expr : ReqlExpr, opts : RunOptArg list, cancelToken : CancellationToken) = + this.Result (expr, opts, cancelToken) |> asOption /// Execute the query with optional arguments and a cancellation token, returning the result of the type specified, /// or None if no result is found [] - member this.ResultOption (expr, opts : RunOptArg list, cancelToken : CancellationToken, conn) = + member this.ResultOption (expr : ReqlExpr, opts : RunOptArg list, cancelToken : CancellationToken, + conn : IConnection) = this.ResultOption (expr, opts, cancelToken) conn /// Execute the query, returning the result of the type specified using the given cancellation token [] - member _.AsyncResult (expr, cancelToken) = fun conn -> async { - return! asyncResultWithCancel<'T> cancelToken conn expr - } + member _.AsyncResult (expr : ReqlExpr, cancelToken : CancellationToken) = asyncResultWithCancel<'T> cancelToken expr /// Execute the query, returning the result of the type specified using the given cancellation token [] - member _.AsyncResult (expr, cancelToken, conn) = asyncResultWithCancel<'T> cancelToken conn expr + member this.AsyncResult (expr : ReqlExpr, cancelToken : CancellationToken, conn : IConnection) = + this.AsyncResult (expr, cancelToken) conn /// Execute the query, returning the result of the type specified [] - member _.AsyncResult expr = fun conn -> async { - return! asyncResult<'T> conn expr - } + member _.AsyncResult (expr : ReqlExpr) = asyncResult<'T> expr /// Execute the query, returning the result of the type specified [] - member _.AsyncResult (expr, conn) = asyncResult<'T> conn expr + member this.AsyncResult (expr : ReqlExpr, conn : IConnection) = this.AsyncResult expr conn /// Execute the query, returning the result of the type specified, using optional arguments [] - member _.AsyncResult (expr, args) = fun conn -> async { - return! asyncResultWithOptArgs<'T> args conn expr - } + member _.AsyncResult (expr : ReqlExpr, args : RunOptArg list) = asyncResultWithOptArgs<'T> args expr /// Execute the query, returning the result of the type specified [] - member _.AsyncResult (expr, args, conn) = asyncResultWithOptArgs<'T> args conn expr + member this.AsyncResult (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) = + this.AsyncResult (expr, args) conn /// Execute the query, returning the result of the type specified, using optional arguments and a cancellation token [] - member _.AsyncResult (expr, args, cancelToken) = fun conn -> async { - return! asyncResultWithOptArgsAndCancel<'T> args cancelToken conn expr - } + member _.AsyncResult (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken) = + asyncResultWithOptArgsAndCancel<'T> args cancelToken expr /// Execute the query, returning the result of the type specified, using optional arguments and a cancellation token [] - member _.AsyncResult (expr, args, cancelToken, conn) = - asyncResultWithOptArgsAndCancel<'T> args cancelToken conn expr + member this.AsyncResult (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken, + conn : IConnection) = + this.AsyncResult (expr, args, cancelToken) conn /// Execute the query, returning the result of the type specified, or None if no result is found [] - member _.AsyncOption expr = fun conn -> async { - let! result = asyncResult<'T> conn expr - return noneIfNull result - } + member this.AsyncOption (expr : ReqlExpr) = this.AsyncResult expr |> asAsyncOption /// Execute the query, returning the result of the type specified, or None if no result is found [] - member this.AsyncOption (expr, conn) = - this.AsyncOption expr conn + member this.AsyncOption (expr : ReqlExpr, conn : IConnection) = this.AsyncOption expr conn /// Execute the query with a cancellation token, returning the result of the type specified, or None if no result is /// found [] - member _.AsyncOption (expr, cancelToken) = fun conn -> async { - let! result = asyncResultWithCancel<'T> cancelToken conn expr - return noneIfNull result - } + member this.AsyncOption (expr : ReqlExpr, cancelToken : CancellationToken) = + this.AsyncResult (expr, cancelToken) |> asAsyncOption /// Execute the query with a cancellation token, returning the result of the type specified, or None if no result is /// found [] - member this.AsyncOption (expr : ReqlExpr, cancelToken : CancellationToken, conn) = + member this.AsyncOption (expr : ReqlExpr, cancelToken : CancellationToken, conn : IConnection) = this.AsyncOption (expr, cancelToken) conn /// Execute the query with optional arguments, returning the result of the type specified, or None if no result is /// found [] - member _.AsyncOption (expr, opts) = fun conn -> async { - let! result = asyncResultWithOptArgs<'T> opts conn expr - return noneIfNull result - } + member this.AsyncOption (expr : ReqlExpr, opts : RunOptArg list) = this.AsyncResult (expr, opts) |> asAsyncOption /// Execute the query with optional arguments, returning the result of the type specified, or None if no result is /// found [] - member this.AsyncOption (expr, opts : RunOptArg list, conn) = + member this.AsyncOption (expr : ReqlExpr, opts : RunOptArg list, conn : IConnection) = this.AsyncOption (expr, opts) conn /// Execute the query with optional arguments and a cancellation token, returning the result of the type specified, /// or None if no result is found [] - member _.AsyncOption (expr, opts, cancelToken) = fun conn -> async { - let! result = asyncResultWithOptArgsAndCancel<'T> opts cancelToken conn expr - return noneIfNull result - } + member this.AsyncOption (expr : ReqlExpr, opts : RunOptArg list, cancelToken : CancellationToken) = + this.AsyncResult (expr, opts, cancelToken) |> asAsyncOption /// Execute the query with optional arguments and a cancellation token, returning the result of the type specified, /// or None if no result is found [] - member this.AsyncOption (expr, opts : RunOptArg list, cancelToken : CancellationToken, conn) = + member this.AsyncOption (expr : ReqlExpr, opts : RunOptArg list, cancelToken : CancellationToken, + conn : IConnection) = this.AsyncOption (expr, opts, cancelToken) conn /// Execute the query synchronously, returning the result of the type specified [] - member _.SyncResult expr = fun conn -> syncResult<'T> conn expr + member _.SyncResult (expr : ReqlExpr) = syncResult<'T> expr /// Execute the query synchronously, returning the result of the type specified [] - member _.SyncResult (expr, conn) = syncResult<'T> conn expr + member this.SyncResult (expr : ReqlExpr, conn : IConnection) = this.SyncResult expr conn /// Execute the query synchronously, returning the result of the type specified, using optional arguments [] - member _.SyncResult (expr, args) = fun conn -> syncResultWithOptArgs<'T> args conn expr + member _.SyncResult (expr : ReqlExpr, args : RunOptArg list) = syncResultWithOptArgs<'T> args expr /// Execute the query synchronously, returning the result of the type specified [] - member _.SyncResult (expr, args, conn) = syncResultWithOptArgs<'T> args conn expr + member this.SyncResult (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) = + this.SyncResult (expr, args) conn /// Execute the query synchronously, returning the result of the type specified, or None if no result is found [] - member _.SyncOption expr = fun conn -> noneIfNull (syncResult<'T> conn expr) + member this.SyncOption (expr : ReqlExpr) = this.SyncResult expr |> asSyncOption /// Execute the query synchronously, returning the result of the type specified, or None if no result is found [] - member _.SyncOption (expr, conn) = noneIfNull (syncResult<'T> conn expr) + member this.SyncOption (expr : ReqlExpr, conn : IConnection) = this.SyncOption expr conn /// Execute the query synchronously with optional arguments, returning the result of the type specified, or None if /// no result is found [] - member _.SyncOption (expr, opts) = fun conn -> noneIfNull (syncResultWithOptArgs<'T> opts conn expr) + member this.SyncOption (expr : ReqlExpr, opts : RunOptArg list) = this.SyncResult (expr, opts) |> asSyncOption /// Execute the query synchronously with optional arguments, returning the result of the type specified, or None if /// no result is found [] - member _.SyncOption (expr, opts, conn) = noneIfNull (syncResultWithOptArgs<'T> opts conn expr) + member this.SyncOption (expr : ReqlExpr, opts : RunOptArg list, conn : IConnection) = + this.SyncOption (expr, opts) conn /// Perform a write operation [] - member _.Write expr = fun conn -> runWrite conn expr + member _.Write (expr : ReqlExpr) = runWrite expr /// Perform a write operation [] - member _.Write (expr, conn) = runWrite conn expr + member this.Write (expr : ReqlExpr, conn : IConnection) = this.Write expr conn /// Perform a write operation using optional arguments [] - member _.Write (expr, args) = fun conn -> runWriteWithOptArgs args conn expr + member _.Write (expr : ReqlExpr, args : RunOptArg list) = runWriteWithOptArgs args expr /// Perform a write operation using optional arguments [] - member _.Write (expr, args, conn) = runWriteWithOptArgs args conn expr + member this.Write (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) = this.Write (expr, args) conn /// Perform a write operation using a cancellation token [] - member _.Write (expr, cancelToken) = fun conn -> runWriteWithCancel cancelToken conn expr + member _.Write (expr : ReqlExpr, cancelToken : CancellationToken) = runWriteWithCancel cancelToken expr /// Perform a write operation using a cancellation token [] - member _.Write (expr, cancelToken, conn) = runWriteWithCancel cancelToken conn expr + member this.Write (expr : ReqlExpr, cancelToken : CancellationToken, conn : IConnection) = + this.Write (expr, cancelToken) conn /// Perform a write operation using optional arguments and a cancellation token [] - member _.Write (expr, args, cancelToken) = fun conn -> runWriteWithOptArgsAndCancel args cancelToken conn expr + member _.Write (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken) = + runWriteWithOptArgsAndCancel args cancelToken expr /// Perform a write operation using optional arguments and a cancellation token [] - member _.Write (expr, args, cancelToken, conn) = runWriteWithOptArgsAndCancel args cancelToken conn expr + member this.Write (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken, conn : IConnection) = + this.Write (expr, args, cancelToken) conn /// Perform a write operation [] - member _.AsyncWrite expr = fun conn -> asyncWrite conn expr + member _.AsyncWrite (expr : ReqlExpr) = asyncWrite expr /// Perform a write operation [] - member _.AsyncWrite (expr, conn) = asyncWrite conn expr + member this.AsyncWrite (expr : ReqlExpr, conn : IConnection) = this.AsyncWrite expr conn /// Perform a write operation using optional arguments [] - member _.AsyncWrite (expr, args) = fun conn -> asyncWriteWithOptArgs args conn expr + member _.AsyncWrite (expr : ReqlExpr, args : RunOptArg list) = asyncWriteWithOptArgs args expr /// Perform a write operation using optional arguments [] - member _.AsyncWrite (expr, args, conn) = asyncWriteWithOptArgs args conn expr + member this.AsyncWrite (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) = + this.AsyncWrite (expr, args) conn /// Perform a write operation using a cancellation token [] - member _.AsyncWrite (expr, cancelToken) = fun conn -> asyncWriteWithCancel cancelToken conn expr + member _.AsyncWrite (expr : ReqlExpr, cancelToken : CancellationToken) = asyncWriteWithCancel cancelToken expr /// Perform a write operation using a cancellation token [] - member _.AsyncWrite (expr, cancelToken, conn) = asyncWriteWithCancel cancelToken conn expr + member this.AsyncWrite (expr : ReqlExpr, cancelToken : CancellationToken, conn : IConnection) = + this.AsyncWrite (expr, cancelToken) conn /// Perform a write operation using optional arguments and a cancellation token [] - member _.AsyncWrite (expr, args, cancelToken) = fun conn -> - asyncWriteWithOptArgsAndCancel args cancelToken conn expr + member _.AsyncWrite (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken) = + asyncWriteWithOptArgsAndCancel args cancelToken expr /// Perform a write operation using optional arguments and a cancellation token [] - member _.AsyncWrite (expr, args, cancelToken, conn) = asyncWriteWithOptArgsAndCancel args cancelToken conn expr + member this.AsyncWrite (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken, + conn : IConnection) = + this.AsyncWrite (expr, args, cancelToken) conn /// Perform a synchronous write operation [] - member _.SyncWrite expr = fun conn -> syncWrite conn expr + member _.SyncWrite (expr : ReqlExpr) = syncWrite expr /// Perform a synchronous write operation [] - member _.SyncWrite (expr, conn) = syncWrite conn expr + member this.SyncWrite (expr : ReqlExpr, conn : IConnection) = this.SyncWrite expr conn /// Perform a write operation using optional arguments [] - member _.SyncWrite (expr, args) = fun conn -> syncWriteWithOptArgs args conn expr + member _.SyncWrite (expr : ReqlExpr, args : RunOptArg list) = syncWriteWithOptArgs args expr /// Perform a write operation using optional arguments [] - member _.SyncWrite (expr, args, conn) = syncWriteWithOptArgs args conn expr + member this.SyncWrite (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) = + this.SyncWrite (expr, args) conn /// Perform a write operation, returning a result even if there are errors [] - member _.WriteResult expr = fun conn -> runWriteResult conn expr + member _.WriteResult (expr : ReqlExpr) = runWriteResult expr /// Perform a write operation, returning a result even if there are errors [] - member _.WriteResult (expr, conn) = runWriteResult conn expr + member this.WriteResult (expr : ReqlExpr, conn : IConnection) = this.WriteResult expr conn /// Perform a write operation with optional arguments, returning a result even if there are errors [] - member _.WriteResult (expr, args) = fun conn -> runWriteResultWithOptArgs args conn expr + member _.WriteResult (expr : ReqlExpr, args : RunOptArg list) = runWriteResultWithOptArgs args expr /// Perform a write operation with optional arguments, returning a result even if there are errors [] - member _.WriteResult (expr, args, conn) = runWriteResultWithOptArgs args conn expr + member this.WriteResult (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) = + this.WriteResult (expr, args) conn /// Perform a write operation with a cancellation token, returning a result even if there are errors [] - member _.WriteResult (expr, cancelToken) = fun conn -> runWriteResultWithCancel cancelToken conn expr + member _.WriteResult (expr : ReqlExpr, cancelToken : CancellationToken) = runWriteResultWithCancel cancelToken expr /// Perform a write operation with a cancellation token, returning a result even if there are errors [] - member _.WriteResult (expr, cancelToken, conn) = runWriteResultWithCancel cancelToken conn expr + member this.WriteResult (expr : ReqlExpr, cancelToken : CancellationToken, conn : IConnection) = + this.WriteResult (expr, cancelToken) conn /// Perform a write operation with optional arguments and a cancellation token, returning a result even if there are /// errors [] - member _.WriteResult (expr, args, cancelToken) = fun conn -> - runWriteResultWithOptArgsAndCancel args cancelToken conn expr + member _.WriteResult (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken) = + runWriteResultWithOptArgsAndCancel args cancelToken expr /// Perform a write operation with optional arguments and a cancellation token, returning a result even if there are /// errors [] - member _.WriteResult (expr, args, cancelToken, conn) = runWriteResultWithOptArgsAndCancel args cancelToken conn expr + member this.WriteResult (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken, + conn : IConnection) = + this.WriteResult (expr, args, cancelToken) conn /// Perform a write operation, returning a result even if there are errors [] - member _.AsyncWriteResult expr = fun conn -> asyncWriteResult conn expr + member _.AsyncWriteResult (expr : ReqlExpr) = asyncWriteResult expr /// Perform a write operation, returning a result even if there are errors [] - member _.AsyncWriteResult (expr, conn) = asyncWriteResult conn expr + member this.AsyncWriteResult (expr : ReqlExpr, conn : IConnection) = this.AsyncWriteResult expr conn /// Perform a write operation with optional arguments, returning a result even if there are errors [] - member _.AsyncWriteResult (expr, args) = fun conn -> asyncWriteResultWithOptArgs args conn expr + member _.AsyncWriteResult (expr : ReqlExpr, args : RunOptArg list) = asyncWriteResultWithOptArgs args expr /// Perform a write operation with optional arguments, returning a result even if there are errors [] - member _.AsyncWriteResult (expr, args, conn) = asyncWriteResultWithOptArgs args conn expr + member this.AsyncWriteResult (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) = + this.AsyncWriteResult (expr, args) conn /// Perform a write operation with a cancellation token, returning a result even if there are errors [] - member _.AsyncWriteResult (expr, cancelToken) = fun conn -> asyncWriteResultWithCancel cancelToken conn expr + member _.AsyncWriteResult (expr : ReqlExpr, cancelToken : CancellationToken) = + asyncWriteResultWithCancel cancelToken expr /// Perform a write operation with a cancellation token, returning a result even if there are errors [] - member _.AsyncWriteResult (expr, cancelToken, conn) = asyncWriteResultWithCancel cancelToken conn expr + member this.AsyncWriteResult (expr : ReqlExpr, cancelToken : CancellationToken, conn : IConnection) = + this.AsyncWriteResult (expr, cancelToken) conn /// Perform a write operation with optional arguments and a cancellation token, returning a result even if there are /// errors [] - member _.AsyncWriteResult (expr, args, cancelToken) = fun conn -> - asyncWriteResultWithOptArgsAndCancel args cancelToken conn expr + member _.AsyncWriteResult (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken) = + asyncWriteResultWithOptArgsAndCancel args cancelToken expr /// Perform a write operation with optional arguments and a cancellation token, returning a result even if there are /// errors [] - member _.AsyncWriteResult (expr, args, cancelToken, conn) = - asyncWriteResultWithOptArgsAndCancel args cancelToken conn expr + member this.AsyncWriteResult (expr : ReqlExpr, args : RunOptArg list, cancelToken : CancellationToken, + conn : IConnection) = + this.AsyncWriteResult (expr, args, cancelToken) conn /// Perform a synchronous write operation, returning a result even if there are errors [] - member _.SyncWriteResult expr = fun conn -> syncWriteResult conn expr + member _.SyncWriteResult (expr : ReqlExpr) = syncWriteResult expr /// Perform a synchronous write operation, returning a result even if there are errors [] - member _.SyncWriteResult (expr, conn) = syncWriteResult conn expr + member this.SyncWriteResult (expr : ReqlExpr, conn : IConnection) = this.SyncWriteResult expr conn /// Perform a synchronous write operation with optional arguments, returning a result even if there are errors [] - member _.SyncWriteResult (expr, args) = fun conn -> syncWriteResultWithOptArgs args conn expr + member _.SyncWriteResult (expr : ReqlExpr, args : RunOptArg list) = syncWriteResultWithOptArgs args expr /// Perform a synchronous write operation with optional arguments, returning a result even if there are errors [] - member _.SyncWriteResult (expr, args, conn) = syncWriteResultWithOptArgs args conn expr + member this.SyncWriteResult (expr : ReqlExpr, args : RunOptArg list, conn : IConnection) = + this.SyncWriteResult (expr, args) conn /// Ignore the result of an operation [] - member _.IgnoreResult (f : IConnection -> Task<'T>) = fun conn -> task { - let! _ = (f conn).ConfigureAwait false - () - } + member _.IgnoreResult (f : IConnection -> Task<'T>) = ignoreResult<'T> f /// Ignore the result of an operation [] - member this.IgnoreResult (f : IConnection -> Task<'T>, conn) = - this.IgnoreResult f conn + member this.IgnoreResult (f : IConnection -> Task<'T>, conn) = this.IgnoreResult f conn /// Ignore the result of an operation [] @@ -802,147 +803,162 @@ type RethinkBuilder<'T> () = /// Retries a variable number of times, waiting each time for the seconds specified [] - member _.WithRetry (f, retries) = withRetry<'T> retries f + member _.WithRetry (f : IConnection -> Task<'T>, retries : float seq) = withRetry<'T> retries f /// Retries a variable number of times, waiting each time for the seconds specified [] - member _.WithRetry (f, retries, conn) = withRetry<'T> retries f conn + member this.WithRetry (f : IConnection -> Task<'T>, retries : float seq, conn : IConnection) = + this.WithRetry (f, retries) conn /// Retries a variable number of times, waiting each time for the seconds specified [] - member _.WithRetryOption (f, retries) = withRetry<'T option> retries f + member _.WithRetryOption (f : IConnection -> Task<'T option>, retries : float seq) = withRetry<'T option> retries f /// Retries a variable number of times, waiting each time for the seconds specified [] - member _.WithRetryOption (f, retries, conn) = withRetry<'T option> retries f conn + member this.WithRetryOption (f : IConnection -> Task<'T option>, retries : float seq, conn : IConnection) = + this.WithRetryOption (f, retries) conn /// Retries a variable number of times, waiting each time for the seconds specified [] - member _.WithAsyncRetry (f, retries) = withAsyncRetry<'T> retries f + member _.WithAsyncRetry (f : IConnection -> Async<'T>, retries : float seq) = withAsyncRetry<'T> retries f /// Retries a variable number of times, waiting each time for the seconds specified [] - member _.WithAsyncRetry (f, retries, conn) = withAsyncRetry<'T> retries f conn + member this.WithAsyncRetry (f : IConnection -> Async<'T>, retries : float seq, conn : IConnection) = + this.WithAsyncRetry (f, retries) conn /// Retries a variable number of times, waiting each time for the seconds specified [] - member _.WithAsyncRetryOption (f, retries) = withAsyncRetry<'T option> retries f + member this.WithAsyncRetryOption (f : IConnection -> Async<'T option>, retries : float seq) = + withAsyncRetry<'T option> retries f /// Retries a variable number of times, waiting each time for the seconds specified [] - member _.WithAsyncRetryOption (f, retries, conn) = withAsyncRetry<'T option> retries f conn + member this.WithAsyncRetryOption (f : IConnection -> Async<'T option>, retries : float seq, conn : IConnection) = + this.WithAsyncRetryOption (f, retries) conn /// Retries a variable number of times, waiting each time for the seconds specified [] - member _.WithSyncRetry (f, retries) = withSyncRetry<'T> retries f + member _.WithSyncRetry (f : IConnection -> 'T, retries : float seq) = withSyncRetry<'T> retries f /// Retries a variable number of times, waiting each time for the seconds specified [] - member _.WithSyncRetry (f, retries, conn) = withSyncRetry<'T> retries f conn + member this.WithSyncRetry (f : IConnection -> 'T, retries : float seq, conn : IConnection) = + this.WithSyncRetry (f, retries) conn /// Retries a variable number of times, waiting each time for the seconds specified [] - member _.WithSyncRetryOption (f, retries) = withSyncRetry<'T option> retries f + member _.WithSyncRetryOption (f : IConnection -> 'T option, retries : float seq) = + withSyncRetry<'T option> retries f /// Retries a variable number of times, waiting each time for the seconds specified [] - member _.WithSyncRetryOption (f, retries, conn) = withSyncRetry<'T option> retries f conn + member this.WithSyncRetryOption (f : IConnection -> 'T option, retries : float seq, conn : IConnection) = + this.WithSyncRetryOption (f, retries) conn /// Retries at 200ms, 500ms, and 1s [] - member _.WithRetryDefault f = withRetryDefault<'T> f + member _.WithRetryDefault (f : IConnection -> Task<'T>) = withRetryDefault<'T> f /// Retries at 200ms, 500ms, and 1s [] - member _.WithRetryDefault (f, conn) = withRetryDefault<'T> f conn + member this.WithRetryDefault (f : IConnection -> Task<'T>, conn : IConnection) = this.WithRetryDefault f conn /// Retries at 200ms, 500ms, and 1s [] - member _.WithRetryOptionDefault f = withRetryDefault<'T option> f + member _.WithRetryOptionDefault (f : IConnection -> Task<'T option>) = withRetryDefault<'T option> f /// Retries at 200ms, 500ms, and 1s [] - member _.WithRetryOptionDefault (f, conn) = withRetryDefault<'T option> f conn + member this.WithRetryOptionDefault (f : IConnection -> Task<'T option>, conn : IConnection) = + this.WithRetryOptionDefault f conn /// Retries at 200ms, 500ms, and 1s [] - member _.WithAsyncRetryDefault f = withAsyncRetryDefault<'T> f + member _.WithAsyncRetryDefault (f : IConnection -> Async<'T>) = withAsyncRetryDefault<'T> f /// Retries at 200ms, 500ms, and 1s [] - member _.WithAsyncRetryDefault (f, conn) = withAsyncRetryDefault<'T> f conn + member this.WithAsyncRetryDefault (f : IConnection -> Async<'T>, conn : IConnection) = + this.WithAsyncRetryDefault f conn /// Retries at 200ms, 500ms, and 1s [] - member _.WithAsyncRetryOptionDefault f = withAsyncRetryDefault<'T option> f + member _.WithAsyncRetryOptionDefault (f : IConnection -> Async<'T option>) = withAsyncRetryDefault<'T option> f /// Retries at 200ms, 500ms, and 1s [] - member _.WithAsyncRetryOptionDefault (f, conn) = withAsyncRetryDefault<'T option> f conn + member this.WithAsyncRetryOptionDefault (f : IConnection -> Async<'T option>, conn : IConnection) = + this.WithAsyncRetryOptionDefault f conn /// Retries at 200ms, 500ms, and 1s [] - member _.WithSyncRetryDefault f = withSyncRetryDefault<'T> f + member _.WithSyncRetryDefault (f : IConnection -> 'T) = withSyncRetryDefault<'T> f /// Retries at 200ms, 500ms, and 1s [] - member _.WithSyncRetryDefault (f, conn) = withSyncRetryDefault<'T> f conn + member this.WithSyncRetryDefault (f : IConnection -> 'T, conn : IConnection) = this.WithSyncRetryDefault f conn /// Retries at 200ms, 500ms, and 1s [] - member _.WithSyncRetryOptionDefault f = withSyncRetryDefault<'T option> f + member _.WithSyncRetryOptionDefault (f : IConnection -> 'T option) = withSyncRetryDefault<'T option> f /// Retries at 200ms, 500ms, and 1s [] - member _.WithSyncRetryOptionDefault (f, conn) = withSyncRetryDefault<'T option> f conn + member this.WithSyncRetryOptionDefault (f : IConnection -> 'T option, conn : IConnection) = + this.WithSyncRetryOptionDefault f conn /// Retries once immediately [] - member _.WithRetryOnce f = withRetryOnce<'T> f + member _.WithRetryOnce (f : IConnection -> Task<'T>) = withRetryOnce<'T> f /// Retries once immediately [] - member _.WithRetryOnce (f, conn) = withRetryOnce<'T> f conn + member this.WithRetryOnce (f : IConnection -> Task<'T>, conn : IConnection) = this.WithRetryOnce f conn /// Retries once immediately [] - member _.WithRetryOptionOnce f = withRetryOnce<'T option> f + member _.WithRetryOptionOnce (f : IConnection -> Task<'T option>) = withRetryOnce<'T option> f /// Retries once immediately [] - member _.WithRetryOptionOnce (f, conn) = withRetryOnce<'T option> f conn + member this.WithRetryOptionOnce (f : IConnection -> Task<'T option>, conn : IConnection) = + this.WithRetryOptionOnce f conn /// Retries once immediately [] - member _.WithAsyncRetryOnce f = withAsyncRetryOnce<'T> f + member _.WithAsyncRetryOnce (f : IConnection -> Async<'T>) = withAsyncRetryOnce<'T> f /// Retries once immediately [] - member _.WithAsyncRetryOnce (f, conn) = withAsyncRetryOnce<'T> f conn + member this.WithAsyncRetryOnce (f : IConnection -> Async<'T>, conn : IConnection) = this.WithAsyncRetryOnce f conn /// Retries once immediately [] - member _.WithAsyncRetryOptionOnce f = withAsyncRetryOnce<'T option> f + member _.WithAsyncRetryOptionOnce (f : IConnection -> Async<'T option>) = withAsyncRetryOnce<'T option> f /// Retries once immediately [] - member _.WithAsyncRetryOptionOnce (f, conn) = withAsyncRetryOnce<'T option> f conn + member this.WithAsyncRetryOptionOnce (f : IConnection -> Async<'T option>, conn : IConnection) = + this.WithAsyncRetryOptionOnce f conn /// Retries once immediately [] - member _.WithSyncRetryOnce f = withSyncRetryOnce<'T> f + member _.WithSyncRetryOnce (f : IConnection -> 'T) = withSyncRetryOnce<'T> f /// Retries once immediately [] - member _.WithSyncRetryOnce (f, conn) = withSyncRetryOnce<'T> f conn + member this.WithSyncRetryOnce (f : IConnection -> 'T, conn : IConnection) = this.WithSyncRetryOnce f conn /// Retries once immediately [] - member _.WithSyncRetryOptionOnce f = withSyncRetryOnce<'T option> f + member _.WithSyncRetryOptionOnce (f : IConnection -> 'T option) = withSyncRetryOnce<'T option> f /// Retries once immediately [] - member _.WithSyncRetryOptionOnce (f, conn) = withSyncRetryOnce<'T option> f conn + member this.WithSyncRetryOptionOnce (f : IConnection -> 'T option, conn : IConnection) = + this.WithSyncRetryOptionOnce f conn /// RethinkDB computation expression diff --git a/src/RethinkDb.Driver.FSharp/Config.fs b/src/RethinkDb.Driver.FSharp/Config.fs index 50bec96..8a1c620 100644 --- a/src/RethinkDb.Driver.FSharp/Config.fs +++ b/src/RethinkDb.Driver.FSharp/Config.fs @@ -28,7 +28,7 @@ module private ConnectionBuilder = | Database x -> builder.Db x -/// RethinDB configuration +/// RethinkDB configuration type DataConfig = { Parameters : DataConfigParameter list } diff --git a/src/RethinkDb.Driver.FSharp/Functions.fs b/src/RethinkDb.Driver.FSharp/Functions.fs index 2b89b1a..d805200 100644 --- a/src/RethinkDb.Driver.FSharp/Functions.fs +++ b/src/RethinkDb.Driver.FSharp/Functions.fs @@ -4,6 +4,7 @@ module RethinkDb.Driver.FSharp.Functions open System.Threading open RethinkDb.Driver open RethinkDb.Driver.Ast +open RethinkDb.Driver.Net [] module private Helpers = @@ -16,122 +17,167 @@ module private Helpers = // ~~ EXECUTION ~~ /// Get a cursor with the results of an expression -let asyncCursor<'T> conn (expr : ReqlExpr) = +let asyncCursor<'T> (expr : ReqlExpr) conn = expr.RunCursorAsync<'T> conn |> Async.AwaitTask +// ~~ WRITES ~~ + +/// Write a ReQL command with a cancellation token, always returning a result +let runWriteResultWithCancel cancelToken (expr : ReqlExpr) = fun conn -> + expr.RunWriteAsync (conn, cancelToken) + +/// Write a ReQL command, always returning a result +let runWriteResult expr = runWriteResultWithCancel CancellationToken.None expr + +/// Write a ReQL command with optional arguments and a cancellation token, always returning a result +let runWriteResultWithOptArgsAndCancel args cancelToken (expr : ReqlExpr) = fun conn -> + expr.RunWriteAsync (conn, RunOptArg.create args, cancelToken) + +/// Write a ReQL command with optional arguments, always returning a result +let runWriteResultWithOptArgs args expr = runWriteResultWithOptArgsAndCancel args CancellationToken.None expr + +/// Write a ReQL command, always returning a result +let asyncWriteResult expr = fun conn -> + runWriteResult expr conn |> Async.AwaitTask + +/// Write a ReQL command with optional arguments, always returning a result +let asyncWriteResultWithOptArgs args expr = fun conn -> + runWriteResultWithOptArgs args expr conn |> Async.AwaitTask + +/// Write a ReQL command with a cancellation token, always returning a result +let asyncWriteResultWithCancel cancelToken expr = fun conn -> + runWriteResultWithCancel cancelToken expr conn |> Async.AwaitTask + +/// Write a ReQL command with optional arguments and a cancellation token, always returning a result +let asyncWriteResultWithOptArgsAndCancel args cancelToken expr = fun conn -> + runWriteResultWithOptArgsAndCancel args cancelToken expr conn |> Async.AwaitTask + +/// Write a ReQL command synchronously, always returning a result +let syncWriteResult expr = fun conn -> + asyncWriteResult expr conn |> Async.RunSynchronously + +/// Write a ReQL command synchronously with optional arguments, always returning a result +let syncWriteResultWithOptArgs args expr = fun conn -> + asyncWriteResultWithOptArgs args expr conn |> Async.RunSynchronously + /// Raise an exception if a write command encountered an error -let private raiseIfWriteError (result : Model.Result) = +let raiseIfWriteError (result : Model.Result) = match result.Errors with | 0UL -> result | _ -> raise <| ReqlRuntimeError result.FirstError /// Write a ReQL command, raising an exception if an error occurs -let runWriteWithCancel cancelToken conn (expr : ReqlExpr) = backgroundTask { - let! result = expr.RunWriteAsync (conn, cancelToken) +let runWriteWithCancel cancelToken expr = fun conn -> backgroundTask { + let! result = runWriteResultWithCancel cancelToken expr conn return raiseIfWriteError result } /// Write a ReQL command, raising an exception if an error occurs -let runWrite conn expr = runWriteWithCancel CancellationToken.None conn expr +let runWrite expr = runWriteWithCancel CancellationToken.None expr /// Write a ReQL command with optional arguments, raising an exception if an error occurs -let runWriteWithOptArgsAndCancel args cancelToken conn (expr : ReqlExpr) = backgroundTask { - let! result = expr.RunWriteAsync (conn, RunOptArg.create args, cancelToken) +let runWriteWithOptArgsAndCancel args cancelToken expr = fun conn -> backgroundTask { + let! result = runWriteResultWithOptArgsAndCancel args cancelToken expr conn return raiseIfWriteError result } /// Write a ReQL command with optional arguments, raising an exception if an error occurs -let runWriteWithOptArgs args conn expr = runWriteWithOptArgsAndCancel args CancellationToken.None conn expr +let runWriteWithOptArgs args expr = runWriteWithOptArgsAndCancel args CancellationToken.None expr /// Write a ReQL command, raising an exception if an error occurs -let asyncWrite conn expr = runWrite conn expr |> Async.AwaitTask +let asyncWrite expr = fun conn -> + runWrite expr conn |> Async.AwaitTask /// Write a ReQL command with optional arguments, raising an exception if an error occurs -let asyncWriteWithOptArgs args conn expr = runWriteWithOptArgs args conn expr |> Async.AwaitTask +let asyncWriteWithOptArgs args expr = fun conn -> + runWriteWithOptArgs args expr conn |> Async.AwaitTask /// Write a ReQL command, raising an exception if an error occurs -let asyncWriteWithCancel cancelToken conn expr = runWriteWithCancel cancelToken conn expr |> Async.AwaitTask +let asyncWriteWithCancel cancelToken expr = fun conn -> + runWriteWithCancel cancelToken expr conn |> Async.AwaitTask /// Write a ReQL command with optional arguments, raising an exception if an error occurs -let asyncWriteWithOptArgsAndCancel args cancelToken conn expr = - runWriteWithOptArgsAndCancel args cancelToken conn expr |> Async.AwaitTask +let asyncWriteWithOptArgsAndCancel args cancelToken expr = fun conn -> + runWriteWithOptArgsAndCancel args cancelToken expr conn |> Async.AwaitTask /// Write a ReQL command synchronously, raising an exception if an error occurs -let syncWrite conn expr = asyncWrite conn expr |> Async.RunSynchronously +let syncWrite expr = fun conn -> + asyncWrite expr conn |> Async.RunSynchronously /// Write a ReQL command synchronously with optional arguments, raising an exception if an error occurs -let syncWriteWithOptArgs args conn expr = asyncWriteWithOptArgs args conn expr |> Async.RunSynchronously - -/// Write a ReQL command with a cancellation token, always returning a result -let runWriteResultWithCancel cancelToken conn (expr : ReqlExpr) = - expr.RunWriteAsync (conn, cancelToken) - -/// Write a ReQL command, always returning a result -let runWriteResult conn expr = runWriteResultWithCancel CancellationToken.None conn expr - -/// Write a ReQL command with optional arguments and a cancellation token, always returning a result -let runWriteResultWithOptArgsAndCancel args cancelToken conn (expr : ReqlExpr) = - expr.RunWriteAsync (conn, RunOptArg.create args, cancelToken) - -/// Write a ReQL command with optional arguments, always returning a result -let runWriteResultWithOptArgs args conn expr = runWriteResultWithOptArgsAndCancel args CancellationToken.None conn expr - -/// Write a ReQL command, always returning a result -let asyncWriteResult conn expr = runWriteResult conn expr |> Async.AwaitTask - -/// Write a ReQL command with optional arguments, always returning a result -let asyncWriteResultWithOptArgs args conn expr = runWriteResultWithOptArgs args conn expr |> Async.AwaitTask - -/// Write a ReQL command with a cancellation token, always returning a result -let asyncWriteResultWithCancel cancelToken conn expr = runWriteResultWithCancel cancelToken conn expr |> Async.AwaitTask - -/// Write a ReQL command with optional arguments and a cancellation token, always returning a result -let asyncWriteResultWithOptArgsAndCancel args cancelToken conn expr = - runWriteResultWithOptArgsAndCancel args cancelToken conn expr |> Async.AwaitTask - -/// Write a ReQL command synchronously, always returning a result -let syncWriteResult conn expr = asyncWriteResult conn expr |> Async.RunSynchronously - -/// Write a ReQL command synchronously with optional arguments, always returning a result -let syncWriteResultWithOptArgs args conn expr = asyncWriteResultWithOptArgs args conn expr |> Async.RunSynchronously +let syncWriteWithOptArgs args expr = fun conn -> + asyncWriteWithOptArgs args expr conn |> Async.RunSynchronously +// ~~ QUERY RESULTS AND MANIPULATION ~~ + /// Run the ReQL command using a cancellation token, returning the result as the type specified -let runResultWithCancel<'T> cancelToken conn (expr : ReqlExpr) = expr.RunResultAsync<'T> (conn, cancelToken) +let runResultWithCancel<'T> cancelToken (expr : ReqlExpr) = fun conn -> + expr.RunResultAsync<'T> (conn, cancelToken) -/// Run the ReQL command using optional arguments and a cancellation token, returning the result as the type specified -let runResultWithOptArgsAndCancel<'T> args cancelToken conn (expr : ReqlExpr) = +/// Run the ReQL command using optional arguments and a cancellation token, returning the result as the type +/// specified +let runResultWithOptArgsAndCancel<'T> args cancelToken (expr : ReqlExpr) = fun conn -> expr.RunResultAsync<'T> (conn, RunOptArg.create args, cancelToken) /// Run the ReQL command, returning the result as the type specified -let runResult<'T> = runResultWithCancel<'T> CancellationToken.None +let runResult<'T> expr = runResultWithCancel<'T> CancellationToken.None expr /// Run the ReQL command using optional arguments, returning the result as the type specified -let runResultWithOptArgs<'T> args = runResultWithOptArgsAndCancel<'T> args CancellationToken.None +let runResultWithOptArgs<'T> args expr = runResultWithOptArgsAndCancel<'T> args CancellationToken.None expr /// Run the ReQL command, returning the result as the type specified -let asyncResult<'T> conn expr = +let asyncResult<'T> expr = fun conn -> runResult<'T> expr conn |> Async.AwaitTask /// Run the ReQL command using optional arguments, returning the result as the type specified -let asyncResultWithOptArgs<'T> args conn expr = - runResultWithOptArgs<'T> args conn expr |> Async.AwaitTask +let asyncResultWithOptArgs<'T> args expr = fun conn -> + runResultWithOptArgs<'T> args expr conn |> Async.AwaitTask /// Run the ReQL command using a cancellation token, returning the result as the type specified -let asyncResultWithCancel<'T> cancelToken conn (expr : ReqlExpr) = - runResultWithCancel<'T> cancelToken conn expr |> Async.AwaitTask +let asyncResultWithCancel<'T> cancelToken expr = fun conn -> + runResultWithCancel<'T> cancelToken expr conn |> Async.AwaitTask -/// Run the ReQL command using optional arguments and a cancellation token, returning the result as the type specified -let asyncResultWithOptArgsAndCancel<'T> args cancelToken conn expr = - runResultWithOptArgsAndCancel<'T> args cancelToken conn expr |> Async.AwaitTask +/// Run the ReQL command using optional arguments and a cancellation token, returning the result as the type +/// specified +let asyncResultWithOptArgsAndCancel<'T> args cancelToken expr = fun conn -> + runResultWithOptArgsAndCancel<'T> args cancelToken expr conn |> Async.AwaitTask /// Run the ReQL command, returning the result as the type specified -let syncResult<'T> conn expr = +let syncResult<'T> expr = fun conn -> asyncResult<'T> expr conn |> Async.RunSynchronously /// Run the ReQL command using optional arguments, returning the result as the type specified -let syncResultWithOptArgs<'T> args conn expr = - asyncResultWithOptArgs<'T> args conn expr |> Async.RunSynchronously +let syncResultWithOptArgs<'T> args expr = fun conn -> + asyncResultWithOptArgs<'T> args expr conn |> Async.RunSynchronously + +/// Convert a null item to an option (works for value types as well as reference types) +let nullToOption<'T> (it : 'T) = + if isNull (box it) then None else Some it + +/// Convert a possibly-null result to an option +let asOption (f : IConnection -> Tasks.Task<'T>) conn = backgroundTask { + let! result = f conn + return nullToOption result +} + +/// Convert a possibly-null result to an option +let asAsyncOption (f : IConnection -> Async<'T>) conn = async { + let! result = f conn + return nullToOption result +} + +/// Convert a possibly-null result to an option +let asSyncOption (f : IConnection -> 'T) conn = nullToOption (f conn) + +/// Ignore the result of a task-based query +let ignoreResult<'T> (f : IConnection -> Tasks.Task<'T>) conn = task { + let! _ = (f conn).ConfigureAwait false + () +} + +/// Apply a connection to the query pipeline (typically the final step) +let withConn<'T> conn (f : IConnection -> 'T) = f conn // ~~ QUERY DEFINITION ~~ @@ -192,7 +238,7 @@ let distinct (expr : ReqlExpr) = expr.Distinct () /// Only retrieve distinct entries from a selection, based on an index -let distinctWithIndex expr (index : string) = +let distinctWithIndex (index : string) expr = (distinct expr).OptArg ("index", index) /// EqJoin the left field on the right-hand table using its primary key @@ -224,7 +270,7 @@ let filter (filterSpec : obj) (expr : ReqlExpr) = expr.Filter filterSpec /// Filter documents, providing optional arguments -let filterWithOptArgs (filterSpec : obj) arg expr = +let filterWithOptArg (filterSpec : obj) arg expr = filter filterSpec expr |> FilterOptArg.apply arg /// Filter documents using a function @@ -232,7 +278,7 @@ let filterFunc f (expr : ReqlExpr) = expr.Filter (ReqlFunction1 f) /// Filter documents using a function, providing optional arguments -let filterFuncWithOptArgs f arg expr = +let filterFuncWithOptArg f arg expr = filterFunc f expr |> FilterOptArg.apply arg /// Filter documents using multiple functions (has the effect of ANDing them) @@ -240,7 +286,7 @@ let filterFuncAll fs expr = (fs |> List.fold (fun (e : ReqlExpr) f -> filterFunc f e) expr) :?> Filter /// Filter documents using multiple functions (has the effect of ANDing them), providing optional arguments -let filterFuncAllWithOptArgs fs arg expr = +let filterFuncAllWithOptArg fs arg expr = filterFuncAll fs expr |> FilterOptArg.apply arg /// Filter documents using JavaScript @@ -248,7 +294,7 @@ let filterJS js (expr : ReqlExpr) = expr.Filter (toJS js) /// Filter documents using JavaScript, providing optional arguments -let filterJSWithOptArgs js arg expr = +let filterJSWithOptArg js arg expr = filterJS js expr |> FilterOptArg.apply arg /// Get a document by its primary key @@ -328,19 +374,19 @@ let innerJoinJS (otherSeq : obj) js (expr : ReqlExpr) = expr.InnerJoin (otherSeq, toJS js) /// Insert a single document (use insertMany for multiple) -let insert (doc : obj) (table : Table) = +let insert<'T> (doc : 'T) (table : Table) = table.Insert doc /// Insert multiple documents -let insertMany (docs : obj seq) (table : Table) = +let insertMany<'T> (docs : 'T seq) (table : Table) = table.Insert (Array.ofSeq docs) /// Insert a single document, providing optional arguments (use insertManyWithOptArgs for multiple) -let insertWithOptArgs (doc : obj) args table = +let insertWithOptArgs<'T> (doc : 'T) args table = insert doc table |> InsertOptArg.apply args /// Insert multiple documents, providing optional arguments -let insertManyWithOptArgs (docs : obj seq) args table = +let insertManyWithOptArgs<'T> (docs : 'T seq) args table = insertMany docs table |> InsertOptArg.apply args /// Test whether a sequence is empty @@ -372,7 +418,7 @@ let mergeJS js (expr : ReqlExpr) = expr.Merge (toJS js) /// Retrieve the nth element in a sequence -let nth n (expr : ReqlExpr) = +let nth (n : int) (expr : ReqlExpr) = expr.Nth n /// Order a sequence by a given field @@ -452,27 +498,27 @@ let sync (table : Table) = table.Sync () /// Return all documents in a table (may be further refined) -let table tableName (db : Db) = +let table (tableName : string) (db : Db) = db.Table tableName /// Return all documents in a table from the default database (may be further refined) -let fromTable tableName = +let fromTable (tableName : string) = r.Table tableName /// Create a table in the given database -let tableCreate tableName (db : Db) = +let tableCreate (tableName : string) (db : Db) = db.TableCreate tableName /// Create a table in the connection-default database -let tableCreateInDefault tableName = +let tableCreateInDefault (tableName : string) = r.TableCreate tableName /// Drop a table in the given database -let tableDrop tableName (db : Db) = +let tableDrop (tableName : string) (db : Db) = db.TableDrop tableName /// Drop a table from the connection-default database -let tableDropFromDefault tableName = +let tableDropFromDefault (tableName : string) = r.TableDrop tableName /// Get a list of tables for the given database @@ -515,10 +561,8 @@ let without (columns : string seq) (expr : ReqlExpr) = let zip (expr : ReqlExpr) = expr.Zip () -// ~~ RETRY ~~ - -open RethinkDb.Driver.Net - +// ~~ RETRY FUNCTIONS ~~ + /// Retry, delaying for each the seconds provided (if required) let withRetry<'T> intervals f = Retry.withRetry<'T> f intervals @@ -539,11 +583,11 @@ let withSyncRetry<'T> intervals f = let withRetryDefault<'T> f = Retry.withRetryDefault<'T> f -/// Retry, delaying for each the seconds provided (if required) +/// Retry failed commands with 200ms, 500ms, and 1 second delays let withAsyncRetryDefault<'T> f = fun conn -> withRetryDefault<'T> (asyncFuncToTask f) conn |> Async.AwaitTask -/// Retry, delaying for each the seconds provided (if required) +/// Retry failed commands with 200ms, 500ms, and 1 second delays let withSyncRetryDefault<'T> f = Retry.withRetrySyncDefault<'T> f @@ -551,10 +595,10 @@ let withSyncRetryDefault<'T> f = let withRetryOnce<'T> f = Retry.withRetryOnce<'T> f -/// Retry, delaying for each the seconds provided (if required) +/// Retry failed commands one time with no delay let withAsyncRetryOnce<'T> f = fun conn -> withRetryOnce<'T> (asyncFuncToTask f) conn |> Async.AwaitTask -/// Retry, delaying for each the seconds provided (if required) +/// Retry failed commands one time with no delay let withSyncRetryOnce<'T> f = Retry.withRetrySyncOnce<'T> f diff --git a/src/RethinkDb.Driver.FSharp/Functions.fsi b/src/RethinkDb.Driver.FSharp/Functions.fsi new file mode 100644 index 0000000..b9844eb --- /dev/null +++ b/src/RethinkDb.Driver.FSharp/Functions.fsi @@ -0,0 +1,442 @@ +/// The function-based Domain-Specific Language (DSL) for RethinkDB +module RethinkDb.Driver.FSharp.Functions + +open System.Threading +open System.Threading.Tasks +open RethinkDb.Driver +open RethinkDb.Driver.Ast +open RethinkDb.Driver.Net + +/// Get a cursor with the results of an expression +val asyncCursor<'T> : ReqlExpr -> IConnection -> Async> + +// ~~ WRITE, ALWAYS RETURNING A RESULT ~~ + +/// Write a ReQL command with a cancellation token, always returning a result +val runWriteResultWithCancel : CancellationToken -> ReqlExpr -> (IConnection -> Task) + +/// Write a ReQL command, always returning a result +val runWriteResult : ReqlExpr -> (IConnection -> Task) + +/// Write a ReQL command with optional arguments and a cancellation token, always returning a result +val runWriteResultWithOptArgsAndCancel : + RunOptArg list -> CancellationToken -> ReqlExpr -> (IConnection -> Task) + +/// Write a ReQL command with optional arguments, always returning a result +val runWriteResultWithOptArgs : RunOptArg list -> ReqlExpr -> (IConnection -> Task) + +/// Write a ReQL command, always returning a result +val asyncWriteResult : ReqlExpr -> (IConnection -> Async) + +/// Write a ReQL command with optional arguments, always returning a result +val asyncWriteResultWithOptArgs : RunOptArg list -> ReqlExpr -> (IConnection -> Async) + +/// Write a ReQL command with a cancellation token, always returning a result +val asyncWriteResultWithCancel : CancellationToken -> ReqlExpr -> (IConnection -> Async) + +/// Write a ReQL command with optional arguments and a cancellation token, always returning a result +val asyncWriteResultWithOptArgsAndCancel : + RunOptArg list -> CancellationToken -> ReqlExpr -> (IConnection -> Async) + +/// Write a ReQL command synchronously, always returning a result +val syncWriteResult : ReqlExpr -> (IConnection -> Model.Result) + +/// Write a ReQL command synchronously with optional arguments, always returning a result +val syncWriteResultWithOptArgs : RunOptArg list -> ReqlExpr -> (IConnection -> Model.Result) + +// ~~ WRITE, RAISING AN EXCEPTION ON ERRORS ~~ + +/// Write a ReQL command, raising an exception if an error occurs +val runWriteWithCancel : CancellationToken -> ReqlExpr -> (IConnection -> Task) + +/// Write a ReQL command, raising an exception if an error occurs +val runWrite : ReqlExpr -> (IConnection -> Task) + +/// Write a ReQL command with optional arguments, raising an exception if an error occurs +val runWriteWithOptArgsAndCancel : + RunOptArg list -> CancellationToken -> ReqlExpr -> (IConnection -> Task) + +/// Write a ReQL command with optional arguments, raising an exception if an error occurs +val runWriteWithOptArgs : RunOptArg list -> ReqlExpr -> (IConnection -> Task) + +/// Write a ReQL command, raising an exception if an error occurs +val asyncWrite : ReqlExpr -> (IConnection -> Async) + +/// Write a ReQL command with optional arguments, raising an exception if an error occurs +val asyncWriteWithOptArgs : RunOptArg list -> ReqlExpr -> (IConnection -> Async) + +/// Write a ReQL command, raising an exception if an error occurs +val asyncWriteWithCancel : CancellationToken -> ReqlExpr -> (IConnection -> Async) + +/// Write a ReQL command with optional arguments, raising an exception if an error occurs +val asyncWriteWithOptArgsAndCancel : + RunOptArg list -> CancellationToken -> ReqlExpr -> (IConnection -> Async) + +/// Write a ReQL command synchronously, raising an exception if an error occurs +val syncWrite : ReqlExpr -> (IConnection -> Model.Result) + +/// Write a ReQL command synchronously with optional arguments, raising an exception if an error occurs +val syncWriteWithOptArgs : RunOptArg list -> ReqlExpr -> (IConnection -> Model.Result) + +// ~~ RUNNING QUERIES AND MANIPULATING RESULTS ~~ + +/// Run the ReQL command using a cancellation token, returning the result as the type specified +val runResultWithCancel<'T> : CancellationToken -> ReqlExpr -> (IConnection -> Task<'T>) + +/// Run the ReQL command using optional arguments and a cancellation token, returning the result as the type specified +val runResultWithOptArgsAndCancel<'T> : RunOptArg list -> CancellationToken -> ReqlExpr -> (IConnection -> Task<'T>) + +/// Run the ReQL command, returning the result as the type specified +val runResult<'T> : ReqlExpr -> (IConnection -> Task<'T>) + +/// Run the ReQL command using optional arguments, returning the result as the type specified +val runResultWithOptArgs<'T> : RunOptArg list -> ReqlExpr -> (IConnection -> Task<'T>) + +/// Run the ReQL command, returning the result as the type specified +val asyncResult<'T> : ReqlExpr -> (IConnection -> Async<'T>) + +/// Run the ReQL command using optional arguments, returning the result as the type specified +val asyncResultWithOptArgs<'T> : RunOptArg list -> ReqlExpr -> (IConnection -> Async<'T>) + +/// Run the ReQL command using a cancellation token, returning the result as the type specified +val asyncResultWithCancel<'T> : CancellationToken -> ReqlExpr -> (IConnection -> Async<'T>) + +/// Run the ReQL command using optional arguments and a cancellation token, returning the result as the type specified +val asyncResultWithOptArgsAndCancel<'T> : RunOptArg list -> CancellationToken -> ReqlExpr -> (IConnection -> Async<'T>) + +/// Run the ReQL command, returning the result as the type specified +val syncResult<'T> : ReqlExpr -> (IConnection -> 'T) + +/// Run the ReQL command using optional arguments, returning the result as the type specified +val syncResultWithOptArgs<'T> : RunOptArg list -> ReqlExpr -> (IConnection -> 'T) + +/// Convert a possibly-null result to an option +val asOption : (IConnection -> Task<'T>) -> IConnection -> Task<'T option> + +/// Convert a possibly-null result to an option +val asAsyncOption : (IConnection -> Async<'T>) -> IConnection -> Async<'T option> + +/// Convert a possibly-null result to an option +val asSyncOption : (IConnection -> 'T) -> IConnection -> 'T option + +/// Ignore the result of a task-based execution +val ignoreResult<'T> : (IConnection -> Task<'T>) -> IConnection -> Task + +/// Apply a connection to the query pipeline (typically the final step) +val withConn<'T> : IConnection -> (IConnection -> 'T) -> 'T + +// ~~ REQL QUERY DEFINITION ~~ + +/// Get documents between a lower bound and an upper bound based on a primary key +val between : obj -> obj -> ReqlExpr -> Between + +/// Get document between a lower bound and an upper bound, specifying one or more optional arguments +val betweenWithOptArgs : obj -> obj -> BetweenOptArg list -> ReqlExpr -> Between + +/// Get documents between a lower bound and an upper bound based on an index +val betweenIndex : obj -> obj -> string -> ReqlExpr -> Between + +/// Get a connection builder that can be used to create one RethinkDB connection +val connection : unit -> Connection.Builder + +/// Count the documents in this query +val count : ReqlExpr -> Count + +/// Count the documents in this query where the function returns true +val countFunc : (ReqlExpr -> bool) -> ReqlExpr -> Count + +/// Count the documents in this query where the function returns true +val countJS : string -> ReqlExpr -> Count + +/// Reference a database +val db : string -> Db + +/// Create a database +val dbCreate : string -> DbCreate + +/// Drop a database +val dbDrop : string -> DbDrop + +/// Get a list of databases +val dbList : unit -> DbList + +/// Delete documents +val delete : ReqlExpr -> Delete + +/// Delete documents, providing optional arguments +val deleteWithOptArgs : DeleteOptArg list -> ReqlExpr -> Delete + +/// Only retrieve distinct entries from a selection +val distinct : ReqlExpr -> Distinct + +/// Only retrieve distinct entries from a selection, based on an index +val distinctWithIndex : string -> ReqlExpr -> Distinct + +/// EqJoin the left field on the right-hand table using its primary key +val eqJoin : string -> Table -> ReqlExpr -> EqJoin + +/// EqJoin the left function on the right-hand table using its primary key +val eqJoinFunc<'T> : (ReqlExpr -> 'T) -> Table -> ReqlExpr -> EqJoin + +/// EqJoin the left function on the right-hand table using the specified index +val eqJoinFuncIndex<'T> : (ReqlExpr -> 'T) -> Table -> string -> ReqlExpr -> EqJoin + +/// EqJoin the left field on the right-hand table using the specified index +val eqJoinIndex : string -> Table -> string -> ReqlExpr -> EqJoin + +/// EqJoin the left JavaScript on the right-hand table using its primary key +val eqJoinJS : string -> Table -> ReqlExpr -> EqJoin + +/// EqJoin the left JavaScript on the right-hand table using the specified index +val eqJoinJSIndex : string -> Table -> string -> ReqlExpr -> EqJoin + +/// Filter documents +val filter : obj -> ReqlExpr -> Filter + +/// Filter documents, providing an optional argument +val filterWithOptArg : obj -> FilterOptArg -> ReqlExpr -> Filter + +/// Filter documents using a function +val filterFunc : (ReqlExpr -> obj) -> ReqlExpr -> Filter + +/// Filter documents using a function, providing an optional argument +val filterFuncWithOptArg : (ReqlExpr -> obj) -> FilterOptArg -> ReqlExpr -> Filter + +/// Filter documents using multiple functions (has the effect of ANDing them) +val filterFuncAll : (ReqlExpr -> obj) list -> ReqlExpr -> Filter + +/// Filter documents using multiple functions (has the effect of ANDing them), providing an optional argument +val filterFuncAllWithOptArg : (ReqlExpr -> obj) list -> FilterOptArg -> ReqlExpr -> Filter + +/// Filter documents using JavaScript +val filterJS : string -> ReqlExpr -> Filter + +/// Filter documents using JavaScript, providing an optional argument +val filterJSWithOptArg : string -> FilterOptArg -> ReqlExpr -> Filter + +/// Get a document by its primary key +val get : obj -> Table -> Get + +/// Get all documents matching primary keys +val getAll : obj seq -> Table -> GetAll + +/// Get all documents matching keys in the given index +val getAllWithIndex : obj seq -> string -> Table -> GetAll + +/// Create an index on the given table +val indexCreate : string -> Table -> IndexCreate + +/// Create an index on the given table, including optional arguments +val indexCreateWithOptArgs : string -> IndexCreateOptArg list -> Table -> IndexCreate + +/// Create an index on the given table using a function +val indexCreateFunc : string -> (ReqlExpr -> obj) -> Table -> IndexCreate + +/// Create an index on the given table using a function, including optional arguments +val indexCreateFuncWithOptArgs : string -> (ReqlExpr -> obj) -> IndexCreateOptArg list -> Table -> IndexCreate + +/// Create an index on the given table using JavaScript +val indexCreateJS : string -> string -> Table -> IndexCreate + +/// Create an index on the given table using JavaScript, including optional arguments +val indexCreateJSWithOptArgs : string -> string -> IndexCreateOptArg list -> Table -> IndexCreate + +/// Drop an index +val indexDrop : string -> Table -> IndexDrop + +/// Get a list of indexes for the given table +val indexList : Table -> IndexList + +/// Rename an index (will fail if new name already exists) +val indexRename : string -> string -> Table -> IndexRename + +/// Rename an index (specifying overwrite action) +val indexRenameWithOptArg : string -> string -> IndexRenameOptArg -> Table -> IndexRename + +/// Get the status of specific indexes for the given table +val indexStatus : string list -> Table -> IndexStatus + +/// Get the status of all indexes for the given table +val indexStatusAll : Table -> IndexStatus + +/// Wait for specific indexes on the given table to become ready +val indexWait : string list -> Table -> IndexWait + +/// Wait for all indexes on the given table to become ready +val indexWaitAll : Table -> IndexWait + +/// Create an inner join between two sequences, specifying the join condition with a function +val innerJoinFunc<'T> : obj -> (ReqlExpr -> ReqlExpr -> 'T) -> ReqlExpr -> InnerJoin + +/// Create an inner join between two sequences, specifying the join condition with JavaScript +val innerJoinJS : obj -> string -> ReqlExpr -> InnerJoin + +/// Insert a single document (use insertMany for multiple) +val insert<'T> : 'T -> Table -> Insert + +/// Insert multiple documents +val insertMany<'T> : 'T seq -> Table -> Insert + +/// Insert a single document, providing optional arguments (use insertManyWithOptArgs for multiple) +val insertWithOptArgs<'T> : 'T -> InsertOptArg list -> Table -> Insert + +/// Insert multiple documents, providing optional arguments +val insertManyWithOptArgs<'T> : 'T seq -> InsertOptArg list -> Table -> Insert + +/// Test whether a sequence is empty +val isEmpty : ReqlExpr -> IsEmpty + +/// End a sequence after a given number of elements +val limit : int -> ReqlExpr -> Limit + +/// Map the results using a function +val mapFunc : (ReqlExpr -> obj) -> ReqlExpr -> Map + +/// Map the results using a JavaScript function +val mapJS : string -> ReqlExpr -> Map + +/// Merge the current query with given document +val merge : obj -> ReqlExpr -> Merge + +/// Merge the current query with the results of a function +val mergeFunc : (ReqlExpr -> obj) -> ReqlExpr -> Merge + +/// Merge the current query with the results of a JavaScript function +val mergeJS : string -> ReqlExpr -> Merge + +/// Retrieve the nth element in a sequence +val nth : int -> ReqlExpr -> Nth + +/// Order a sequence by a given field +val orderBy : string -> ReqlExpr -> OrderBy + +/// Order a sequence in descending order by a given field +val orderByDescending : string -> ReqlExpr -> OrderBy + +/// Order a sequence by a given function +val orderByFunc : (ReqlExpr -> obj) -> ReqlExpr -> OrderBy + +/// Order a sequence in descending order by a given function +val orderByFuncDescending : (ReqlExpr -> obj) -> ReqlExpr -> OrderBy + +/// Order a sequence by a given index +val orderByIndex : string -> ReqlExpr -> OrderBy + +/// Order a sequence in descending order by a given index +val orderByIndexDescending : string -> ReqlExpr -> OrderBy + +/// Order a sequence by a given JavaScript function +val orderByJS : string -> ReqlExpr -> OrderBy + +/// Order a sequence in descending order by a given JavaScript function +val orderByJSDescending : string -> ReqlExpr -> OrderBy + +/// Create an outer join between two sequences, specifying the join condition with a function +val outerJoinFunc<'T> : obj -> (ReqlExpr -> ReqlExpr -> 'T) -> ReqlExpr -> OuterJoin + +/// Create an outer join between two sequences, specifying the join condition with JavaScript +val outerJoinJS : obj -> string -> ReqlExpr -> OuterJoin + +/// Select one or more attributes from an object or sequence +val pluck : string seq -> ReqlExpr -> Pluck + +/// Replace documents +val replace : obj -> ReqlExpr -> Replace + +/// Replace documents, providing optional arguments +val replaceWithOptArgs : obj -> ReplaceOptArg list -> ReqlExpr -> Replace + +/// Replace documents using a function +val replaceFunc : (ReqlExpr -> obj) -> ReqlExpr -> Replace + +/// Replace documents using a function, providing optional arguments +val replaceFuncWithOptArgs : (ReqlExpr -> obj) -> ReplaceOptArg list -> ReqlExpr -> Replace + +/// Replace documents using JavaScript +val replaceJS : string -> ReqlExpr -> Replace + +/// Replace documents using JavaScript, providing optional arguments +val replaceJSWithOptArgs : string -> ReplaceOptArg list -> ReqlExpr -> Replace + +/// Skip a number of elements from the head of a sequence +val skip : int -> ReqlExpr -> Skip + +/// Ensure changes to a table are written to permanent storage +val sync : Table -> Sync + +/// Return all documents in a table (may be further refined) +val table : string -> Db -> Table + +/// Return all documents in a table from the default database (may be further refined) +val fromTable : string -> Table + +/// Create a table in the given database +val tableCreate : string -> Db -> TableCreate + +/// Create a table in the connection-default database +val tableCreateInDefault : string -> TableCreate + +/// Drop a table in the given database +val tableDrop : string -> Db -> TableDrop + +/// Drop a table from the connection-default database +val tableDropFromDefault : string -> TableDrop + +/// Get a list of tables for the given database +val tableList : Db -> TableList + +/// Get a list of tables from the connection-default database +val tableListFromDefault : unit -> TableList + +/// Update documents +val update : obj -> ReqlExpr -> Update + +/// Update documents, providing optional arguments +val updateWithOptArgs : obj -> UpdateOptArg list -> ReqlExpr -> Update + +/// Update documents using a function +val updateFunc : (ReqlExpr -> obj) -> ReqlExpr -> Update + +/// Update documents using a function, providing optional arguments +val updateFuncWithOptArgs : (ReqlExpr -> obj) -> UpdateOptArg list -> ReqlExpr -> Update + +/// Update documents using JavaScript +val updateJS : string -> ReqlExpr -> Update + +/// Update documents using JavaScript, providing optional arguments +val updateJSWithOptArgs : string -> UpdateOptArg list -> ReqlExpr -> Update + +/// Exclude fields from the result +val without : string seq -> ReqlExpr -> Without + +/// Merge the right-hand fields into the left-hand document of a sequence +val zip : ReqlExpr -> Zip + +// ~~ RETRY FUNCTIONS ~~ + +/// Retry, delaying for each the seconds provided (if required) +val withRetry<'T> : float seq -> (IConnection -> Task<'T>) -> (IConnection -> Task<'T>) + +/// Retry, delaying for each the seconds provided (if required) +val withAsyncRetry<'T> : float seq -> (IConnection -> Async<'T>) -> (IConnection -> Async<'T>) + +/// Retry, delaying for each the seconds provided (if required) +val withSyncRetry<'T> : float seq -> (IConnection -> 'T) -> (IConnection -> 'T) + +/// Retry failed commands with 200ms, 500ms, and 1 second delays +val withRetryDefault<'T> : (IConnection -> Task<'T>) -> (IConnection -> Task<'T>) + +/// Retry failed commands with 200ms, 500ms, and 1 second delays +val withAsyncRetryDefault<'T> : (IConnection -> Async<'T>) -> (IConnection -> Async<'T>) + +/// Retry failed commands with 200ms, 500ms, and 1 second delays +val withSyncRetryDefault<'T> : (IConnection -> 'T) -> (IConnection -> 'T) + +/// Retry failed commands one time with no delay +val withRetryOnce<'T> : (IConnection -> Task<'T>) -> (IConnection -> Task<'T>) + +/// Retry failed commands one time with no delay +val withAsyncRetryOnce<'T> : (IConnection -> Async<'T>) -> (IConnection -> Async<'T>) + +/// Retry failed commands one time with no delay +val withSyncRetryOnce<'T> : (IConnection -> 'T) -> (IConnection -> 'T) diff --git a/src/RethinkDb.Driver.FSharp/README.md b/src/RethinkDb.Driver.FSharp/README.md index 515ea1f..bcdcdfd 100644 --- a/src/RethinkDb.Driver.FSharp/README.md +++ b/src/RethinkDb.Driver.FSharp/README.md @@ -23,7 +23,7 @@ open RethinkDb.Driver.FSharp let getPost postId conn = rethink { - fromTable "Post" + withTable "Post" get postId resultOption withRetryOptionDefault conn @@ -31,7 +31,7 @@ let getPost postId conn = let updatePost post conn = rethink { - fromTable "Post" + withTable "Post" get post.id update post write @@ -45,22 +45,24 @@ let updatePost post conn = ```fsharp open RethinkDb.Driver.FSharp.Functions -// NOTE: this returns Task; checking for null/option is not handled -// as it is with the CE version +// Remove the conn parameter and usage for point-free style + let getPost postId conn = fromTable "Post" |> get postId |> runResult - |> withRetryDefault conn + |> asOption + |> withRetryDefault + |> withConn conn -// NOTE: this returns Task; ignoring inline is not available as -// it is with the CE version let updatePost post conn = fromTable "Post" |> get post.id |> update post |> runWrite - |> withRetryDefault conn + |> ignoreResult + |> withRetryDefault + |> withConn conn ``` ### Retry Logic @@ -76,5 +78,10 @@ Many RethinkDB commands support optional arguments to tweak the behavior of that between 1 100 [ LowerBound Open; UpperBound Closed ] // ... ``` +--- -[csharp-pkg]: https://www.nuget.org/packages/RethinkDb.Driver/ \ No newline at end of file +More information is available on the [project site][]. + + +[csharp-pkg]: https://www.nuget.org/packages/RethinkDb.Driver/ +[project site]: https://bitbadger.solutions/open-source/rethinkdb-driver-fsharp/ diff --git a/src/RethinkDb.Driver.FSharp/RethinkDb.Driver.FSharp.fsproj b/src/RethinkDb.Driver.FSharp/RethinkDb.Driver.FSharp.fsproj index 4bf73a3..1e03e3d 100644 --- a/src/RethinkDb.Driver.FSharp/RethinkDb.Driver.FSharp.fsproj +++ b/src/RethinkDb.Driver.FSharp/RethinkDb.Driver.FSharp.fsproj @@ -3,22 +3,28 @@ net6.0;netstandard2.0 Idiomatic F# extensions on the official RethinkDB C# driver - Daniel J. Summers + Daniel J. Summers,Bit Badger Solutions Apache-2.0 - https://github.com/danieljsummers/RethinkDb.Driver.FSharp - https://github.com/danieljsummers/RethinkDb.Driver.FSharp/raw/main/pkg/icon.png + https://github.com/bit-badger/RethinkDb.Driver.FSharp + git + https://bitbadger.solutions/open-source/rethinkdb-driver-fsharp/ icon.png README.md false See LICENSE RethinkDB document F# 0.9.0 - beta-01 + beta-03 + + Retry logic now works with functions; added signature for function moduel and explicit type annotations to the + DSL builder + +