You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently developing a Rails application using MySQL with Binary + ULID for managing IDs. I would like to manage the tables required by rodauth in the same manner, using Binary + ULID for the table IDs.
Problem
In rodauth, the design assumes that the account_id is the same for both reading and writing operations. This assumption is not suitable for cases where a conversion is desired between reads and writes, such as with Binary types. Using Binary as the ID directly leads to errors in transformations, such as when generating JWTs.
Suggestion
In Rails, it is possible to declare a custom type using ActiveRecord::Type and alter the processing for reads and writes from the database, as shown below:
classULIDType < ActiveRecord::Type::Binary# Convert value before writing to the database (here, the value is returned as is because no conversion is necessary)defcast(value)valueend# Convert the database read value to a Ruby objectdefdeserialize(value)raw_value=super(value)# Retrieve the binary data from the databasereturnifraw_value.nil?Utils::Ulid.binary_to_ulid_string(raw_value.to_s)end# Convert the Ruby object to a format that can be saved in the databasedefserialize(value)returnifvalue.nil?raw_value=Utils::Ulid.string_to_ulid_byte(value)super(raw_value)endendActiveRecord::Type.register(:ulid,ULIDType)
If rodauth could declare its own type in a similar way and allow users to customize it, I believe it could become even more popular. Should this feature be added to rodauth, or more appropriately, to Sequel? What are your thoughts on this proposal?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Background
I am currently developing a Rails application using MySQL with Binary + ULID for managing IDs. I would like to manage the tables required by rodauth in the same manner, using Binary + ULID for the table IDs.
Problem
In rodauth, the design assumes that the
account_id
is the same for both reading and writing operations. This assumption is not suitable for cases where a conversion is desired between reads and writes, such as with Binary types. Using Binary as the ID directly leads to errors in transformations, such as when generating JWTs.Suggestion
In Rails, it is possible to declare a custom type using
ActiveRecord::Type
and alter the processing for reads and writes from the database, as shown below:If rodauth could declare its own type in a similar way and allow users to customize it, I believe it could become even more popular. Should this feature be added to rodauth, or more appropriately, to Sequel? What are your thoughts on this proposal?
Beta Was this translation helpful? Give feedback.
All reactions