| Catmandu::Store(3pm) | User Contributed Perl Documentation | Catmandu::Store(3pm) |
Catmandu::Store - Namespace for packages that can make data persistent
# From the command line
$ catmandu import JSON into MongoDB --database_name 'bibliography' < data.json
$ catmandu export MongoDB --database_name 'bibliography' to YAML
$ catmandu export MongoDB --database_name 'bibliography' --query '{"PublicationYear": "1937"}'
$ catmandu count MongoDB --database_name 'bibliography' --query '{"PublicationYear": "1937"}'
# From Perl
use Catmandu;
my $store = Catmandu->store('MongoDB',database_name => 'bibliography');
my $obj1 = $store->bag->add({ name => 'Patrick' });
printf "obj1 stored as %s\n" , $obj1->{_id};
# Force an id in the store
my $obj2 = $store->bag->add({ _id => 'test123' , name => 'Nicolas' });
my $obj3 = $store->bag->get('test123');
$store->bag->delete('test123');
$store->bag->delete_all;
# Some stores can be searched
my $hits = $store->bag->search(query => 'name:Patrick');
A Catmandu::Store is a stub for Perl packages that can store data into databases or search engines. The database as a whole is called a 'store'. Databases also have compartments (e.g. tables) called Catmandu::Bag-s. Some stores can be searched using Catmandu::Searchable methods.
my $store = Catmandu::Store::MyDB->new(default_plugins => ['Datestamps']);
my $store = Catmandu::Store::MyDB->new(default_bag => 'stuff');
# this will return the stuff bag
my $bag = $store->bag;
my $store = Catmandu::Store::Hash->new(
bags => {stuff => {plugins => ['Datestamps']}});
# this bag will use the L<Catmandu::Plugin::Datestamps> role
$store->bag('stuff')
# this bag won't
$store->bag('otherbag')
# this will use the Catmandu::Store::MyDB::Bag class for bags
Catmandu::Store::MyDB->new()
# this will use MyBag
Catmandu::Store::MyDB->new(bag_class => 'MyBag')
# this store will use the my_id key to hold id's
Catmandu::Store::MyDB->new(key_prefix => 'my_')
Create or retieve a bag with name $name. Returns a Catmandu::Bag.
Helper method that applies "key_prefix" to the $key given.
Return the current logger. Can be used when creating your own Stores.
E.g.
package Catmandu::Store::Hash;
...
sub generator {
my ($self) = @_;
$self->log->debug("generating record");
...
}
See also: Catmandu for activating the logger in your main code.
Catmandu::Bag, Catmandu::Searchable
| 2019-01-29 | perl v5.28.1 |