The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

HDB::Encode - Hybrid DataBase - HASH/ARRAY enconding.

DESCRIPTION

You can save HASH and ARRAY structures inside columns of a table in the database.

** The column that will receive the encoded data need to have a good size for the encoded HASH/ARRAY!

USAGE

my %HASH = (
'a' => 1 ,
'b' => 2 ,
'c' => 3 ,
'd' => { 'da' => 41 , 'db' => 42 } ,
'e' => [qw(x y z)] ,
) ;

$HDB->insert( 'users' , {
user => 'joe' ,
name => 'joe tribianny' ,
more => \%HASH ,
} ) ;

...

$HDB->insert( 'users' , {
user => 'joe' ,
name => 'joe tribianny' ,
more => { a => 1 , b => 2 } ,
} ) ;

...

my %hash = $HDB->select( 'users' , 'user == joe' , col => 'more' , '$$@' ) ; # $$@ to return directly the HASH.

METHODS

** You don't need to use this methods, HDB will make everything automatically.

Pack (\%HASH or \@ARRAY)

Encode a HASH/ARRAY. Will use Pack_HASH & Pack_ARRAY.

Pack_HASH (\%HASH)

Encode a HASH.

Pack_ARRAY (\@ARRAY)

Encode an ARRAY.

UnPack (ENCODED_HASH or ENCODED_ARRAY)

Decode a HASH/ARRAY. Will use UnPack_HASH & UnPack_ARRAY.

UnPack_HASH (ENCODED_HASH)

Decode a HASH.

UnPack_ARRAY (ENCODED_ARRAY)

Decode an ARRAY.

Is_Packed_HASH (DATA)

Check if the encoded data is a HASH.

Is_Packed_ARRAY (DATA)

Check if the encoded data is an ARRAY.

Check_Pack_Size (DATA)

Check if the encoded data is ok.

Packed_SIZE (\%HASH or \@ARRAY)

Return the size of the HASH/ARRAY encoded. This will calculate the size without generate the encoded data.

Will use Packed_SIZE_HASH & Packed_SIZE_ARRAY.

Packed_SIZE_HASH (\%HASH)

Return the size of the HASH encoded without generate it.

Packed_SIZE_ARRAY (\@ARRAY)

Return the size of the ARRAY encoded without generate it.

ENCODED DATA

The encoded HASH/ARRAY are very similar:

%HDB_PACKED_HASH%[1.0]{50}:DATA

1.0  >> Format version.
50   >> DATA size.
DATA >> The encoded data.

# For ARRAY is:
%HDB_PACKED_ARRAY%...

** The data has this begin to identify the encoded data in the database.
** The size is used to check if the data is crashed.

DATA for HASH:

02:aa4:bbbb

0    >> normal value. 1 for HASH in the value. 2 for ARRAY in the value.
2    >> size of key.
aa   >> key
4    >> size of value.  
bbbb >> value

DATA for ARRAY:

02:aa

0  >> normal value. 1 for HASH in the value. 2 for ARRAY in the value.
2  >> size of value.
aa >> value

SEE ALSO

HDB, HDB::CMDS, HDB::sqlite, HDB::mysql.

AUTHOR

Graciliano M. P. <gm@virtuasites.com.br>

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.