Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

store JSON/YAML in a column and have it deflate/inflate automatically?

0
10 Posted

store JSON/YAML in a column and have it deflate/inflate automatically?

0

You can use DBIx::Class::InflateColumn to accomplish YAML/JSON storage transparently. If you want to use JSON, then in your table schema class, do the following: use JSON; __PACKAGE__->add_columns(qw/ … my_column ../) __PACKAGE__->inflate_column(‘my_column’, { inflate => sub { jsonToObj(shift) }, deflate => sub { objToJson(shift) }, }); For YAML, in your table schema class, do the following: use YAML; __PACKAGE__->add_columns(qw/ … my_column ../) __PACKAGE__->inflate_column(‘my_column’, { inflate => sub { YAML::Load(shift) }, deflate => sub { YAML::Dump(shift) }, }); This technique is an easy way to store supplemental unstructured data in a table. 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.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.