@@ -119,6 +119,8 @@ impl std::error::Error for MagnetLinkError {
119119/// More information is specified in [BEP-0009](https://bittorrent.org/beps/bep_0009.html), and
120120/// even more appears in the wild, as explained [on Wikipedia](https://en.wikipedia.org/wiki/Magnet_URI_scheme).
121121#[ derive( Clone , Debug ) ]
122+ // #[derive(sea_orm::DeriveValueType)]
123+ // #[sea_orm(value_type = "String")]
122124pub struct MagnetLink {
123125 /// Only mandatory field for magnet link parsing, unless the
124126 /// `magnet_force_name` crate feature is enabled.
@@ -322,6 +324,70 @@ impl std::fmt::Display for MagnetLink {
322324 }
323325}
324326
327+ impl PartialEq for MagnetLink {
328+ fn eq ( & self , other : & Self ) -> bool {
329+ self . query == other. query
330+ }
331+ }
332+
333+ #[ cfg( feature = "sea_orm" ) ]
334+ impl From < MagnetLink > for sea_orm:: sea_query:: Value {
335+ fn from ( m : MagnetLink ) -> Self {
336+ Self :: String ( Some ( m. to_string ( ) ) )
337+ }
338+ }
339+
340+ #[ cfg( feature = "sea_orm" ) ]
341+ impl sea_orm:: TryGetable for MagnetLink {
342+ fn try_get_by < I : sea_orm:: ColIdx > (
343+ res : & sea_orm:: QueryResult ,
344+ index : I ,
345+ ) -> Result < Self , sea_orm:: error:: TryGetError > {
346+ let val: String = res. try_get_by ( index) ?;
347+ MagnetLink :: new ( & val) . map_err ( |e| {
348+ sea_orm:: error:: TryGetError :: DbErr ( sea_orm:: DbErr :: TryIntoErr {
349+ from : "String" ,
350+ into : "MagnetLink" ,
351+ source : std:: sync:: Arc :: new ( e) ,
352+ } )
353+ } )
354+ }
355+ }
356+
357+ #[ cfg( feature = "sea_orm" ) ]
358+ impl sea_orm:: sea_query:: ValueType for MagnetLink {
359+ fn try_from ( v : sea_orm:: Value ) -> Result < Self , sea_orm:: sea_query:: ValueTypeErr > {
360+ match v {
361+ // TODO: What to do with None String?
362+ // This should probably work with Option<MagnetLink> but not with MagnetLink
363+ // but i have no idea how sea orm works...
364+ sea_orm:: Value :: String ( Some ( s) ) => {
365+ MagnetLink :: new ( & s) . map_err ( |_e| sea_orm:: sea_query:: ValueTypeErr )
366+ }
367+ _ => Err ( sea_orm:: sea_query:: ValueTypeErr ) ,
368+ }
369+ }
370+
371+ fn type_name ( ) -> String {
372+ "MagnetLink" . to_string ( )
373+ }
374+
375+ fn array_type ( ) -> sea_orm:: sea_query:: ArrayType {
376+ sea_orm:: sea_query:: ArrayType :: String
377+ }
378+
379+ fn column_type ( ) -> sea_orm:: sea_query:: ColumnType {
380+ sea_orm:: sea_query:: ColumnType :: String ( sea_orm:: sea_query:: table:: StringLen :: None )
381+ }
382+ }
383+
384+ #[ cfg( feature = "sea_orm" ) ]
385+ impl sea_orm:: sea_query:: Nullable for MagnetLink {
386+ fn null ( ) -> sea_orm:: sea_query:: Value {
387+ sea_orm:: sea_query:: Value :: String ( None )
388+ }
389+ }
390+
325391#[ cfg( test) ]
326392mod tests {
327393 use super :: * ;
0 commit comments