11use neon:: types:: buffer:: TypedArray ;
22use neon:: types:: JsPromise ;
33use neon:: { prelude:: * , types:: JsBigInt } ;
4+ use tokio:: time:: Instant ;
45use std:: cell:: RefCell ;
56use std:: sync:: Arc ;
67use tokio:: sync:: Mutex ;
@@ -84,8 +85,14 @@ impl Statement {
8485 raw_stmt. reset ( ) ;
8586 let fut = raw_stmt. run ( params) ;
8687 let rt = runtime ( & mut cx) ?;
88+
89+ let initial = Instant :: now ( ) ;
90+
8791 rt. block_on ( fut)
8892 . or_else ( |err| throw_libsql_error ( & mut cx, err) ) ?;
93+
94+ let duration = Instant :: now ( ) - initial;
95+
8996 let ( changes, last_insert_rowid) = {
9097 let raw_conn = stmt. conn . clone ( ) ;
9198 let raw_conn = raw_conn. blocking_lock ( ) ;
@@ -97,11 +104,18 @@ impl Statement {
97104 let last_insert_rowid = raw_conn. last_insert_rowid ( ) ;
98105 ( changes, last_insert_rowid)
99106 } ;
107+
100108 let info = cx. empty_object ( ) ;
109+
101110 let changes = cx. number ( changes as f64 ) ;
102111 info. set ( & mut cx, "changes" , changes) ?;
112+
113+ let duration = cx. number ( duration. as_secs_f64 ( ) as f64 ) ;
114+ info. set ( & mut cx, "duration" , duration) ?;
115+
103116 let last_insert_row_id = cx. number ( last_insert_rowid as f64 ) ;
104117 info. set ( & mut cx, "lastInsertRowid" , last_insert_row_id) ?;
118+
105119 Ok ( info. upcast ( ) )
106120 }
107121
@@ -115,9 +129,15 @@ impl Statement {
115129 let rt = runtime ( & mut cx) ?;
116130 let result = rt. block_on ( fut) ;
117131 let mut rows = result. or_else ( |err| throw_libsql_error ( & mut cx, err) ) ?;
132+
133+ let initial = Instant :: now ( ) ;
134+
118135 let result = rt
119136 . block_on ( rows. next ( ) )
120137 . or_else ( |err| throw_libsql_error ( & mut cx, err) ) ?;
138+
139+ let duration = Instant :: now ( ) - initial;
140+
121141 let result = match result {
122142 Some ( row) => {
123143 if * stmt. raw . borrow ( ) {
@@ -127,6 +147,13 @@ impl Statement {
127147 } else {
128148 let mut result = cx. empty_object ( ) ;
129149 convert_row ( & mut cx, safe_ints, & mut result, & rows, & row) ?;
150+
151+ let metadata = cx. empty_object ( ) ;
152+ result. set ( & mut cx, "_metadata" , metadata) ?;
153+
154+ let duration = cx. number ( duration. as_secs_f64 ( ) ) ;
155+ metadata. set ( & mut cx, "duration" , duration) ?;
156+
130157 Ok ( result. upcast ( ) )
131158 }
132159 }
0 commit comments