Scot
Scot

Reputation: 1

Native SQL in StrongLoop Loopback Server

I have a situation where the model in the database does not match the model in the API. Specifically, my products' API contains contract price, which is in a separate table, and that table has price specific to each customer/product combination.

Outside of StrongLoop, I would typically solve this with custom/native SQL, but I read in the documentation that such is ill advised in StrongLoop. I have other situations like this where the database model does not efficiently represent the API model, typically due to legacy data definitions in the databases.

  1. Should I go down the path of custom/native SQL anyway?
  2. If so, are there examples and/or best practices I should follow?
  3. If not, what other ways should I solve the problem?

Upvotes: 0

Views: 1790

Answers (1)

JSimonsen
JSimonsen

Reputation: 2692

It is possible to run a native SQL query in your case, which would work for your issue. However, not the warning on the documentation page for the Native SQL docs here

This feature has not been fully tested and is not officially supported: the API may change in future releases. In general, it is always better to perform database actions through connected models. Directly executing SQL may lead to unexpected results, corrupted data, and other issues.

You can also find an example of a similar situation in a previous question asked here:

Execute raw query on MySQL Loopback Connector

Upvotes: 1

Related Questions