# Get All Records via Stream API

> Stream all collection data to handle large datasets without memory overload.

Source: https://docs.apimaker.dev/v1/examples/sys/db/gen/getAllByStreamGen.html

`g.sys.db.gen.getAllByStreamGen` calls the [get all by stream generated API](https://docs.apimaker.dev/v1/docs/apis-all/generated-apis/auto-generated-get-all-by-stream-api.html) from your code : no schema, the data as it is in the table.

## Structure

**Get all by stream**

```typescript
let response = [];
await g.sys.db.gen.getAllByStreamGen({
    instance: "INSTANCE_NAME", database: 'DB_NAME', collection: "COLLECTION_NAME",
    queryParams: {
        deep: `[{
            s_key: "SOURCE_COLLECTION_COLUMN_NAME",
            t_key: "TARGET_COLLECTION_COLUMN_NAME",
            t_col: "TARGET_COLLECTION_NAME",
            select: "COLUMN_NAMES"  
        }]`,
        select: "COLUMN_NAMES",
        sort: "-COLUMN_NAME",
        limit: 2,
        find: `{"price": 42187}`,
        skip: 1,
    }
}, (item) => {
    response.push(item);
});
```

## Simple Get all

**Simple Get all from table**

```typescript
let response = [];
await g.sys.db.gen.getAllByStreamGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
}, (item) => {
    response.push(item);
});
```

## With header

**Get all with header**

```typescript
let response = [];
await g.sys.db.gen.getAllByStreamGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    headers: {
        "x-am-response-case": "capitalCase"
    }
}, (item) => {
    response.push(item);
});
```

## With header and queryParams

**Get all with header and queryParams**

```typescript
let response = [];
await g.sys.db.gen.getAllByStreamGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    headers: {
        "x-am-response-case": "capitalCase"
    },
    queryParams: {
        select: "first_name,last_name"
    }
}, (item) => {
    response.push(item);
});
```

## With multiple queryParams

**Get all With multiple queryParams**

```typescript
let response = [];
await g.sys.db.gen.getAllByStreamGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    headers: {
        "x-am-response-case": "capitalCase"
    },
    queryParams: {
        select: "first_name,last_name",
        limit: 2
    }
}, (item) => {
    response.push(item);
});
```

## With all params

**Get all With all params**

```typescript
let response = [];
await g.sys.db.gen.getAllByStreamGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    headers: {
        "x-am-response-case": "capitalCase"
    },
    queryParams: {
        select: "first_name,last_name",
        limit: 1,
        sort: "customer_id",
    }
}, (item) => {
    response.push(item);
});
```

## Multi-tenant
- `instance: "crm::acme"` works on the database of the tenant `acme` of the [multi-tenant](https://docs.apimaker.dev/v1/docs/features/multi-tenant.html) instance `crm`.
- With `instance: "crm"`, the call works on the database of the tenant of the request: a custom API called with the [x-am-tenant-username](https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-tenant-username) header passes it on to the APIs it calls. A request without a tenant works on the structure database.

**Get all customers of the tenant acme by stream**

```typescript
let response = [];
await g.sys.db.gen.getAllByStreamGen({
    instance: "crm::acme", database: "crm", collection: "customers",
}, (item) => {
    response.push(item);
});
```

## Related

- [Get all by stream generated API](https://docs.apimaker.dev/v1/docs/apis-all/generated-apis/auto-generated-get-all-by-stream-api.html) · [Schema API from code](https://docs.apimaker.dev/v1/examples/sys/db/getAllByStream.html) · [The global object g](https://docs.apimaker.dev/v1/docs/pre-defined-terms/global-object-g.html)
