Boulder::Store(3pm) | User Contributed Perl Documentation | Boulder::Store(3pm) |
Boulder::Store - Simple persistent storage for Stone tag/value objects
Boulder:Store; my $store=new Boulder::Store('test.db',1); my $s = new Stone (Name=>'george', Age=>23, Sex=>M, Address=>{ Street=>'29 Rockland drive', Town=>'Fort Washington', ZIP=>'77777' } ); $store->put($s); $store->put(new Stone(Name=>'fred', Age=>30, Sex=>M, Address=>{ Street=>'19 Gravel Path', Town=>'Bedrock', ZIP=>'12345'}, Phone=>{ Day=>'111-1111', Eve=>'222-2222' } )); $store->put(new Stone(Name=>'andrew', Age=>18, Sex=>M)); $store->add_index('Name'); my $stone = $store->get(0); print "name = ",$stone->Name;
Boulder::Store provides persistent storage for Boulder objects using a simple DB_File implementation. To use it, you need to have Berkeley db installed (also known as libdb), and the Perl DB_File module. See the DB_File package for more details on obtaining Berkeley db if you do not already have it.
Boulder::Store provides an unsophisticated query mechanism which takes advantage of indexes that you specify. Despite its lack of sophistication, the query system is often very helpful.
Because the underlying storage implementation is not multi-user, only one process can have the database for writing at a time. A fcntl()-based locking mechanism is used to give a process that has the database opened for writing exclusive access to the database. This also prevents the database from being opened for reading while another process is writing to it (this is a good thing). Multiple simultaneous processes can open the database read only.
Physically the data is stored in a human-readable file with the extension ".data".
If called in an array context, read_record() returns a list of all stones in the database that contains one or more of the provided tags.
If no record number is provided, this call will look for the presence of a 'record_no' tag in the stone itself and put it back in that position. This allows you to pull a stone out of the database, modify it, and then put it back in without worrying about its record number. If no record is found in the stone, then the effect is identical to write_record().
The record number of the inserted stone is returned from this call, or -1 if an error occurred.
$db->query('STS.left_primer.length'=>30);
Only the non-bracketed forms of the index string are allowed (this is probably a bug...)
If the tag path was declared to be an index, then this search will be fast. Otherwise Boulder::Store must iterate over every record in the database.
You can mix query types in the parameter provided to query(). For example, here's how to look up all stones in which the sex is male and the age is greater than 30:
$db->query('sex'=>'M',EVAL=>'<age> > 30');
When a query is in effect, read_record() returns only Stones that satisfy the query. In an array context, read_record() returns a list of all Stones that satisfy the query. When no more satisfactory Stones are found, read_record() returns undef until a new query is entered or reset() is called.
$db->add_index('age','sex','person.pets');
You can add indexes any time you like, when the database is first created or later. There is a trade off: write_record(), put(), and other data-modifying calls will become slower as more indexes are added.
The index is stored in an external file with the extension ".index". An index file is created even if you haven't indexed any tags.
Boulder::Store makes heavy use of the flock() call in order to avoid corruption of DB_File databases when multiple processes try to write simultaneously. flock() may not work correctly across NFS mounts, particularly on Linux machines that are not running the rpc.lockd daemon. Please confirm that your flock() works across NFS before attempting to use Boulder::Store. If the store.t test hangs during testing, this is the likely culprit.
Lincoln D. Stein <lstein@cshl.org>, Cold Spring Harbor Laboratory, Cold Spring Harbor, NY. This module can be used and distributed on the same terms as Perl itself.
Boulder, Boulder::Stream, Stone
2022-06-08 | perl v5.34.0 |