File tree Expand file tree Collapse file tree 5 files changed +40
-1
lines changed Expand file tree Collapse file tree 5 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ const {
39
39
statementIsReader,
40
40
statementGet,
41
41
statementRun,
42
+ statementInterrupt,
42
43
statementRowsSync,
43
44
statementColumns,
44
45
statementSafeIntegers,
@@ -384,6 +385,13 @@ class Statement {
384
385
}
385
386
}
386
387
388
+ /**
389
+ * Interrupts the statement.
390
+ */
391
+ interrupt ( ) {
392
+ statementInterrupt . call ( this . stmt ) ;
393
+ }
394
+
387
395
/**
388
396
* Returns the columns in the result set returned by this prepared statement.
389
397
*/
Original file line number Diff line number Diff line change @@ -328,6 +328,21 @@ test.serial("Database.interrupt()", async (t) => {
328
328
} ) ;
329
329
} ) ;
330
330
331
+
332
+ test . serial ( "Statement.interrupt()" , async ( t ) => {
333
+ const db = t . context . db ;
334
+ const stmt = await db . prepare ( "WITH RECURSIVE infinite_loop(n) AS (SELECT 1 UNION ALL SELECT n + 1 FROM infinite_loop) SELECT * FROM infinite_loop;" ) ;
335
+ const fut = stmt . all ( ) ;
336
+ stmt . interrupt ( ) ;
337
+ await t . throwsAsync ( async ( ) => {
338
+ await fut ;
339
+ } , {
340
+ instanceOf : t . context . errorType ,
341
+ message : 'interrupted' ,
342
+ code : 'SQLITE_INTERRUPT'
343
+ } ) ;
344
+ } ) ;
345
+
331
346
test . serial ( "Concurrent writes over same connection" , async ( t ) => {
332
347
const db = t . context . db ;
333
348
await db . exec ( `
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ const {
52
52
statementIsReader,
53
53
statementGet,
54
54
statementRun,
55
+ statementInterrupt,
55
56
statementRowsAsync,
56
57
statementColumns,
57
58
statementSafeIntegers,
@@ -386,6 +387,13 @@ class Statement {
386
387
}
387
388
}
388
389
390
+ /**
391
+ * Interrupts the statement.
392
+ */
393
+ interrupt ( ) {
394
+ statementInterrupt . call ( this . stmt ) ;
395
+ }
396
+
389
397
/**
390
398
* Returns the columns in the result set returned by this prepared statement.
391
399
*/
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ fn main(mut cx: ModuleContext) -> NeonResult<()> {
52
52
cx. export_function ( "statementRaw" , Statement :: js_raw) ?;
53
53
cx. export_function ( "statementIsReader" , Statement :: js_is_reader) ?;
54
54
cx. export_function ( "statementRun" , Statement :: js_run) ?;
55
+ cx. export_function ( "statementInterrupt" , Statement :: js_interrupt) ?;
55
56
cx. export_function ( "statementGet" , Statement :: js_get) ?;
56
57
cx. export_function ( "statementRowsSync" , Statement :: js_rows_sync) ?;
57
58
cx. export_function ( "statementRowsAsync" , Statement :: js_rows_async) ?;
Original file line number Diff line number Diff line change 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 ;
5
4
use std:: cell:: RefCell ;
6
5
use std:: sync:: Arc ;
7
6
use tokio:: sync:: Mutex ;
7
+ use tokio:: time:: Instant ;
8
8
9
9
use crate :: errors:: throw_libsql_error;
10
10
use crate :: runtime;
@@ -119,6 +119,13 @@ impl Statement {
119
119
Ok ( info. upcast ( ) )
120
120
}
121
121
122
+ pub fn js_interrupt ( mut cx : FunctionContext ) -> JsResult < JsNull > {
123
+ let stmt: Handle < ' _ , JsBox < Statement > > = cx. this ( ) ?;
124
+ let mut raw_stmt = stmt. stmt . blocking_lock ( ) ;
125
+ raw_stmt. interrupt ( ) ;
126
+ Ok ( cx. null ( ) )
127
+ }
128
+
122
129
pub fn js_get ( mut cx : FunctionContext ) -> JsResult < JsValue > {
123
130
let stmt: Handle < ' _ , JsBox < Statement > > = cx. this ( ) ?;
124
131
let params = cx. argument :: < JsValue > ( 0 ) ?;
You can’t perform that action at this time.
0 commit comments