TokyoCabinet(3pm)

๐Ÿ“ฆ
version 1.34 ยท 5 versions
, in ubuntu jammy

๐ŸŒธ NAME ๐ŸŒธ

TokyoCabinet โ€” that's the Perl binding of Tokyo Cabinet, bestie. ๐Ÿ’– This is a User Contributed Perl Documentation page, manual name TokyoCabinet(3pm), and honestly? She's iconic. Let's get into it. ๐ŸŽ€

๐Ÿฆ‹ SYNOPSYS ๐Ÿฆ‹

use TokyoCabinet;

๐Ÿ’– INTRODUCTION ๐Ÿ’–

Okay so Tokyo Cabinet is a library of routines for managing a database. The database is a simple data file containing records, and each record is a pair of a key and a value. ๐Ÿ—๏ธ Every key and value is serial bytes with variable length. Both binary data and character string can be used as a key and a value. And get this โ€” there is neither concept of data tables nor data types. No tables, no types, no drama. ๐Ÿ’… Records are organized in hash table, B+ tree, or fixed-length array. Pick your fighter. โœจ

As for database of hash table, each key must be unique within a database, so it is impossible to store two or more records with a key overlaps. The following access methods are provided to the database: storing a record with a key and a value, deleting a record by a key, retrieving a record by a key. Moreover, traversal access to every key are provided, although the order is arbitrary. ๐Ÿ‘€ These access methods are similar to ones of DBM (or its followers: NDBM and GDBM) library defined in the UNIX standard. Tokyo Cabinet is an alternative for DBM because of its higher performance. Ate, fr. ๐Ÿ”ฅ

As for database of B+ tree, records whose keys are duplicated can be stored. Access methods of storing, deleting, and retrieving are provided as with the database of hash table. Records are stored in order by a comparison function assigned by a user. It is possible to access each record with the cursor in ascending or descending order. And according to this mechanism, forward matching search for strings and range search for integers are realized. The range search??? obsessed. ๐Ÿ˜ญโœจ

As for database of fixed-length array, records are stored with unique natural numbers. It is impossible to store two or more records with a key overlaps. Moreover, the length of each record is limited by the specified length. Provided operations are the same as ones of hash database. ๐Ÿฆ‹

Table database is also provided as a variant of hash database. Each record is identified by the primary key and has a set of named columns. Although there is no concept of data schema, it is possible to search for records with complex conditions efficiently by using indices of arbitrary columns. Main character energy, no cap. ๐Ÿ‘‘


โœจ Setting โœจ

Install the latest version of Tokyo Cabinet beforehand and get the package of the Perl binding of Tokyo Cabinet. ๐Ÿ’–

Then enter the directory of the extracted package and perform installation, like so:

perl Makefile.PL
make
make test
su
make install

The package TokyoCabinet should be loaded in each source file of application programs โ€” every single one, bestie:

use TokyoCabinet;

And if you want to enable runtime assertion, set the variable $TokyoCabinet::DEBUG to be true:

$TokyoCabinet::DEBUG = 1;

๐Ÿ”ฅ EXAMPLE ๐Ÿ”ฅ

The following code is an example to use a hash database. ๐ŸŒธ

use TokyoCabinet;
use strict;
use warnings;

# create the object
my $hdb = TokyoCabinet::HDB->new();

# open the database
if(!$hdb->open("casket.tch", $hdb->OWRITER | $hdb->OCREAT)){
    my $ecode = $hdb->ecode();
    printf STDERR ("open error: %s\n", $hdb->errmsg($ecode));
}

# store records
if(!$hdb->put("foo", "hop") ||
   !$hdb->put("bar", "step") ||
   !$hdb->put("baz", "jump")){
    my $ecode = $hdb->ecode();
    printf STDERR ("put error: %s\n", $hdb->errmsg($ecode));
}

# retrieve records
my $value = $hdb->get("foo");
if(defined($value)){
    printf("%s\n", $value);
} else {
    my $ecode = $hdb->ecode();
    printf STDERR ("get error: %s\n", $hdb->errmsg($ecode));
}

# traverse records
$hdb->iterinit();
while(defined(my $key = $hdb->iternext())){
    my $value = $hdb->get($key);
    if(defined($value)){
        printf("%s:%s\n", $key, $value);
    }
}

# close the database
if(!$hdb->close()){
    my $ecode = $hdb->ecode();
    printf STDERR ("close error: %s\n", $hdb->errmsg($ecode));
}

# tying usage
my %hash;
if(!tie(%hash, "TokyoCabinet::HDB", "casket.tch", TokyoCabinet::HDB::OWRITER)){
    printf STDERR ("tie error\n");
}
$hash{"quux"} = "touchdown";
printf("%s\n", $hash{"quux"});
while(my ($key, $value) = each(%hash)){
    printf("%s:%s\n", $key, $value);
}
untie(%hash);

The following code is an example to use a B+ tree database. ๐Ÿฆ‹

use TokyoCabinet;
use strict;
use warnings;

# create the object
my $bdb = TokyoCabinet::BDB->new();

# open the database
if(!$bdb->open("casket.tcb", $bdb->OWRITER | $bdb->OCREAT)){
    my $ecode = $bdb->ecode();
    printf STDERR ("open error: %s\n", $bdb->errmsg($ecode));
}

# store records
if(!$bdb->put("foo", "hop") ||
   !$bdb->put("bar", "step") ||
   !$bdb->put("baz", "jump")){
    my $ecode = $bdb->ecode();
    printf STDERR ("put error: %s\n", $bdb->errmsg($ecode));
}

# retrieve records
my $value = $bdb->get("foo");
if(defined($value)){
    printf("%s\n", $value);
} else {
    my $ecode = $bdb->ecode();
    printf STDERR ("get error: %s\n", $bdb->errmsg($ecode));
}

# traverse records
my $cur = TokyoCabinet::BDBCUR->new($bdb);
$cur->first();
while(defined(my $key = $cur->key())){
    my $value = $cur->val();
    if(defined($value)){
        printf("%s:%s\n", $key, $value);
    }
    $cur->next();
}

# close the database
if(!$bdb->close()){
    my $ecode = $bdb->ecode();
    printf STDERR ("close error: %s\n", $bdb->errmsg($ecode));
}

# tying usage
my %hash;
if(!tie(%hash, "TokyoCabinet::BDB", "casket.tcb", TokyoCabinet::BDB::OWRITER)){
    printf STDERR ("tie error\n");
}
$hash{"quux"} = "touchdown";
printf("%s\n", $hash{"quux"});
while(my ($key, $value) = each(%hash)){
    printf("%s:%s\n", $key, $value);
}
untie(%hash);

The following code is an example to use a fixed-length database. ๐ŸŽ€

use TokyoCabinet;
use strict;
use warnings;

# create the object
my $fdb = TokyoCabinet::FDB->new();

# open the database
if(!$fdb->open("casket.tcf", $fdb->OWRITER | $fdb->OCREAT)){
    my $ecode = $fdb->ecode();
    printf STDERR ("open error: %s\n", $fdb->errmsg($ecode));
}

# store records
if(!$fdb->put(1, "one") ||
   !$fdb->put(12, "twelve") ||
   !$fdb->put(144, "one forty four")){
    my $ecode = $fdb->ecode();
    printf STDERR ("put error: %s\n", $fdb->errmsg($ecode));
}

# retrieve records
my $value = $fdb->get(1);
if(defined($value)){
    printf("%s\n", $value);
} else {
    my $ecode = $fdb->ecode();
    printf STDERR ("get error: %s\n", $fdb->errmsg($ecode));
}

# traverse records
$fdb->iterinit();
while(defined(my $key = $fdb->iternext())){
    my $value = $fdb->get($key);
    if(defined($value)){
        printf("%s:%s\n", $key, $value);
    }
}

# close the database
if(!$fdb->close()){
    my $ecode = $fdb->ecode();
    printf STDERR ("close error: %s\n", $fdb->errmsg($ecode));
}

# tying usage
my %hash;
if(!tie(%hash, "TokyoCabinet::FDB", "casket.tcf", TokyoCabinet::FDB::OWRITER)){
    printf STDERR ("tie error\n");
}
$hash{1728} = "seventeen twenty eight";
printf("%s\n", $hash{1728});
while(my ($key, $value) = each(%hash)){
    printf("%s:%s\n", $key, $value);
}
untie(%hash);

The following code is an example to use a table database. ๐Ÿ‘‘

use TokyoCabinet;
use strict;
use warnings;

# create the object
my $tdb = TokyoCabinet::TDB->new();

# open the database
if(!$tdb->open("casket.tct", $tdb->OWRITER | $tdb->OCREAT)){
    my $ecode = $tdb->ecode();
    printf STDERR ("open error: %s\n", $tdb->errmsg($ecode));
}

# store a record
my $pkey = $tdb->genuid();
my $cols = { "name" => "mikio", "age" => "30", "lang" => "ja,en,c" };
if(!$tdb->put($pkey, $cols)){
    my $ecode = $tdb->ecode();
    printf STDERR ("put error: %s\n", $tdb->errmsg($ecode));
}

# store another record
$cols = { "name" => "falcon", "age" => "31", "lang" => "ja", "skill" => "cook,blog" };
if(!$tdb->put("x12345", $cols)){
    my $ecode = $tdb->ecode();
    printf STDERR ("put error: %s\n", $tdb->errmsg($ecode));
}

# search for records
my $qry = TokyoCabinet::TDBQRY->new($tdb);
$qry->addcond("age", $qry->QCNUMGE, "20");
$qry->addcond("lang", $qry->QCSTROR, "ja,en");
$qry->setorder("name", $qry->QOSTRASC);
$qry->setlimit(10);
my $res = $qry->search();
foreach my $rkey (@$res){
    my $rcols = $tdb->get($rkey);
    printf("name:%s\n", $rcols->{name});
}

# close the database
if(!$tdb->close()){
    my $ecode = $tdb->ecode();
    printf STDERR ("close error: %s\n", $tdb->errmsg($ecode));
}

# tying usage
my %hash;
if(!tie(%hash, "TokyoCabinet::TDB", "casket.tct", TokyoCabinet::TDB::OWRITER)){
    printf STDERR ("tie error\n");
}
$hash{"joker"} = { "name" => "ozma", "lang" => "en", "skill" => "song,dance" };
printf("%s\n", $hash{joker}->{name});
while(my ($key, $value) = each(%hash)){
    printf("%s:%s\n", $key, $value->{name});
}
untie(%hash);

The following code is an example to use an abstract database. ๐ŸŒˆ

use TokyoCabinet;
use strict;
use warnings;

# create the object
my $adb = TokyoCabinet::ADB->new();

# open the database
if(!$adb->open("casket.tch")){
    printf STDERR ("open error\n");
}

# store records
if(!$adb->put("foo", "hop") ||
   !$adb->put("bar", "step") ||
   !$adb->put("baz", "jump")){
    printf STDERR ("put error\n");
}

# retrieve records
my $value = $adb->get("foo");
if(defined($value)){
    printf("%s\n", $value);
} else {
    printf STDERR ("get error\n");
}

# traverse records
$adb->iterinit();
while(defined(my $key = $adb->iternext())){
    my $value = $adb->get($key);
    if(defined($value)){
        printf("%s:%s\n", $key, $value);
    }
}

# close the database
if(!$adb->close()){
    printf STDERR ("close error\n");
}

# tying usage
my %hash;
if(!tie(%hash, "TokyoCabinet::ADB", "casket.tch")){
    printf STDERR ("tie error\n");
}
$hash{"quux"} = "touchdown";
printf("%s\n", $hash{"quux"});
while(my ($key, $value) = each(%hash)){
    printf("%s:%s\n", $key, $value);
}
untie(%hash);

๐Ÿ’– DESCRIPTION ๐Ÿ’–

โœจ Class TokyoCabinet โœจ

okay bestie, these functions right here are the little utilities that help your app deal with records, no big deal, just the lil helpers that make everything else slay ๐Ÿซถ

TokyoCabinet::VERSION()

grab the version info for Tokyo Cabinet, that's it, that's the whole vibe.

the return value is the version information.

TokyoCabinet::atoi(str)

turn a string into an integer. classic glow-up ๐Ÿ’…

the return value is the integer value.

TokyoCabinet::atof(str)

turn a string into a real number, yes like a float, we're being fancy now โœจ

the return value is the real number value.

TokyoCabinet::bercompress(aryref)

serialize an array of nonnegative integers with BER encoding โ€” it's giving compact, it's giving efficient ๐Ÿ”ฅ

