Skip to content
Browse files

followers and following: the model

  • Loading branch information...
1 parent 3da8b2e commit f2c2644fb75f3e097be1263651117c1c2949bd20 @garu committed
Showing with 31 additions and 0 deletions.
  1. +31 −0 tweetylicious.pl
View
31 tweetylicious.pl
@@ -42,10 +42,41 @@ package Model;
content TEXT NOT NULL,
date INTEGER NOT NULL);'
);
+ $dbh->do('CREATE TABLE follow (id INTEGER NOT NULL PRIMARY KEY
+ ASC AUTOINCREMENT,
+ source TEXT NOT NULL
+ CONSTRAINT fk_user_username
+ REFERENCES user(username)
+ ON DELETE CASCADE,
+ destination TEXT NOT NULL);'
+ );
},
};
+# this returns who follows our user.
+# Each element is a hash of usernames and gravatars
+sub get_followers_for {
+ return Model->selectall_hashref(
+ 'SELECT username, gravatar FROM user, follow
+ WHERE user.username = follow.source
+ AND follow.destination = ?',
+ 'username', {} , $_[0],
+ );
+}
+
+
+# this returns who our user follows
+sub get_followed_by {
+ return Model->selectall_hashref(
+ 'select username, gravatar from user, follow
+ where user.username = follow.destination
+ and follow.source = ?',
+ 'username', {}, $_[0],
+ );
+}
+
+
# this returns our search results
sub search_posts {
my @items_to_search = @_;

0 comments on commit f2c2644

Please sign in to comment.
Something went wrong with that request. Please try again.