1
1
use neon:: types:: buffer:: TypedArray ;
2
2
use neon:: types:: JsPromise ;
3
3
use neon:: { prelude:: * , types:: JsBigInt } ;
4
+ use tokio:: time:: Instant ;
4
5
use std:: cell:: RefCell ;
5
6
use std:: sync:: Arc ;
6
7
use tokio:: sync:: Mutex ;
@@ -84,8 +85,14 @@ impl Statement {
84
85
raw_stmt. reset ( ) ;
85
86
let fut = raw_stmt. run ( params) ;
86
87
let rt = runtime ( & mut cx) ?;
88
+
89
+ let initial = Instant :: now ( ) ;
90
+
87
91
rt. block_on ( fut)
88
92
. or_else ( |err| throw_libsql_error ( & mut cx, err) ) ?;
93
+
94
+ let duration = Instant :: now ( ) - initial;
95
+
89
96
let ( changes, last_insert_rowid) = {
90
97
let raw_conn = stmt. conn . clone ( ) ;
91
98
let raw_conn = raw_conn. blocking_lock ( ) ;
@@ -97,11 +104,18 @@ impl Statement {
97
104
let last_insert_rowid = raw_conn. last_insert_rowid ( ) ;
98
105
( changes, last_insert_rowid)
99
106
} ;
107
+
100
108
let info = cx. empty_object ( ) ;
109
+
101
110
let changes = cx. number ( changes as f64 ) ;
102
111
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
+
103
116
let last_insert_row_id = cx. number ( last_insert_rowid as f64 ) ;
104
117
info. set ( & mut cx, "lastInsertRowid" , last_insert_row_id) ?;
118
+
105
119
Ok ( info. upcast ( ) )
106
120
}
107
121
@@ -115,9 +129,15 @@ impl Statement {
115
129
let rt = runtime ( & mut cx) ?;
116
130
let result = rt. block_on ( fut) ;
117
131
let mut rows = result. or_else ( |err| throw_libsql_error ( & mut cx, err) ) ?;
132
+
133
+ let initial = Instant :: now ( ) ;
134
+
118
135
let result = rt
119
136
. block_on ( rows. next ( ) )
120
137
. or_else ( |err| throw_libsql_error ( & mut cx, err) ) ?;
138
+
139
+ let duration = Instant :: now ( ) - initial;
140
+
121
141
let result = match result {
122
142
Some ( row) => {
123
143
if * stmt. raw . borrow ( ) {
@@ -127,6 +147,13 @@ impl Statement {
127
147
} else {
128
148
let mut result = cx. empty_object ( ) ;
129
149
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
+
130
157
Ok ( result. upcast ( ) )
131
158
}
132
159
}
0 commit comments