Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
updating our model: posts!
  • Loading branch information
garu committed Jun 14, 2010
1 parent 99b3d53 commit e03bb40
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tweetylicious.pl
Expand Up @@ -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) = @_;
Expand Down

0 comments on commit e03bb40

Please sign in to comment.