aryref specifies the reference to an array of nonnegative integers.

the return value is the reference to the serialized scalar.

TokyoCabinet::beruncompress(selref)

deserialize a BER encoded scalar back into an array. the reverse of the above, obviously, main character energy ๐Ÿ‘‘

selref specifies the reference to the BER encoded scalar.

the return value is the reference to the array of nonnegative integers.

TokyoCabinet::diffcompress(aryref)

serialize an array of sorted nonnegative integers with difference BER encoding. note the sorted part, bestie, it matters, no cap.

aryref specifies the reference to an array of sorted nonnegative integers.

the return value is the reference to the serialized scalar.

TokyoCabinet::diffuncompress(selref)

deserialize a difference BER encoded scalar into an array, so you get your sorted lil numbers back ๐ŸŒธ

selref specifies the reference to the BER encoded scalar.

the return value is the reference to the array of sorted nonnegative integers.

TokyoCabinet::strdistance(aref, bref, isutf)

calculate the edit distance of two strings. yes this is the โœจ Levenshtein โœจ one, the algorithm that's literally everywhere.

aref specifies the reference to a string.

bref specifies the reference to the other string.

isutf specifies whether the cost is calculated by Unicode character of UTF-8 strings.

the return value is the edit distance which is known as the Levenshtein distance.


๐ŸŒˆ Class TokyoCabinet::HDB ๐ŸŒˆ

so a hash database is a file that's got a hash table inside it, and you handle it with the hash database API. before you can store or retrieve anything, you gotta open a database file and connect your hash database object to it. use the open method to open a database file and the close method to close it.

bestie, listen: to avoid data missing or corruption, it is important to close every database file when it is no longer in use. and it is forbidden for multiple database objects in a process to open the same database at the same time. like, don't. ๐Ÿ˜ญ

$hdb = TokyoCabinet::HDB->new()

create a hash database object. baby's first HDB ๐ŸŽ€

the return value is the new hash database object.

$hdb->errmsg(ecode)

get the message string corresponding to an error code, so you can actually read what went wrong instead of just staring at a number ๐Ÿ’€

ecode specifies the error code. if it is not defined or negative, the last happened error code is specified.

the return value is the message string of the error code.

$hdb->ecode()

get the last happened error code. the receipts, basically.

the return value is the last happened error code.

the following error codes are defined:

  • $hdb->ESUCCESS for success โœจ
  • $hdb->ETHREAD for threading error
  • $hdb->EINVALID for invalid operation
  • $hdb->ENOFILE for file not found
  • $hdb->ENOPERM for no permission
  • $hdb->EMETA for invalid meta data
  • $hdb->ERHEAD for invalid record header
  • $hdb->EOPEN for open error
  • $hdb->ECLOSE for close error
  • $hdb->ETRUNC for trunc error
  • $hdb->ESYNC for sync error
  • $hdb->ESTAT for stat error
  • $hdb->ESEEK for seek error
  • $hdb->EREAD for read error
  • $hdb->EWRITE for write error
  • $hdb->EMMAP for mmap error
  • $hdb->ELOCK for lock error
  • $hdb->EUNLINK for unlink error
  • $hdb->ERENAME for rename error
  • $hdb->EMKDIR for mkdir error
  • $hdb->ERMDIR for rmdir error
  • $hdb->EKEEP for existing record
  • $hdb->ENOREC for no record found
  • $hdb->EMISC for miscellaneous error

$hdb->tune(bnum, apow, fpow, opts)

set the tuning parameters. this is the part where you customize the vibe before anything even opens ๐Ÿ”ง

bnum specifies the number of elements of the bucket array. if it is not defined or not more than 0, the default value is specified. the default value is 131071. suggested size of the bucket array is about from 0.5 to 4 times of the number of all records to be stored.

apow specifies the size of record alignment by power of 2. if it is not defined or negative, the default value is specified. the default value is 4 standing for 2^4=16.

fpow specifies the maximum number of elements of the free block pool by power of 2. if it is not defined or negative, the default value is specified. the default value is 10 standing for 2^10=1024.

opts specifies options by bitwise-or:

  • $hdb->TLARGE specifies that the size of the database can be larger than 2GB by using 64-bit bucket array
  • $hdb->TDEFLATE specifies that each record is compressed with Deflate encoding
  • $hdb->TBZIP specifies that each record is compressed with BZIP2 encoding
  • $hdb->TTCBS specifies that each record is compressed with TCBS encoding

if it is not defined, no option is specified.

if successful, the return value is true, else, it is false.

heads up bestie: the tuning parameters of the database should be set before the database is opened. timing is everything, periodt.

$hdb->setcache(rcnum)

set the caching parameters. speed boost era ๐Ÿƒโ€โ™€๏ธ๐Ÿ’จ

rcnum specifies the maximum number of records to be cached. if it is not defined or not more than 0, the record cache is disabled. it is disabled by default.

if successful, the return value is true, else, it is false.

note that the caching parameters of the database should be set before the database is opened.

$hdb->setxmsiz(xmsiz)

set the size of the extra mapped memory.

xmsiz specifies the size of the extra mapped memory. if it is not defined or not more than 0, the extra mapped memory is disabled. the default size is 67108864.

if successful, the return value is true, else, it is false.

note that the mapping parameters should be set before the database is opened.

$hdb->setdfunit(dfunit)

set the unit step number of auto defragmentation. tidy up bestie โœจ

dfunit specifie the unit step number. if it is not more than 0, the auto defragmentation is disabled. it is disabled by default.

if successful, the return value is true, else, it is false.

note that the defragmentation parameters should be set before the database is opened.

$hdb->open(path, omode)

open a database file. this is the moment, the grand entrance ๐Ÿ‘‘

path specifies the path of the database file.

omode specifies the connection mode:

  • $hdb->OWRITER as a writer
  • $hdb->OREADER as a reader

if the mode is $hdb->OWRITER, the following may be added by bitwise-or:

  • $hdb->OCREAT, which means it creates a new database if not exist
  • $hdb->OTRUNC, which means it creates a new database regardless if one exists
  • $hdb->OTSYNC, which means every transaction synchronizes updated contents with the device

both of $hdb->OREADER and $hdb->OWRITER can be added to by bitwise-or:

  • $hdb->ONOLCK, which means it opens the database file without file locking
  • $hdb->OLCKNB, which means locking is performed without blocking

if it is not defined, $hdb->OREADER is specified.

if successful, the return value is true, else, it is false.

$hdb->close()

close the database file. say bye bye properly, bestie ๐Ÿซถ

if successful, the return value is true, else, it is false.

update of a database is assured to be written when the database is closed. if a writer opens a database but does not close it appropriately, the database will be broken.

not me stressing this again: if you don't close it right, it's broken. like actually broken. ๐Ÿ˜ญ

$hdb->put(key, value)

store a record. the classic.

key specifies the key.

value specifies the value.

if successful, the return value is true, else, it is false.

if a record with the same key exists in the database, it is overwritten.

$hdb->putkeep(key, value)

store a new record, but only if it's actually new. respectful king behavior ๐Ÿ’…

key specifies the key.

value specifies the value.

if successful, the return value is true, else, it is false.

if a record with the same key exists in the database, this method has no effect.

$hdb->putcat(key, value)

concatenate a value at the end of the existing record. just tacking it on the end, no cap.

key specifies the key.

value specifies the value.

if successful, the return value is true, else, it is false.

if there is no corresponding record, a new record is created.

$hdb->putasync(key, value)

store a record in asynchronous fashion. it's giving "I'll get to it" but make it โœจefficientโœจ

key specifies the key.

value specifies the value.

if successful, the return value is true, else, it is false.

if a record with the same key exists in the database, it is overwritten. records passed to this method are accumulated into the inner buffer and wrote into the file at a blast.

$hdb->out(key)

remove a record. gone, deleted, unfollowed ๐Ÿšซ

key specifies the key.

if successful, the return value is true, else, it is false.

$hdb->get(key)

retrieve a record. the moment we've all been waiting for ๐ŸŒŸ

key specifies the key.

if successful, the return value is the value of the corresponding record. undef is returned if no record corresponds.

$hdb->vsiz(key)

get the size of the value of a record. how big is it, bestie? ๐Ÿ“

key specifies the key.

if successful, the return value is the size of the value of the corresponding record, else, it is -1.

$hdb->iterinit()

initialize the iterator. get ready to walk through everything ๐Ÿšถโ€โ™€๏ธ

if successful, the return value is true, else, it is false.

the iterator is used in order to access the key of every record stored in a database.

$hdb->iternext()

get the next key of the iterator. one step at a time, bestie.

if successful, the return value is the next key, else, it is undef. undef is returned when no record is to be get out of the iterator.

it is possible to access every record by iteration of calling this method. it is allowed to update or remove records whose keys are fetched while the iteration. however, it is not assured if updating the database is occurred while the iteration. besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.

so yeah, the order is genuinely random. don't come for me when it's not alphabetical. ๐Ÿ™ˆ

$hdb->fwmkeys(prefix, max)

get forward matching keys โ€” like a lil autocomplete moment ๐Ÿ”

prefix specifies the prefix of the corresponding keys.

max specifies the maximum number of keys to be fetched. if it is not defined or negative, no limit is specified.

The return value is a reference to an array holding the keys of all the matching records. This method never fails, bestie โ€” it literally cannot fail. No record matches? You still get an empty array back. ๐Ÿซถ

Heads up though: this one can be very slow, because every single key in the database gets scanned. Every one. It's giving "walking the whole mall looking for one specific store". ๐Ÿšถโ€โ™€๏ธ๐Ÿ’€
  • $hdb->addint(key, num) โ€” add an integer to a record. ๐Ÿ’–
    • key is the key, obviously.
    • num is the additional value you're adding on.
    • If it works, you get the summation value back. If it doesn't, you get undef. ๐Ÿ˜ญ
    • If that record already exists, the value gets treated as an integer and added to. If no record matches, a brand-new record gets stored with the additional value in it.
    • โš ๏ธ Because records are stored in binary format, you gotta process them with the unpack function using the i operator after you retrieve them. Don't forget, bestie.
  • $hdb->adddouble(key, num) โ€” add a real number to a record. โœจ
    • key is the key.
    • num is the additional value.
    • Success? You get the summation value. Failure? undef. ๐Ÿ’€
    • If the corresponding record exists, the value gets treated as a real number and added to. If no record corresponds, a new record of the additional value is stored.
    • โš ๏ธ Same deal as above: records live in binary format, so process them with unpack using the d operator after retrieval.
  • $hdb->sync() โ€” synchronize updated contents with the file and the device. ๐ŸŒธ
    • True on success, false on failure.
    • This one is super useful when another process connects to the same database file. Sharing is caring but syncing is necessary.
  • $hdb->optimize(bnum, apow, fpow, opts) โ€” optimize the database file. ๐Ÿ’…
    • bnum is the number of elements of the bucket array. If it's not defined or not more than 0, the default value kicks in โ€” and that default is two times the number of records.
    • apow is the size of record alignment by power of 2. If it's not defined or negative, the current setting stays put, no changes.
    • fpow is the maximum number of elements of the free block pool by power of 2. If it's not defined or negative, again, current setting is not changed.
    • opts is options by bitwise-or: $hdb->TLARGE says the database size can go larger than 2GB using a 64-bit bucket array, $hdb->TDEFLATE says every record gets compressed with Deflate encoding, $hdb->TBZIP says every record gets compressed with BZIP2 encoding, and $hdb->TTCBS says every record gets compressed with TCBS encoding. If it's not defined or it's 0xff, the current setting is not changed.
    • True on success, false otherwise.
    • This is the glow-up your database file needs when data fragmentation from successive updating has it looking a mess. ๐Ÿ”ฅ
  • $hdb->vanish() โ€” remove all records. ๐Ÿ‘‹ Poof, gone, bye.
    • True on success, false otherwise.
  • $hdb->copy(path) โ€” copy the database file.
    • path is the path of the destination file. And here's the fun part: if it starts with @, the trailing substring gets executed as a command line. ๐Ÿ˜ณ
    • True on success, false otherwise. And it returns false if that executed command returns a non-zero code.
    • The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So yes, this is perfect for making a backup file of your database file. ๐Ÿ’พ
  • $hdb->tranbegin() โ€” begin the transaction. ๐ŸŽฌ
    • True on success, false otherwise.
    • The database gets locked by the thread while the transaction is happening, so only one transaction can be active with a database object at the same time. Which means โ€” if every database operation is performed inside the transaction, the serializable isolation level is assumed. Iconic behavior, honestly. All updated regions are kept track of by write ahead logging during the transaction. And if the database gets closed mid-transaction, the transaction is aborted implicitly. No warning, just vibes revoked. ๐Ÿ˜ญ
  • $hdb->trancommit() โ€” commit the transaction. โœ…
    • True on success, false otherwise.
    • Update in the transaction is fixed when it's committed successfully. Locked in, periodt.
  • $hdb->tranabort() โ€” abort the transaction. ๐Ÿ™ˆ
    • True on success, false otherwise.
    • Update in the transaction is discarded when it's aborted. The state of the database is rollbacked to before the transaction. We're pretending it never happened.
  • $hdb->path() โ€” get the path of the database file. ๐Ÿ›ฃ๏ธ
    • The return value is the path of the database file, or undef if the object doesn't connect to any database file.
  • $hdb->rnum() โ€” get the number of records. ๐Ÿ”ข
    • The return value is the number of records, or 0 if the object doesn't connect to any database file.
  • $hdb->fsiz() โ€” get the size of the database file. ๐Ÿ“
    • The return value is the size of the database file, or 0 if the object doesn't connect to any database file.

