Permalink
Browse files

Add CouchDB.Table.replace

  • Loading branch information...
1 parent 588e1da commit 178b9448a845b8780534544f6a099c1f9753a51a @VictorNicollet committed Aug 30, 2012
Showing with 8 additions and 0 deletions.
  1. +1 −0 src/couchDB.mli
  2. +6 −0 src/couchDB_table.ml
  3. +1 −0 src/couchDB_types.ml
View
@@ -56,6 +56,7 @@ module type TABLE = sig
val delete : id -> (#ctx,unit) Run.t
val delete_if : id -> (elt -> bool) -> (#ctx,unit) Run.t
+ val replace : id -> (elt option -> elt) -> (#ctx,unit) Run.t
val update : id -> (elt -> elt) -> (#ctx,unit) Run.t
val set : id -> elt -> (#ctx,unit) Run.t
View
@@ -259,6 +259,9 @@ module Database = functor (Config:ImplTypes.CONFIG) -> struct
| Some e -> Run.return ((),`put (f e))
| None -> Run.return ((),`keep))
+ let replace id f =
+ transact id (fun e -> Run.return ((),`put (f e)))
+
let set id elt =
Raw.transaction id (fun _ -> Run.return ((),`put elt))
@@ -359,6 +362,9 @@ struct
let update id f =
Database.update (Id.to_id id) (Type.of_json |- f |- Type.to_json)
+ let replace id f =
+ Database.replace (Id.to_id id) (BatOption.map Type.of_json |- f |- Type.to_json)
+
let set id elt =
Database.set (Id.to_id id) (Type.to_json elt)
View
@@ -34,6 +34,7 @@ module type TABLE = sig
val delete : id -> (#ctx,unit) Run.t
val delete_if : id -> (elt -> bool) -> (#ctx,unit) Run.t
+ val replace : id -> (elt option -> elt) -> (#ctx,unit) Run.t
val update : id -> (elt -> elt) -> (#ctx,unit) Run.t
val set : id -> elt -> (#ctx,unit) Run.t

0 comments on commit 178b944

Please sign in to comment.