@@ -653,27 +653,32 @@ impl Statement {
653653 ///
654654 /// * `params` - The parameters to bind to the statement.
655655 #[ napi]
656- pub fn run ( & self , params : Option < napi:: JsUnknown > ) -> Result < RunResult > {
657- let rt = runtime ( ) ?;
658- rt. block_on ( async move {
659- let total_changes_before = self . conn . total_changes ( ) ;
660- let start = std:: time:: Instant :: now ( ) ;
661-
662- let params = map_params ( & self . stmt , params) ?;
663- self . stmt . run ( params) . await . map_err ( Error :: from) ?;
664- let changes = if self . conn . total_changes ( ) == total_changes_before {
656+ pub fn run ( & self , env : Env , params : Option < napi:: JsUnknown > ) -> Result < napi:: JsObject > {
657+ self . stmt . reset ( ) ;
658+ let params = map_params ( & self . stmt , params) ?;
659+ let total_changes_before = self . conn . total_changes ( ) ;
660+ let start = std:: time:: Instant :: now ( ) ;
661+ let stmt = self . stmt . clone ( ) ;
662+ let conn = self . conn . clone ( ) ;
663+
664+ let future = async move {
665+ stmt. run ( params) . await . map_err ( Error :: from) ?;
666+ let changes = if conn. total_changes ( ) == total_changes_before {
665667 0
666668 } else {
667- self . conn . changes ( )
669+ conn. changes ( )
668670 } ;
669- let last_insert_row_id = self . conn . last_insert_rowid ( ) ;
671+ let last_insert_row_id = conn. last_insert_rowid ( ) ;
670672 let duration = start. elapsed ( ) . as_secs_f64 ( ) ;
671- self . stmt . reset ( ) ;
672673 Ok ( RunResult {
673674 changes : changes as f64 ,
674675 duration,
675676 lastInsertRowid : last_insert_row_id,
676677 } )
678+ } ;
679+
680+ env. execute_tokio_future ( future, move |& mut _env, result| {
681+ Ok ( result)
677682 } )
678683 }
679684
@@ -866,6 +871,32 @@ impl Statement {
866871 }
867872}
868873
874+ /// Runs a statement in blocking mode.
875+ #[ napi]
876+ pub fn statement_run_sync ( stmt : & Statement , params : Option < napi:: JsUnknown > ) -> Result < RunResult > {
877+ stmt. stmt . reset ( ) ;
878+ let rt = runtime ( ) ?;
879+ rt. block_on ( async move {
880+ let params = map_params ( & stmt. stmt , params) ?;
881+ let total_changes_before = stmt. conn . total_changes ( ) ;
882+ let start = std:: time:: Instant :: now ( ) ;
883+
884+ stmt. stmt . run ( params) . await . map_err ( Error :: from) ?;
885+ let changes = if stmt. conn . total_changes ( ) == total_changes_before {
886+ 0
887+ } else {
888+ stmt. conn . changes ( )
889+ } ;
890+ let last_insert_row_id = stmt. conn . last_insert_rowid ( ) ;
891+ let duration = start. elapsed ( ) . as_secs_f64 ( ) ;
892+ Ok ( RunResult {
893+ changes : changes as f64 ,
894+ duration,
895+ lastInsertRowid : last_insert_row_id,
896+ } )
897+ } )
898+ }
899+
869900#[ napi]
870901pub fn statement_iterate_sync (
871902 stmt : & Statement ,
0 commit comments