โœจ Tying functions of TokyoCabinet::HDB โœจ

tie(%hash, "TokyoCabinet::HDB", path, omode, bnum, apow, fpow, opts, rcnum)

Tie a hash variable to a hash database file. Let's get into it, bestie. ๐Ÿ’–

  • path is the path of the database file. ๐Ÿ—‚๏ธ
  • omode is the connection mode: TokyoCabinet::HDB::OWRITER for a writer, TokyoCabinet::HDB::OREADER for a reader.
    • If the mode is TokyoCabinet::HDB::OWRITER, you can bitwise-or these on: TokyoCabinet::HDB::OCREAT, which creates a new database if one doesn't exist; TokyoCabinet::HDB::OTRUNC, which creates a new database regardless of whether one already exists (bold, lowkey ruthless); and TokyoCabinet::HDB::OTSYNC, which means every transaction synchronizes updated contents with the device.
    • Both TokyoCabinet::HDB::OREADER and TokyoCabinet::HDB::OWRITER can have these bitwise-or'd on: TokyoCabinet::HDB::ONOLCK, which opens the database file without file locking, or TokyoCabinet::HDB::OLCKNB, which means locking is performed without blocking.
    • If omode isn't defined, TokyoCabinet::HDB::OREADER is what you get.
  • bnum is the number of elements of the bucket array. If it's not defined or not more than 0, the default is used, and that default is 131071. Suggested size of the bucket array is about from 0.5 to 4 times of the number of all records you're gonna store.
  • apow is the size of record alignment by power of 2. If it's not defined or negative, the default is used โ€” and that's 4, standing for 2^4=16.
  • fpow is the maximum number of elements of the free block pool by power of 2. If it's not defined or negative, the default applies: 10, standing for 2^10=1024.
  • opts is options by bitwise-or: TokyoCabinet::HDB::TLARGE says the database size can be larger than 2GB by using a 64-bit bucket array, TokyoCabinet::HDB::TDEFLATE says each record is compressed with Deflate encoding, TokyoCabinet::HDB::TBZIP says each record is compressed with BZIP2 encoding, TokyoCabinet::HDB::TTCBS says each record is compressed with TCBS encoding. If opts isn't defined, no option is specified.
  • rcnum is the maximum number of records to be cached. If it's not defined or not more than 0, the record cache is disabled โ€” and it's disabled by default anyway. ๐Ÿ™…โ€โ™€๏ธ

If successful, the return value is true, else it's false.

  • untie(%hash) โ€” untie a hash variable from the database file. โœ‚๏ธ The return value is always true. Always. No notes.
  • $hash{key} = value โ€” store a record. ๐Ÿ’พ
    • key is the key.
    • value is the value.
    • True on success, false otherwise.
    • If a record with the same key already exists in the database, it gets overwritten. Sorry to whoever was there first. ๐Ÿซถ
  • delete($hash{key}) โ€” remove a record. ๐Ÿ—‘๏ธ
    • key is the key.
    • True on success, false otherwise.
  • $hash{key} โ€” retrieve a record. ๐Ÿ”
    • key is the key.
    • If it works, the return value is the value of the corresponding record. undef comes back if no record corresponds. ๐Ÿ˜ญ
  • exists($hash{key}) โ€” check whether a record corresponding to a key exists. ๐Ÿ‘€
    • key is the key.
    • The return value is true if the record exists, else it's false.
  • $hash = () โ€” remove all records. ๐Ÿงน The return value is always undef.
  • (the iterator) โ€” the inner methods FIRSTKEY and NEXTKEY are also implemented, so you can use the tying functions each, keys, and so on. Iterate away, queen. ๐Ÿ‘‘

๐ŸŒˆ Class TokyoCabinet::BDB ๐ŸŒˆ

B+ tree database is a file containing a B+ tree, and it's handled with the B+ tree database API. Before you do any operations to store or retrieve records, you gotta open a database file and connect the B+ tree database object to it. The method open opens a database file and the method close closes it. And listen โ€” to avoid data missing or corruption, it is important to close every database file when it's no longer in use. Also: it is forbidden for multiple database objects in a process to open the same database at the same time. Do not test this. ๐Ÿ’€

  • $bdb = TokyoCabinet::BDB->new() โ€” create a B+ tree database object. โœจ The return value is the new B+ tree database object.
  • $bdb->errmsg(ecode) โ€” get the message string corresponding to an error code. ๐Ÿ“ข
    • ecode is the error code. If it's not defined or negative, the last happened error code is used.
    • The return value is the message string of the error code.
  • $bdb->ecode() โ€” get the last happened error code. ๐Ÿšจ The return value is the last happened error code.

okay so the following error codes are defined, bestie, and you're literally gonna want them memorized ๐Ÿ’–

  • $bdb->ESUCCESS โ€” for success, we love a win โœจ
  • $bdb->ETHREAD โ€” for threading error, not the vibe ๐Ÿ˜ญ
  • $bdb->EINVALID โ€” for invalid operation, we don't do that here ๐Ÿ’€
  • $bdb->ENOFILE โ€” for file not found, where is it bestie ๐Ÿ˜ญ
  • $bdb->ENOPERM โ€” for no permission, rude โœ‹
  • $bdb->EMETA โ€” for invalid meta data, meta? invalid? no ๐Ÿ’…
  • $bdb->ERHEAD โ€” for invalid record header, head empty ๐Ÿง 
  • $bdb->EOPEN โ€” for open error, can't open? tragic ๐ŸŽ€
  • $bdb->ECLOSE โ€” for close error, can't even close ๐Ÿ’€
  • $bdb->ETRUNC โ€” for trunc error, truncated? bye โœ‚๏ธ
  • $bdb->ESYNC โ€” for sync error, out of sync bestie ๐Ÿ˜ญ
  • $bdb->ESTAT โ€” for stat error, stats? no ๐Ÿ“‰
  • $bdb->ESEEK โ€” for seek error, can't find it ๐Ÿ”
  • $bdb->EREAD โ€” for read error, can't read? illiterate ๐Ÿ’€
  • $bdb->EWRITE โ€” for write error, can't write? writer's block โœ๏ธ
  • $bdb->EMMAP โ€” for mmap error, memory map? more like memory trap ๐Ÿ˜ญ
  • $bdb->ELOCK โ€” for lock error, locked out ๐Ÿ”’
  • $bdb->EUNLINK โ€” for unlink error, can't unlink? toxic ๐Ÿ’”
  • $bdb->ERENAME โ€” for rename error, name change denied ๐Ÿ’…
  • $bdb->EMKDIR โ€” for mkdir error, can't make dir? make it make sense ๐Ÿ˜ญ
  • $bdb->ERMDIR โ€” for rmdir error, can't remove dir? stay put ๐Ÿ 
  • $bdb->EKEEP โ€” for existing record, already here bestie ๐Ÿ‘‘
  • $bdb->ENOREC โ€” for no record found, ghosted ๐Ÿ‘ป
  • $bdb->EMISC โ€” for miscellaneous error, random chaos ๐ŸŒช๏ธ

โœจ METHODS โœจ

$bdb->setcmpfunc(cmp)

okay so this one is literally setting the custom comparison function, bestie. cmp specifies the custom comparison function. It can be either the reference of a block or the name of a function. If it works, you get true, otherwise false. The default comparison function compares keys of two records by lexical order. The constants $bdb->CMPLEXICAL (dafault), $bdb->CMPDECIMAL, $bdb->CMPINT32, and $bdb->CMPINT64 are built-in. Note that the comparison function should be set before the database is opened. Moreover, user-defined comparison functions should be set every time the database is being opened. periodt ๐Ÿ’…

$bdb->tune(lmemb, nmemb, bnum, apow, fpow, opts)

Set the tuning parameters. This is the glow-up for your DB, bestie. ๐ŸŽ€

  • lmemb specifies the number of members in each leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 128. ๐Ÿƒ
  • nmemb specifies the number of members in each non-leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 256. ๐Ÿ‚
  • bnum specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 32749. Suggested size of the bucket array is about from 1 to 4 times of the number of all pages to be stored. ๐Ÿชฃ
  • apow specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^8=256. โœจ
  • fpow specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024. ๐Ÿ†“
  • opts specifies options by bitwise-or: $bdb->TLARGE specifies that the size of the database can be larger than 2GB by using 64-bit bucket array, $bdb->TDEFLATE specifies that each record is compressed with Deflate encoding, $bdb->TBZIP specifies that each record is compressed with BZIP2 encoding, $bdb->TTCBS specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified. ๐ŸŽ›๏ธ

If successful, the return value is true, else, it is false. Note that the tuning parameters of the database should be set before the database is opened. Don't forget bestie! ๐Ÿ˜ค

$bdb->setcache(lcnum, ncnum)

Set the caching parameters. Cache me outside, how bout dat? ๐Ÿ’…

  • lcnum specifies the maximum number of leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 1024. ๐Ÿƒ
  • ncnum specifies the maximum number of non-leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified. The default value is 512. ๐Ÿ‚

If successful, the return value is true, else, it is false.

Note that the caching parameters of the database should be set before the database is opened. So set it before you open, periodt. โœจ

$bdb->setxmsiz(xmsiz)

Set the size of the extra mapped memory. ๐Ÿ—บ๏ธ

xmsiz specifies the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. It is disabled by default. ๐Ÿ’ค

If successful, the return value is true, else, it is false.

Note that the mapping parameters should be set before the database is opened. ๐Ÿซถ

$bdb->setdfunit(dfunit)

Set the unit step number of auto defragmentation. It's giving tidy up energy ๐Ÿงน

dfunit specifie the unit step number. If it is not more than 0, the auto defragmentation is disabled. It is disabled by default.

If successful, the return value is true, else, it is false.

Note that the defragmentation parameters should be set before the database is opened. โœจ

$bdb->open(path, omode)

Open a database file. Let's gooo ๐Ÿ”ฅ

  • path specifies the path of the database file. ๐Ÿ“
  • omode specifies the connection mode: $bdb->OWRITER as a writer, $bdb->OREADER as a reader. If the mode is $bdb->OWRITER, the following may be added by bitwise-or: $bdb->OCREAT, which means it creates a new database if not exist, $bdb->OTRUNC, which means it creates a new database regardless if one exists, $bdb->OTSYNC, which means every transaction synchronizes updated contents with the device. Both of $bdb->OREADER and $bdb->OWRITER can be added to by bitwise-or: $bdb->ONOLCK, which means it opens the database file without file locking, or $bdb->OLCKNB, which means locking is performed without blocking. If it is not defined, $bdb->OREADER is specified. ๐Ÿšช

If successful, the return value is true, else, it is false.

$bdb->close()

Close the database file. Bye bestie ๐Ÿ‘‹

If successful, the return value is true, else, it is false.

Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken. So close it, bestie, or it's broken broken ๐Ÿ’”

$bdb->put(key, value)

Store a record. Put it in the bag ๐Ÿ’…

  • key specifies the key. ๐Ÿ”‘
  • value specifies the value. ๐Ÿ’Ž

If successful, the return value is true, else, it is false.

If a record with the same key exists in the database, it is overwritten. Overwritten, periodt. ๐Ÿ”„

$bdb->putkeep(key, value)

