# Get All by Stream

> Fetch all records from a collection in a streaming manner, useful for handling large datasets efficiently.

Source: https://docs.apimaker.dev/v4/examples/sys/db/getAllByStream.html

> **The code in every language**
>
> Each example is the inside of `main`, written in every [language](https://docs.apimaker.dev/v4/docs/languages/index.html) API Maker runs : pick yours in the tabs, and every page shows it from then on. The types a call takes (`GetAll`, `DeepItem`…) are those of `am` : `from am import GetAll` in Python, `use am::GetAll;` in Rust, `import am.GetAll;` in Java and Kotlin ; PHP and C# have them without an import, Go names them `am.GetAll`.

`g.sys.db.getAllByStream` calls the [get all by stream schema API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-get-all-by-stream-api.html) of any table from your code, with the same headers and query parameters as over HTTP. Each row goes to your function as the database sends it, so a large table never sits in memory at once.

## Get all using stream API

**TypeScript**

**Get all from table**

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

**Python**

**Get all from table**

```python
response = []
await g.sys.db.get_all_by_stream(
    GetAll(
        'mysql_8', 'inventory', 'customers',
    ),
    response.append,
)
```

**PHP**

**Get all from table**

```php
$response = [];
$g->sys->db->getAllByStream(
    new GetAll(
        'mysql_8', 'inventory', 'customers',
    ),
    function ($item) use (&$response) {
        $response[] = $item;
    },
);
```

**C#**

**Get all from table**

```csharp
var response = new List<JsonObject>();
await g.Sys.Db.GetAllByStream(new GetAll("mysql_8", "inventory", "customers"), item => response.Add(item));
```

**Go**

**Get all from table**

```go
response := []am.M{}
if err := g.Sys.Db.GetAllByStream(am.GetAll{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
}, func(item am.M) error {
	response = append(response, item)
	return nil
}); err != nil {
	return nil, err
}
```

**Rust**

**Get all from table**

```rust
let mut response = Vec::new();
g.sys.db.get_all_by_stream(GetAll::new("mysql_8", "inventory", "customers"), |item| {
    response.push(item.clone());
    Ok(())
})?;
```

**Java**

**Get all from table**

```java
var response = new ArrayList<JsonObject>();
g.sys.db.getAllByStream(new GetAll("mysql_8", "inventory", "customers"), item -> response.add(item));
```

**Kotlin**

**Get all from table**

```kotlin
val response = mutableListOf<JsonObject>()
g.sys.db.getAllByStream(GetAll("mysql_8", "inventory", "customers")) { item -> response.add(item) }
```

## With header

**TypeScript**

**Get all with header**

```typescript
let response = [];
await g.sys.db.getAllByStream({
    instance: "mysql_8", database: "inventory", collection: "customers",
    headers: {
        "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
}, (item) => {
    response.push(item);
});
```

**Python**

**Get all with header**

```python
response = []
await g.sys.db.get_all_by_stream(
    GetAll(
        'mysql_8', 'inventory', 'customers',
        headers={
            'x-am-response-case': 'capitalCase',  # noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        },
    ),
    response.append,
)
```

**PHP**

**Get all with header**

```php
$response = [];
$g->sys->db->getAllByStream(
    new GetAll(
        'mysql_8', 'inventory', 'customers',
        headers: [
            'x-am-response-case' => 'capitalCase', // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        ],
    ),
    function ($item) use (&$response) {
        $response[] = $item;
    },
);
```

**C#**

**Get all with header**

```csharp
var response = new List<JsonObject>();
await g.Sys.Db.GetAllByStream(new GetAll("mysql_8", "inventory", "customers")
{
    Headers = new JsonObject
    {
        ["x-am-response-case"] = "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    },
}, item => response.Add(item));
```

**Go**

**Get all with header**

```go
response := []am.M{}
if err := g.Sys.Db.GetAllByStream(am.GetAll{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Headers: am.M{
		"x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
	},
}, func(item am.M) error {
	response = append(response, item)
	return nil
}); err != nil {
	return nil, err
}
```

**Rust**

**Get all with header**

```rust
let mut response = Vec::new();
g.sys.db.get_all_by_stream(
    GetAll::new("mysql_8", "inventory", "customers")
        .headers(json!({
            "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        })),
    |item| {
        response.push(item.clone());
        Ok(())
    },
)?;
```

**Java**

**Get all with header**

```java
var response = new ArrayList<JsonObject>();
g.sys.db.getAllByStream(new GetAll("mysql_8", "inventory", "customers")
    .headers(Map.of(
        "x-am-response-case", "capitalCase" // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    )), item -> response.add(item));
```

**Kotlin**

**Get all with header**

```kotlin
val response = mutableListOf<JsonObject>()
g.sys.db.getAllByStream(
    GetAll("mysql_8", "inventory", "customers")
        .headers(mapOf(
            "x-am-response-case" to "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        )),
) { item -> response.add(item) }
```

## With queryParams

**TypeScript**

**Get all With queryParams**

```typescript
let response = [];
await g.sys.db.getAllByStream({
    instance: "mysql_8", database: "inventory", collection: "customers",
    queryParams: {
        select: "first_name,last_name",
        limit: 10,
        sort: "customer_id",
        find: {
            "first_name": "John"
        },
        skip: 1,
        getTotalCount: true,
        deep: [{
            s_key: "customer_id",
            t_key: "owner_id",
            t_col: "products",
            select: "name, description, price"
        }]
    },
}, (item) => {
    response.push(item);
});
```

**Python**

**Get all With queryParams**

```python
response = []
await g.sys.db.get_all_by_stream(
    GetAll(
        'mysql_8', 'inventory', 'customers',
        select='first_name,last_name',
        limit=10,
        sort='customer_id',
        find={
            'first_name': 'John',
        },
        skip=1,
        get_total_count=True,
        deep=[
            DeepItem(
                'customer_id',
                t_key='owner_id',
                t_col='products',
                select='name, description, price',
            ),
        ],
    ),
    response.append,
)
```

**PHP**

**Get all With queryParams**

```php
$response = [];
$g->sys->db->getAllByStream(
    new GetAll(
        'mysql_8', 'inventory', 'customers',
        select: 'first_name,last_name',
        limit: 10,
        sort: 'customer_id',
        find: [
            'first_name' => 'John',
        ],
        skip: 1,
        getTotalCount: true,
        deep: [
            new DeepItem(
                'customer_id',
                tKey: 'owner_id',
                tCol: 'products',
                select: 'name, description, price',
            ),
        ],
    ),
    function ($item) use (&$response) {
        $response[] = $item;
    },
);
```

**C#**

**Get all With queryParams**

```csharp
var response = new List<JsonObject>();
await g.Sys.Db.GetAllByStream(new GetAll("mysql_8", "inventory", "customers")
{
    Select = "first_name,last_name",
    Limit = 10,
    Sort = "customer_id",
    Find = new JsonObject
    {
        ["first_name"] = "John",
    },
    Skip = 1,
    GetTotalCount = true,
    Deep = new[]
    {
        new DeepItem("customer_id")
        {
            TKey = "owner_id",
            TCol = "products",
            Select = "name, description, price",
        },
    },
}, item => response.Add(item));
```

**Go**

**Get all With queryParams**

```go
response := []am.M{}
if err := g.Sys.Db.GetAllByStream(am.GetAll{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Select: "first_name,last_name",
	Limit:  10,
	Sort:   "customer_id",
	Find: am.M{
		"first_name": "John",
	},
	Skip:          1,
	GetTotalCount: true,
	Deep: []am.DeepItem{
		{
			SKey:   "customer_id",
			TKey:   "owner_id",
			TCol:   "products",
			Select: "name, description, price",
		},
	},
}, func(item am.M) error {
	response = append(response, item)
	return nil
}); err != nil {
	return nil, err
}
```

**Rust**

**Get all With queryParams**

```rust
let mut response = Vec::new();
g.sys.db.get_all_by_stream(
    GetAll::new("mysql_8", "inventory", "customers")
        .select("first_name,last_name")
        .limit(10)
        .sort("customer_id")
        .find(json!({
            "first_name": "John",
        }))
        .skip(1)
        .get_total_count(true)
        .deep(vec![
            DeepItem::new("customer_id")
                .t_key("owner_id")
                .t_col("products")
                .select("name, description, price"),
        ]),
    |item| {
        response.push(item.clone());
        Ok(())
    },
)?;
```

**Java**

**Get all With queryParams**

```java
var response = new ArrayList<JsonObject>();
g.sys.db.getAllByStream(new GetAll("mysql_8", "inventory", "customers")
    .select("first_name,last_name")
    .limit(10)
    .sort("customer_id")
    .find(Map.of(
        "first_name", "John"
    ))
    .skip(1)
    .getTotalCount(true)
    .deep(List.of(
        new DeepItem("customer_id")
            .tKey("owner_id")
            .tCol("products")
            .select("name, description, price")
    )), item -> response.add(item));
```

**Kotlin**

**Get all With queryParams**

```kotlin
val response = mutableListOf<JsonObject>()
g.sys.db.getAllByStream(
    GetAll("mysql_8", "inventory", "customers")
        .select("first_name,last_name")
        .limit(10)
        .sort("customer_id")
        .find(mapOf(
            "first_name" to "John",
        ))
        .skip(1)
        .getTotalCount(true)
        .deep(listOf(
            DeepItem("customer_id")
                .tKey("owner_id")
                .tCol("products")
                .select("name, description, price"),
        )),
) { item -> response.add(item) }
```

## Structure

**TypeScript**

**Get all by stream with all params**

```typescript
let response = [];
await g.sys.db.getAllByStream({
    instance: "INSTANCE_NAME", database: 'DB_NAME', collection: "COLLECTION_NAME",
    headers: {
        "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        "x-am-response-object-type": "make_flat", // no_action | make_flat
        "x-am-meta": "true", // true, false
        "x-am-internationalization": "USER_I18N_ID",
        "x-am-run-in-sandbox": "2",
        "x-am-content-type-response": "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        "x-am-cache-control": "reset_cache", // no_action | reset_cache
        "x-am-get-encrypted-data": "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
        "x-am-sandbox-timeout": "13000",
        "x-no-compression": "true", // true | false
        "x-am-encrypted-payload": "true", // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        "x-am-tenant-username": "TENANT_USERNAME", // ex: acme
        // Authorization headers
        "x-am-authorization": "AUTHORIZATION_TOKEN",
        "x-am-user-authorization": "API_USER_TOKEN",
        "x-aws-authorization": "AWS_TOKEN",
        "x-google-authorization": "GOOGLE_TOKEN",
        "x-azure-authorization": "AZURE_TOKEN",
    },
    queryParams: {
        find: {
            "COLUMN_NAME": "COLUMN_VALUE"
        },
        skip: 1,
        limit: 5,
        sort: "COLUMN_NAME",
        select: "COMMA_SEPARATED_COLUMN_NAMES",
        getTotalCount: true,
        deep: [
            {
                s_key: "SOURCE_COLLECTION_COLUMN_NAME",
                t_instance: "TARGET_INSTANCE_NAME",
                t_db: "TARGET_DATABASE_NAME",
                t_col: "TARGET_COLLECTION_NAME",
                t_key: "TARGET_COLLECTION_COLUMN_NAME",
                find: {
                    "COLUMN_NAME": "COLUMN_VALUE"
                },
                isMultiple: true,
                limit: 10,
                select: "COMMA_SEPARATED_COLUMN_NAMES",
                skip: 2,
                sort: "COLUMN_NAME",
                deep: [
                    {
                        s_key: "SOURCE_COLLECTION_COLUMN_NAME",
                        t_instance: "TARGET_INSTANCE_NAME",
                        t_db: "TARGET_DATABASE_NAME",
                        t_col: "TARGET_COLLECTION_NAME",
                        t_key: "TARGET_COLLECTION_COLUMN_NAME",
                        find: {
                            "COLUMN_NAME": "COLUMN_VALUE"
                        },
                        isMultiple: true,
                        limit: 10,
                        select: "COMMA_SEPARATED_COLUMN_NAMES",
                        skip: 2,
                        sort: "COLUMN_NAME",
                    }
                ]
            }
        ]
    },
}, (item) => {
    response.push(item);
});
```

**Python**

**Get all by stream with all params**

```python
response = []
await g.sys.db.get_all_by_stream(
    GetAll(
        'INSTANCE_NAME', 'DB_NAME', 'COLLECTION_NAME',
        headers={
            'x-am-response-case': 'capitalCase',  # noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
            'x-am-response-object-type': 'make_flat',  # no_action | make_flat
            'x-am-meta': 'true',  # true, false
            'x-am-internationalization': 'USER_I18N_ID',
            'x-am-run-in-sandbox': '2',
            'x-am-content-type-response': 'text/xml',  # application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
            'x-am-cache-control': 'reset_cache',  # no_action | reset_cache
            'x-am-get-encrypted-data': 'get_only_encryption',  # no_encryption | get_only_encryption | get_data_and_encryption
            'x-am-sandbox-timeout': '13000',
            'x-no-compression': 'true',  # true | false
            'x-am-encrypted-payload': 'true',  # user will send 'true', when payload is encrypted for transfer
            # Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
            'x-am-tenant-username': 'TENANT_USERNAME',  # ex: acme
            # Authorization headers
            'x-am-authorization': 'AUTHORIZATION_TOKEN',
            'x-am-user-authorization': 'API_USER_TOKEN',
            'x-aws-authorization': 'AWS_TOKEN',
            'x-google-authorization': 'GOOGLE_TOKEN',
            'x-azure-authorization': 'AZURE_TOKEN',
        },
        find={
            'COLUMN_NAME': 'COLUMN_VALUE',
        },
        skip=1,
        limit=5,
        sort='COLUMN_NAME',
        select='COMMA_SEPARATED_COLUMN_NAMES',
        get_total_count=True,
        deep=[
            DeepItem(
                'SOURCE_COLLECTION_COLUMN_NAME',
                t_instance='TARGET_INSTANCE_NAME',
                t_db='TARGET_DATABASE_NAME',
                t_col='TARGET_COLLECTION_NAME',
                t_key='TARGET_COLLECTION_COLUMN_NAME',
                find={
                    'COLUMN_NAME': 'COLUMN_VALUE',
                },
                is_multiple=True,
                limit=10,
                select='COMMA_SEPARATED_COLUMN_NAMES',
                skip=2,
                sort='COLUMN_NAME',
                deep=[
                    DeepItem(
                        'SOURCE_COLLECTION_COLUMN_NAME',
                        t_instance='TARGET_INSTANCE_NAME',
                        t_db='TARGET_DATABASE_NAME',
                        t_col='TARGET_COLLECTION_NAME',
                        t_key='TARGET_COLLECTION_COLUMN_NAME',
                        find={
                            'COLUMN_NAME': 'COLUMN_VALUE',
                        },
                        is_multiple=True,
                        limit=10,
                        select='COMMA_SEPARATED_COLUMN_NAMES',
                        skip=2,
                        sort='COLUMN_NAME',
                    ),
                ],
            ),
        ],
    ),
    response.append,
)
```

**PHP**

**Get all by stream with all params**

```php
$response = [];
$g->sys->db->getAllByStream(
    new GetAll(
        'INSTANCE_NAME', 'DB_NAME', 'COLLECTION_NAME',
        headers: [
            'x-am-response-case' => 'capitalCase', // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
            'x-am-response-object-type' => 'make_flat', // no_action | make_flat
            'x-am-meta' => 'true', // true, false
            'x-am-internationalization' => 'USER_I18N_ID',
            'x-am-run-in-sandbox' => '2',
            'x-am-content-type-response' => 'text/xml', // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
            'x-am-cache-control' => 'reset_cache', // no_action | reset_cache
            'x-am-get-encrypted-data' => 'get_only_encryption', // no_encryption | get_only_encryption | get_data_and_encryption
            'x-am-sandbox-timeout' => '13000',
            'x-no-compression' => 'true', // true | false
            'x-am-encrypted-payload' => 'true', // user will send 'true', when payload is encrypted for transfer
            // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
            'x-am-tenant-username' => 'TENANT_USERNAME', // ex: acme
            // Authorization headers
            'x-am-authorization' => 'AUTHORIZATION_TOKEN',
            'x-am-user-authorization' => 'API_USER_TOKEN',
            'x-aws-authorization' => 'AWS_TOKEN',
            'x-google-authorization' => 'GOOGLE_TOKEN',
            'x-azure-authorization' => 'AZURE_TOKEN',
        ],
        find: [
            'COLUMN_NAME' => 'COLUMN_VALUE',
        ],
        skip: 1,
        limit: 5,
        sort: 'COLUMN_NAME',
        select: 'COMMA_SEPARATED_COLUMN_NAMES',
        getTotalCount: true,
        deep: [
            new DeepItem(
                'SOURCE_COLLECTION_COLUMN_NAME',
                tInstance: 'TARGET_INSTANCE_NAME',
                tDb: 'TARGET_DATABASE_NAME',
                tCol: 'TARGET_COLLECTION_NAME',
                tKey: 'TARGET_COLLECTION_COLUMN_NAME',
                find: [
                    'COLUMN_NAME' => 'COLUMN_VALUE',
                ],
                isMultiple: true,
                limit: 10,
                select: 'COMMA_SEPARATED_COLUMN_NAMES',
                skip: 2,
                sort: 'COLUMN_NAME',
                deep: [
                    new DeepItem(
                        'SOURCE_COLLECTION_COLUMN_NAME',
                        tInstance: 'TARGET_INSTANCE_NAME',
                        tDb: 'TARGET_DATABASE_NAME',
                        tCol: 'TARGET_COLLECTION_NAME',
                        tKey: 'TARGET_COLLECTION_COLUMN_NAME',
                        find: [
                            'COLUMN_NAME' => 'COLUMN_VALUE',
                        ],
                        isMultiple: true,
                        limit: 10,
                        select: 'COMMA_SEPARATED_COLUMN_NAMES',
                        skip: 2,
                        sort: 'COLUMN_NAME',
                    ),
                ],
            ),
        ],
    ),
    function ($item) use (&$response) {
        $response[] = $item;
    },
);
```

**C#**

**Get all by stream with all params**

```csharp
var response = new List<JsonObject>();
await g.Sys.Db.GetAllByStream(new GetAll("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME")
{
    Headers = new JsonObject
    {
        ["x-am-response-case"] = "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        ["x-am-response-object-type"] = "make_flat", // no_action | make_flat
        ["x-am-meta"] = "true", // true, false
        ["x-am-internationalization"] = "USER_I18N_ID",
        ["x-am-run-in-sandbox"] = "2",
        ["x-am-content-type-response"] = "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        ["x-am-cache-control"] = "reset_cache", // no_action | reset_cache
        ["x-am-get-encrypted-data"] = "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
        ["x-am-sandbox-timeout"] = "13000",
        ["x-no-compression"] = "true", // true | false
        ["x-am-encrypted-payload"] = "true", // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        ["x-am-tenant-username"] = "TENANT_USERNAME", // ex: acme
        // Authorization headers
        ["x-am-authorization"] = "AUTHORIZATION_TOKEN",
        ["x-am-user-authorization"] = "API_USER_TOKEN",
        ["x-aws-authorization"] = "AWS_TOKEN",
        ["x-google-authorization"] = "GOOGLE_TOKEN",
        ["x-azure-authorization"] = "AZURE_TOKEN",
    },
    Find = new JsonObject
    {
        ["COLUMN_NAME"] = "COLUMN_VALUE",
    },
    Skip = 1,
    Limit = 5,
    Sort = "COLUMN_NAME",
    Select = "COMMA_SEPARATED_COLUMN_NAMES",
    GetTotalCount = true,
    Deep = new[]
    {
        new DeepItem("SOURCE_COLLECTION_COLUMN_NAME")
        {
            TInstance = "TARGET_INSTANCE_NAME",
            TDb = "TARGET_DATABASE_NAME",
            TCol = "TARGET_COLLECTION_NAME",
            TKey = "TARGET_COLLECTION_COLUMN_NAME",
            Find = new JsonObject
            {
                ["COLUMN_NAME"] = "COLUMN_VALUE",
            },
            IsMultiple = true,
            Limit = 10,
            Select = "COMMA_SEPARATED_COLUMN_NAMES",
            Skip = 2,
            Sort = "COLUMN_NAME",
            Deep = new[]
            {
                new DeepItem("SOURCE_COLLECTION_COLUMN_NAME")
                {
                    TInstance = "TARGET_INSTANCE_NAME",
                    TDb = "TARGET_DATABASE_NAME",
                    TCol = "TARGET_COLLECTION_NAME",
                    TKey = "TARGET_COLLECTION_COLUMN_NAME",
                    Find = new JsonObject
                    {
                        ["COLUMN_NAME"] = "COLUMN_VALUE",
                    },
                    IsMultiple = true,
                    Limit = 10,
                    Select = "COMMA_SEPARATED_COLUMN_NAMES",
                    Skip = 2,
                    Sort = "COLUMN_NAME",
                },
            },
        },
    },
}, item => response.Add(item));
```

**Go**

**Get all by stream with all params**

```go
response := []am.M{}
if err := g.Sys.Db.GetAllByStream(am.GetAll{
	Instance: "INSTANCE_NAME", Database: "DB_NAME", Collection: "COLLECTION_NAME",
	Headers: am.M{
		"x-am-response-case":         "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
		"x-am-response-object-type":  "make_flat",   // no_action | make_flat
		"x-am-meta":                  "true",        // true, false
		"x-am-internationalization":  "USER_I18N_ID",
		"x-am-run-in-sandbox":        "2",
		"x-am-content-type-response": "text/xml",            // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
		"x-am-cache-control":         "reset_cache",         // no_action | reset_cache
		"x-am-get-encrypted-data":    "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
		"x-am-sandbox-timeout":       "13000",
		"x-no-compression":           "true", // true | false
		"x-am-encrypted-payload":     "true", // user will send 'true', when payload is encrypted for transfer
		// Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
		"x-am-tenant-username": "TENANT_USERNAME", // ex: acme
		// Authorization headers
		"x-am-authorization":      "AUTHORIZATION_TOKEN",
		"x-am-user-authorization": "API_USER_TOKEN",
		"x-aws-authorization":     "AWS_TOKEN",
		"x-google-authorization":  "GOOGLE_TOKEN",
		"x-azure-authorization":   "AZURE_TOKEN",
	},
	Find: am.M{
		"COLUMN_NAME": "COLUMN_VALUE",
	},
	Skip:          1,
	Limit:         5,
	Sort:          "COLUMN_NAME",
	Select:        "COMMA_SEPARATED_COLUMN_NAMES",
	GetTotalCount: true,
	Deep: []am.DeepItem{
		{
			SKey:      "SOURCE_COLLECTION_COLUMN_NAME",
			TInstance: "TARGET_INSTANCE_NAME",
			TDb:       "TARGET_DATABASE_NAME",
			TCol:      "TARGET_COLLECTION_NAME",
			TKey:      "TARGET_COLLECTION_COLUMN_NAME",
			Find: am.M{
				"COLUMN_NAME": "COLUMN_VALUE",
			},
			IsMultiple: true,
			Limit:      10,
			Select:     "COMMA_SEPARATED_COLUMN_NAMES",
			Skip:       2,
			Sort:       "COLUMN_NAME",
			Deep: []am.DeepItem{
				{
					SKey:      "SOURCE_COLLECTION_COLUMN_NAME",
					TInstance: "TARGET_INSTANCE_NAME",
					TDb:       "TARGET_DATABASE_NAME",
					TCol:      "TARGET_COLLECTION_NAME",
					TKey:      "TARGET_COLLECTION_COLUMN_NAME",
					Find: am.M{
						"COLUMN_NAME": "COLUMN_VALUE",
					},
					IsMultiple: true,
					Limit:      10,
					Select:     "COMMA_SEPARATED_COLUMN_NAMES",
					Skip:       2,
					Sort:       "COLUMN_NAME",
				},
			},
		},
	},
}, func(item am.M) error {
	response = append(response, item)
	return nil
}); err != nil {
	return nil, err
}
```

**Rust**

**Get all by stream with all params**

```rust
let mut response = Vec::new();
g.sys.db.get_all_by_stream(
    GetAll::new("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME")
        .headers(json!({
            "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
            "x-am-response-object-type": "make_flat", // no_action | make_flat
            "x-am-meta": "true", // true, false
            "x-am-internationalization": "USER_I18N_ID",
            "x-am-run-in-sandbox": "2",
            "x-am-content-type-response": "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
            "x-am-cache-control": "reset_cache", // no_action | reset_cache
            "x-am-get-encrypted-data": "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
            "x-am-sandbox-timeout": "13000",
            "x-no-compression": "true", // true | false
            "x-am-encrypted-payload": "true", // user will send 'true', when payload is encrypted for transfer
            // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
            "x-am-tenant-username": "TENANT_USERNAME", // ex: acme
            // Authorization headers
            "x-am-authorization": "AUTHORIZATION_TOKEN",
            "x-am-user-authorization": "API_USER_TOKEN",
            "x-aws-authorization": "AWS_TOKEN",
            "x-google-authorization": "GOOGLE_TOKEN",
            "x-azure-authorization": "AZURE_TOKEN",
        }))
        .find(json!({
            "COLUMN_NAME": "COLUMN_VALUE",
        }))
        .skip(1)
        .limit(5)
        .sort("COLUMN_NAME")
        .select("COMMA_SEPARATED_COLUMN_NAMES")
        .get_total_count(true)
        .deep(vec![
            DeepItem::new("SOURCE_COLLECTION_COLUMN_NAME")
                .t_instance("TARGET_INSTANCE_NAME")
                .t_db("TARGET_DATABASE_NAME")
                .t_col("TARGET_COLLECTION_NAME")
                .t_key("TARGET_COLLECTION_COLUMN_NAME")
                .find(json!({
                    "COLUMN_NAME": "COLUMN_VALUE",
                }))
                .is_multiple(true)
                .limit(10)
                .select("COMMA_SEPARATED_COLUMN_NAMES")
                .skip(2)
                .sort("COLUMN_NAME")
                .deep(vec![
                    DeepItem::new("SOURCE_COLLECTION_COLUMN_NAME")
                        .t_instance("TARGET_INSTANCE_NAME")
                        .t_db("TARGET_DATABASE_NAME")
                        .t_col("TARGET_COLLECTION_NAME")
                        .t_key("TARGET_COLLECTION_COLUMN_NAME")
                        .find(json!({
                            "COLUMN_NAME": "COLUMN_VALUE",
                        }))
                        .is_multiple(true)
                        .limit(10)
                        .select("COMMA_SEPARATED_COLUMN_NAMES")
                        .skip(2)
                        .sort("COLUMN_NAME"),
                ]),
        ]),
    |item| {
        response.push(item.clone());
        Ok(())
    },
)?;
```

**Java**

**Get all by stream with all params**

```java
var response = new ArrayList<JsonObject>();
g.sys.db.getAllByStream(new GetAll("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME")
    .headers(JsonObject.of(
        "x-am-response-case", "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        "x-am-response-object-type", "make_flat", // no_action | make_flat
        "x-am-meta", "true", // true, false
        "x-am-internationalization", "USER_I18N_ID",
        "x-am-run-in-sandbox", "2",
        "x-am-content-type-response", "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
        "x-am-cache-control", "reset_cache", // no_action | reset_cache
        "x-am-get-encrypted-data", "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
        "x-am-sandbox-timeout", "13000",
        "x-no-compression", "true", // true | false
        "x-am-encrypted-payload", "true", // user will send 'true', when payload is encrypted for transfer
        // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
        "x-am-tenant-username", "TENANT_USERNAME", // ex: acme
        // Authorization headers
        "x-am-authorization", "AUTHORIZATION_TOKEN",
        "x-am-user-authorization", "API_USER_TOKEN",
        "x-aws-authorization", "AWS_TOKEN",
        "x-google-authorization", "GOOGLE_TOKEN",
        "x-azure-authorization", "AZURE_TOKEN"
    ))
    .find(Map.of(
        "COLUMN_NAME", "COLUMN_VALUE"
    ))
    .skip(1)
    .limit(5)
    .sort("COLUMN_NAME")
    .select("COMMA_SEPARATED_COLUMN_NAMES")
    .getTotalCount(true)
    .deep(List.of(
        new DeepItem("SOURCE_COLLECTION_COLUMN_NAME")
            .tInstance("TARGET_INSTANCE_NAME")
            .tDb("TARGET_DATABASE_NAME")
            .tCol("TARGET_COLLECTION_NAME")
            .tKey("TARGET_COLLECTION_COLUMN_NAME")
            .find(Map.of(
                "COLUMN_NAME", "COLUMN_VALUE"
            ))
            .isMultiple(true)
            .limit(10)
            .select("COMMA_SEPARATED_COLUMN_NAMES")
            .skip(2)
            .sort("COLUMN_NAME")
            .deep(List.of(
                new DeepItem("SOURCE_COLLECTION_COLUMN_NAME")
                    .tInstance("TARGET_INSTANCE_NAME")
                    .tDb("TARGET_DATABASE_NAME")
                    .tCol("TARGET_COLLECTION_NAME")
                    .tKey("TARGET_COLLECTION_COLUMN_NAME")
                    .find(Map.of(
                        "COLUMN_NAME", "COLUMN_VALUE"
                    ))
                    .isMultiple(true)
                    .limit(10)
                    .select("COMMA_SEPARATED_COLUMN_NAMES")
                    .skip(2)
                    .sort("COLUMN_NAME")
            ))
    )), item -> response.add(item));
```

**Kotlin**

**Get all by stream with all params**

```kotlin
val response = mutableListOf<JsonObject>()
g.sys.db.getAllByStream(
    GetAll("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME")
        .headers(mapOf(
            "x-am-response-case" to "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
            "x-am-response-object-type" to "make_flat", // no_action | make_flat
            "x-am-meta" to "true", // true, false
            "x-am-internationalization" to "USER_I18N_ID",
            "x-am-run-in-sandbox" to "2",
            "x-am-content-type-response" to "text/xml", // application/json | text/xml | text/yaml | text/plain | text/html | application/octet-stream
            "x-am-cache-control" to "reset_cache", // no_action | reset_cache
            "x-am-get-encrypted-data" to "get_only_encryption", // no_encryption | get_only_encryption | get_data_and_encryption
            "x-am-sandbox-timeout" to "13000",
            "x-no-compression" to "true", // true | false
            "x-am-encrypted-payload" to "true", // user will send 'true', when payload is encrypted for transfer
            // Multi-tenant : the tenant of the request, each instance finds it in its own tenants table
            "x-am-tenant-username" to "TENANT_USERNAME", // ex: acme
            // Authorization headers
            "x-am-authorization" to "AUTHORIZATION_TOKEN",
            "x-am-user-authorization" to "API_USER_TOKEN",
            "x-aws-authorization" to "AWS_TOKEN",
            "x-google-authorization" to "GOOGLE_TOKEN",
            "x-azure-authorization" to "AZURE_TOKEN",
        ))
        .find(mapOf(
            "COLUMN_NAME" to "COLUMN_VALUE",
        ))
        .skip(1)
        .limit(5)
        .sort("COLUMN_NAME")
        .select("COMMA_SEPARATED_COLUMN_NAMES")
        .getTotalCount(true)
        .deep(listOf(
            DeepItem("SOURCE_COLLECTION_COLUMN_NAME")
                .tInstance("TARGET_INSTANCE_NAME")
                .tDb("TARGET_DATABASE_NAME")
                .tCol("TARGET_COLLECTION_NAME")
                .tKey("TARGET_COLLECTION_COLUMN_NAME")
                .find(mapOf(
                    "COLUMN_NAME" to "COLUMN_VALUE",
                ))
                .isMultiple(true)
                .limit(10)
                .select("COMMA_SEPARATED_COLUMN_NAMES")
                .skip(2)
                .sort("COLUMN_NAME")
                .deep(listOf(
                    DeepItem("SOURCE_COLLECTION_COLUMN_NAME")
                        .tInstance("TARGET_INSTANCE_NAME")
                        .tDb("TARGET_DATABASE_NAME")
                        .tCol("TARGET_COLLECTION_NAME")
                        .tKey("TARGET_COLLECTION_COLUMN_NAME")
                        .find(mapOf(
                            "COLUMN_NAME" to "COLUMN_VALUE",
                        ))
                        .isMultiple(true)
                        .limit(10)
                        .select("COMMA_SEPARATED_COLUMN_NAMES")
                        .skip(2)
                        .sort("COLUMN_NAME"),
                )),
        )),
) { item -> response.add(item) }
```

## Multi-tenant
- `instance: "crm::acme"` works on the database of the tenant `acme` of the [multi-tenant](https://docs.apimaker.dev/v4/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/v4/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.

**TypeScript**

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

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

**Python**

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

```python
response = []
await g.sys.db.get_all_by_stream(
    GetAll(
        'crm::acme', 'crm', 'customers',
    ),
    response.append,
)
```

**PHP**

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

```php
$response = [];
$g->sys->db->getAllByStream(
    new GetAll(
        'crm::acme', 'crm', 'customers',
    ),
    function ($item) use (&$response) {
        $response[] = $item;
    },
);
```

**C#**

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

```csharp
var response = new List<JsonObject>();
await g.Sys.Db.GetAllByStream(new GetAll("crm::acme", "crm", "customers"), item => response.Add(item));
```

**Go**

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

```go
response := []am.M{}
if err := g.Sys.Db.GetAllByStream(am.GetAll{
	Instance: "crm::acme", Database: "crm", Collection: "customers",
}, func(item am.M) error {
	response = append(response, item)
	return nil
}); err != nil {
	return nil, err
}
```

**Rust**

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

```rust
let mut response = Vec::new();
g.sys.db.get_all_by_stream(GetAll::new("crm::acme", "crm", "customers"), |item| {
    response.push(item.clone());
    Ok(())
})?;
```

**Java**

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

```java
var response = new ArrayList<JsonObject>();
g.sys.db.getAllByStream(new GetAll("crm::acme", "crm", "customers"), item -> response.add(item));
```

**Kotlin**

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

```kotlin
val response = mutableListOf<JsonObject>()
g.sys.db.getAllByStream(GetAll("crm::acme", "crm", "customers")) { item -> response.add(item) }
```

## Without a schema

`g.sys.db.gen.getAllByStreamGen` takes the same arguments and calls the [get all by stream generated API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-get-all-by-stream-api.html#without-a-schema) : no schema, so the data is read and written as it is in the table, without the conversions, validations and defaults of the schema.

| Language | The call |
|---|---|
| TypeScript | `g.sys.db.gen.getAllByStreamGen(…)` |
| Python | `g.sys.db.gen.get_all_by_stream_gen(…)` |
| PHP | `$g->sys->db->gen->getAllByStreamGen(…)` |
| C#, Go | `g.Sys.Db.Gen.GetAllByStreamGen(…)` |
| Rust | `g.sys.db.get_all_by_stream_gen(GetAll::new(…))` |
| Java, Kotlin | `g.sys.db.gen.getAllByStreamGen(…)` |

## Related

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