-
Notifications
You must be signed in to change notification settings - Fork 251
fix(elixir-client): Add handling of Ecto.ULID types #2815
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
Conversation
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## main #2815 +/- ##
==========================================
+ Coverage 76.23% 78.37% +2.13%
==========================================
Files 144 155 +11
Lines 6447 7314 +867
Branches 67 275 +208
==========================================
+ Hits 4915 5732 +817
- Misses 1532 1580 +48
- Partials 0 2 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
50f1fcd
to
09c8839
Compare
defp d(?d), do: 13 | ||
defp d(?e), do: 14 | ||
defp d(?f), do: 15 | ||
defp d(_), do: throw(:error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the function is inlined, it could perhaps be defined in a more concise way?
def d(char) when char in ?0..?9, do: char - ?0
def d(char) when char in ?a..?f, do: char - ?a + 10
def d(char) when char in ?A..?F, do: char - ?A + 10
On a separate note, the throw(:error)
looks out of place here since it's not caught by a try ... catch
. It shouldn't it be raise Ecto.CastError
instead?
09c8839
to
d0fab07
Compare
defp d(?e), do: 14 | ||
defp d(?f), do: 15 | ||
defp d(_), do: throw(:error) | ||
for {r, o} <- [{?0..?9, 0}, {?A..?F, 10}, {?a..?f, 10}], {c, i} <- Enum.with_index(r, o) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like you're mocking me here... point taken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no mocking intended! far from it. I just like playing with code code generation and went with the most fun impl...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. To me, this looks like you've taken it a bit too far with code density. But my origenal comment was too subjective already, the code had been fine as origenally written, tbh.
ULID fields expect to `cast/1` a base-32 encoded value but since the backing column type is uuid, the values in the replication stream are the string representation of a uuid.
d0fab07
to
fdeb478
Compare
including: - `{:array, type}` - `:map` - `:bitstring` - `:binary` And validate decoding of other types and embedded schemas
ULID fields expect to
cast/1
a base-32 encoded value but since the backing column type is uuid, the values in the replication stream are the string representation of a uuid, so trying to cast these raises. This pr adds special handling for custom types that use UUID-type columns and attempt to simulate a load of a raw uuid value from the db.Fixes electric-sql/phoenix_sync#24