loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.95k stars 1.07k forks source link

how to execute native SQL queries in loopback4? I need to do a inner join between to tables #4869

Closed dip-sinha closed 4 years ago

dip-sinha commented 4 years ago
achrinza commented 4 years ago

[RepositoryNameHere].execute() is the command to write native SQL queries.

Rojasivalingam commented 4 years ago

can anyone explain how to connect native sql in loopback 4

hacksparrow commented 4 years ago

@Rojasivalingam use Repository.execute() eg:

userRepository.execute(
    'SELECT * from User WHERE name=? && id=?',
    ['Apple', 3]
);

The returned object is the the result object of https://www.npmjs.com/package/mysql, you will have to process it on your own.

Rojasivalingam commented 4 years ago

Actually , I wants to know about the execution of the query in detail . I'm new to loopback so any help is appreciated

On Wed, Oct 7, 2020 at 7:29 PM Hage Yaapa notifications@github.com wrote:

@Rojasivalingam https://github.com/Rojasivalingam use Repository.execute() eg:

userRepository.execute( 'SELECT * from User WHERE name=? && id=?', ['Apple', 3]);

The returned object is the the result object of https://www.npmjs.com/package/mysql, you will have to process it on your own.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/strongloop/loopback-next/issues/4869#issuecomment-704955756, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQYR57TBA23Y5OYJK27HHS3SJRX5TANCNFSM4LGLMYWQ .

hacksparrow commented 4 years ago

Create a LoopBack project using the lb4 command, you can access the repository in the controller, where you can specify the SQL command as I have shown. Start here.

Rojasivalingam commented 4 years ago

yeah...!! Thanks anyways

On Thu, Oct 8, 2020 at 3:33 PM Hage Yaapa notifications@github.com wrote:

Create a LoopBack project using the lb4 command, you can access the repository in the controller, where you can specify the SQL command as I have shown. Start here https://loopback.io/doc/en/lb4/Getting-started.html.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/strongloop/loopback-next/issues/4869#issuecomment-705467801, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQYR57UMXEA5HBUAUIJX26TSJWFA5ANCNFSM4LGLMYWQ .

bajtos commented 4 years ago

See also https://loopback.io/doc/en/lb4/Executing-database-commands.html