I am writing javascript first time. within the azure function app I have one async function to insert data using query see function code as below
async function insertData(query) {
var connection = new Connection(config);
var result = 'Connecting'
await connection.on('connect', function (err) {
if (err) {
console.log('Connect: ' + err);
result = 'Connect: ' + err;
} else {
request = new Request(query + "; select @@identity", function (err, rowCount) {
if (err) {
console.log('Insert: ' + err);
result = 'Insert: ' + err;
} else {
console.log('Insert complete.');
result = 'Insert complete';
}
connection.close();
});
connection.execSql(request);
}
});
return result;
};
and I am calling this fuction from main triggerd function like this
var result = insertData(query); // calling function from here
context.log('Result ' + result); // Result [object Promise]
but it is not giving proper value of result
at log it is Result [object Promise]
it should be Insert complete
as it inserted recorted successfuly
can you please currect me? Thanks!