Code examples
/
Generated APIs (g.sys.db.gen)
Update by id
g.sys.db.gen.updateByIdGen calls the update by id generated API from your code : no schema, the data as it is in the table.
Structure
Update by id let updateById = await g . sys . db . gen . updateByIdGen ({
instance : "INSTANCE_NAME" , database : 'DB_NAME' , collection : "COLLECTION_NAME" ,
id : 1008 ,
primaryKey : "id" ,
updateData : {
"first_name" : "Tanmay" ,
"last_name" : "Samay"
},
returnOriginal : true ,
select : "COLUMN_NAMES" ,
upsert : false
});
Simple updateById
Update By Id let updateById = await g . sys . db . gen . updateByIdGen ({
instance : "mysql_8" ,
database : "inventory" ,
collection : "customers" ,
id : 1 ,
updateData : {
"first_name" : "MALLORY"
}
});
updateById primaryKey override
Update By Id primarykey override let updateById = await g . sys . db . gen . updateByIdGen ({
instance : "mysql_8" ,
database : "inventory" ,
collection : "customers" ,
id : "Alice" ,
primaryKey : "first_name" ,
updateData : {
"first_name" : "MALLORY"
}
});
updateById [select]
Update By Id with select let updateById = await g . sys . db . gen . updateByIdGen ({
instance : "mysql_8" ,
database : "inventory" ,
collection : "customers" ,
id : "Alice" ,
primaryKey : "first_name" ,
updateData : {
"first_name" : "MALLORY"
},
select : "first_name,last_name"
});
Update By Id with select let updateById = await g . sys . db . gen . updateByIdGen ({
instance : "mysql_8" ,
database : "inventory" ,
collection : "customers" ,
id : "Alice" ,
primaryKey : "first_name" ,
updateData : {
"first_name" : "MALLORY"
},
select : "first_name,last_name" ,
headers : {
"x-am-response-case" : "capitalCase"
}
});
updateById [upsert]
Update By Id with upsert let updateById = await g . sys . db . gen . updateByIdGen ({
instance : "mysql_8" ,
database : "inventory" ,
collection : "customers" ,
id : "Alice" ,
primaryKey : "first_name" ,
updateData : {
"first_name" : "MALLORY"
},
select : "first_name,last_name" ,
headers : {
"x-am-response-case" : "capitalCase"
},
upsert : true
});
updateById [returnDocument]
Update By Id with upsert let updateById = await g . sys . db . gen . updateByIdGen ({
instance : "mysql_8" ,
database : "inventory" ,
collection : "customers" ,
id : "Alice" ,
primaryKey : "first_name" ,
updateData : {
"first_name" : "MALLORY"
},
select : "first_name,last_name" ,
headers : {
"x-am-response-case" : "capitalCase"
},
returnDocument : true
});
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.
Update the customer 1 of the tenant acme let updateById = await g . sys . db . gen . updateByIdGen ({
instance : "crm::acme" , database : "crm" , collection : "customers" ,
id : 1 ,
updateData : {
"first_name" : "MALLORY"
}
});