# Get by ID

> Retrieve a single record from a collection based on its unique identifier using API Maker's g.sys.db.getById method.

Source: https://docs.apimaker.dev/v4/examples/sys/db/getById.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.getById` calls the [get by id schema API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-get-by-id-api.html) of any table from your code, with the same headers and query parameters as over HTTP. It returns the data. The whole envelope (`success`, `statusCode`, `data`, `totalCount`, `errors`…) comes back when `true` is passed as the second argument in TypeScript, and through `full` in the other languages : `g.sys.db.full` (`g.Sys.Db.Full` in C# and Go, `$g->sys->db->full` in PHP).

## Get by id

**TypeScript**

**Get by id from table**

```typescript
let getById = await g.sys.db.getById({
    instance: "mysql_8", database: "inventory", collection: "customers",
    id: 2
});
```

**Python**

**Get by id from table**

```python
get_by_id = await g.sys.db.get_by_id(
    'mysql_8', 'inventory', 'customers',
    2,
)
```

**PHP**

**Get by id from table**

```php
$getById = $g->sys->db->getById(
    'mysql_8', 'inventory', 'customers',
    2,
);
```

**C#**

**Get by id from table**

```csharp
var getById = await g.Sys.Db.GetById(new GetById("mysql_8", "inventory", "customers", 2));
```

**Go**

**Get by id from table**

```go
getById, err := g.Sys.Db.GetById(am.GetById{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Id: 2,
})
if err != nil {
	return nil, err
}
```

**Rust**

**Get by id from table**

```rust
let get_by_id = g.sys.db.get_by_id(GetById::new("mysql_8", "inventory", "customers", json!(2)))?;
```

**Java**

**Get by id from table**

```java
var getById = g.sys.db.getById(new GetById("mysql_8", "inventory", "customers", 2));
```

**Kotlin**

**Get by id from table**

```kotlin
val getById = g.sys.db.getById(GetById("mysql_8", "inventory", "customers", 2))
```

## With [primaryKey] override

**TypeScript**

**Get by id with primary key override**

```typescript
let getById= await g.sys.db.getById({
    instance: "mysql_8", database: "inventory", collection: "customers",
    id: "NICK",
    primaryKey:"first_name",
});
```

**Python**

**Get by id with primary key override**

```python
get_by_id = await g.sys.db.get_by_id(
    'mysql_8', 'inventory', 'customers',
    'NICK',
    primary_key='first_name',
)
```

**PHP**

**Get by id with primary key override**

```php
$getById = $g->sys->db->getById(
    'mysql_8', 'inventory', 'customers',
    'NICK',
    primaryKey: 'first_name',
);
```

**C#**

**Get by id with primary key override**

```csharp
var getById = await g.Sys.Db.GetById(new GetById("mysql_8", "inventory", "customers", "NICK")
{
    PrimaryKey = "first_name",
});
```

**Go**

**Get by id with primary key override**

```go
getById, err := g.Sys.Db.GetById(am.GetById{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Id:         "NICK",
	PrimaryKey: "first_name",
})
if err != nil {
	return nil, err
}
```

**Rust**

**Get by id with primary key override**

```rust
let get_by_id = g.sys.db.get_by_id(
    GetById::new("mysql_8", "inventory", "customers", "NICK")
        .primary_key("first_name"),
)?;
```

**Java**

**Get by id with primary key override**

```java
var getById = g.sys.db.getById(new GetById("mysql_8", "inventory", "customers", "NICK")
    .primaryKey("first_name"));
```

**Kotlin**

**Get by id with primary key override**

```kotlin
val getById = g.sys.db.getById(
    GetById("mysql_8", "inventory", "customers", "NICK")
        .primaryKey("first_name"),
)
```

## With header

**TypeScript**

**Get by id with header**

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

**Python**

**Get by id with header**

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

**PHP**

**Get by id with header**

```php
$getById = $g->sys->db->getById(
    'mysql_8', 'inventory', 'customers',
    2,
    headers: [
        'x-am-response-case' => 'capitalCase', // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    ],
);
```

**C#**

**Get by id with header**

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

**Go**

**Get by id with header**

