logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

DBIx::Class::InflateColumn::Serializer - Inflators to serialize data structures for DBIx::Class

Author

           Jose Luis Martinez
           CPAN ID: JLMARTIN
           CAPSiDE
           jlmartinez@capside.comhttp://www.pplusdomain.net

Description

       These modules help you store and access serialized data structures in the columns of your DB from your
       DBIx::Classes. They are inspired from the DBIx::Class::Manual::FAQ and the DBIC test suite, and provide a
       bit more protection than the inflators proposed in the FAQ. The intention is to provide a suite of well
       proven and reusable inflators and deflators to complement DBIx::Class.

       Added features for these inflators are:
        - throw an exception if the serialization doesn't fit in the field
        - throw an exception if the deserialization results in an error

       Right now there are three serializers:
        - Storable
        - JSON
        - YAML

Name

       DBIx::Class::InflateColumn::Serializer - Inflators to serialize data structures for DBIx::Class

Notes

       As stated in the DBIC FAQ: "Be careful not to overuse this capability, however. If you find yourself
       depending more and more on some data within the inflated column, then it may be time to factor that data
       out."

See Also

       DBIx::Class, DBIx::Class::Manual::FAQ

perl v5.34.0                                       2022-06-13             DBIx::Class::In...umn::Serializer(3pm)

Synopsis

         package MySchema::Table;
         use base 'DBIx::Class';

         __PACKAGE__->load_components('InflateColumn::Serializer', 'Core');
         __PACKAGE__->add_columns(
           'data_column' => {
             'data_type' => 'VARCHAR',
             'size'      => 255,
             'serializer_class'   => 'JSON'
           }
         );

       Then in your code...

         my $struct = { 'I' => { 'am' => 'a struct' };
         $obj->data_column($struct);
         $obj->update;

       And you can recover your data structure with:

         my $obj = ...->find(...);
         my $struct = $obj->data_column;

       The data structures you assign to "data_column" will be saved in the database in JSON format.

Thanks

       Matt S Trout for his valuable feedback

       Ask Bjorn Hansen

       Karen Etheridge

Usage

       1. Choose your serializer: JSON, YAML or Storable

       2. Add 'InflateColumn::Serializer' into the load_components of your table class

       3. add 'serializer_class' => SERIALIZER to the properties of the column that you want to (de/i)nflate
          with the SERIALIZER class.

See Also