Skip to content
This page View Markdown Open in ChatGPT Open in Claude

Get by id

g.sys.db.getById calls the get by id schema API of any table from your code, with the same headers and query parameters as over HTTP. It returns the data, or the whole envelope when true is passed as the second argument.

Get by id

Get by id from table
1
2
3
4
let getById = await g.sys.db.getById({
    instance: "mysql_8", database: "inventory", collection: "customers",
    id: 2
});

With [primaryKey] override

Get by id with primary key override
1
2
3
4
5
let getById= await g.sys.db.getById({
    instance: "mysql_8", database: "inventory", collection: "customers",
    id: "NICK",
    primaryKey:"first_name",
});

With header

Get by id with header
1
2
3
4
5
6
7
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
    },
});

Structure

Get by id with all params
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-secret": "PROVIDE_SECRET_ID",
        "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",
    },
});

Multi-tenant

  • instance: "crm::acme" works on the database of the tenant acme of the multi-tenant 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 header passes it on to the APIs it calls. A request without a tenant works on the structure database.
Get the customer 1 of the tenant acme
1
2
3
4
let getById = await g.sys.db.getById({
    instance: "crm::acme", database: "crm", collection: "customers",
    id: 1
});