Changeset 15 in bookmarks for trunk/bkmk


Ignore:
Timestamp:
02/09/13 21:02:43 (12 years ago)
Author:
peter
Message:
  • Bookmarks uses Moose instead of Class::Accessor
  • if not dbh is specified in the Bookmarks constructor, it can use a dbname parameter to create a SQLite DBH
  • the SQLite DBH created form dbname has the foreign_keys pragma set
  • added foreign key constraints to the bookmarks.sql table definitions for bookmarks and tags
  • added a required --file option to bkmk to specify the database file to use
  • added a load command to bkmk that loads bookmarks dumped as YAML using bkmk list
  • Bookmarks::add() can take mtime and id parameters (useful for reconstructing a database from the YAML dump of bkmk list)
  • BookmarkApp and bkmk no longer use DBI directly; just pass a dbname to the Bookmarks constructor
  • changed the default database for BookmarkApp to fk.db (schema from this revision's updated bookmarks.sql, with foreign keys)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bkmk

    r14 r15  
    22use strict; 
    33 
    4 use DBI; 
    54use YAML; 
    65use Bookmarks; 
     6use Getopt::Long; 
    77 
    8 my $dbname = 'new.db'; 
     8GetOptions( 
     9    'file|f=s' => \my $DBNAME, 
     10); 
    911 
    10 my $dbh = DBI->connect("dbi:SQLite:dbname=$dbname", "", "", { RaiseError => 1, PrintError => 0 }); 
     12die "Usage: $0 --file <dbname> <command>\n" unless $DBNAME; 
    1113 
    1214my $bookmarks = Bookmarks->new({ 
    13     dbh => $dbh, 
     15    dbname => $DBNAME, 
    1416}); 
    1517 
     
    3436        # TODO: coordinate this commandline script with the CGI app 
    3537        print Dump(\@resources); 
    36     } 
     38    }, 
     39    load => sub { 
     40        my ($src_file) = @_; 
     41        my $src_bookmarks = YAML::LoadFile($src_file); 
     42        for my $bookmark (@{ $src_bookmarks }) { 
     43            $bookmarks->add($bookmark); 
     44        } 
     45    }, 
    3746); 
    3847 
Note: See TracChangeset for help on using the changeset viewer.