Custom types: MariaDB UUID & INET6 #3582
Replies: 1 comment 1 reply
-
This implementation looks correct.
That's by design. The sql type is used as compile time marker of the actual SQL type of expressions in the DSL, the rust type is used for loading/binding values. Strictly speaking there is no 1:1 mapping between these types, but a n:m mapping. One SQL type could be represented by several rust side types (see the timestamp types for example). One rust side type could be represented by several SQL side types (again see the timestamp types for examples.)
That's a language level restriction. It's called orphan rule and it's there to ensure that there exists exactly one possible trait impl. These rules are required to enforce that. |
Beta Was this translation helpful? Give feedback.
-
At long last, I think I have a working implementation for the MariaDB UUID and INET6 types, which aren't present in MySql.
What confused me for a bit was that you need two types: one that is the database's representation (derives
SqlType
andQueryId
to actually select it), and one that is the user-facing representation (derivesFromSqlRow
,AsExpression
). Because you can't implement these traits on foreign types likeUuid
andIpv6Addr
, you need a wrapper which can deref to those types.Still not 100% on this implementation so I'll take feedback if anyone has any suggestions.
Beta Was this translation helpful? Give feedback.
All reactions