Store a new record. But only if it's new, no duplicates allowed โœ‹

  • key specifies the key. ๐Ÿ”‘
  • value specifies the value. ๐Ÿ’Ž

If successful, the return value is true, else, it is false.

If a record with the same key exists in the database, this method has no effect. It's giving "I'm not gonna do anything" ๐Ÿ’€

$bdb->putcat(key, value)

Concatenate a value at the end of the existing record. Glue it on ๐Ÿงด

  • key specifies the key. ๐Ÿ”‘
  • value specifies the value. ๐Ÿ’Ž

If successful, the return value is true, else, it is false.

If there is no corresponding record, a new record is created. So it's like put but with extra steps โœจ

$bdb->putdup(key, value)

Store a record with allowing duplication of keys. Duplicates? We allow it here ๐Ÿ’…

  • key specifies the key. ๐Ÿ”‘
  • value specifies the value. ๐Ÿ’Ž

If successful, the return value is true, else, it is false.

If a record with the same key exists in the database, the new record is placed after the existing one. Queue up bestie ๐Ÿšถโ€โ™€๏ธ๐Ÿšถโ€โ™€๏ธ

$bdb->putlist(key, values)

Store records with allowing duplication of keys. A whole list of them, go off ๐Ÿ‘‘

  • key specifies the key. ๐Ÿ”‘
  • values specifies the reference to an array of the values. ๐Ÿ“š

If successful, the return value is true, else, it is false.

If a record with the same key exists in the database, the new records are placed after the existing one. Line them up ๐Ÿ’…

$bdb->out(key)

Remove a record. Out out out ๐Ÿ—‘๏ธ

  • key specifies the key. ๐Ÿ”‘

If successful, the return value is true, else, it is false.

If the key of duplicated records is specified, the first one is selected. First come, first served ๐Ÿ’€

$bdb->outlist(key)

Remove records. Plural. All of them. No survivors ๐Ÿ’…

  • key specifies the key. ๐Ÿ”‘

If successful, the return value is true, else, it is false.

If the key of duplicated records is specified, all of them are removed. Every single one. Periodt. ๐Ÿงน

$bdb->get(key)

Retrieve a record. Give it to me ๐Ÿซด

  • key specifies the key. ๐Ÿ”‘

If successful, the return value is the value of the corresponding record. undef is returned if no record corresponds. So if it's not there, you get undef, not the vibe ๐Ÿ˜ญ

If the key of duplicated records is specified, the first one is selected. First one, bestie. ๐Ÿฅ‡

$bdb->getlist(key)

Retrieve records. Plural. The whole squad ๐Ÿซ‚

  • key specifies the key. ๐Ÿ”‘

If successful, the return value is the reference to an array of the values of the corresponding records. undef is returned if no record corresponds. No records? undef, tragic. ๐Ÿ’”

$bdb->vnum(key)

Get the number of records corresponding a key. Count them ๐Ÿ”ข

  • key specifies the key. ๐Ÿ”‘

If successful, the return value is the number of the corresponding records, else, it is 0. Zero. Zilch. Nada. 0๏ธโƒฃ

$bdb->vsiz(key)

Get the size of the value of a record. How big is it? ๐Ÿ“

  • key specifies the key. ๐Ÿ”‘

If successful, the return value is the size of the value of the corresponding record, else, it is -1. Negative one, yikes. โž–1๏ธโƒฃ

If the key of duplicated records is specified, the first one is selected. First one again. ๐Ÿฅ‡

$bdb->range(bkey, binc, ekey, einc, max)

Get keys of ranged records. Range, bestie, like a playlist from here to there ๐ŸŽถ

  • bkey specifies the key of the beginning border. If it is not defined, the first record is specified. ๐Ÿ
  • binc specifies whether the beginning border is inclusive or not. If it is not defined, false is specified. ๐Ÿšช
  • ekey specifies the key of the ending border. If it is not defined, the last record is specified. ๐Ÿ
  • einc specifies whether the ending border is inclusive or not. If it is not defined, false is specified. ๐Ÿšช
  • max specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified. โ™พ๏ธ

The return value is the reference to an array of the keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds. So it's the chill one, never fails, always returns something, even if it's empty. We love a reliable method ๐Ÿ’…

$bdb->fwmkeys(prefix, max)

Get forward matching keys. Forward like your future ๐Ÿ”ฎ

  • prefix specifies the prefix of the corresponding keys. ๐ŸŒฑ
  • max specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified. โ™พ๏ธ

The return value is the reference to an array of the keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds. Again, never fails, iconic. โœจ

$bdb->addint(key, num)

Add an integer to a record. Math, but make it cute ๐Ÿงฎ

  • key specifies the key. ๐Ÿ”‘
  • num specifies the additional value. โž•

If successful, the return value is the summation value, else, it is undef. So you get the sum, or undef if it didn't work. ๐Ÿ’…

okay so continuing from that addint moment, no need to re-intro: if the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. And because records are stored in binary format, you gotta process them with the unpack function using the i operator after retrieval. that's just how it is bestie ๐Ÿ’…

  • $bdb->adddouble(key, num) โ€” add a real number to a record, slay ๐Ÿ“
    • key โ€” specifies the key.
    • num โ€” specifies the additional value.

If successful, the return value is the summation value, else, it is undef.

If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the unpack function using the d operator after retrieval. not me reminding you twice, but the d is doing the heavy lifting here ๐Ÿซถ

  • $bdb->sync() โ€” synchronize updated contents with the file and the device โœจ

If successful, the return value is true, else, it is false.

This method is useful when another process connects the same database file. sharing is caring, fr fr.

  • $bdb->optimize(lmemb, nmemb, bnum, apow, fpow, opts) โ€” optimize the database file, aka the glow-up ๐Ÿ’–
    • lmemb โ€” specifies the number of members in each leaf page. If it is not defined or not more than 0, the current setting is not changed.
    • nmemb โ€” specifies the number of members in each non-leaf page. If it is not defined or not more than 0, the current setting is not changed.
    • bnum โ€” specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of pages.
    • apow โ€” specifies the size of record alignment by power of 2. If it is not defined or negative, the current setting is not changed.
    • fpow โ€” specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the current setting is not changed.
    • opts โ€” specifies options by bitwise-or: $bdb->TLARGE specifies that the size of the database can be larger than 2GB by using a 64-bit bucket array, $bdb->TDEFLATE specifies that each record is compressed with Deflate encoding, $bdb->TBZIP specifies that each record is compressed with BZIP2 encoding, $bdb->TTCBS specifies that each record is compressed with TCBS encoding. If it is not defined or 0xff, the current setting is not changed.

If successful, the return value is true, else, it is false.

This method is useful to reduce the size of the database file with data fragmentation by successive updating. so basically it's the declutter era of your db ๐Ÿ”ฅ

  • $bdb->vanish() โ€” remove all records ๐Ÿซง

If successful, the return value is true, else, it is false.

not me casually yeeting every single record. it's giving scorched earth. it's giving "no thoughts, empty table." use with intention bestie ๐Ÿ˜ญ
  • $bdb->copy(path) โ€” copy the database file ๐Ÿ“
    • path โ€” specifies the path of the destination file. If it begins with @, the trailing substring is executed as a command line.

If successful, the return value is true, else, it is false. False is returned if the executed command returns non-zero code.

The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file. iconic behavior, honestly ๐Ÿ’…

  • $bdb->tranbegin() โ€” begin the transaction โœจ

If successful, the return value is true, else, it is false.

The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. Because all pages are cached on memory while the transaction, the amount of referred records is limited by the memory capacity. If the database is closed during transaction, the transaction is aborted implicitly.

so like, main character energy but you're the only main character allowed on stage at once. periodt.
  • $bdb->trancommit() โ€” commit the transaction ๐Ÿ’–

If successful, the return value is true, else, it is false.

Update in the transaction is fixed when it is committed successfully. no take-backs, bestie.

  • $bdb->tranabort() โ€” abort the transaction ๐Ÿ™ˆ

If successful, the return value is true, else, it is false.

Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction. we love a clean escape route โœจ

  • $bdb->path() โ€” get the path of the database file ๐Ÿ›ค๏ธ

The return value is the path of the database file or undef if the object does not connect to any database file.

  • $bdb->rnum() โ€” get the number of records ๐Ÿ”ข

The return value is the number of records or 0 if the object does not connect to any database file.

  • $bdb->fsiz() โ€” get the size of the database file ๐Ÿ“

The return value is the size of the database file or 0 if the object does not connect to any database file.


๐Ÿฆ‹ Class TokyoCabinet::BDBCUR ๐Ÿฆ‹

  • $cur = TokyoCabinet::BDBCUR->new(bdb) โ€” create a cursor object ๐ŸŽ€
    • bdb โ€” specifies the B+ tree database object.

The return value is the new cursor object.

Note that the cursor is available only after initialization with the first or the jump methods and so on. Moreover, the position of the cursor will be indefinite when the database is updated after the initialization of the cursor. so like, don't get attached to where it's sitting, okay? it moves ๐Ÿ˜ญ
  • $cur->first() โ€” move the cursor to the first record โญ

If successful, the return value is true, else, it is false. False is returned if there is no record in the database.

  • $cur->last() โ€” move the cursor to the last record ๐ŸŒˆ

If successful, the return value is true, else, it is false. False is returned if there is no record in the database.

  • $cur->jump(key) โ€” move the cursor to the front of records corresponding a key ๐Ÿฆ˜
    • key โ€” specifies the key.

If successful, the return value is true, else, it is false. False is returned if there is no record corresponding the condition.

The cursor is set to the first record corresponding the key or the next substitute if a completely matching record does not exist. so it's flexible, it's forgiving, it's giving supportive bestie energy ๐Ÿ’–

  • $cur->prev() โ€” move the cursor to the previous record โฌ…๏ธ

If successful, the return value is true, else, it is false. False is returned if there is no previous record.

  • $cur->next() โ€” move the cursor to the next record โžก๏ธ

If successful, the return value is true, else, it is false. False is returned if there is no next record.

  • $cur->put(value, cpmode) โ€” insert a record around the cursor ๐ŸŽฏ
    • value โ€” specifies the value.
    • cpmode โ€” specifies detail adjustment: $cur->CPCURRENT, which means that the value of the current record is overwritten, $cur->CPBEFORE, which means that the new record is inserted before the current record, $cur->CPCAFTER, which means that the new record is inserted after the current record.

If successful, the return value is true, else, it is false. False is returned when the cursor is at an invalid position.

After insertion, the cursor is moved to the inserted record. it literally follows the new thing, obsessed ๐Ÿซถ

  • $cur->out() โ€” remove the record where the cursor is ๐Ÿ’€

If successful, the return value is true, else, it is false. False is returned when the cursor is at an invalid position.

After deletion, the cursor is moved to the next record if possible.

  • $cur->key() โ€” get the key of the record where the cursor is ๐Ÿ”‘

If successful, the return value is the key, else, it is undef. 'undef' is returned when the cursor is at an invalid position.

  • $cur->val() โ€” get the value of the record where the cursor is ๐Ÿ’Ž

If successful, the return value is the value, else, it is undef. 'undef' is returned when the cursor is at an invalid position.


๐Ÿงš Tying functions of TokyoCabinet::BDB ๐Ÿงš

  • tie(%hash, "TokyoCabinet::BDB", path, omode, lmemb, nmemb, bnum, apow, fpow, opts, lcnum, ncnum) โ€” tie a hash variable to a B+ tree database file ๐ŸŒธ
    • path โ€” specifies the path of the database file.
    • omode โ€” specifies the connection mode: TokyoCabinet::BDB::OWRITER as a writer, TokyoCabinet::BDB::OREADER as a reader. If the mode is TokyoCabinet::BDB::OWRITER, the following may be added by bitwise-or: TokyoCabinet::BDB::OCREAT, which means it creates a new database if not exist, TokyoCabinet::BDB::OTRUNC, which means it creates a new database regardless if one exists, TokyoCabinet::BDB::OTSYNC, which means every transaction synchronizes updated contents with the device. Both of TokyoCabinet::BDB::OREADER and TokyoCabinet::BDB::OWRITER can be added to by bitwise-or: TokyoCabinet::BDB::ONOLCK, which means it opens the database file without file locking, or TokyoCabinet::BDB::OLCKNB, which means locking is performed without blocking. If it is not defined, TokyoCabinet::BDB::OREADER is specified.
    • lmemb โ€” specifies the number of members in each leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 128.
    • nmemb โ€” specifies the number of members in each non-leaf page. If it is not defined or not more than 0, the default value is specified. The default value is 256.
    • bnum โ€” specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is 32749.
    • apow โ€” specifies the size of record alignment by power of 2. If it is not defined or negative, the default value is specified. The default value is 4 standing for 2^8=256.
    • fpow โ€” specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.
    • opts โ€” specifies options by bitwise-or: TokyoCabinet::BDB::TLARGE specifies that the size of the database can be larger than 2GB by using a 64-bit bucket array, TokyoCabinet::BDB::TDEFLATE specifies that each record is compressed with Deflate encoding, TokyoCabinet::BDB::TBZIP specifies that each record is compressed with BZIP2 encoding, TokyoCabinet::BDB::TTCBS specifies that each record is compressed with TCBS encoding. If it is not defined, no option is specified.
    • lcnum โ€” specifies the maximum number of leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified.
    • ncnum โ€” specifies the maximum number of non-leaf nodes to be cached. If it is not defined or not more than 0, the default value is specified.

