LibreCat / Catmandu-DBI

A Catmandu::Store plugin for DBI based interfaces
Other
0 stars 1 forks source link

Support a basic search on mapped fields #14

Closed phochste closed 7 years ago

phochste commented 7 years ago

If I have a store like:

my $store = Catmandu::Store::DBI->new(
    data_source => 'DBI:mysql:database=test',
    bags => {
        # books table
        books => {
            mapping => {
                # these keys will be directly mapped to columns
                # all other keys will be serialized in the data column
                title => {type => 'string', required => 1, column => 'book_title'},
                isbn => {type => 'string', unique => 1},
                authors => {type => 'string', array => 1}
            }
        }
    }
);

I would like to do a :

my $hits = $store->bags('books')->search("title = 'DNA'");

This documentation mentions a reference to Catmandu::Searchable anyway.

nicolasfranck commented 7 years ago

That's already possible using the "select" syntax:

my $selector = $bag->select( title => "DNA" );
my $total = $selector->count();
my $hits = $selector->slice(0,100);

Catmandu::Store::DBI::Bag overrides the method "select":

vpeil commented 7 years ago

should be included in POD, if not already there!

phochste commented 7 years ago

The POD is confusing. This is option is not described and even there is a suggestion in the POD that this store is a Catmandu::Searchable,

nicolasfranck commented 7 years ago

It isn't a Catmandu::Searchable. Those require a method "search". It just has an speed enhancement for the method "select". But you're right, it should be documented that you can use the "select" method safely without worrying about Catmandu iterating over the whole bag.

phochste commented 7 years ago

@nicolasfranck I know it isn't Catmandu::Searchable by reading the code. But the documentation mentions Catmandu::Searchable. Could you delete this ..this is very confusing.

nicolasfranck commented 7 years ago

I've added some documentation in this branch:

https://github.com/LibreCat/Catmandu-DBI/blob/document_iterator/lib/Catmandu/Store/DBI/Bag.pm

Does this provide enough information?