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