-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use async/await in native sql #4227
Comments
You may wrap it in your own promise function if you don't find corresponding doc for your datasource |
Can you set an example? |
You may try this. Don't forget to replace the query function with your database |
As @sujeshthekkepatt wrote: const result = await new Promise((resolve, reject) => {
dataSource.connector.execute(sqlStatement, params, options, (err, result) => {
if (err) reject(err);
else resolve(result);
});
}); You may want to write a small helper function: // usage
const result = await executeAsync(dataSource, sqlStatement, params, options);
// implementation
function executeAsync(dataSource, sqlStatement, params, options) {
return new Promise((resolve, reject) => {
dataSource.connector.execute(sqlStatement, params, options, (err, result) => {
if (err) reject(err);
else resolve(result);
});
});
} FWIW: For LoopBack 4, we added const result = await dataSource.execute(sqlStatement, params, options); |
How can i use native sql with async/await:
https://loopback.io/doc/en/lb3/Executing-native-SQL.html
Thanks
The text was updated successfully, but these errors were encountered: