X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FManual%2FFAQ.pod;h=a76cccaf1c52fa573a325828038abc565b7f784f;hb=75e75a9f4b3bcd73696a575e72f8a33b985823fd;hp=540bd213c4d41a6b359b1e2c4198b1fee78390dd;hpb=d84c7d7885c9f2c04ab7f6ea095bcfd85a600a2e;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Manual/FAQ.pod b/lib/DBIx/Class/Manual/FAQ.pod index 540bd21..a76ccca 100644 --- a/lib/DBIx/Class/Manual/FAQ.pod +++ b/lib/DBIx/Class/Manual/FAQ.pod @@ -307,9 +307,11 @@ scalar reference: ->update({ somecolumn => \'othercolumn' }) -=item .. store JSON in a column and have it deflate/inflate automatically? +=item .. store JSON/YAML in a column and have it deflate/inflate automatically? -In your table schema class, do the following: +You can use L to accomplish YAML/JSON storage transparently. + +If you want to use JSON, then in your table schema class, do the following: use JSON; @@ -319,6 +321,21 @@ In your table schema class, do the following: 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. + =back =head2 Misc