From af24722b2e0fbfcc10c4ff81801a409898362cc5 Mon Sep 17 00:00:00 2001 From: Peter McGoron Date: Sat, 16 Oct 2021 13:40:43 -0400 Subject: [PATCH] add check function --- src/letsqlite.ml | 4 ++++ src/letsqlite.mli | 4 ++++ 2 files changed, 8 insertions(+) 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]. *)