Code examples
/
Database APIs (g.sys.db)
Get by id
The code in every language
Each example is the inside of main, written in every language 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 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 Python PHP C# Go Rust Java Kotlin
Get by id from table let getById = await g . sys . db . getById ({
instance : "mysql_8" , database : "inventory" , collection : "customers" ,
id : 2
});
Get by id from table get_by_id = await g . sys . db . get_by_id (
'mysql_8' , 'inventory' , 'customers' ,
2 ,
)
Get by id from table $getById = $g->sys->db->getById(
'mysql_8', 'inventory', 'customers',
2,
);
Get by id from table var getById = await g . Sys . Db . GetById ( new GetById ( "mysql_8" , "inventory" , "customers" , 2 ));
Get by id from table getById , err := g . Sys . Db . GetById ( am . GetById {
Instance : "mysql_8" , Database : "inventory" , Collection : "customers" ,
Id : 2 ,
})
if err != nil {
return nil , err
}
Get by id from table let get_by_id = g . sys . db . get_by_id ( GetById :: new ( "mysql_8" , "inventory" , "customers" , json ! ( 2 ))) ? ;
Get by id from table var getById = g . sys . db . getById ( new GetById ( "mysql_8" , "inventory" , "customers" , 2 ));
Get by id from table val getById = g . sys . db . getById ( GetById ( "mysql_8" , "inventory" , "customers" , 2 ))
With [primaryKey] override
TypeScript Python PHP C# Go Rust Java Kotlin
Get by id with primary key override let getById = await g . sys . db . getById ({
instance : "mysql_8" , database : "inventory" , collection : "customers" ,
id : "NICK" ,
primaryKey : "first_name" ,
});
Get by id with primary key override get_by_id = await g . sys . db . get_by_id (
'mysql_8' , 'inventory' , 'customers' ,
'NICK' ,
primary_key = 'first_name' ,
)
Get by id with primary key override $getById = $g->sys->db->getById(
'mysql_8', 'inventory', 'customers',
'NICK',
primaryKey: 'first_name',
);
Get by id with primary key override var getById = await g . Sys . Db . GetById ( new GetById ( "mysql_8" , "inventory" , "customers" , "NICK" )
{
PrimaryKey = "first_name" ,
});
Get by id with primary key override 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
}
Get by id with primary key override let get_by_id = g . sys . db . get_by_id (
GetById :: new ( "mysql_8" , "inventory" , "customers" , "NICK" )
. primary_key ( "first_name" ),
) ? ;
Get by id with primary key override var getById = g . sys . db . getById ( new GetById ( "mysql_8" , "inventory" , "customers" , "NICK" )
. primaryKey ( "first_name" ));
Get by id with primary key override val getById = g . sys . db . getById (
GetById ( "mysql_8" , "inventory" , "customers" , "NICK" )
. primaryKey ( "first_name" ),
)
TypeScript Python PHP C# Go Rust Java Kotlin
Get by id with header 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
},
});
Get by id with header 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
},
)
Get by id with header $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
],
);
Get by id with header 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
},
});
Get by id with header 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
}
Get by id with header 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
})),
) ? ;
Get by id with header 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
)));
Get by id with header 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 Python PHP C# Go Rust Java Kotlin
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-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" ,
},
});
Get by id with all params 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' ,
},
)
Get by id with all params $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',
],
);
Get by id with all params 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" ,
},
});
Get by id with all params 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
}
Get by id with all params 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" ,
})),
) ? ;
Get by id with all params 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"
)));
Get by id with all params 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 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.
TypeScript Python PHP C# Go Rust Java Kotlin
Get the customer 1 of the tenant acme let getById = await g . sys . db . getById ({
instance : "crm::acme" , database : "crm" , collection : "customers" ,
id : 1
});
Get the customer 1 of the tenant acme get_by_id = await g . sys . db . get_by_id (
'crm::acme' , 'crm' , 'customers' ,
1 ,
)
Get the customer 1 of the tenant acme $getById = $g->sys->db->getById(
'crm::acme', 'crm', 'customers',
1,
);
Get the customer 1 of the tenant acme var getById = await g . Sys . Db . GetById ( new GetById ( "crm::acme" , "crm" , "customers" , 1 ));
Get the customer 1 of the tenant acme getById , err := g . Sys . Db . GetById ( am . GetById {
Instance : "crm::acme" , Database : "crm" , Collection : "customers" ,
Id : 1 ,
})
if err != nil {
return nil , err
}
Get the customer 1 of the tenant acme let get_by_id = g . sys . db . get_by_id ( GetById :: new ( "crm::acme" , "crm" , "customers" , json ! ( 1 ))) ? ;
Get the customer 1 of the tenant acme var getById = g . sys . db . getById ( new GetById ( "crm::acme" , "crm" , "customers" , 1 ));
Get the customer 1 of the tenant acme 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 : 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(…)