Documentation ¶
Overview ¶
This package contains the blog's models and holds the database connection globally but as an unexported value.
Index ¶
Constants ¶
View Source
const ( SQL_POST_BY_ID = `` /* 197-byte string literal not displayed */ SQL_POST_BY_SLUG = `` /* 195-byte string literal not displayed */ SQL_POSTS_BY_USER = ` SELECT idPost, title, slug, date, draft FROM posts WHERE idUser=? ORDER BY draft DESC, date DESC` SQL_POSTS_BY_TAG = `` /* 200-byte string literal not displayed */ SQL_ALL_POSTS = `` /* 152-byte string literal not displayed */ SQL_ALL_TAGS = `SELECT DISTINCT tag FROM post_tags INNER JOIN posts USING(idPost) WHERE posts.draft=false` SQL_INSERT_POST = ` INSERT INTO posts (slug, title, abstract, body, idUser, draft) VALUES (?, ?, ?, ?, ?, ?)` SQL_INSERT_TAGS = ` INSERT IGNORE INTO post_tags (idPost, tag) VALUES (?, ?)` SQL_REMOVE_TAGS = `DELETE from post_tags WHERE idPost=?` SQL_DELETE_POST = `DELETE from posts WHERE idPost=?` SQL_UPDATE_POST = ` UPDATE posts SET slug=?, title=?, abstract=?, body=?, idUser=?, draft=? WHERE idPost=?` SQL_USER_BY_ID = ` SELECT name, email FROM users WHERE idUser=?` SQL_USER_AUTH = ` SELECT name, idUser FROM users WHERE email=? AND password=?` )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Post ¶
type Post struct { Id int Slug string Title, Body string Abstract string Author User Date time.Time Draft bool Tags []string }
func PostsByTag ¶
Retrieves all posts that match a given tag and are not drafts, ordered by date
func PostsByUser ¶
Fetches all posts by user's ID
func (*Post) FormattedDate ¶
func (*Post) Save ¶
Saves a post to the database. If it has a set ID it will try to update an already existing post, otherwise it will insert a new post and generate an ID for it. An unset ID is an ID of value 0.
func (*Post) TagsString ¶
type User ¶
Contains information about a user
func (*User) LoginCorrect ¶
Verifies if a password & e-mail combination is correct for the user and fetches rest of data
Click to show internal directories.
Click to hide internal directories.