Code examples
/
Database APIs (g.sys.db)
Distinct
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.distinct calls the distinct 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).
Simple distinct
TypeScript Python PHP C# Go Rust Java Kotlin
Simple distinct let distinct = await g . sys . db . distinct ({
instance : "mysql_8" , database : "inventory" , collection : "customers" ,
distinctField : "first_name"
});
Simple distinct distinct = await g . sys . db . distinct (
'mysql_8' , 'inventory' , 'customers' ,
'first_name' ,
)
Simple distinct $distinct = $g->sys->db->distinct(
'mysql_8', 'inventory', 'customers',
'first_name',
);
Simple distinct var distinct = await g . Sys . Db . Distinct ( new Distinct ( "mysql_8" , "inventory" , "customers" , "first_name" ));
Simple distinct distinct , err := g . Sys . Db . Distinct ( am . Distinct {
Instance : "mysql_8" , Database : "inventory" , Collection : "customers" ,
DistinctField : "first_name" ,
})
if err != nil {
return nil , err
}
Simple distinct let distinct = g . sys . db . distinct ( Distinct :: new ( "mysql_8" , "inventory" , "customers" , "first_name" )) ? ;
Simple distinct var distinct = g . sys . db . distinct ( new Distinct ( "mysql_8" , "inventory" , "customers" , "first_name" ));
Simple distinct val distinct = g . sys . db . distinct ( Distinct ( "mysql_8" , "inventory" , "customers" , "first_name" ))
TypeScript Python PHP C# Go Rust Java Kotlin
distinct with header let distinct = await g . sys . db . distinct ({
instance : "mysql_8" , database : "inventory" , collection : "customers" ,
distinctField : "first_name" ,
headers : {
"x-am-response-case" : "capitalCase" , // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
},
});
distinct with header distinct = await g . sys . db . distinct (
'mysql_8' , 'inventory' , 'customers' ,
'first_name' ,
headers = {
'x-am-response-case' : 'capitalCase' , # noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
},
)
distinct with header $distinct = $g->sys->db->distinct(
'mysql_8', 'inventory', 'customers',
'first_name',
headers: [
'x-am-response-case' => 'capitalCase', // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
],
);
distinct with header var distinct = await g . Sys . Db . Distinct ( new Distinct ( "mysql_8" , "inventory" , "customers" , "first_name" )
{
Headers = new JsonObject
{
["x-am-response-case"] = "capitalCase" , // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
},
});
distinct with header distinct , err := g . Sys . Db . Distinct ( am . Distinct {
Instance : "mysql_8" , Database : "inventory" , Collection : "customers" ,
DistinctField : "first_name" ,
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
}
distinct with header let distinct = g . sys . db . distinct (
Distinct :: new ( "mysql_8" , "inventory" , "customers" , "first_name" )
. headers ( json ! ({
"x-am-response-case" : "capitalCase" , // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
})),
) ? ;
distinct with header var distinct = g . sys . db . distinct ( new Distinct ( "mysql_8" , "inventory" , "customers" , "first_name" )
. headers ( Map . of (
"x-am-response-case" , "capitalCase" // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
)));
distinct with header val distinct = g . sys . db . distinct (
Distinct ( "mysql_8" , "inventory" , "customers" , "first_name" )
. headers ( mapOf (
"x-am-response-case" to "capitalCase" , // noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
)),
)
distinct with order
ascending
TypeScript Python PHP C# Go Rust Java Kotlin
distinct with order let distinct = await g . sys . db . distinct ({
instance : "mysql_8" , database : "inventory" , collection : "customers" ,
distinctField : "first_name" ,
order : "asc"
});
distinct with order distinct = await g . sys . db . distinct (
'mysql_8' , 'inventory' , 'customers' ,
'first_name' ,
order = 'asc' ,
)
distinct with order $distinct = $g->sys->db->distinct(
'mysql_8', 'inventory', 'customers',
'first_name',
order: 'asc',
);
distinct with order var distinct = await g . Sys . Db . Distinct ( new Distinct ( "mysql_8" , "inventory" , "customers" , "first_name" )
{
Order = "asc" ,
});
distinct with order distinct , err := g . Sys . Db . Distinct ( am . Distinct {
Instance : "mysql_8" , Database : "inventory" , Collection : "customers" ,
DistinctField : "first_name" ,
Order : "asc" ,
})
if err != nil {
return nil , err
}
distinct with order let distinct = g . sys . db . distinct (
Distinct :: new ( "mysql_8" , "inventory" , "customers" , "first_name" )
. order ( "asc" ),
) ? ;
distinct with order var distinct = g . sys . db . distinct ( new Distinct ( "mysql_8" , "inventory" , "customers" , "first_name" )
. order ( "asc" ));
distinct with order val distinct = g . sys . db . distinct (
Distinct ( "mysql_8" , "inventory" , "customers" , "first_name" )
. order ( "asc" ),
)
descending
TypeScript Python PHP C# Go Rust Java Kotlin
distinct with header let distinct = await g . sys . db . distinct ({
instance : "mysql_8" , database : "inventory" , collection : "customers" ,
distinctField : "first_name" ,
order : "desc"
});
distinct with header distinct = await g . sys . db . distinct (
'mysql_8' , 'inventory' , 'customers' ,
'first_name' ,
order = 'desc' ,
)
distinct with header $distinct = $g->sys->db->distinct(
'mysql_8', 'inventory', 'customers',
'first_name',
order: 'desc',
);
distinct with header var distinct = await g . Sys . Db . Distinct ( new Distinct ( "mysql_8" , "inventory" , "customers" , "first_name" )
{
Order = "desc" ,
});
distinct with header distinct , err := g . Sys . Db . Distinct ( am . Distinct {
Instance : "mysql_8" , Database : "inventory" , Collection : "customers" ,
DistinctField : "first_name" ,
Order : "desc" ,
})
if err != nil {
return nil , err
}
distinct with header let distinct = g . sys . db . distinct (
Distinct :: new ( "mysql_8" , "inventory" , "customers" , "first_name" )
. order ( "desc" ),
) ? ;
distinct with header var distinct = g . sys . db . distinct ( new Distinct ( "mysql_8" , "inventory" , "customers" , "first_name" )
. order ( "desc" ));
distinct with header val distinct = g . sys . db . distinct (
Distinct ( "mysql_8" , "inventory" , "customers" , "first_name" )
. order ( "desc" ),
)
Structure
TypeScript Python PHP C# Go Rust Java Kotlin
Distinct method let distinct = await g . sys . db . distinct ({
instance : "INSTANCE_NAME" , database : 'DB_NAME' , collection : "COLLECTION_NAME" ,
distinctField : "COLUMN_NAME" ,
order : "asc" , // asc | desc
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" ,
},
});
Distinct method distinct = await g . sys . db . distinct (
'INSTANCE_NAME' , 'DB_NAME' , 'COLLECTION_NAME' ,
'COLUMN_NAME' ,
order = 'asc' , # asc | desc
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' ,
},
)
Distinct method $distinct = $g->sys->db->distinct(
'INSTANCE_NAME', 'DB_NAME', 'COLLECTION_NAME',
'COLUMN_NAME',
order: 'asc', // asc | desc
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',
],
);
Distinct method var distinct = await g . Sys . Db . Distinct ( new Distinct ( "INSTANCE_NAME" , "DB_NAME" , "COLLECTION_NAME" , "COLUMN_NAME" )
{
Order = "asc" , // asc | desc
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" ,
},
});
Distinct method distinct , err := g . Sys . Db . Distinct ( am . Distinct {
Instance : "INSTANCE_NAME" , Database : "DB_NAME" , Collection : "COLLECTION_NAME" ,
DistinctField : "COLUMN_NAME" ,
Order : "asc" , // asc | desc
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
}
Distinct method let distinct = g . sys . db . distinct (
Distinct :: new ( "INSTANCE_NAME" , "DB_NAME" , "COLLECTION_NAME" , "COLUMN_NAME" )
. order ( "asc" ) // asc | desc
. 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" ,
})),
) ? ;
Distinct method var distinct = g . sys . db . distinct ( new Distinct ( "INSTANCE_NAME" , "DB_NAME" , "COLLECTION_NAME" , "COLUMN_NAME" )
. order ( "asc" ) // asc | desc
. 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"
)));
Distinct method val distinct = g . sys . db . distinct (
Distinct ( "INSTANCE_NAME" , "DB_NAME" , "COLLECTION_NAME" , "COLUMN_NAME" )
. order ( "asc" ) // asc | desc
. 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
Distinct first names of the customers of the tenant acme let distinct = await g . sys . db . distinct ({
instance : "crm::acme" , database : "crm" , collection : "customers" ,
distinctField : "first_name"
});
Distinct first names of the customers of the tenant acme distinct = await g . sys . db . distinct (
'crm::acme' , 'crm' , 'customers' ,
'first_name' ,
)
Distinct first names of the customers of the tenant acme $distinct = $g->sys->db->distinct(
'crm::acme', 'crm', 'customers',
'first_name',
);
Distinct first names of the customers of the tenant acme var distinct = await g . Sys . Db . Distinct ( new Distinct ( "crm::acme" , "crm" , "customers" , "first_name" ));
Distinct first names of the customers of the tenant acme distinct , err := g . Sys . Db . Distinct ( am . Distinct {
Instance : "crm::acme" , Database : "crm" , Collection : "customers" ,
DistinctField : "first_name" ,
})
if err != nil {
return nil , err
}
Distinct first names of the customers of the tenant acme let distinct = g . sys . db . distinct ( Distinct :: new ( "crm::acme" , "crm" , "customers" , "first_name" )) ? ;
Distinct first names of the customers of the tenant acme var distinct = g . sys . db . distinct ( new Distinct ( "crm::acme" , "crm" , "customers" , "first_name" ));
Distinct first names of the customers of the tenant acme val distinct = g . sys . db . distinct ( Distinct ( "crm::acme" , "crm" , "customers" , "first_name" ))
Without a schema
g.sys.db.gen.distinctGen takes the same arguments and calls the distinct 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.distinctGen(…)
Python
g.sys.db.gen.distinct_gen(…)
PHP
$g->sys->db->gen->distinctGen(…)
C#, Go
g.Sys.Db.Gen.DistinctGen(…)
Rust
g.sys.db.distinct_gen(Distinct::new(…))
Java, Kotlin
g.sys.db.gen.distinctGen(…)