Last change
on this file since 17 was
15,
checked in by peter, 12 years ago
|
- 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)
|
-
Property svn:executable set to
*
|
File size:
1.2 KB
|
Rev | Line | |
---|
[2] | 1 | #!/usr/bin/perl -w |
---|
| 2 | use strict; |
---|
| 3 | |
---|
| 4 | use YAML; |
---|
| 5 | use Bookmarks; |
---|
[15] | 6 | use Getopt::Long; |
---|
[2] | 7 | |
---|
[15] | 8 | GetOptions( |
---|
| 9 | 'file|f=s' => \my $DBNAME, |
---|
| 10 | ); |
---|
[2] | 11 | |
---|
[15] | 12 | die "Usage: $0 --file <dbname> <command>\n" unless $DBNAME; |
---|
[2] | 13 | |
---|
| 14 | my $bookmarks = Bookmarks->new({ |
---|
[15] | 15 | dbname => $DBNAME, |
---|
[2] | 16 | }); |
---|
| 17 | |
---|
| 18 | my $command = shift; |
---|
| 19 | |
---|
| 20 | my %action_for = ( |
---|
| 21 | get => sub { |
---|
| 22 | my $identifier = shift; |
---|
| 23 | my $query = $identifier =~ /^\d+$/ ? { id => $identifier } : { uri => $identifier }; |
---|
| 24 | my $bookmark = $bookmarks->get_bookmark($query); |
---|
| 25 | |
---|
| 26 | print $bookmark ? Dump($bookmark) : "Not Found\n"; |
---|
| 27 | }, |
---|
| 28 | add => sub { |
---|
| 29 | my ($uri, $title, @tags) = @_; |
---|
| 30 | my $bookmark = $bookmarks->add({ uri => $uri, title => $title, tags => \@tags }); |
---|
| 31 | print Dump($bookmark); |
---|
| 32 | }, |
---|
[14] | 33 | list => sub { |
---|
| 34 | my @resources = $bookmarks->get_resources(); |
---|
| 35 | # TODO: list by tags, date, etc. |
---|
| 36 | # TODO: coordinate this commandline script with the CGI app |
---|
| 37 | print Dump(\@resources); |
---|
[15] | 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 | }, |
---|
[2] | 46 | ); |
---|
| 47 | |
---|
| 48 | $action_for{$command}->(@ARGV); |
---|
| 49 | |
---|
| 50 | =begin |
---|
| 51 | |
---|
| 52 | use YAML; |
---|
| 53 | |
---|
Note: See
TracBrowser
for help on using the repository browser.