Skip to content

Instantly share code, notes, and snippets.

@rniwa
Created May 24, 2010 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rniwa/412348 to your computer and use it in GitHub Desktop.
Save rniwa/412348 to your computer and use it in GitHub Desktop.
ENTITY sites
{
int site_id,
string url,
int created_at,
int updated_at
PRIMARY(url)
}
ENTITY users
{
int user_id,
string login,
string email,
string crypted_password,
string salt,
int created_at,
int updated_at,
string remember_token,
int remember_token_expires_at,
string activation_code,
int activated_at,
string state,
int deleted_at,
string name_prefix,
string name_first,
string name_middle,
string name_last,
int birthdate,
int fb_user_id,
string email_hash
PRIMARY(login)
}
ENTITY accounts
{
int account_id,
string username,
string password,
int created_at,
int updated_at,
FOREIGN KEY user_id REF users,
FOREIGN KEY site_id REF sites,
string type
PRIMARY(username, site_id)
}
ENTITY comments
{
int comment_id,
FOREIGN KEY author_id REF users,
string author_name,
string author_email,
string title,
string body,
int posted_at,
int created_at,
int updated_at,
FOREIGN KEY site_id REF sites,
string url,
string signature,
bool has_merit
PRIMARY(signature)
}
ENTITY friendships
{
int friendship_id,
FOREIGN KEY user_id REF users,
FOREIGN KEY friend_id REF users,
int created_at,
int updated_at,
FOREIGN KEY site_id REF sites
PRIMARY(user_id, friend_id)
}
ENTITY profile_items
{
int profile_item_id,
FOREIGN KEY user_id REF users,
FOREIGN KEY site_id REF sites,
string key,
string value,
int created_at,
int updated_at
PRIMARY(user_id, site_id, key)
}
ENTITY viewerships
{
int viewership_id,
int rating,
int created_at,
int updated_at,
FOREIGN KEY user_id REF users,
FOREIGN KEY comment_id REF comments
PRIMARY(user_id, comment_id)
}
QUERY siteById
FETCH sites
WHERE site_id = [1:id]
LIMIT 10 MAX 10
QUERY friendshipByUserAndFriend
FETCH friendships
WHERE user_id = [1:user] AND friend_id = [2:friend]
LIMIT 10 MAX 10
QUERY userByComment
FETCH users
OF comments BY author_id
WHERE comments.comment_id = [1:comment_id]
LIMIT 10 MAX 10
QUERY userByFacebook
FETCH users
WHERE fb_user_id = [1:facebookid]
LIMIT 10 MAX 10
// comment.rb
QUERY commentBySignature
FETCH comments
WHERE signature = [1:signature]
LIMIT 10 MAX 10
QUERY profileItemsByUser
FETCH profile_items
WHERE user_id = [1:user]
LIMIT 100 MAX 100
QUERY friendsByUser
FETCH users
OF friendships BY friend_id
WHERE friendships.user_id = [1:user]
LIMIT 500 MAX 500
// diggaccount.rb
QUERY accountByUsernameAndType
FETCH accounts
WHERE username = [1:username] AND type = [2:t]
LIMIT 10 MAX 10
QUERY siteByUrl
FETCH sites
WHERE url = [1:url]
LIMIT 1 MAX 1
// friendship.rb
QUERY friendshipsByUser
FETCH friendships
WHERE user_id = [1:user]
LIMIT 500 MAX 500
// TODO: user.rb
QUERY userByFacebookId
FETCH users
WHERE fb_user_id = [1:facebookid]
LIMIT 2 MAX 2
QUERY userByEmailHash
FETCH users
WHERE email_hash = [1:emailhash]
LIMIT 2 MAX 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment