@@ -2445,4 +2445,129 @@ ORDER BY name
24452445 assert . equal ( quotedIdentifier ( 'table name' ) , '"table name"' ) ;
24462446 } ) ;
24472447 } ) ;
2448+
2449+ test ( "iterate over DuckDBResult stream in chunks" , async ( ) => {
2450+ await withConnection ( async ( connection ) => {
2451+ const result = await connection . stream (
2452+ "select i::int, i::int + 10, (i + 100)::varchar from range(3) t(i)" ,
2453+ ) ;
2454+
2455+ for await ( const chunk of result ) {
2456+ assert . strictEqual ( chunk . rowCount , 3 ) ;
2457+ let i = 0 ;
2458+ assertValues < number , DuckDBIntegerVector > (
2459+ chunk ,
2460+ i ++ ,
2461+ DuckDBIntegerVector ,
2462+ [ 0 , 1 , 2 ] ,
2463+ ) ;
2464+ assertValues < number , DuckDBIntegerVector > (
2465+ chunk ,
2466+ i ++ ,
2467+ DuckDBIntegerVector ,
2468+ [ 10 , 11 , 12 ] ,
2469+ ) ;
2470+ assertValues < string , DuckDBVarCharVector > (
2471+ chunk ,
2472+ i ++ ,
2473+ DuckDBVarCharVector ,
2474+ [ "100" , "101" , "102" ] ,
2475+ ) ;
2476+ }
2477+ } ) ;
2478+ } ) ;
2479+
2480+ test ( "iterate over many DuckDBResult chunks" , async ( ) => {
2481+ await withConnection ( async ( connection ) => {
2482+ const chunkSize = 2048 ;
2483+ const totalExpectedCount = chunkSize * 3 ;
2484+ const result = await connection . stream (
2485+ `select i::int from range(${ totalExpectedCount } ) t(i)`
2486+ ) ;
2487+
2488+ let total = 0 ;
2489+ for await ( const chunk of result ) {
2490+ assert . equal ( chunk . rowCount , chunkSize ) ;
2491+ total += chunk . rowCount ;
2492+ }
2493+
2494+ assert . equal ( total , totalExpectedCount ) ;
2495+ } ) ;
2496+ } ) ;
2497+
2498+ test ( "iterate stream of rows" , async ( ) => {
2499+ await withConnection ( async ( connection ) => {
2500+ const result = await connection . stream (
2501+ "select i::int, i::int + 10, (i + 100)::varchar from range(3) t(i)" ,
2502+ ) ;
2503+
2504+ const expectedRows : DuckDBValue [ ] [ ] = [
2505+ [ 0 , 10 , '100' ] ,
2506+ [ 1 , 11 , '101' ] ,
2507+ [ 2 , 12 , '102' ]
2508+ ] ;
2509+
2510+ for await ( const rows of result . yieldRows ( ) ) {
2511+ for ( let i = 0 ; i < rows . length ; i ++ ) {
2512+ assert . deepEqual ( rows [ i ] , expectedRows [ i ] ) ;
2513+ }
2514+ }
2515+ } ) ;
2516+ } ) ;
2517+
2518+ test ( "iterate stream of row objects" , async ( ) => {
2519+ await withConnection ( async ( connection ) => {
2520+ const result = await connection . stream (
2521+ "select i::int as a, i::int + 10 as b, (i + 100)::varchar as c from range(3) t(i)" ,
2522+ ) ;
2523+
2524+ const expectedRows : Record < string , DuckDBValue > [ ] = [
2525+ { a : 0 , b : 10 , c : '100' } ,
2526+ { a : 1 , b : 11 , c : '101' } ,
2527+ { a : 2 , b : 12 , c : '102' }
2528+ ] ;
2529+
2530+ for await ( const rows of result . yieldRowObjects ( ) ) {
2531+ for ( let i = 0 ; i < rows . length ; i ++ ) {
2532+ assert . deepEqual ( rows [ i ] , expectedRows [ i ] ) ;
2533+ }
2534+ }
2535+ } ) ;
2536+ } ) ;
2537+
2538+ test ( "iterate result stream rows js" , async ( ) => {
2539+ await withConnection ( async ( connection ) => {
2540+ const result = await connection . stream ( createTestJSQuery ( ) ) ;
2541+ for await ( const row of result . yieldRowsJs ( ) ) {
2542+ assert . deepEqual ( row , createTestJSRowsJS ( ) ) ;
2543+ }
2544+ } ) ;
2545+ } ) ;
2546+
2547+ test ( "iterate result stream object js" , async ( ) => {
2548+ await withConnection ( async ( connection ) => {
2549+ const result = await connection . stream ( createTestJSQuery ( ) ) ;
2550+ for await ( const row of result . yieldRowObjectJs ( ) ) {
2551+ assert . deepEqual ( row , createTestJSRowObjectsJS ( ) ) ;
2552+ }
2553+ } ) ;
2554+ } ) ;
2555+
2556+ test ( "iterate result stream rows json" , async ( ) => {
2557+ await withConnection ( async ( connection ) => {
2558+ const result = await connection . stream ( `from test_all_types()` ) ;
2559+ for await ( const row of result . yieldRowsJson ( ) ) {
2560+ assert . deepEqual ( row , createTestAllTypesRowsJson ( ) ) ;
2561+ }
2562+ } ) ;
2563+ } ) ;
2564+
2565+ test ( "iterate result stream object json" , async ( ) => {
2566+ await withConnection ( async ( connection ) => {
2567+ const result = await connection . stream ( `from test_all_types()` ) ;
2568+ for await ( const row of result . yieldRowObjectJson ( ) ) {
2569+ assert . deepEqual ( row , createTestAllTypesRowObjectsJson ( ) ) ;
2570+ }
2571+ } ) ;
2572+ } ) ;
24482573} ) ;
0 commit comments