Changeset 9 in bookmarks for trunk/Bookmarks.pm


Ignore:
Timestamp:
03/25/12 15:45:11 (12 years ago)
Author:
peter
Message:
  • use SQL::Interp to generate the SQL for Bookmarks::get_resources()
  • Bookmarks::get_resources() accepts a limit parameter to add a limit to the SQL query
  • added a feed run mode that returns an Atom feed of the most recent 12 bookmarks; can have an optional ?tag parameter that only looks for bookmarks with that tag
  • added an explicit "list" dispatch target that calls the `list run mode
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Bookmarks.pm

    r7 r9  
    22 
    33use Class::Accessor 'antlers'; 
     4use SQL::Interp qw{:all}; 
    45use Bookmark; 
    56 
     
    3637    my $params = shift; 
    3738    my $tag = $params->{tag}; 
    38     my $sth_resource; 
    39     if ($tag) { 
    40         $sth_resource = $self->dbh->prepare('select * from resources join tags on resources.uri = tags.uri join bookmarks on resources.uri = bookmarks.uri where tags.tag = ? order by ctime desc'); 
    41         $sth_resource->execute($tag); 
    42     } else { 
    43         $sth_resource = $self->dbh->prepare('select * from resources join bookmarks on resources.uri = bookmarks.uri order by ctime desc'); 
    44         $sth_resource->execute; 
    45     } 
     39    my $limit = $params->{limit}; 
     40 
     41    my ($sql, @bind) = sql_interp( 
     42        'select * from resources join bookmarks on resources.uri = bookmarks.uri', 
     43        ($tag   ? ('join tags on resources.uri = tags.uri where tags.tag =', \$tag) : ''), 
     44        'order by ctime desc', 
     45        ($limit ? ('limit', \$limit) : ''), 
     46    ); 
     47 
     48    my $sth_resource = $self->dbh->prepare($sql); 
     49    $sth_resource->execute(@bind); 
    4650 
    4751    my $sth_tag = $self->dbh->prepare('select tag from tags where uri = ? order by tag'); 
Note: See TracChangeset for help on using the changeset viewer.