Fix table addressing

This commit is contained in:
Daniel J. Summers 2022-04-19 12:49:31 -04:00
parent cd1458af1e
commit 835501d7e5
2 changed files with 21 additions and 15 deletions
README.md
src/RethinkDb.Driver.FSharp

View File

@ -1,7 +1,7 @@
# RethinkDb.Driver.FSharp # RethinkDb.Driver.FSharp
Idiomatic F# extensions for the C# RethinkDB driver Idiomatic F# extensions for the C# RethinkDB driver
![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/RethinkDb.Driver.FSharp) [![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/RethinkDb.Driver.FSharp)](https://www.nuget.org/packages/RethinkDb.Driver.FSharp/)
## Using ## Using
@ -28,7 +28,7 @@ let fetchPost (postId : string) =
/// string -> (IConnection -> Task<Post>) /// string -> (IConnection -> Task<Post>)
let fetchPost (postId : string) = let fetchPost (postId : string) =
rethink<Post> { rethink<Post> {
withTableInDb "Post" "Blog" withTable "Blog.Post"
get postId get postId
result result
withRetryDefault withRetryDefault

View File

@ -18,6 +18,14 @@ type RethinkBuilder<'T> () =
fields fields
|> List.fold (fun (m : Model.MapObject) item -> m.With (fst item, snd item)) (RethinkDB.R.HashMap ()) |> List.fold (fun (m : Model.MapObject) item -> m.With (fst item, snd item)) (RethinkDB.R.HashMap ())
/// Split a table name with a "." separator into database and table parts
let dbAndTable (table : string) =
match table.Contains "." with
| true ->
let parts = table.Split '.'
Some parts[0], parts[1]
| false -> None, table
member _.Bind (expr : ReqlExpr, f : ReqlExpr -> ReqlExpr) = f expr member _.Bind (expr : ReqlExpr, f : ReqlExpr -> ReqlExpr) = f expr
member this.For (expr, f) = this.Bind (expr, f) member this.For (expr, f) = this.Bind (expr, f)
@ -28,15 +36,14 @@ type RethinkBuilder<'T> () =
/// Specify a database for further commands /// Specify a database for further commands
[<CustomOperation "withDb">] [<CustomOperation "withDb">]
member _.Db (expr : RethinkDB, db : string) = match db with "" -> expr.Db () | _ -> expr.Db db member _.Db (r : RethinkDB, db : string) = match db with "" -> r.Db () | _ -> r.Db db
/// Specify a table in the default database /// Identify a table (of form "dbName.tableName"; if no db name, uses default database)
[<CustomOperation "withTable">] [<CustomOperation "withTable">]
member _.TableInDefaultDb (expr : RethinkDB, table : string) = expr.Table table member this.Table (r : RethinkDB, table : string) =
match dbAndTable table with
/// Specify a table in a specific database | Some db, tbl -> this.Db(r, db).Table tbl
[<CustomOperation "withTable">] | None, _ -> r.Table table
member _.Table (db : Db, table : string) = db.Table table
/// Create an equality join with another table /// Create an equality join with another table
[<CustomOperation "eqJoin">] [<CustomOperation "eqJoin">]
@ -61,13 +68,12 @@ type RethinkBuilder<'T> () =
[<CustomOperation "tableList">] [<CustomOperation "tableList">]
member this.TableList (r : RethinkDB, db : string) = this.Db(r, db).TableList () member this.TableList (r : RethinkDB, db : string) = this.Db(r, db).TableList ()
/// Create a table in the default database /// Create a table (of form "dbName.tableName"; if no db name, uses default database)
[<CustomOperation "tableCreate">] [<CustomOperation "tableCreate">]
member _.TableCreate (r : RethinkDB, table : string) = r.TableCreate table member this.TableCreate (r : RethinkDB, table : string) =
match dbAndTable table with
/// Create a table in the default database | Some db, tbl -> this.Db(r, db).TableCreate tbl
[<CustomOperation "tableCreate">] | None, _ -> r.TableCreate table
member _.TableCreate (db : Db, table : string) = db.TableCreate table
/// List all indexes for a table /// List all indexes for a table
[<CustomOperation "indexList">] [<CustomOperation "indexList">]