If successful, the return value is true, else, it is false.

untie(%hash)

Unhook a hash variable from the database file. ๐Ÿ’ซ

The return value is always true. No drama, no maybe.

$hash{key} = value

Store a record. ๐Ÿ’พ

key is the key, bestie. That's literally its whole job.

value is the value. Slay.

If it works, the return value is true. If it doesn't, it's false. ๐Ÿ™ˆ

And heads up: if a record with that same key is already chilling in the database, it gets overwritten. Gone. Replaced. Not sorry.

delete($hash{key})

Remove a record. ๐Ÿ—‘๏ธ

key specifies the key.

If it works, return value true; if not, false.

$hash{key}

Retrieve a record. ๐Ÿ”

key specifies the key.

If it works, you get back the value of the corresponding record. If nothing matches, you get undef. That's the vibe check failing, fr fr.

exists($hash{key})

Check whether a record corresponding to a key exists. ๐Ÿ‘€

key specifies the key.

Return value is true if the record exists, else it's false. Simple as.

$hash = ()

Remove all the records. Every single one. ๐Ÿ’€

The return value is always undef.

(the iterator)

The inner methods FIRSTKEY and NEXTKEY are also implemented, so you can use the tying functions each, keys, and so on. โœจ Iterator girlies, this one's for you.


Class TokyoCabinet::FDB ๐Ÿฆ‹

A fixed-length database is a file containing an array of fixed-length elements, and it's handled with the fixed-length database API. Before you can store or retrieve records, you have to open a database file and connect the fixed-length database object to it. The method open opens a database file, and the method close closes it.

To avoid data missing or corruption, it is important to close every database file when it is no longer in use. And it is forbidden for multiple database objects in a process to open the same database at the same time. Like, don't. ๐Ÿšซ

$fdb = TokyoCabinet::FDB->new()

Create a fixed-length database object. ๐ŸŽ€

Return value is the brand-new fixed-length database object. Main character energy, honestly.

$fdb->errmsg(ecode)

Get the message string that corresponds to an error code. ๐Ÿ’ฌ

ecode specifies the error code. If it's not defined, or if it's negative, then the last happened error code is used instead.

Return value is the message string of the error code.

$fdb->ecode()

Get the last happened error code. ๐Ÿšจ

Return value is the last happened error code.

Here are all the error codes that are defined, collect them all bestie:

  • $fdb->ESUCCESS โ€” success โœจ
  • $fdb->ETHREAD โ€” threading error
  • $fdb->EINVALID โ€” invalid operation
  • $fdb->ENOFILE โ€” file not found
  • $fdb->ENOPERM โ€” no permission
  • $fdb->EMETA โ€” invalid meta data
  • $fdb->ERHEAD โ€” invalid record header
  • $fdb->EOPEN โ€” open error
  • $fdb->ECLOSE โ€” close error
  • $fdb->ETRUNC โ€” trunc error
  • $fdb->ESYNC โ€” sync error
  • $fdb->ESTAT โ€” stat error
  • $fdb->ESEEK โ€” seek error
  • $fdb->EREAD โ€” read error
  • $fdb->EWRITE โ€” write error
  • $fdb->EMMAP โ€” mmap error
  • $fdb->ELOCK โ€” lock error
  • $fdb->EUNLINK โ€” unlink error
  • $fdb->ERENAME โ€” rename error
  • $fdb->EMKDIR โ€” mkdir error
  • $fdb->ERMDIR โ€” rmdir error
  • $fdb->EKEEP โ€” existing record
  • $fdb->ENOREC โ€” no record found
  • $fdb->EMISC โ€” miscellaneous error

$fdb->tune(width, limsiz)

Set the tuning parameters. ๐ŸŽ›๏ธ

width specifies the width of the value of each record. If it's not defined, or if it's not more than 0, the default value is used. That default is 255.

limsiz specifies the limit size of the database file. If it's not defined, or if it's not more than 0, the default value is used. That default is 268435456.

If it works, return value is true; if not, false.

Note that the tuning parameters of the database should be set before the database is opened. Timing is everything, iykyk.

$fdb->open(path, omode)

Open a database file. ๐Ÿ“‚

path specifies the path of the database file.

omode specifies the connection mode: $fdb->OWRITER as a writer, $fdb->OREADER as a reader. If the mode is $fdb->OWRITER, you can bitwise-or these extras onto it:

  • $fdb->OCREAT โ€” creates a new database if one doesn't exist
  • $fdb->OTRUNC โ€” creates a new database regardless of whether one already exists

And both $fdb->OREADER and $fdb->OWRITER can have these bitwise-ored on:

  • $fdb->ONOLCK โ€” opens the database file without file locking
  • $fdb->OLCKNB โ€” locking is performed without blocking

If omode isn't defined, $fdb->OREADER is specified.

If it works, return value is true; if not, false.

$fdb->close()

Close the database file. ๐Ÿšช

If it works, return value is true; if not, false.

Update of a database is assured to be written when the database is closed. And listen: if a writer opens a database but does not close it appropriately, the database will be broken. Broken broken. Not a vibe. ๐Ÿ˜ญ

$fdb->put(key, value)

Store a record. ๐Ÿ’พ

key specifies the key. It should be more than 0. And check this out:

  • If it's "min", the minimum ID number of existing records is specified.
  • If it's "prev", the number less by one than the minimum ID number of existing records is specified.
  • If it's "max", the maximum ID number of existing records is specified.
  • If it's "next", the number greater by one than the maximum ID number of existing records is specified.

value specifies the value.

If it works, return value is true; if not, false.

If a record with the same key already exists in the database, it is overwritten. Bye.

$fdb->putkeep(key, value)

Store a new record. ๐ŸŒฑ

key specifies the key. It should be more than 0. And again:

  • If it's "min", the minimum ID number of existing records is specified.
  • If it's "prev", the number less by one than the minimum ID number of existing records is specified.
  • If it's "max", the maximum ID number of existing records is specified.
  • If it's "next", the number greater by one than the maximum ID number of existing records is specified.

value specifies the value.

If it works, return value is true; if not, false.

If a record with the same key already exists in the database, this method has no effect. It just politely does nothing. Respectful king behavior.

$fdb->putcat(key, value)

Concatenate a value at the end of the existing record. ๐Ÿงต

key specifies the key. It should be more than 0. And one more time:

  • If it's "min", the minimum ID number of existing records is specified.
  • If it's "prev", the number less by one than the minimum ID number of existing records is specified.
  • If it's "max", the maximum ID number of existing records is specified.
  • If it's "next", the number greater by one than the maximum ID number of existing records is specified.

value specifies the value.

If it works, return value is true; if not, false.

If there's no corresponding record, a new record is created. No cap.

$fdb->out(key)

Remove a record. ๐Ÿ—‘๏ธ

key specifies the key. It should be more than 0. If it's "min", the minimum ID number of existing records is specified. If it's "max", the maximum ID number of existing records is specified.

If it works, return value is true; if not, false.

$fdb->get(key)

Retrieve a record. ๐Ÿ”

key specifies the key. It should be more than 0. If it's "min", the minimum ID number of existing records is specified. If it's "max", the maximum ID number of existing records is specified.

If it works, the return value is the value of the corresponding record. undef is returned if no record corresponds. ๐Ÿ’”

$fdb->vsiz(key)

Get the size of the value of a record. ๐Ÿ“

key specifies the key. It should be more than 0. If it's "min", the minimum ID number of existing records is specified. If it's "max", the maximum ID number of existing records is specified.

If it works, the return value is the size of the value of the corresponding record. If not, it's -1.

$fdb->iterinit()

Initialize the iterator. ๐Ÿ”„

If it works, return value is true; if not, false.

The iterator is used in order to access the key of every record stored in a database. Every. Single. One. ๐Ÿ‘‘

$fdb->iternext()

Get the next key of the iterator. โžก๏ธ

If it works, the return value is the next key; if not, it's undef. undef is returned when there's no record left to get out of the iterator.

It's possible to access every record by iterating calls to this method. It's allowed to update or remove records whose keys are fetched while the iteration is happening. And the order of this traversal access method is ascending of the ID number. So it goes up. Always up. โœจ

$fdb->range(interval, max)

Get keys with an interval notation. ๐Ÿ“

interval specifies the interval notation.

max specifies the maximum number of keys to be fetched. If it's not defined, or if it's negative, no limit is specified.

The return value is the reference to an array of the keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds. Resilient queen. ๐Ÿ’…

$fdb->addint(key, num)

Add an integer to a record. โž•

key specifies the key. It should be more than 0. You know the drill:

  • If it's "min", the minimum ID number of existing records is specified.
  • If it's "prev", the number less by one than the minimum ID number of existing records is specified.
  • If it's "max", the maximum ID number of existing records is specified.
  • If it's "next", the number greater by one than the maximum ID number of existing records is specified.

num specifies the additional value.

If it works, the return value is the summation value; if not, it's undef.

If the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. And heads up: because records are stored in binary format, they should be processed with the unpack function with the i operator after retrieval. Don't forget, bestie. ๐Ÿ”ฅ

$fdb->adddouble(key, num)

Add a real number to a record. โž•โœจ

key specifies the key. It should be more than 0. Once more with feeling:

  • If it's "min", the minimum ID number of existing records is specified.
  • If it's "prev", the number less by one than the minimum ID number of existing records is specified.
  • If it's "max", the maximum ID number of existing records is specified.
  • If it's "next", the number greater by one than the maximum ID number of existing records is specified.

num specifies the additional value.

If it works, the return value is the summation value; if not, it's undef. ๐Ÿซถ

If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a brand new record holding the additional value gets stored instead. And because these records live in binary format, bestie, you gotta run them through the unpack function with the d operator after you retrieve them. ๐Ÿ’…

  • $fdb->sync() โ€” Synchronize the updated contents with the file and the device. Returns true if it worked out, false if it didn't. This one is lowkey a lifesaver when another process is connected to the same database file. ๐Ÿซถ
  • $fdb->optimize(width, limsiz) โ€” Optimize the database file. width is the width of the value of each record โ€” leave it undefined or โ‰ค 0 and the current setting just stays put. limsiz is the limit size of the database file โ€” same deal, undefined or โ‰ค 0 and nothing changes. True on success, false otherwise. โœจ
  • $fdb->vanish() โ€” Remove all the records. Gone. Poof. ๐Ÿซฅ Returns true if it worked, false if not.
  • $fdb->copy(path) โ€” Copy the database file. path is where the destination file goes โ€” and if it starts with @, the trailing substring gets executed as a command line (yes, for real). Returns true on success, false on failure, and false if that executed command returns a non-zero code. The database file is assured to stay synchronized and unmodified while the copying or executing is happening, so this method is genuinely the move for making a backup file of your database. ๐Ÿ”ฅ
  • $fdb->tranbegin() โ€” Begin the transaction. True on success, false on failure. While the transaction is live the database is locked by the thread, so only one transaction can be active with a database object at the same time. Which means: if every database operation happens inside the transaction, the serializable isolation level is assumed. All updated regions are kept track of by write ahead logging during the transaction. And heads up โ€” if the database gets closed during the transaction, the transaction is aborted implicitly. ๐Ÿ˜ญ
  • $fdb->trancommit() โ€” Commit the transaction. True on success, false on failure. The update in the transaction is fixed once it commits successfully. โœจ
  • $fdb->tranabort() โ€” Abort the transaction. True on success, false on failure. The update in the transaction is discarded when it's aborted, and the state of the database gets rollbacked to before the transaction. No harm no foul. ๐Ÿ’œ
  • $fdb->path() โ€” Get the path of the database file. Returns the path of the database file, or undef if the object isn't connected to any database file.
  • $fdb->rnum() โ€” Get the number of records. Returns that number, or 0 if the object isn't connected to any database file.
  • $fdb->fsiz() โ€” Get the size of the database file. Returns that size, or 0 if the object isn't connected to any database file.

