File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
src/extensions/ocsipersist-pgsql Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ let create_table db table =
8888let insert db table key value =
8989 let query = sprintf " INSERT INTO %s VALUES ( $1 , $2 )
9090 ON CONFLICT ( key ) DO UPDATE SET value = $2 " table
91+ (* TODO: compatibility with < 9.5*)
9192 in exec db query [key; marshal value] >> Lwt. return ()
9293
9394
@@ -139,10 +140,12 @@ let find table key = use_pool @@ fun db ->
139140let add table key value = use_pool @@ fun db ->
140141 insert db table key value
141142
142- let replace_if_exists table key value =
143- try_lwt
144- find table key >> add table key value
145- with Not_found -> Lwt. return ()
143+ let replace_if_exists table key value = use_pool @@ fun db ->
144+ let query = sprintf " UPDATE %s SET value = $2 WHERE key = $1 RETURNING 0" table in
145+ lwt result = exec db query [key; marshal value] in
146+ match result with
147+ | [] -> raise Not_found
148+ | _ -> Lwt. return ()
146149
147150let remove table key = use_pool @@ fun db ->
148151 let query = sprintf " DELETE FROM %s WHERE key = $1 " table in
You can’t perform that action at this time.
0 commit comments