```go
getById, err := g.Sys.Db.GetById(am.GetById{
	Instance: "mysql_8", Database: "inventory", Collection: "customers",
	Id: 2,
	Headers: am.M{
		"x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Get by id with header**

```rust
let get_by_id = g.sys.db.get_by_id(
    GetById::new("mysql_8", "inventory", "customers", json!(2))
        .headers(json!({
            "x-am-response-case": "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        })),
)?;
```

**Java**

**Get by id with header**

```java
var getById = g.sys.db.getById(new GetById("mysql_8", "inventory", "customers", 2)
    .headers(Map.of(
        "x-am-response-case", "capitalCase" // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
    )));
```

**Kotlin**

**Get by id with header**

```kotlin
val getById = g.sys.db.getById(
    GetById("mysql_8", "inventory", "customers", 2)
        .headers(mapOf(
            "x-am-response-case" to "capitalCase", // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
        )),
)
```

## Structure

**TypeScript**

**Get by id with all params**

```typescript
let getById = await g.sys.db.getById({
    instance: "INSTANCE_NAME", database: 'DB_NAME', collection: "COLLECTION_NAME",
    id: 100050,
    primaryKey: 'COLUMN_NAME',
    select: "COMMA_SEPARATED_COLUMN_NAMES",
    deep: [{ // string, string[], array of objects are supported
        s_key: "customer_id",
        t_key: "owner_id",
        t_col: "products",
        select: "proName,proDescription,proPrice"
    }],
    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",
    },
});
```

**Python**

**Get by id with all params**

```python
get_by_id = await g.sys.db.get_by_id(
    'INSTANCE_NAME', 'DB_NAME', 'COLLECTION_NAME',
    100050,
    primary_key='COLUMN_NAME',
    select='COMMA_SEPARATED_COLUMN_NAMES',
    deep=[
        DeepItem(
            # string, string[], array of objects are supported
            'customer_id',
            t_key='owner_id',
            t_col='products',
            select='proName,proDescription,proPrice',
        ),
    ],
    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',
    },
)
```

**PHP**

**Get by id with all params**

```php
$getById = $g->sys->db->getById(
    'INSTANCE_NAME', 'DB_NAME', 'COLLECTION_NAME',
    100050,
    primaryKey: 'COLUMN_NAME',
    select: 'COMMA_SEPARATED_COLUMN_NAMES',
    deep: [
        new DeepItem(
            // string, string[], array of objects are supported
            'customer_id',
            tKey: 'owner_id',
            tCol: 'products',
            select: 'proName,proDescription,proPrice',
        ),
    ],
    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',
    ],
);
```

**C#**

**Get by id with all params**

```csharp
var getById = await g.Sys.Db.GetById(new GetById("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", 100050)
{
    PrimaryKey = "COLUMN_NAME",
    Select = "COMMA_SEPARATED_COLUMN_NAMES",
    Deep = new[]
    {
        new DeepItem("customer_id")
        {
            TKey = "owner_id",
            TCol = "products",
            Select = "proName,proDescription,proPrice",
        },
    },
    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",
    },
});
```

**Go**

**Get by id with all params**

```go
getById, err := g.Sys.Db.GetById(am.GetById{
	Instance: "INSTANCE_NAME", Database: "DB_NAME", Collection: "COLLECTION_NAME",
	Id:         100050,
	PrimaryKey: "COLUMN_NAME",
	Select:     "COMMA_SEPARATED_COLUMN_NAMES",
	Deep: []am.DeepItem{
		{
			// string, string[], array of objects are supported
			SKey:   "customer_id",
			TKey:   "owner_id",
			TCol:   "products",
			Select: "proName,proDescription,proPrice",
		},
	},
	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",
	},
})
if err != nil {
	return nil, err
}
```

**Rust**

**Get by id with all params**

```rust
let get_by_id = g.sys.db.get_by_id(
    GetById::new("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", json!(100050))
        .primary_key("COLUMN_NAME")
        .select("COMMA_SEPARATED_COLUMN_NAMES")
        .deep(vec![
            DeepItem::new("customer_id")
                .t_key("owner_id")
                .t_col("products")
                .select("proName,proDescription,proPrice"),
        ])
        .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",
        })),
)?;
```

**Java**

**Get by id with all params**

```java
var getById = g.sys.db.getById(new GetById("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", 100050)
    .primaryKey("COLUMN_NAME")
    .select("COMMA_SEPARATED_COLUMN_NAMES")
    .deep(List.of(
        new DeepItem("customer_id")
            .tKey("owner_id")
            .tCol("products")
            .select("proName,proDescription,proPrice")
    ))
    .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"
    )));
```

**Kotlin**

**Get by id with all params**

```kotlin
val getById = g.sys.db.getById(
    GetById("INSTANCE_NAME", "DB_NAME", "COLLECTION_NAME", 100050)
        .primaryKey("COLUMN_NAME")
        .select("COMMA_SEPARATED_COLUMN_NAMES")
        .deep(listOf(
            DeepItem("customer_id")
                .tKey("owner_id")
                .tCol("products")
                .select("proName,proDescription,proPrice"),
        ))
        .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",
        )),
)
```

## 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 the customer 1 of the tenant acme**

```typescript
let getById = await g.sys.db.getById({
    instance: "crm::acme", database: "crm", collection: "customers",
    id: 1
});
```

**Python**

**Get the customer 1 of the tenant acme**

```python
get_by_id = await g.sys.db.get_by_id(
    'crm::acme', 'crm', 'customers',
    1,
)
```

**PHP**

**Get the customer 1 of the tenant acme**

```php
$getById = $g->sys->db->getById(
    'crm::acme', 'crm', 'customers',
    1,
);
```

**C#**

**Get the customer 1 of the tenant acme**

```csharp
var getById = await g.Sys.Db.GetById(new GetById("crm::acme", "crm", "customers", 1));
```

**Go**

**Get the customer 1 of the tenant acme**

```go
getById, err := g.Sys.Db.GetById(am.GetById{
	Instance: "crm::acme", Database: "crm", Collection: "customers",
	Id: 1,
})
if err != nil {
	return nil, err
}
```

**Rust**

**Get the customer 1 of the tenant acme**

```rust
let get_by_id = g.sys.db.get_by_id(GetById::new("crm::acme", "crm", "customers", json!(1)))?;
```

**Java**

**Get the customer 1 of the tenant acme**

```java
var getById = g.sys.db.getById(new GetById("crm::acme", "crm", "customers", 1));
```

**Kotlin**

**Get the customer 1 of the tenant acme**

```kotlin
val getById = g.sys.db.getById(GetById("crm::acme", "crm", "customers", 1))
```

## Without a schema

`g.sys.db.gen.getByIdGen` takes the same arguments and calls the [get by id generated API](https://docs.apimaker.dev/v4/docs/apis-all/schema-apis/auto-generated-schema-based-get-by-id-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.getByIdGen(…)` |
| Python | `g.sys.db.gen.get_by_id_gen(…)` |
| PHP | `$g->sys->db->gen->getByIdGen(…)` |
| C#, Go | `g.Sys.Db.Gen.GetByIdGen(…)` |
| Rust | `g.sys.db.get_by_id_gen(GetById::new(…))` |
| Java, Kotlin | `g.sys.db.gen.getByIdGen(…)` |

## Related

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