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

Add crossJoin, innerJoin, leftJoin, rightJoin and fullJoin. #32

Closed
5 of 7 tasks
mahdiaslami opened this issue Mar 4, 2022 · 3 comments · Fixed by #39 or #40
Closed
5 of 7 tasks

Add crossJoin, innerJoin, leftJoin, rightJoin and fullJoin. #32

mahdiaslami opened this issue Mar 4, 2022 · 3 comments · Fixed by #39 or #40
Assignees

Comments

@mahdiaslami
Copy link
Owner

mahdiaslami commented Mar 4, 2022

  • Cross Join
  • Inner Join: Add join().
  • Add innerJoin() helper.
  • Left Outer Join: Add leftJoin().
  • Right Outer Join: Add rightJoin().
  • Full Join: Add fullJoin().
  • Resolve all todos.
@mahdiaslami mahdiaslami self-assigned this Jun 2, 2022
@mahdiaslami
Copy link
Owner Author

Cross join added before.

@mahdiaslami
Copy link
Owner Author

Problem

  • What should we do to prevent overwriting properties?
  • How should we compare two columns with the same name?

1. Force using an alias in join.

query(childs)
    .join(parents, 'p')
        .on('parent_id').col.equal('p.id')
    .get()

And result is like:

const r = {
    id: 1,
    name: 'foo',
    /* [[OTHER CHILD PROPS]] */

    p: {
        id: 2,
        name: 'bar',
        /* [[OTHER PARENT PROPS]] */
    }
}

2. Force using an alias for join and query when using join.

query(childs, 'c')
    .join(parents, 'p')
        .on('c.parent_id').col.equal('p.id')
    .get()

And result is like:

const r = {
    c: {
        id: 1,
        name: 'foo',
        /* [[OTHER CHILD PROPS]] */
    },
    
    p: {
        id: 2,
        name: 'bar',
        /* [[OTHER PARENT PROPS]] */
    }
}

3. Implement both ways 1 and 2, And make them optional.

  • If a developer does not provide both aliases, overwrite columns with the same name.
  • When the column name in the on() method is the same as the column name in the on().col.<condition>() method then the first column always belongs to the main array. and the second column always belongs to the joined array.

@mahdiaslami mahdiaslami linked a pull request Jun 4, 2022 that will close this issue
@mahdiaslami mahdiaslami reopened this Jun 4, 2022
@mahdiaslami mahdiaslami linked a pull request Jun 5, 2022 that will close this issue
@mahdiaslami mahdiaslami reopened this Jun 5, 2022
@mahdiaslami
Copy link
Owner Author

mahdiaslami commented Jun 20, 2022

I think this issue is too big and I must separate it into smaller issues that will handle in one sprint.

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

Successfully merging a pull request may close this issue.

1 participant