aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Peter McGoron 2021-10-16 13:40:43 -0400
committerGravatar Peter McGoron 2021-10-16 13:40:43 -0400
commitaf24722b2e0fbfcc10c4ff81801a409898362cc5 (patch)
treefc4726ea78bb6fc4d5dffe3418e38c4cbb284389
parentadd a boolean to the monad to be more flexible with error management (diff)
add check function
-rw-r--r--src/letsqlite.ml4
-rw-r--r--src/letsqlite.mli4
2 files changed, 8 insertions, 0 deletions
diff --git a/src/letsqlite.ml b/src/letsqlite.ml
index 83bf0c6..c34b9c5 100644
--- a/src/letsqlite.ml
+++ b/src/letsqlite.ml
@@ -125,6 +125,10 @@ let finalize = function
Rc.check (S.finalize s); v
)
+let check s = match s with
+| Failed e -> raise (S.SqliteError (Rc.to_string e))
+| Norm (v,_) -> (v,s)
+
let exec db s = prepare db s () >>$ step
let reexec db s = reprepare db s @>$ step
let bsrc l = bind_values l @>$ step @>$ reset @>$ clear_bindings
diff --git a/src/letsqlite.mli b/src/letsqlite.mli
index 1449f31..0ba7c9a 100644
--- a/src/letsqlite.mli
+++ b/src/letsqlite.mli
@@ -162,6 +162,10 @@ val finalize : 'a stmt_m -> 'a
(** [finalize] raises an exception if the execution failed, and [V]
otherwise. *)
+val check : 'a stmt_m -> ('a * 'a stmt_m)
+(** [check] checks if the statement is an error value and throws an
+ exception if it is. If it is not, then it returns [(V,S)]. *)
+
val bind_values : Sqlite3.Data.t list -> ('a,'a) monad_fun
(** [bind_values l] binds each index of [l] to a positional parameter
in [S]. *)