Warning: In general, it is always better to perform
database actions through
Repository methods. Directly executing native database
commands may lead to unexpected results and other issues.
When you project outgrows built-in
Repository methods, you can execute native
database commands to implement more complex data queries and manipulations, for
example execute a custom SQL query or invoke a MongoDB command.
LoopBack provides two APIs:
Both methods offer the same set of signatures, the implementation in Repository is just a thin wrapper delegating the task to DataSource.
const result = await repository.execute('SELECT * FROM Products');
See API docs for parameter reference, additional information and examples:
Each connector implements a slightly
different flavor of
execute() to match the capabilities supported by the
database engine. Please refer to connector documentation to learn more about
the expected parameters and command/query syntax to use.
Not all connectors support execution of native database commands. Check your
connector’s documentation to learn more. The following connectors are known to