# Query for Get Data by Stream API (generated)

> Stream the rows of a JSON query with the generated query by stream API of API Maker - the body of the query API, the answer of get all by stream, for exports and big result sets.

Source: https://docs.apimaker.dev/v1/docs/apis-all/generated-apis/auto-generated-query-for-get-data-by-stream-api.html

The body of [query for get data](/v1/docs/apis-all/generated-apis/auto-generated-query-for-get-data-api.html) with the answer of [get all by stream](/v1/docs/apis-all/generated-apis/auto-generated-get-all-by-stream-api.html) : rows are sent as the database produces them.

| | |
|---|---|
| Method | POST |
| URL | `/api/gen/admin/mysql8/inventory/customers/query-stream` |
| Body | `{ find, select, sort, skip, limit, deep, getTotalCount }` |
| Query params | none |
| Answer | `data` : an array of rows, streamed |
| Databases | MongoDB, MySQL, MariaDB, PostgreSQL, SQL Server, Oracle, TiDB, Percona |
| Cached | no : streams always come from the database |
| From code | [`g.sys.db.gen.queryByStreamGen`](/v1/examples/sys/db/gen/queryByStreamGen.html) |
| API id | `GEN_POST_QUERY_STREAM` (groups, settings, hooks, WebSocket subscriptions) |
| The other family | [Query for get data by stream as a schema API](/v1/docs/apis-all/schema-apis/auto-generated-schema-based-query-for-get-data-by-stream-api.html) |

!!! info "Schemaless : the data passes as it is"
    The generated APIs never read the [schema](/v1/docs/schema/schema.html) of the table. Nothing is converted, validated, defaulted, encrypted or numbered : what you send is what the database gets, and a filter matches the type you send (`"22"` does not match the number `22`). On MongoDB, strings which look like ObjectIds are converted. Every table has these APIs, with or without a schema ; the same operations under `/api/schema` apply the schema.

## The URL

`/api/gen/admin/mysql8/inventory/customers/query-stream` : replace `admin` with the user path of your account, `mysql8` with your instance, `inventory` with the database and `customers` with the table. The examples use this table :

| customer_id | first_name | last_name | last_update           | pincode | isActive |
|-------------|------------|-----------|-----------------------|---------|----------|
| 1           | Bob        | lin       | 2022-11-14 04: 34: 58 | 382345  | 1        |
| 2           | Alice      | Page      | 2022-10-15 02: 10: 40 | 382346  | 1        |
| 3           | Mallory    | Brown     | 2022-09-13 03: 44: 05 | 382347  | 1        |
| 4           | Eve        | Mathly    | 2022-11-12 01: 59: 33 | 382348  | 1        |
| 5           | Eve        | Page      | 2022-11-12 01: 59: 33 | 382349  | 1        |

## The call

```text
POST /api/gen/admin/mysql8/inventory/customers/query-stream
```

```json title="Body"
{ "find": { "isActive": 1 }, "sort": "customer_id", "select": "customer_id,first_name" }
```

```json title="Answer, written in chunks"
{ "data": [ { "customer_id": 1, "first_name": "Bob" }, { "customer_id": 2, "first_name": "Alice" } ], "success": true, "statusCode": 200, "meta": {} }
```

- Same keys and operators as the query API, find and join and deep included. Read `success` at the end : an error after the first rows closes the answer with `"success": false` and the errors.
- Never cached ; post hooks can not change what was sent.

## From your code

```typescript linenums="1"
const out: any[] = [];
await g.sys.db.gen.queryByStreamGen({
    instance: 'mysql8', database: 'inventory', collection: 'customers',
    find: { isActive: 1 }, select: 'customer_id,first_name',
}, (row) => out.push(row));
```

## Headers

Every call takes the [request headers](/v1/docs/apis-all/header/requestHeader.html) : the tokens, `x-am-response-case`, `x-am-content-type-response` (JSON, XML, YAML…), `x-am-response-object-type: make_flat`, `x-am-cache-control`, `x-am-get-encrypted-data`, `x-am-internationalization`, `x-am-tenant-username`, `x-am-meta`.

## Errors

| Code | When |
|---|---|
| `401` | The token in `x-am-authorization` is missing or invalid. |
| `403` | No group of the API user grants this API of this table, or a field of the request. |
| `404` | The instance, database or table of the URL does not exist. |
| `400` | The query or the body is wrong : the [error messages](/v1/docs/apis-all/error-codes.html) say which key and why. |

## Related

- [All APIs at a glance](/v1/docs/apis-all/overview.html) · [Query params](/v1/docs/apis-all/query-params/query-params.html) · [Response format](/v1/docs/apis-all/response-format.html) · [Pre hooks](/v1/docs/apis-all/hooks/preHook-api.html) and [post hooks](/v1/docs/apis-all/hooks/postHook-api.html) · [Automatic caching](/v1/docs/features/automatic-caching.html)
