diff --git a/src/RethinkDb.Driver.FSharp/Builder.fs b/src/RethinkDb.Driver.FSharp/Builder.fs index fa5f287..fa52b0e 100644 --- a/src/RethinkDb.Driver.FSharp/Builder.fs +++ b/src/RethinkDb.Driver.FSharp/Builder.fs @@ -36,7 +36,8 @@ type RethinkBuilder<'T> () = /// Specify a database for further commands [] - member _.Db (r : RethinkDB, db : string) = match db with "" -> r.Db () | _ -> r.Db db + member _.Db (r : RethinkDB, db : string) = + match db with "" -> invalidArg db "db name cannot be blank" | _ -> r.Db db /// Identify a table (of form "dbName.tableName"; if no db name, uses default database) [] @@ -60,13 +61,18 @@ type RethinkBuilder<'T> () = [] member _.DbCreate (r : RethinkDB, db : string) = r.DbCreate db + /// Drop a database + [] + member _.DbDrop (r : RethinkDB, db : string) = r.DbDrop db + /// List all tables for the default database [] member _.TableList (r : RethinkDB) = r.TableList () /// List all tables for the specified database [] - member this.TableList (r : RethinkDB, db : string) = this.Db(r, db).TableList () + member this.TableList (r : RethinkDB, db : string) = + match db with "" -> this.TableList r | _ -> this.Db(r, db).TableList () /// Create a table (of form "dbName.tableName"; if no db name, uses default database) [] @@ -75,6 +81,13 @@ type RethinkBuilder<'T> () = | Some db, tbl -> this.Db(r, db).TableCreate tbl | None, _ -> r.TableCreate table + /// Drop a table (of form "dbName.tableName"; if no db name, uses default database) + [] + member this.TableDrop (r : RethinkDB, table : string) = + match dbAndTable table with + | Some db, tbl -> this.Db(r, db).TableDrop tbl + | None, _ -> r.TableDrop table + /// List all indexes for a table [] member _.IndexList (tbl : Table) = tbl.IndexList () @@ -97,6 +110,35 @@ type RethinkBuilder<'T> () = member this.IndexCreate (tbl : Table, index : string, f : ReqlExpr -> obj, opts : IndexCreateOptArg list) = this.IndexCreate (tbl, index, f) |> IndexCreateOptArg.apply opts + /// Drop an index for a table + [] + member _.IndexDrop (tbl : Table, index : string) = tbl.IndexDrop index + + /// Rename an index on a table + [] + member _.IndexRename (tbl : Table, oldName : string, newName : string) = tbl.IndexRename (oldName, newName) + + /// Rename an index on a table, specifying an overwrite option + [] + member this.IndexRename (tbl : Table, oldName : string, newName : string, arg : IndexRenameOptArg) = + this.IndexRename(tbl, oldName, newName) |> IndexRenameOptArg.apply arg + + /// Get the status of all indexes on a table + [] + member _.IndexStatus (tbl : Table) = tbl.IndexStatus () + + /// Get the status of specific indexes on a table + [] + member _.IndexStatus (tbl : Table, indexes : string list) = tbl.IndexStatus (Array.ofList indexes) + + /// Wait for all indexes on a table to become ready + [] + member _.IndexWait (tbl : Table) = tbl.IndexWait () + + /// Wait for specific indexes on a table to become ready + [] + member _.IndexWait (tbl : Table, indexes : string list) = tbl.IndexWait (Array.ofList indexes) + // data retrieval / manipulation /// Get a document from a table by its ID @@ -249,6 +291,10 @@ type RethinkBuilder<'T> () = member this.Delete (expr : ReqlExpr, opts : DeleteOptArg list) = this.Delete expr |> DeleteOptArg.apply opts + /// Wait for updates to a table to be synchronized to disk + [] + member _.Sync (tbl : Table) = tbl.Sync () + // executing queries /// Execute the query, returning the result of the type specified diff --git a/src/RethinkDb.Driver.FSharp/Functions.fs b/src/RethinkDb.Driver.FSharp/Functions.fs index 46e04cd..7437897 100644 --- a/src/RethinkDb.Driver.FSharp/Functions.fs +++ b/src/RethinkDb.Driver.FSharp/Functions.fs @@ -178,13 +178,29 @@ let indexDrop (indexName : string) (table : Table) = let indexList (table : Table) = table.IndexList () -/// Rename an index (overwrite will fail) +/// Rename an index (will fail if new name already exists) let indexRename (oldName : string) (newName : string) (table : Table) = table.IndexRename (oldName, newName) /// Rename an index (overwrite will succeed) let indexRenameWithOverwrite (oldName : string) (newName : string) (table : Table) = - table.IndexRename(oldName, newName).OptArg ("overwrite", true) + indexRename oldName newName table |> IndexRenameOptArg.apply Overwrite + +/// Get the status of specific indexes for the given table +let indexStatus (table : Table) (indexes : string list) = + table.IndexStatus (Array.ofList indexes) + +/// Get the status of all indexes for the given table +let indexStatusAll (table : Table) = + table.IndexStatus () + +/// Wait for specific indexes on the given table to become ready +let indexWait (table : Table) (indexes : string list) = + table.IndexWait (Array.ofList indexes) + +/// Wait for all indexes on the given table to become ready +let indexWaitAll (table : Table) = + table.IndexWait () /// Create an inner join between two sequences, specifying the join condition with a function let innerJoinFunc<'T> (otherSeq : obj) (f : ReqlExpr -> ReqlExpr -> 'T) (expr : ReqlExpr) = diff --git a/src/RethinkDb.Driver.FSharp/OptArgs.fs b/src/RethinkDb.Driver.FSharp/OptArgs.fs index 7445c74..c997950 100644 --- a/src/RethinkDb.Driver.FSharp/OptArgs.fs +++ b/src/RethinkDb.Driver.FSharp/OptArgs.fs @@ -149,6 +149,20 @@ type Conflict = | Resolve f -> ReqlFunction3 f :> obj "conflict", value + +/// Optional arguments for the `indexRename` statement +type IndexRenameOptArg = + | FailIfExists + | Overwrite + +/// Function to support `indexRename` optional argument +module IndexRenameOptArg = + + /// Apply an optional argument to an indexRename statement + let apply opt (ir : IndexRename) = + ir.OptArg("overwrite", match opt with FailIfExists -> false | Overwrite -> true) + + /// Optional arguments for the `insert` statement type InsertOptArg = /// The durability of the command