models

package
v0.0.0-...-3bc4b72 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2015 License: GPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateComment

func CreateComment(comment Comment) error

CreateComment executes the query that creates a comment

func CreatePost

func CreatePost(post Post) error

CreatePost executes the query that creates a post

func CreateSub

func CreateSub(sub Sub) error

TODO: make create take and return a struct CreateSub executes the query that creates a sub

func CreateUser

func CreateUser(user User) error

TODO: make create take and return a struct CreateUser executes the query that creates a user

func CreateVote

func CreateVote(vote Vote) error

CreateVote executes a query that creates a vote, it assures the value is -1, 0, or 1

func DeleteComment

func DeleteComment(id uint64) error

DeleteComment executes the query that deletes a comment

func DeletePost

func DeletePost(id uint64) error

DeletePost executes the query to delete a post by id

func DeleteSub

func DeleteSub(id uint64) error

DeleteSub executes the query that deletes a sub by name

func InitDb

func InitDb()

InitDb creates a database connection and executes the idempotent schema

func Slugify

func Slugify(name string) string

Slugify converts a string in to a slug

func UpdateComment

func UpdateComment(comment Comment) error

UpdateComment executes the query that updates a comment

func UpdatePost

func UpdatePost(post Post) error

UpdatePost executes the query that updates a post

func UpdateSub

func UpdateSub(sub Sub) error

UpdateSub executes the query that updates a sub

func UpdateVote

func UpdateVote(vote Vote) error

UpdateVote executes a query that updates a vote, it assures the value is -1, 0, or 1

Types

type Comment

type Comment struct {
	ID              uint64      `db:"id" json:"id"`
	UserID          uint64      `db:"user_id" json:"userId"`
	CommentableID   uint64      `db:"commentable_id" json:"commentableId"`
	CommentableType string      `db:"commentable_type" json:"commentableType"`
	Body            string      `db:"body" json:"body"`
	CreatedAt       time.Time   `db:"created_at" json:"createdAt"`
	UpdatedAt       time.Time   `db:"updated_at" json:"updatedAt"`
	DeletedAt       pq.NullTime `db:"deleted_at" json:"deletedAt"`
}

Comment is a struct

func GetComment

func GetComment(id uint64) (Comment, error)

GetComment executes the query that gets a comment

type Comments

type Comments []Comment

Comments is a list of Comment

func GetComments

func GetComments(commentableID uint64, commentableType string) (Comments, error)

GetComments executes the query that gets a comments

type Post

type Post struct {
	ID        uint64      `db:"id" json:"id"`
	UserID    uint64      `db:"user_id" json:"userId"`
	SubID     uint64      `db:"sub_id" json:"subId"`
	Title     string      `db:"title" json:"title"`
	Body      string      `db:"body" json:"body"`
	CreatedAt time.Time   `db:"created_at" json:"createdAt"`
	UpdatedAt time.Time   `db:"updated_at" json:"updatedAt"`
	DeletedAt pq.NullTime `db:"deleted_at" json:"deletedAt"`

	Score Score `json:"score"`
}

Post is a struct

func GetPost

func GetPost(id uint64) (Post, error)

GetPost executes the query to get a post by id, includes the posts score

type Posts

type Posts []Post

Posts is a list of Post

func GetPosts

func GetPosts(subID uint64) (Posts, error)

GetPosts executes the query to get all posts within a given sub

type Score

type Score int

Score the score for something votable

type Sub

type Sub struct {
	ID          uint64      `db:"id" json:"id"`
	Slug        string      `db:"slug" json:"slug"`
	Name        string      `db:"name" json:"name"`
	Description string      `db:"description" json:"description"`
	CreatedAt   time.Time   `db:"created_at" json:"createdAt"`
	UpdatedAt   time.Time   `db:"updated_at" json:"updatedAt"`
	DeletedAt   pq.NullTime `db:"deleted_at" json:"deletedAt"`
}

Sub is a struct

func GetSubByID

func GetSubByID(id uint64) (Sub, error)

GetSub executes the query that gets a sub by id

func GetSubBySlug

func GetSubBySlug(slug string) (Sub, error)

GetSub executes the query that gets a sub by id

type Subs

type Subs []Sub

Subs is a list of Sub

func GetSubs

func GetSubs() (Subs, error)

GetSubs executes the query that gets a list of all subs

type User

type User struct {
	ID         uint64      `db:"id" json:"id"`
	Username   string      `db:"username" json:"username"`
	Passphrase string      `db:"passphrase" json:"passphrase"`
	CreatedAt  time.Time   `db:"created_at" json:"createdAt"`
	UpdatedAt  time.Time   `db:"updated_at" json:"updatedAt"`
	DeletedAt  pq.NullTime `db:"deleted_at" json:"deletedAt"`
}

Comment is a struct

func GetUserByUsername

func GetUserByUsername(username string) (User, error)

GetUserByUsername executes the query that gets a user by username

type Users

type Users []User

Comments is a list of Comment

type Vote

type Vote struct {
	ID          uint64      `db:"id" json:"id"`
	UserID      uint64      `db:"user_id" json:"userId"`
	VotableID   uint64      `db:"votable_id" json:"votableId"`
	VotableType string      `db:"votable_type" json:"votableType"`
	Value       int         `db:"value" json:"value"`
	CreatedAt   time.Time   `db:"created_at" json:"createdAt"`
	UpdatedAt   time.Time   `db:"updated_at" json:"updatedAt"`
	DeletedAt   pq.NullTime `db:"deleted_at" json:"deletedAt"`
}

Vote is a struct

func GetVoteForUser

func GetVoteForUser(vote Vote) (Vote, error)

GetVoteForUser executes a query that gets a vote for a particular user on the particular votable

type Votes

type Votes []Vote

Votes is a list of Vote

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL