Changeset 34 in mp3-find for trunk


Ignore:
Timestamp:
05/22/06 18:25:32 (19 years ago)
Author:
peter
Message:
  • added tests for the new database methods
  • updated docs for DB.pm
  • added new test file to the MANIFEST
  • updated public changelog (Changes)
Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changes

    r25 r34  
    11Revision history for Perl extension MP3::Find. 
     2 
     30.06 
     4    - deprecated the create_db, update_db, and sync_db methods 
     5    - databases can be selected by a custom DSN or an already open database handle 
    26 
    370.05 28 Apr 2006 
  • trunk/MANIFEST

    r18 r34  
    66t/02-filesystem.t 
    77t/03-db.t 
     8t/04-new-db.t 
    89t/mp3s/not-an-mp3 
    910t/mp3s/dont_look_here/testv2.4.0.mp3 
  • trunk/lib/MP3/Find/DB.pm

    r33 r34  
    7272     
    7373    # create another database 
    74     $finder->create_db('my_mp3s.db'); 
    75      
    76     # update the database from the filesystem 
    77     $finder->update_db('my_mp3s.db', ['/home/peter/mp3', '/home/peter/cds']); 
     74    $finder->create({ db_file => 'my_mp3s.db' }); 
     75     
     76    # update the database by searching the filesystem 
     77    $finder->update({ 
     78        db_file => 'my_mp3s.db', 
     79        dirs => ['/home/peter/mp3', '/home/peter/cds'], 
     80    }); 
     81 
     82    # or just update specific mp3s 
     83    $finder->update({ 
     84        db_file => 'my_mp3s.db', 
     85        files => \@filenames, 
     86    }); 
    7887     
    7988    # and then blow it away 
     
    8695=head1 DESCRIPTION 
    8796 
    88 This is the SQLite database backend for L<MP3::Find>. 
    89  
    90 B<Note:> I'm still working out some kinks in here, so this backend 
    91 is currently not as stable as the Filesystem backend. 
    92  
    93 =head2 Special Options 
    94  
    95 =over 
    96  
    97 =item C<db_file> 
    98  
    99 The name of the SQLite database file to use. Defaults to F<~/mp3.db>. 
    100  
    101 The database should have at least one table named C<mp3> with the 
    102 following schema: 
     97This is the database backend for L<MP3::Find>. The easiest way to 
     98use it is with a SQLite database, but you can also pass in your own 
     99DSN or database handle. 
     100 
     101The database you use should have at least one table named C<mp3> with  
     102the following schema: 
    103103 
    104104    CREATE TABLE mp3 ( 
     
    133133    ); 
    134134 
     135B<Note:> I'm still working out some kinks in here, so this backend 
     136is currently not as stable as the Filesystem backend. Expect API 
     137fluctuations for now. 
     138 
     139B<Deprecated Methods:> C<create_db>, C<update_db>, and C<sync_db> 
     140have been deprectaed in this release, and will be removed in a future 
     141release. PLease switch to the new methods C<create>, C<update>, and 
     142C<sync>. 
     143 
     144=head2 Special Options 
     145 
     146When using this backend, provide one of the following additional options 
     147to the C<search> method: 
     148 
     149=over 
     150 
     151=item C<dsn>, C<username>, C<password> 
     152 
     153A custom DSN and (optional) username and password. This gets passed 
     154to the C<connect> method of L<DBI>. 
     155 
     156=item C<dbh> 
     157 
     158An already created L<DBI> database handle object. 
     159 
     160=item C<db_file> 
     161 
     162The name of the SQLite database file to use. 
     163 
    135164=back 
    136165 
    137166=cut 
    138167 
     168# get a database handle from named arguments 
    139169sub _get_dbh { 
    140170    my $args = shift; 
     171 
     172    # we got an explicit $dbh object 
    141173    return $args->{dbh} if defined $args->{dbh}; 
     174 
     175    # or a custom DSN 
    142176    if (defined $args->{dsn}) { 
    143177        my $dbh = DBI->connect( 
     
    149183        return $dbh; 
    150184    } 
     185     
    151186    # default to a SQLite database 
    152187    if (defined $args->{db_file}) { 
     
    159194        return $dbh; 
    160195    } 
     196 
    161197    return; 
    162198} 
     
    182218 
    183219The C<status_callback> gets called each time an entry in the 
    184 database is added, updated, or deleted by the C<update_db> and 
    185 C<sync_db> methods. The arguments passed to the callback are 
     220database is added, updated, or deleted by the C<update> and 
     221C<sync> methods. The arguments passed to the callback are 
    186222a status code (A, U, or D) and the filename for that entry. 
    187223The default callback just prints these to C<STDERR>: 
     
    224260    $finder->create_db($db_filename); 
    225261 
    226 Creates a SQLite database in the file named c<$db_filename>. 
     262Creates a SQLite database in the file named C<$db_filename>. 
    227263 
    228264=cut 
     
    530566=head1 TODO 
    531567 
    532 Database maintanence routines (e.g. clear out old entries) 
    533  
    534 Allow the passing of a DSN or an already created C<$dbh> instead 
    535 of a SQLite database filename; or write driver classes to handle 
    536 database dependent tasks (create_db/destroy_db). 
     568Store/search ID3v2 tags 
     569 
     570Driver classes to handle database dependent tasks? 
    537571 
    538572=head1 SEE ALSO 
Note: See TracChangeset for help on using the changeset viewer.