# Get All Records API

> Fetch all collection records quickly—perfect for admin panels and bulk processing.

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

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

## Structure
```typescript
let getAll = await g.sys.db.gen.getAllGen({
    instance: "INSTANCE_NAME", database: 'DB_NAME', collection: "COLLECTION_NAME",
    queryParams: {
        deep: JSON.stringify([{
            s_key: "SOURCE_COLLECTION_COLUMN_NAME",
            t_key: "TARGET_COLLECTION_COLUMN_NAME",
            t_col: "TARGET_COLLECTION_NAME",
            select: "COLUMN_NAMES"
        }]),
        select: "COLUMN_NAMES",
        limit: 2,
        sort: "COLUMN_NAME"
    }
});
```

## Simple Get all with one condition

**Simple Get all from table**

```typescript
let getAll = await g.sys.db.gen.getAllGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    queryParams: {
        find: {
            first_name: 'James'
        }
    }
});
```

## With header

**Get all with header**

```typescript
let getAll = await g.sys.db.gen.getAllGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    headers: {
        "x-am-response-case": "capitalCase"
    }
});
```

## With header and queryParams

**Get all with header and queryParams**

```typescript
let getAll = await g.sys.db.gen.getAllGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    headers: {
        "x-am-meta": "true"
    },
    queryParams: {
        select: "first_name,last_name"
    }
});
```

## With multiple queryParams

**Get all with multiple queryParams**

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

## With all params

**Get all with all params**

```typescript
let getAll = await g.sys.db.gen.getAllGen({
    instance: "mysql_8",
    database: "inventory",
    collection: "customers",
    headers: {
        "x-am-response-case": "capitalCase"
    },
    queryParams: {
        select: "first_name,last_name",
        limit: 1,
        sort: "customer_id",
        deep: [{
            s_key: "customer_id",
            t_key: "owner_id",
            t_col: "products",
            select: "proName,proDescription,proPrice"
        }]
    }
});
```

## 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**

```typescript
let getAll = await g.sys.db.gen.getAllGen({
    instance: "crm::acme", database: "crm", collection: "customers",
    queryParams: {
        sort: "customer_id"
    }
});
```

**Get all customers of the tenant globex, named with the header of the call**

```typescript
let getAll = await g.sys.db.gen.getAllGen({
    instance: "crm", database: "crm", collection: "customers",
    headers: {
        "x-am-tenant-username": "globex"
    }
});
```

## Related

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