<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Node-DuckDB API](./node-duckdb.md) &gt; [Connection](./node-duckdb.connection.md) &gt; [executeIterator](./node-duckdb.connection.executeiterator.md)

## Connection.executeIterator() method

Asynchronously executes the query and returns an iterator that points to the first result in the result set.

<b>Signature:</b>

```typescript
executeIterator<T>(command: string, options?: IExecuteOptions): Promise<ResultIterator<T>>;
```

## Parameters

| Parameter | Type                                                | Description                                                                         |
| --------- | --------------------------------------------------- | ----------------------------------------------------------------------------------- |
| command   | string                                              | SQL command to execute                                                              |
| options   | [IExecuteOptions](./node-duckdb.iexecuteoptions.md) | optional options object of type [IExecuteOptions](./node-duckdb.iexecuteoptions.md) |

<b>Returns:</b>

Promise&lt;[ResultIterator](./node-duckdb.resultiterator.md)<!-- -->&lt;T&gt;&gt;

## Example 1

Printing rows:

```ts
import { Connection, DuckDB, RowResultFormat } from "node-duckdb";
async function queryDatabaseWithIterator() {
  const db = new DuckDB();
  const connection = new Connection(db);
  await connection.executeIterator("CREATE TABLE people(id INTEGER, name VARCHAR);");
  await connection.executeIterator("INSERT INTO people VALUES (1, 'Mark'), (2, 'Hannes'), (3, 'Bob');");
  const result = await connection.executeIterator("SELECT * FROM people;");
  // print the first row
  console.log(result.fetchRow());
  // print the rest of the rows
  console.log(result.fetchAllRows());
  const result2 = await connection.executeIterator("SELECT * FROM people;", { rowResultFormat: RowResultFormat.Array });
  console.log(result2.fetchAllRows());
  connection.close();
  db.close();
}
queryDatabaseWithIterator();
```

## Example 2

Providing generics type:

```ts
const result = await connection.executeIterator<number[]>(`SELECT CAST(1 AS TINYINT)`, {
  rowResultFormat: RowResultFormat.Array,
});
expect(result.fetchRow()).toMatchObject([1]);
```
