Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

searching posts: model

  • Loading branch information...
commit e338ebe169481f60d8aaa9204d0b2fc358cf6d0b 1 parent 6abdd89
@garu authored
Showing with 16 additions and 0 deletions.
  1. +16 −0 tweetylicious.pl
View
16 tweetylicious.pl
@@ -46,6 +46,22 @@ package Model;
};
+# this returns our search results
+sub search_posts {
+ my @items_to_search = @_;
+ my $query = 'OR post.content LIKE ? ' x (@items_to_search - 1);
+ return Model->selectall_arrayref(
+ "SELECT user.username, post.id, gravatar, content,
+ datetime(date, 'unixepoch', 'localtime') as date
+ FROM user
+ LEFT JOIN post ON user.username = post.username
+ WHERE post.content LIKE ? $query
+ ORDER BY date DESC",
+ { Slice => {} }, map { "%$_%" } @items_to_search
+ );
+}
+
+
# this returns sorted posts from all users in @users
sub fetch_posts_by {
my @users = @_;
Please sign in to comment.
Something went wrong with that request. Please try again.