Skip to content
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

How to do customize query in loopback 4? #3798

Closed
1057437122 opened this issue Sep 24, 2019 · 5 comments
Closed

How to do customize query in loopback 4? #3798

1057437122 opened this issue Sep 24, 2019 · 5 comments
Assignees

Comments

@1057437122
Copy link

Hello , what i want to do is to query like this ' select a.id,b.name,c.size from a left join b on a.id=b.aid left join c on b.id=c.bid where a.id=xxxx';
if I use PHP laravel i can do with model like this 'A::query()->select('a.id','b.name','c.size')->leftJoin('b','a.id','=','b.aid')->leftJoin(c,'c.bid','=','b.id')->where('a.id','xxx')->get()
I didn't find any documents about this type query in loopback.

@1057437122 1057437122 changed the title How to do self designed query in loopback 4? How to do customize query in loopback 4? Sep 24, 2019
@dhmlau dhmlau transferred this issue from strongloop/loopback Sep 24, 2019
@dhmlau
Copy link
Member

dhmlau commented Sep 24, 2019

Transferring to loopback-next repo since this is for LB4.

@1057437122
Copy link
Author

so ? This is not supported in lb4 ?

@dhmlau
Copy link
Member

dhmlau commented Sep 25, 2019

@1057437122, the GitHub issue was originally created in loopback repo where it should be in loopback-next repo since this is related to LB4. That's why I transferred it to the right repo.

Regarding your question, there's some relevant code snippet mentioned in: #3459 (comment). Could you please give it a try?
Here is the API docs link:

@dhmlau dhmlau self-assigned this Sep 25, 2019
@1057437122
Copy link
Author

@1057437122, the GitHub issue was originally created in loopback repo where it should be in loopback-next repo since this is related to LB4. That's why I transferred it to the right repo.

Regarding your question, there's some relevant code snippet mentioned in: #3459 (comment). Could you please give it a try?
Here is the API docs link:

OK, thanks for the reply , I'll try

@dhmlau
Copy link
Member

dhmlau commented Sep 25, 2019

@1057437122, inspired by the example from #3459 (comment). I've added one more endpoint / function in the controller so that it's easier to test.

  @get('/test', {
    responses: {
      '200': {
        description: 'test for executing query',
      },
    },
  })
  async test(): Promise<any> {
    return this.customerRepository.dataSource.execute('SELECT * FROM CUSTOMER');
  }

Please note that the command you put as the parameter are specific to the database you're calling. I'm using Postgresql, but the above example is simple enough that is probably working for other relational database.

Hope it helps!

With that, I'd like close this issue for this question. If you encounter other issues, feel free to open a new issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants