model

package
v0.0.0-...-4d7371f Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2013 License: MIT Imports: 6 Imported by: 3

README

TODO

  • Post needs to give direct access to the Author, like Comment does.
  • It would be nice if methods on an DB object that has been Destroyed would return in an error or panic()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Author

type Author struct {
	// contains filtered or unexported fields
}

Represents an author of the blog

func (*Author) Destroy

func (a *Author) Destroy() error

Removes the user from the author table. The user attached to the author is not destroyed.

func (*Author) Id

func (a *Author) Id() int64

func (*Author) Posts

func (a *Author) Posts() ([]Post, error)

func (*Author) Save

func (a *Author) Save() error

Save an author to the connence. If the provided user didn't exist, it will create it first.

func (*Author) User

func (a *Author) User() *User

type Comment

type Comment struct {
	// contains filtered or unexported fields
}

Represents a comment on a post. Comments are made by Users.

func (*Comment) Content

func (c *Comment) Content() string

func (*Comment) ContentMarkdown

func (c *Comment) ContentMarkdown() string

func (*Comment) Date

func (c *Comment) Date() time.Time

func (*Comment) Destroy

func (c *Comment) Destroy() error

Deletes the comment from the database. Returns an error if something went wrong.

func (*Comment) DownVote

func (c *Comment) DownVote() int64

func (*Comment) Id

func (c *Comment) Id() int64

func (*Comment) Post

func (c *Comment) Post() (*Post, error)

func (*Comment) Save

func (c *Comment) Save() error

Saves the post (or update it if it already exists) to the database. Returns an error if something went wrong.

func (*Comment) SetContent

func (c *Comment) SetContent(content string)

func (*Comment) SetDate

func (c *Comment) SetDate(date time.Time)

func (*Comment) SetDownVote

func (c *Comment) SetDownVote(count int64)

func (*Comment) SetUpVote

func (c *Comment) SetUpVote(count int64)

func (*Comment) UpVote

func (c *Comment) UpVote() int64

func (*Comment) User

func (c *Comment) User() (*User, error)

type DBConnection

type DBConnection struct {
	// contains filtered or unexported fields
}

Keeps all info required to save stuff on a database

func NewConnection

func NewConnection(modelaser DBVendor) (*DBConnection, error)

Creates a connection with the given DBVendor argument. You can then use that connection to create objects on the DB and then use those objects to update the DB.

func (*DBConnection) DeleteConnection

func (conn *DBConnection) DeleteConnection()

Drops all the tables held in the database to which this object is linked. WARNING: all your data will be lost. You should only do that in a testing environment.

func (*DBConnection) FindAllAuthors

func (conn *DBConnection) FindAllAuthors() ([]Author, error)

Finds all the Authors known to this blog. Returns an empty slice and an error stating no rows matched the request if no authors are known to this blog.

func (*DBConnection) FindAllComments

func (conn *DBConnection) FindAllComments() ([]Comment, error)

Finds all the comments in the database. Returns an empty slice with an error if not comments were found.

func (*DBConnection) FindAllLabels

func (conn *DBConnection) FindAllLabels() ([]Label, error)

Finds all the labels in the database

func (*DBConnection) FindAllPosts

func (conn *DBConnection) FindAllPosts() ([]Post, error)

Finds all the posts in the database

func (*DBConnection) FindAllUsers

func (conn *DBConnection) FindAllUsers() ([]User, error)

Finds all the users in the database

func (*DBConnection) FindAuthorById

func (conn *DBConnection) FindAuthorById(id int64) (*Author, error)

Returns an author given its id. If the id is not known to the blog a nil value is returned with an error.

func (*DBConnection) FindCommentById

func (conn *DBConnection) FindCommentById(id int64) (*Comment, error)

Finds a comment that matches the given id. Returns nil and an error if the id didn't match any comment.

func (*DBConnection) FindLabelById

func (conn *DBConnection) FindLabelById(id int64) (*Label, error)

func (*DBConnection) FindPostById

func (conn *DBConnection) FindPostById(id int64) (*Post, error)

Finds a post that matches the given id

func (*DBConnection) FindUserById

func (conn *DBConnection) FindUserById(id int64) (*User, error)

Finds a user that matches the given id

func (*DBConnection) FindUserByOAuthId

func (conn *DBConnection) FindUserByOAuthId(oauthId string) (*User, error)

Finds a user that matches the given id

func (*DBConnection) NewAuthor

func (conn *DBConnection) NewAuthor(user *User) *Author

Creates an author. The Author is NOT saved. To save it, you must call the save method on the returned Author.

func (*DBConnection) NewComment

func (conn *DBConnection) NewComment(userId int64, postId int64, content string, date time.Time) *Comment

Creates a new Comment attached to the database. It is NOT saved in the database, you must call "Save" on this comment to have it persisted

func (*DBConnection) NewPost

func (conn *DBConnection) NewPost(author *Author, title string, content string, imageURL string, date time.Time) *Post

Creates a new Post attached to the Database (but not saved)

func (*DBConnection) NewUser

func (conn *DBConnection) NewUser(username string, regDate time.Time,
	timezone int, oauthId string, access string, refresh string, email string) *User

Creates a new User attached to the Database (but it is not saved).

type DBVendor

type DBVendor interface {
	// not exported because only used within package
	Name() string
	Driver() string
}

Interface to abstract between different drivers (SQLite or Postgres)

type Label

type Label struct {
	// contains filtered or unexported fields
}

Represents a label from the blog

func (*Label) Destroy

func (l *Label) Destroy() error

Deletes the label from the database. If any post is referencing this label, they will not do so anymore

func (*Label) Id

func (l *Label) Id() int64

func (*Label) Name

func (l *Label) Name() string

func (*Label) Posts

func (l *Label) Posts() ([]Post, error)

Returns all the posts making reference to this label.

func (*Label) Save

func (l *Label) Save() error

Saves the Label (or update it if it already exists) to the database

func (*Label) SetName

func (l *Label) SetName(name string)

type Post

type Post struct {
	// contains filtered or unexported fields
}

Represents a post in the blog

func (*Post) AddLabel

func (p *Post) AddLabel(name string) (Label, error)

func (*Post) Author

func (p *Post) Author() *Author

func (*Post) Comments

func (p *Post) Comments() ([]Comment, error)

func (*Post) Content

func (p *Post) Content() string

func (*Post) ContentMarkdown

func (p *Post) ContentMarkdown() string

func (*Post) Date

func (p *Post) Date() time.Time

func (*Post) Destroy

func (p *Post) Destroy() error

Deletes the post from the database

func (*Post) Id

func (p *Post) Id() int64

func (*Post) ImageURL

func (p *Post) ImageURL() string

func (*Post) Labels

func (p *Post) Labels() ([]Label, error)

Returns all the post associated with this post, if any.

func (*Post) RemoveLabel

func (p *Post) RemoveLabel(label *Label) error

Removes a label from a post. If the post if the only post referring to that label, it will delete the label altogether. Otherwise it will remove the label only for that post, leaving other posts unaffected

func (*Post) Save

func (p *Post) Save() error

Saves the post (or update it if it already exists) to the database

func (*Post) SetContent

func (p *Post) SetContent(content string)

func (*Post) SetDate

func (p *Post) SetDate(time time.Time)

func (*Post) SetImageURL

func (p *Post) SetImageURL(imageURL string)

func (*Post) SetTitle

func (p *Post) SetTitle(title string)

func (*Post) Title

func (p *Post) Title() string

func (*Post) Update

func (p *Post) Update() error

type Postgreser

type Postgreser struct {
	// contains filtered or unexported fields
}

A connection to a PostgreSQL model.

func NewPostgreser

func NewPostgreser(modelurl string) Postgreser

Prepares a Postgreser for use as DBVendor

func (Postgreser) DateField

func (model Postgreser) DateField() string

func (Postgreser) Driver

func (model Postgreser) Driver() string

The name of the driver for the PostgreSQL driver

func (Postgreser) IncrementPrimaryKey

func (model Postgreser) IncrementPrimaryKey() string

func (Postgreser) Name

func (model Postgreser) Name() string

The name of the PostgreSQL model

type User

type User struct {
	// contains filtered or unexported fields
}

Represents a User of the blog

func (*User) AccessToken

func (u *User) AccessToken() string

func (*User) Comments

func (u *User) Comments() ([]Comment, error)

func (User) Destroy

func (u User) Destroy() error

Deletes the user from the database

func (*User) Email

func (u *User) Email() string

func (*User) Id

func (u *User) Id() int64

func (*User) OauthId

func (u *User) OauthId() string

func (*User) RefreshToken

func (u *User) RefreshToken() string

func (*User) RegistrationDate

func (u *User) RegistrationDate() time.Time

func (*User) Save

func (u *User) Save() error

Saves the user (or update it if it already exists) to the database

func (*User) SetEmail

func (u *User) SetEmail(email string)

func (*User) SetOauthId

func (u *User) SetOauthId(id string)

func (*User) SetRegistrationDate

func (u *User) SetRegistrationDate(date time.Time)

func (*User) SetTimezone

func (u *User) SetTimezone(zone int)

func (*User) SetToken

func (u *User) SetToken(access, refresh string)

func (*User) SetUsername

func (u *User) SetUsername(username string)

func (*User) Timezone

func (u *User) Timezone() int

func (*User) Username

func (u *User) Username() string

Jump to

Keyboard shortcuts

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