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

Pg::hstore - Perl extension for encoding/decoding postgresql's hstore data type.

Bugs

       None known.  Feel free to clone/contribue from https://bitbucket.org/PSIAlt/p5-pg-hstore

Description

decode(string)
       Decode given HSTORE value. NULL values will be converted to Perl undef; NULL or empty keys will be
       ignored.  Returns hash ref with key => value pairs. Can return undef on internal error.  Keys and values
       will have same UTF8 flag as incoming string.

   encode(hashref)
       Encodes given hash ref to HSTORE-format string. undef values will be converted to NULL. Empty or undef
       keys will be ignored.  Returns hstore-serialized string. Can return undef on internal error.  String will
       have UTF8 flag ON if any of hashref values have it.

Export

       None by default.  Can export hstore_encode and hstore_decode subs:

        use Pg::hstore qw/hstore_encode hstore_decode/;

Name

       Pg::hstore - Perl extension for encoding/decoding postgresql's hstore data type.

Synopsis

         use Pg::hstore;
         ...
         my $row = $sth->fetchrow_hashref;   #Getting row from DB
         print "hstore data: ", $row->{addinfo}, "\n";
         my $addinfo = Pg::hstore::decode($row->{addinfo});   #Decoding into perl hashref

         #now $addinfo is 1-level hash ref with key->value
         print "addinfo->'full_name' = ", $addinfo->{full_name}, "\n";

         ...
         #Updating hstore. This type of updating can wipe other process work on addinfo field
         $addinfo->{full_name} = "John the ripper";
         $dbh->do("update users set addinfo=? where id=?", undef,
            Pg::hstore::encode($addinfo), 123);

See Also