AnyhowStep/tsql

Consider adding method similar to innerJoinUsingPrimaryKey(), but reverse direction

Opened this issue · 0 comments

innerJoinUsingPrimaryKey() is a convenience function for,

//snip
  .from(myTable)
  .innerJoin(
      otherTable,
      () => tsql.eqPrimaryKeyOfTable(
          myTable,
          otherTable
      )
  )

Using innerJoinUsingPrimaryKey(), you know that you are joining to a single row of otherTable. Because you're joining on otherTable's primary key.


It may be useful to have a function that goes the other way around,

//snip
  .from(myTable)
  .innerJoin(
      otherTable,
      () => tsql.eqPrimaryKeyOfTable(
          otherTable,
          myTable
      )
  )

This time, we could possibly be joining to one or many rows of otherTable, because we're joining on myTable's primary key. Zero, one, or many rows of otherTable may have the same value.

I have no idea what to call this convenience function yet, though.

  • innerJoinUsingSourcePrimaryKey()?
  • innerJoinUsingPrimaryKeyManyRows()?
  • innerJoinUsingPrimaryKey2()?
  • innerJoinUsingPrimaryKeyReverse()?

No clue.


leftJoin and candidateKey joins should also have this "reverse" function.

Without these functions, we have to go back to using tsql.eqPrimaryKeyOfTable().
However, it may not be so bad. In my personal experience, it is not often that I want to do the reverse. And if I do, it usually indicates suspcious code.

However, my personal experience may not be the same as everyone else's experience...