๐ŸŽ€ Tying functions of TokyoCabinet::FDB ๐ŸŽ€

  • tie(%hash, "TokyoCabinet::FDB", path, omode, width, limsiz) โ€” Tie a hash variable to a hash database file. So iconic of Perl tbh.

path is the path of the database file.

omode is the connection mode: TokyoCabinet::FDB::OWRITER for writer, TokyoCabinet::FDB::OREADER for reader. If the mode is TokyoCabinet::FDB::OWRITER, you can bitwise-or these in: TokyoCabinet::FDB::OCREAT, which creates a new database if one doesn't exist, and TokyoCabinet::FDB::OTRUNC, which creates a new database regardless of whether one exists. Both TokyoCabinet::FDB::OREADER and TokyoCabinet::FDB::OWRITER can be bitwise-or'd with TokyoCabinet::FDB::ONOLCK, which opens the database file without file locking, or TokyoCabinet::FDB::OLCKNB, which does locking without blocking. Leave it undefined and TokyoCabinet::FDB::OREADER is what you get.

width is the width of the value of each record. Undefined or โ‰ค 0 and the default kicks in โ€” that default is 255.

limsiz is the limit size of the database file. Undefined or โ‰ค 0 and the default kicks in โ€” that default is 268435456.

True on success, false otherwise. โœจ

  • untie(%hash) โ€” Untie a hash variable from the database file. The return value is always true. periodt.
  • $hash{key} = value โ€” Store a record. key is the key, and it should be more than 0. Special vibes: if it's "min", the minimum ID number of existing records is specified; if it's "prev", the number less by one than the minimum ID number of existing records is specified; if it's "max", the maximum ID number of existing records is specified; and if it's "next", the number greater by one than the maximum ID number of existing records is specified. value is, well, the value. True on success, false otherwise. And if a record with the same key already exists in the database, bestie it gets overwritten. ๐Ÿ’€
  • delete($hash{key}) โ€” Remove a record. key is the key and it should be more than 0. If it's "min", the minimum ID number of existing records is specified. If it's "max", the maximum ID number of existing records is specified. True on success, false otherwise.
  • $hash{key} โ€” Retrieve a record. key is the key and it should be more than 0. If it's "min", the minimum ID number of existing records is specified. If it's "max", the maximum ID number of existing records is specified. On success the return value is the value of the corresponding record, and undef comes back if no record corresponds. ๐Ÿฆ‹
  • exists($hash{key}) โ€” Check whether a record corrsponding a key exists. (That typo is canon, we don't fix canon. ๐Ÿซถ) key is the key and it should be more than 0. If it's "min", the minimum ID number of existing records is specified. If it's "max", the maximum ID number of existing records is specified. Returns true if the record exists, false if it doesn't.
  • $hash = () โ€” Remove all records. The return value is always undef.
  • (the iterator) โ€” The inner methods FIRSTKEY and NEXTKEY are also implemented, so you can use the tying functions each, keys, and so on. iykyk. ๐ŸŒˆ

๐Ÿ‘‘ Class TokyoCabinet::TDB ๐Ÿ‘‘

Table database is a file containing records composed of the primary keys and arbitrary columns, and it's handled with the table database API. Before you do any operations to store or retrieve records, you have to open a database file and connect the table database object to it. The method open opens a database file and the method close closes it. To avoid data missing or corruption, it is important to close every database file when it's no longer in use. And it is forbidden for multible database objects in a process to open the same database at the same time. (Again: typo is canon. ๐ŸŽ€)

  • $tdb = TokyoCabinet::TDB->new() โ€” Create a table database object. The return value is the new table database object. Fresh off the press. โœจ
  • $tdb->errmsg(ecode) โ€” Get the message string corresponding to an error code. ecode is the error code โ€” undefined or negative means the last happened error code is specified instead. The return value is the message string of the error code.
  • $tdb->ecode() โ€” Get the last happened error code. The return value is the last happened error code. Here's the full roster of defined codes, no skips: $tdb->ESUCCESS for success, $tdb->ETHREAD for threading error, $tdb->EINVALID for invalid operation, $tdb->ENOFILE for file not found, $tdb->ENOPERM for no permission, $tdb->EMETA for invalid meta data, $tdb->ERHEAD for invalid record header, $tdb->EOPEN for open error, $tdb->ECLOSE for close error, $tdb->ETRUNC for trunc error, $tdb->ESYNC for sync error, $tdb->ESTAT for stat error, $tdb->ESEEK for seek error, $tdb->EREAD for read error, $tdb->EWRITE for write error, $tdb->EMMAP for mmap error, $tdb->ELOCK for lock error, $tdb->EUNLINK for unlink error, $tdb->ERENAME for rename error, $tdb->EMKDIR for mkdir error, $tdb->ERMDIR for rmdir error, $tdb->EKEEP for existing record, $tdb->ENOREC for no record found, and $tdb->EMISC for miscellaneous error. ๐Ÿ’…
  • $tdb->tune(bnum, apow, fpow, opts) โ€” Set the tuning parameters. bnum is the number of elements of the bucket array โ€” undefined or โ‰ค 0 and you get the default, which is 131071. Suggested size of the bucket array is about from 0.5 to 4 times the number of all records to be stored. apow is the size of record alignment by power of 2 โ€” undefined or negative and the default is used, which is 4 standing for 2^4=16. fpow is the maximum number of elements of the free block pool by power of 2 โ€” undefined or negative and the default is used, which is 10 standing for 2^10=1024. opts specifies options by bitwise-or: $tdb->TLARGE means the size of the database can be larger than 2GB by using a 64-bit bucket array, $tdb->TDEFLATE means each record is compressed with Deflate encoding, $tdb->TBZIP means each record is compressed with BZIP2 encoding, and $tdb->TTCBS means each record is compressed with TCBS encoding. Leave it undefined and no option is specified. True on success, false otherwise.
Heads up bestie: the tuning parameters of the database should be set before the database is opened. Do it in the wrong order and that's on you. ๐Ÿ˜ญ
  • $tdb->setcache(rcnum, lcnum, ncnum) โ€” Set the caching parameters. rcnum is the maximum number of records to be cached โ€” undefined or โ‰ค 0 and the record cache is disabled, and it's disabled by default. lcnum is the maximum number of leaf nodes to be cached โ€” undefined or โ‰ค 0 and the default is used, which is 4096. ncnum is the maximum number of non-leaf nodes to be cached โ€” undefined or โ‰ค 0 and the default is used, which is 512. True on success, false otherwise. ๐Ÿงš
Note: the caching parameters of the database should be set before the database is opened. Like, do it first, bestie. No cap. ๐Ÿ’…

$tdb->setxmsiz(xmsiz)

Set the size of the extra mapped memory. xmsiz specifies the size of the extra mapped memory. If it is not defined or not more than 0, the extra mapped memory is disabled. The default size is 67108864.

If successful, the return value is true, else, it is false.

Note: the mapping parameters should be set before the database is opened. ๐Ÿซถ

$tdb->setdfunit(dfunit)

Set the unit step number of auto defragmentation. dfunit specifies the unit step number. If it is not more than 0, the auto defragmentation is disabled. It is disabled by default.

If successful, the return value is true, else, it is false.

Note: the defragmentation parameters should be set before the database is opened. โœจ

$tdb->open(path, omode)

Open a database file. path specifies the path of the database file.

omode specifies the connection mode: $tdb->OWRITER as a writer, $tdb->OREADER as a reader. If the mode is $tdb->OWRITER, the following may be added by bitwise-or:

  • $tdb->OCREAT โ€” creates a new database if not exist.
  • $tdb->OTRUNC โ€” creates a new database regardless if one exists.
  • $tdb->OTSYNC โ€” every transaction synchronizes updated contents with the device.

Both of $tdb->OREADER and $tdb->OWRITER can be added to by bitwise-or:

  • $tdb->ONOLCK โ€” opens the database file without file locking.
  • $tdb->OLCKNB โ€” locking is performed without blocking.

If it is not defined, $tdb->OREADER is specified.

If successful, the return value is true, else, it is false.

$tdb->close()

Close the database file. If successful, the return value is true, else, it is false.

Update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken. ๐Ÿ’€ Like, actually broken. Do not ghost your database, bestie.

$tdb->put(pkey, cols)

Store a record. pkey specifies the primary key. cols specifies the reference to a hash containing columns.

If successful, the return value is true, else, it is false.

If a record with the same key exists in the database, it is overwritten. ๐Ÿ‘‘

$tdb->putkeep(pkey, cols)

Store a new record. pkey specifies the primary key. cols specifies the reference to a hash containing columns.

If successful, the return value is true, else, it is false.

If a record with the same key exists in the database, this method has no effect. ๐Ÿ™ˆ

$tdb->putcat(pkey, cols)

Concatenate columns of the existing record. pkey specifies the primary key. cols specifies the reference to a hash containing columns.

If successful, the return value is true, else, it is false.

If there is no corresponding record, a new record is created. ๐Ÿฆ‹

$tdb->out(pkey)

Remove a record. pkey specifies the primary key.

If successful, the return value is true, else, it is false. ๐Ÿ’…

$tdb->get(pkey)

Retrieve a record. pkey specifies the primary key.

If successful, the return value is the reference to a hash of the columns of the corresponding record. undef is returned if no record corresponds. ๐Ÿ˜ญ

$tdb->vsiz(pkey)

Get the size of the value of a record. pkey specifies the primary key.

If successful, the return value is the size of the value of the corresponding record, else, it is -1. ๐Ÿ“

$tdb->iterinit()

Initialize the iterator. If successful, the return value is true, else, it is false.

The iterator is used in order to access the primary key of every record stored in a database. โœจ

$tdb->iternext()

Get the next primary key of the iterator.

If successful, the return value is the next primary key, else, it is undef. undef is returned when no record is to be get out of the iterator.

It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access. ๐ŸŒ€

$tdb->fwmkeys(prefix, max)

Get forward matching primary keys. prefix specifies the prefix of the corresponding keys. max specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.

The return value is the reference to an array of the keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.

Note: this method may be very slow because every key in the database is scanned. ๐ŸŒ

$tdb->addint(pkey, num)

Add an integer to a record. pkey specifies primary key. num specifies the additional value.

If successful, the return value is the summation value, else, it is undef.

The additional value is stored as a decimal string value of a column whose name is "_num". If no record corresponds, a new record with the additional value is stored. โž•

$tdb->adddouble(pkey, num)

Add a real number to a record. pkey specifies primary key. num specifies the additional value.

If successful, the return value is the summation value, else, it is undef.

The additional value is stored as a decimal string value of a column whose name is "_num". If no record corresponds, a new record with the additional value is stored. โž—

$tdb->sync()

Synchronize updated contents with the file and the device. If successful, the return value is true, else, it is false.

This method is useful when another process connects the same database file. ๐Ÿ”„

$tdb->optimize(bnum, apow, fpow, opts)

Optimize the database file.

bnum specifies the number of elements of the bucket array. If it is not defined or not more than 0, the default value is specified. The default value is two times of the number of records.

apow specifies the size of record alignment by power of 2. If it is not defined or negative, the current setting is not changed.

fpow specifies the maximum number of elements of the free block pool by power of 2. If it is not defined or negative, the current setting is not changed.

opts specifies options by bitwise-or:

  • $tdb->TLARGE โ€” the size of the database can be larger than 2GB by using 64-bit bucket array.
  • $tdb->TDEFLATE โ€” each record is compressed with Deflate encoding.
  • $tdb->TBZIP โ€” each record is compressed with BZIP2 encoding.
  • $tdb->TTCBS โ€” each record is compressed with TCBS encoding.

If it is not defined or 0xff, the current setting is not changed.

If successful, the return value is true, else, it is false.

This method is useful to reduce the size of the database file with data fragmentation by successive updating. ๐Ÿงน

$tdb->vanish()

Remove all records. If successful, the return value is true, else, it is false. ๐Ÿ’จ

$tdb->copy(path)

Copy the database file. path specifies the path of the destination file. If it begins with @, the trailing substring is executed as a command line.

If successful, the return value is true, else, it is false. false is returned if the executed command returns non-zero code.

The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file. ๐Ÿ’พ

$tdb->tranbegin()

Begin the transaction. If successful, the return value is true, else, it is false.

The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly. ๐Ÿ”’

$tdb->trancommit()

Commit the transaction. If successful, the return value is true, else, it is false.

Update in the transaction is fixed when it is committed successfully. โœ…

$tdb->tranabort()

Abort the transaction. If successful, the return value is true, else, it is false.

Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction. โ†ฉ๏ธ

$tdb->path()

Get the path of the database file. The return value is the path of the database file or undef if the object does not connect to any database file. ๐Ÿ“‚

$tdb->rnum()

Get the number of records. The return value is the number of records or 0 if the object does not connect to any database file. ๐Ÿ”ข

$tdb->fsiz()

Get the size of the database file. The return value is the size of the database file or 0 if the object does not connect to any database file. ๐Ÿ“ฆ

$tdb->setindex(name, type)

Set a column index. name specifies the name of a column. If the name of an existing index is specified, the index is rebuilt. An empty string means the primary key.

type specifies the index type:

  • $tdb->ITLEXICAL โ€” for lexical string.
  • $tdb->ITDECIMAL โ€” for decimal string.
  • $tdb->ITTOKEN โ€” for token inverted index.
  • $tdb->ITQGRAM โ€” for q-gram inverted index.

If it is $tdb->ITOPT, the index is optimized. If it is $tdb->ITVOID, the index is removed. If $tdb->ITKEEP is added by bitwise-or and the index exists, this method merely returns failure.

If successful, the return value is true, else, it is false. ๐Ÿ—‚๏ธ

$tdb->genuid()

Generate a unique ID number. The return value is the new unique ID number or -1 on failure. ๐Ÿ†”

Class TokyoCabinet::TDBQRY

$qry = TokyoCabinet::TDBQRY->new(tdb)

Create a query object. tdb specifies the table database object.

The return value is the new query object. ๐ŸŽ€

$qry->addcond(name, op, expr)

Add a narrowing condition.

name is the name of a column, bestie โ€” and an empty string means the primary key. ๐Ÿ’…

op is the operation type, and there are a lot of them, so buckle up:

  • $qry->QCSTREQ โ€” string that's equal to the expression
  • $qry->QCSTRINC โ€” string that's included in the expression
  • $qry->QCSTRBW โ€” string that begins with the expression
  • $qry->QCSTREW โ€” string that ends with the expression
  • $qry->QCSTRAND โ€” string that includes all tokens in the expression
  • $qry->QCSTROR โ€” string that includes at least one token in the expression
  • $qry->QCSTROREQ โ€” string that's equal to at least one token in the expression
  • $qry->QCSTRRX โ€” string that matches regular expressions of the expression
  • $qry->QCNUMEQ โ€” number equal to the expression
  • $qry->QCNUMGT โ€” number greater than the expression
  • $qry->QCNUMGE โ€” number greater than or equal to the expression
  • $qry->QCNUMLT โ€” number less than the expression
  • $qry->QCNUMLE โ€” number less than or equal to the expression
  • $qry->QCNUMBT โ€” number between two tokens of the expression
  • $qry->QCNUMOREQ โ€” number equal to at least one token in the expression
  • $qry->QCFTSPH โ€” full-text search with the phrase of the expression
  • $qry->QCFTSAND โ€” full-text search with all tokens in the expression
  • $qry->QCFTSOR โ€” full-text search with at least one token in the expression
  • $qry->QCFTSEX โ€” full-text search with the compound expression

And every single one of those operations can be flagged by bitwise-or:

  • $qry->QCNEGATE โ€” negation
  • $qry->QCNOIDX โ€” using no index

expr is the operand expression. ๐Ÿ“

The return value is always undef. no cap.


$qry->setorder(name, type)

Sets the order of the result. So iconic of it.

name is the name of a column. An empty string means the primary key. ๐Ÿ”‘

type is the order type:

  • $qry->QOSTRASC โ€” string ascending
  • $qry->QOSTRDESC โ€” string descending
  • $qry->QONUMASC โ€” number ascending
  • $qry->QONUMDESC โ€” number descending

If it's not defined, $qry->QOSTRASC is what you get. ๐Ÿ’ซ

The return value is always undef.


$qry->setlimit(max, skip)

Sets the max number of records in the result. Very "we're not doing all of it" of you.

max is the maximum number of records of the result. If it's not defined or negative, no limit is specified. โœจ

skip is the number of skipped records of the result. If it's not defined or not more than 0, no record is skipped.

The return value is always undef.


Executes the search. Go off. ๐Ÿ”ฅ

The return value is the reference to an array of the primary keys of the corresponding records. This method does never fail โ€” she's built different. It returns an empty array even if no record corresponds.


$qry->searchout()

Removes each corresponding record. ๐Ÿ’€

If successful, the return value is true, else, it is false.


$qry->proc(proc)

Processes each corresponding record, one by one, main character energy.

proc is the iterator function called for each record. It can be either the reference of a block or the name of a function. The function receives two parameters: the first parameter is the primary key, and the second parameter is the reference to a hash containing columns. ๐Ÿซถ

It returns flags of the post treatment by bitwise-or:

  • $qry->QPPUT โ€” to modify the record
  • $qry->QPOUT โ€” to remove the record
  • $qry->QPSTOP โ€” to stop the iteration

If successful, the return value is true, else, it is false.


$qry->hint()

Gets the hint string.

The return value is the hint string. That's it, that's the whole method. ๐ŸŽ€


$qry->metasearch(others, type)

Retrieves records with multiple query objects and gets the set of the result. Group project, but make it databases. ๐ŸŒˆ

others is the reference to an array of the query objects except for the self object.

type is a set operation type:

  • $qry->MSUNION โ€” the union set
  • $qry->MSISECT โ€” the intersection set
  • $qry->MSDIFF โ€” the difference set

If it's not defined, $qry->MSUNION is specified.

The return value is the reference to an array of the primary keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.

Also, if the first query object has the order setting, the result array is sorted by the order. periodt.


$qry->kwic(cols, name, width, opts)

Generates keyword-in-context strings. Very scholarly of her, honestly. ๐Ÿงš

cols is the reference to a hash containing columns.

name is the name of a column. If it's not defined, the first column of the query is specified.

width is the width of strings picked up around each keyword. If it's not defined or negative, the whole text is picked up.

opts specifies options by bitwise-or:

  • $qry->KWMUTAB โ€” each keyword is marked up between two tab characters
  • $qry->KWMUCTRL โ€” each keyword is marked up by the STX (0x02) code and the ETX (0x03) code
  • $qry->KWMUBRCT โ€” each keyword is marked up by the two square brackets
  • $qry->KWNOOVER โ€” each context does not overlap
  • $qry->KWPULEAD โ€” the lead string is picked up forcibly

If it's not defined, no option is specified.

The return value is the reference to an array of strings around keywords. โœจ


๐Ÿฆ‹ Tying functions of TokyoCabinet::TDB ๐Ÿฆ‹

tie(%hash, "TokyoCabinet::TDB", path, omode, bnum, apow, fpow, opts, rcnum, lcnum, ncnum)

Ties a hash variable to a table database file. Yes bestie, your hash is the database now. ๐Ÿ’œ

path is the path of the database file.

omode is the connection mode:

  • TokyoCabinet::TDB::OWRITER โ€” as a writer
  • TokyoCabinet::TDB::OREADER โ€” as a reader

If the mode is TokyoCabinet::TDB::OWRITER, the following may be added by bitwise-or:

  • TokyoCabinet::TDB::OCREAT โ€” creates a new database if not exist
  • TokyoCabinet::TDB::OTRUNC โ€” creates a new database regardless if one exists
  • TokyoCabinet::TDB::OTSYNC โ€” every transaction synchronizes updated contents with the device

Both TokyoCabinet::TDB::OREADER and TokyoCabinet::TDB::OWRITER can be added to by bitwise-or:

  • TokyoCabinet::TDB::ONOLCK โ€” opens the database file without file locking
  • TokyoCabinet::TDB::OLCKNB โ€” locking is performed without blocking

If it's not defined, TokyoCabinet::TDB::OREADER is specified.

bnum is the number of elements of the bucket array. If it's not defined or not more than 0, the default value is specified. The default value is 131071. Suggested size of the bucket array is about from 0.5 to 4 times of the number of all records to be stored. ๐Ÿ“

apow is the size of record alignment by power of 2. If it's not defined or negative, the default value is specified. The default value is 4 standing for 2^4=16.

fpow is the maximum number of elements of the free block pool by power of 2. If it's not defined or negative, the default value is specified. The default value is 10 standing for 2^10=1024.

opts specifies options by bitwise-or:

  • TokyoCabinet::TDB::TLARGE โ€” the size of the database can be larger than 2GB by using 64-bit bucket array
  • TokyoCabinet::TDB::TDEFLATE โ€” each record is compressed with Deflate encoding
  • TokyoCabinet::TDB::TBZIP โ€” each record is compressed with BZIP2 encoding
  • TokyoCabinet::TDB::TTCBS โ€” each record is compressed with TCBS encoding

If it's not defined, no option is specified.

rcnum is the maximum number of records to be cached. If it's not defined or not more than 0, the record cache is disabled. It is disabled by default.

lcnum is the maximum number of leaf nodes to be cached. If it's not defined or not more than 0, the default value is specified. The default value is 2048.

ncnum is the maximum number of non-leaf nodes to be cached. If it's not defined or not more than 0, the default value is specified. The default value is 512.

If successful, the return value is true, else, it is false.


untie(%hash)

Unties a hash variable from the database file. Sad girl breakup era ๐Ÿ˜ญ

The return value is always true.


$hash{pkey} = cols

Stores a record.

pkey is the primary key. ๐Ÿ”‘

cols is the reference to a hash containing columns.

If successful, the return value is true, else, it is false.

If a record with the same key exists in the database, it is overwritten. periodt.


delete($hash{pkey})

Removes a record. ๐Ÿ’€

pkey is the primary key.

If successful, the return value is true, else, it is false.


$hash{pkey}

Retrieves a record.

pkey is the primary key.

If successful, the return value is the reference to a hash of the columns of the corresponding record. undef is returned if no record corresponds. ๐Ÿ™ˆ


exists($hash{pkey})

Checks whether a record corresponding a key exists. (Yes, the original says "corrsponding" โ€” we don't fix typos in the manpage, we simply vibe with them. ๐Ÿ’…)

pkey is the primary key.

The return value is true if the record exists, else it is false.


$hash = ()

Removes all records. Full reset, no notes. ๐Ÿงน

The return value is always undef.


(the iterator)

The inner methods FIRSTKEY and NEXTKEY are also implemented so that you can use the tying functions each, keys, and so on. ๐ŸŒธ


๐Ÿ‘‘ Class TokyoCabinet::ADB ๐Ÿ‘‘

Abstract database is a set of interfaces to use on-memory hash database, on-memory tree database, hash database, B+ tree database, fixed-length database, and table database with the same API. One interface, six databases, versatility slay. โœจ

Before operations to store or retrieve records, it is necessary to connect the abstract database object to the concrete one. The method open is used to open a concrete database and the method close is used to close the database.

To avoid data missing or corruption, it is important to close every database instance when it is no longer in use. It is forbidden for multible database objects in a process to open the same database at the same time. ๐Ÿšจ (Yes, "multible" โ€” again, verbatim, don't come for me.)

$adb = TokyoCabinet::ADB->new()

Creates an abstract database object.

The return value is the new abstract database object. ๐ŸŽ€


$adb->open(name)

Opens a database.

okay so back to name, bestie, because this one carries the whole vibe of your database ๐Ÿ’…

name is literally the name of the database. And the suffix is doing so much work here:

  • if it's "*", congrats, you get an on-memory hash database โœจ
  • if it's "+", it's an on-memory tree database ๐ŸŒธ
  • if its suffix is ".tch", you get a hash database
  • if its suffix is ".tcb", it's a B+ tree database
  • if its suffix is ".tcf", it's a fixed-length database
  • if its suffix is ".tct", it's a table database
  • anything else? this method just fails, no cap ๐Ÿ˜ญ

And you can trail tuning parameters after the name, separated by "#". Each parameter is the name and the value, separated by "=". Which ones are supported depends on the database type, and it's giving very specific:

  • On-memory hash database supports "bnum", "capnum", and "capsiz".
  • On-memory tree database supports "capnum" and "capsiz".
  • Hash database supports "mode", "bnum", "apow", "fpow", "opts", "rcnum", and "xmsiz".
  • B+ tree database supports "mode", "lmemb", "nmemb", "bnum", "apow", "fpow", "opts", "lcnum", "ncnum", and "xmsiz".
  • Fixed-length database supports "mode", "width", and "limsiz".
  • Table database supports "mode", "bnum", "apow", "fpow", "opts", "rcnum", "lcnum", "ncnum", "xmsiz", and "idx".

If it works, the return value is true, else it's false.

Now the tuning parameters themselves, since they're iconic and you need to know them:

  • "capnum" โ€” the capacity number of records. That's the count, bestie.
  • "capsiz" โ€” the capacity size of using memory. That's the memory budget.
  • Records that spill the capacity get removed, in the storing order. Not a drill ๐Ÿ’€
  • "mode" can contain "w" of writer, "r" of reader, "c" of creating, "t" of truncating, "e" of no locking, and "f" of non-blocking lock. The default mode is relevant to "wc".
  • "opts" can contain "l" of large option, "d" of Deflate option, "b" of BZIP2 option, and "t" of TCBS option.
  • "idx" specifies the column name of an index and its type, separated by ":".

Like, example time, because it's giving:

"casket.tch#bnum=1000000#opts=ld"

That means the name of the database file is "casket.tch", the bucket number is 1000000, and the options are large and Deflate. Obsessed actually ๐ŸŽ€


๐Ÿ’– $adb->close() ๐Ÿ’–

Close the database. Bye bestie ๐Ÿ‘‹

If it works, the return value is true, else it's false.

real talk: update of a database is assured to be written when the database is closed. If a writer opens a database but does not close it appropriately, the database will be broken. That's not a vibe, that's a warning. Close your databases, queen ๐Ÿซถ

โœจ $adb->put(key, value) โœจ

Store a record. The main character move ๐Ÿ’…

key specifies the key.

value specifies the value.

If it works, the return value is true, else it's false.

If a record with the same key already exists in the database, it gets overwritten. No mercy, no hesitation.


๐Ÿฆ‹ $adb->putkeep(key, value) ๐Ÿฆ‹

Store a new record. Like put but shyer ๐Ÿ™ˆ

key specifies the key.

value specifies the value.

If it works, the return value is true, else it's false.

If a record with the same key already exists in the database, this method has no effect. It's not gonna fight the existing record, it's just gonna stand there.


๐ŸŒธ $adb->putcat(key, value) ๐ŸŒธ

Concatenate a value at the end of the existing record. String growth arc โœจ

key specifies the key.

value specifies the value.

If it works, the return value is true, else it's false.

If there is no corresponding record, a new record is created. It's flexible like that.


๐Ÿ’€ $adb->out(key) ๐Ÿ’€

Remove a record. Gone, reduced to atoms.

key specifies the key.

If it works, the return value is true, else it's false.


๐Ÿ”ฅ $adb->get(key) ๐Ÿ”ฅ

Retrieve a record. The payoff, the moment we've all been waiting for ๐Ÿ‘‘

key specifies the key.

If it works, the return value is the value of the corresponding record. undef is returned if no record corresponds.


๐ŸŽ€ $adb->vsiz(key) ๐ŸŽ€

Get the size of the value of a record.

key specifies the key.

If it works, the return value is the size of the value of the corresponding record, else it's -1.


๐ŸŒˆ $adb->iterinit() ๐ŸŒˆ

Initialize the iterator. Setting the stage ๐Ÿ’…

If it works, the return value is true, else it's false.

The iterator is used in order to access the key of every record stored in a database. All of them. Periodt.


โญ $adb->iternext() โญ

Get the next key of the iterator. Keep it moving, bestie.

If it works, the return value is the next key, else it's undef. undef is returned when no record is to be get out of the iterator. That's the lil "we're done here" signal ๐Ÿซถ

It is possible to access every record by iteration of calling this method. It is allowed to update or remove records whose keys are fetched while the iteration. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access. So like, don't count on it being in order, iykyk ๐Ÿ˜ญ


๐Ÿงš $adb->fwmkeys(prefix, max) ๐Ÿงš

Get forward matching keys.

prefix specifies the prefix of the corresponding keys.

max specifies the maximum number of keys to be fetched. If it is not defined or negative, no limit is specified.

The return value is the reference to an array of the keys of the corresponding records. This method does never fail. It returns an empty array even if no record corresponds.

heads up bestie: this method may be very slow because every key in the database is scanned. Like, every single one. It's giving O(n) and not in a cute way ๐Ÿ’€

๐Ÿ’œ $adb->addint(key, num) ๐Ÿ’œ

Add an integer to a record. Math era โœจ

key specifies the key.

num specifies the additional value.

If it works, the return value is the summation value, else it's undef.

If the corresponding record exists, the value is treated as an integer and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the unpack function with the i operator after retrieval. Don't forget that part, it'll bite you ๐Ÿซถ


๐Ÿ’– $adb->adddouble(key, num) ๐Ÿ’–

Add a real number to a record. Floaties, but make it data ๐Ÿ’…

key specifies the key.

num specifies the additional value.

If it works, the return value is the summation value, else it's undef.

If the corresponding record exists, the value is treated as a real number and is added to. If no record corresponds, a new record of the additional value is stored. Because records are stored in binary format, they should be processed with the unpack function with the d operator after retrieval. Note it's d this time, not i. Don't mix them up bestie ๐Ÿ˜ญ


๐ŸŽ€ $adb->sync() ๐ŸŽ€

Synchronize updated contents with the file and the device. Flush it, girl.

If it works, the return value is true, else it's false.


๐Ÿ‘‘ $adb->optimize(params) ๐Ÿ‘‘

Optimize the storage. Glow up for your database โœจ

params specifies the string of the tuning parameters, which works as with the tuning of parameters the method open. If it is not defined, it is not used.

If it works, the return value is true, else it's false.


๐ŸŒธ $adb->vanish() ๐ŸŒธ

Remove all records. Everything. Poof. Clean slate energy ๐Ÿฆ‹

If it works, the return value is true, else it's false.


๐Ÿฆ‹ $adb->copy(path) ๐Ÿฆ‹

Copy the database file. Backup arc, we love to see it ๐Ÿ’–

path specifies the path of the destination file. If it begins with @, the trailing substring is executed as a command line.

If it works, the return value is true, else it's false. False is returned if the executed command returns non-zero code.

The database file is assured to be kept synchronized and not modified while the copying or executing operation is in progress. So, this method is useful to create a backup file of the database file. Iconic, honestly ๐Ÿซถ


๐Ÿ’œ $adb->tranbegin() ๐Ÿ’œ

Begin the transaction. The saga starts here ๐Ÿ‘‘

If it works, the return value is true, else it's false.

The database is locked by the thread while the transaction so that only one transaction can be activated with a database object at the same time. Thus, the serializable isolation level is assumed if every database operation is performed in the transaction. All updated regions are kept track of by write ahead logging while the transaction. If the database is closed during transaction, the transaction is aborted implicitly. So close carefully, bestie ๐Ÿ˜ญ


โœจ $adb->trancommit() โœจ

Commit the transaction. Make it official ๐Ÿ’…

If it works, the return value is true, else it's false.

Update in the transaction is fixed when it is committed successfully.


๐Ÿ’€ $adb->tranabort() ๐Ÿ’€

Abort the transaction. Nvm, forget I said anything ๐Ÿ™ˆ

If it works, the return value is true, else it's false.

Update in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction. We love a rewind.


๐ŸŒˆ $adb->path() ๐ŸŒˆ

Get the path of the database file.

The return value is the path of the database file or undef if the object does not connect to any database instance. "*" stands for on-memory hash database. "+" stands for on-memory tree database.


โญ $adb->rnum() โญ

Get the number of records.

The return value is the number of records or 0 if the object does not connect to any database instance.


๐Ÿงš $adb->size() ๐Ÿงš

Get the size of the database.

The return value is the size of the database file or 0 if the object does not connect to any database instance.


๐Ÿ’… $adb->misc(name, args) ๐Ÿ’…

Call a versatile function for miscellaneous operations. The wildcard method, it does whatever ๐ŸŽ€

name specifies the name of the function.

args specifies the reference to an array of arguments. If it is not defined, no argument is specified.

If it works, the return value is the reference to an array of the result. undef is returned on failure.


๐Ÿซถ Tying functions of TokyoCabinet::ADB ๐Ÿซถ

๐Ÿ’– tie(%hash, "TokyoCabinet::ADB", name) ๐Ÿ’–

Tie a hash variable to an abstract database instance. Yes, like actual Perl magic, it's giving โœจ

name specifies the name of the database. And it's the exact same rules as before, so here we go again bestie:

  • if it's "*", the database will be an on-memory hash database
  • if it's "+", the database will be an on-memory tree database
  • if its suffix is ".tch", the database will be a hash database
  • if its suffix is ".tcb", the database will be a B+ tree database
  • if its suffix is ".tcf", the database will be a fixed-length database
  • if its suffix is ".tct", the database will be a table database
  • otherwise, this method fails ๐Ÿ˜ญ

Tuning parameters can trail the name, separated by "#". Each parameter is composed of the name and the value, separated by "=". On-memory hash database supports "bnum", "capnum", and "capsiz". On-memory tree database supports "capnum" and "capsiz". Hash database supports "mode", "bnum", "apow", "fpow", "opts", "rcnum", and "xmsiz". B+ tree database supports "mode", "lmemb", "nmemb", "bnum", "apow", "fpow", "opts", "lcnum", "ncnum", and "xmsiz". Fixed-length database supports "mode", "width", and "limsiz". Table database supports "mode", "bnum", "apow", "fpow", "opts", "rcnum", "lcnum", "ncnum", "xmsiz", and "idx".

If it works, the return value is true, else it's false.

๐ŸŒธ untie(%hash) ๐ŸŒธ

untie ๐Ÿ’ซ

Unhooks your hash from the database, bestie. That's it, that's the whole thing. The return value is always true โ€” no drama, no false alarms. ๐Ÿซถ


$hash{key} = value โ€” the store era ๐Ÿ›๏ธ

Drops a record into the database.

  • key is, yeah, the key. ๐Ÿ”‘
  • value is the value.

If it works out, you get a true back. If not, false. ๐Ÿ˜ญ And heads up: if a record with that same key is already sitting in the database, it gets overwritten โ€” no merge, no warning, just gone-gone. ๐Ÿ’€


delete($hash{key}) โ€” yeet a record ๐Ÿ—‘๏ธ

Removes a record from the database.

  • key specifies the key, as per usual.

True if it worked, false if it didn't. Simple as. โœจ


$hash{key} โ€” the retrieval โœจ

Grabs a record back out.

  • key specifies the key. You know the drill.

If it goes well, you get the value of the corresponding record. And if there's no record matching that key? You get undef. No record, no vibes. ๐Ÿ™ˆ


exists($hash{key}) โ€” the vibe check ๐Ÿ‘€

Asks the database: does a record corresponding to this key even exist?

  • key specifies the key.

True if the record exists, false if it doesn't. That's the whole check. ๐Ÿ’…


$hash = () โ€” clear it ALL out ๐Ÿงน

Removes every single record. Not a few. All of them.

The return value is always undef โ€” don't be out here checking it like it's a success flag, it is not, it is undef, periodt. ๐Ÿ˜ญ


(the iterator) ๐Ÿ”„

The inner methods FIRSTKEY and NEXTKEY are also implemented, so you can use the tying functions each, keys, and so on. So like โ€” go off, iterate through everything, the plumbing is already there. ๐Ÿ‘‘


Copyright (C) 2006-2010 FAL Labs
All rights reserved.

Tokyo Cabinet is free software โ€” you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License or any later version. Pick whichever, we're flexible. ๐ŸŒˆ

Tokyo Cabinet is distributed in the hope that it will be useful, but โ€” and this is important, bestie, read it twice โ€” WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. So if it breaks, that's on the vibes, not on anyone's legal team. ๐Ÿ’€

Want the deets? See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Tokyo Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. Real address, real stamp, real envelope energy. ๐Ÿ“ฌ


and that's a wrap on the whole page, gorgeous ๐ŸŽ€ this little masterpiece was cooked up by perl v5.34.0, dated 2022-02-06, and it lives at TokyoCabinet(3pm). go forth and tie your hashes. no cap. ๐Ÿ’–โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from