Permalink
Browse files

updating our model: posts!

  • Loading branch information...
garu committed Jun 13, 2010
1 parent 99b3d53 commit e03bb401fabfa72715b45e16ea61165a3c856027
Showing with 25 additions and 0 deletions.
  1. +25 −0 tweetylicious.pl
View
@@ -33,10 +33,35 @@ package Model;
bio TEXT
);'
);
+ $dbh->do('CREATE TABLE post (id INTEGER NOT NULL PRIMARY KEY
+ ASC AUTOINCREMENT,
+ username TEXT NOT NULL
+ CONSTRAINT fk_user_username
+ REFERENCES user(username)
+ ON DELETE CASCADE,
+ content TEXT NOT NULL,
+ date INTEGER NOT NULL);'
+ );
},
};
+# this returns sorted posts from all users in @users
+sub fetch_posts_by {
+ my @users = @_;
+ my $query = 'OR post.username = ? ' x (@users - 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.username = ? $query
+ ORDER BY date DESC",
+ { Slice => {} }, @users
+ );
+}
+
+
# this validates registration data before we commit to the database
sub validate {
my ($user, $pass, $pass2, $routes) = @_;

0 comments on commit e03bb40

Please sign in to comment.