Add initial support for composite primary keys #417
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request allows the
table!
macro and codegen to handle tableswhich use more than one column for their primary key. At the moment they
are fairly useless, but they will compile.
The methods in question are primarily used for
FindDsl
andassociations. Things like update are defined in terms of
FindDsl
andIdentifiable
. Since the generators for those traits don't handlecomposite primary keys, none of that can be used (yet).
Working on this also made me realize a bit of a hole in our type system.
We implement
Expression
for a tuple of expressions as a commadelimited list. However, a comma delimited list isn't always valid. In
particular a composite table does actually implement
FindDsl
for anexpression that matches it's primary key -- and would generate invalid
SQL like
pk1, pk2 = $1, $2
. Luckily, we're saved by the fact thattuples don't implement
AsExpression
, so trying to do.find((1, 2))
won't compile.
I'm not sure if we should fix this or not, but the fix would basically
mean separating out "arbitrary expression" from "expression valid as a
select or returning clause", and potentially other places where tuples
appear such as set clauses and in expressions. For now though, as long
as the inproper code doesn't compile for the reasonable cases, I'm not
super worried. We should fix this eventually though, as I don't like
something that we can statically determine is invalid SQL compiling.
Ref #42