Documentation ¶
Overview ¶
Package db defines the requirements for our database, via the Store interface, and implements it for postgres.
Index ¶
- Variables
- type Album
- type Group
- type GroupMember
- type PGStore
- func (pg *PGStore) AddAlbum(name string) error
- func (pg *PGStore) AddGroup(username string, groupname string) error
- func (pg *PGStore) AddPhoto(p Photo, albumID string) error
- func (pg *PGStore) AddUser(username string, hash []byte) error
- func (pg *PGStore) DeleteAlbumBySlug(slug string) error
- func (pg *PGStore) DeletePhotoByID(id string) error
- func (pg *PGStore) Exec(query string, args ...interface{}) error
- func (pg *PGStore) ExecuteSchema(filename string) error
- func (pg *PGStore) GetAlbumBySlug(slug string) (*Album, error)
- func (pg *PGStore) GetAlbumIDByPhotoID(photoID string) (string, error)
- func (pg *PGStore) GetAlbumPhotosByID(id string) ([]Photo, error)
- func (pg *PGStore) GetAlbumSlugByID(id string) (string, error)
- func (pg *PGStore) GetAllAlbums() ([]Album, error)
- func (pg *PGStore) GetAllUsers() ([]User, error)
- func (pg *PGStore) GetGroupByID(id string) (Group, []GroupMember, error)
- func (pg *PGStore) GetGroupsForUser(u User) ([]Group, error)
- func (pg *PGStore) GetPhotoByID(id string) (*Photo, error)
- func (pg *PGStore) GetUserByUsername(username string) (*User, error)
- func (pg *PGStore) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (pg *PGStore) RemoveUser(username string) error
- func (pg *PGStore) RenameAlbumByID(id, newName string) error
- func (pg *PGStore) RevokeSession(session string) error
- func (pg *PGStore) SessionGet(session string, newExpiration time.Time) (*Session, error)
- func (pg *PGStore) UpdatePhotoAlbum(photoID, albumID string) error
- func (pg *PGStore) UpdatePhotoCaptionByID(id, newCaption string) error
- func (pg *PGStore) UserAddSession(user User, session string, expires time.Time) error
- type Photo
- type Session
- type Store
- type User
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAlbumExists is returned when the unique requirement of an // album name is violated ErrAlbumExists = errors.New("DB: Album exists") // ErrAlbumNameInvalid is returned when an album name is not valid. // Most likely to fire when a slug is blank. (jphotos#60) ErrAlbumNameInvalid = errors.New("DB: Album name invalid") )
var ( // ErrNotFound is returned when the requested value isn't found ErrNotFound = errors.New("DB: Not Found") )
var ( // ErrUsernameExists is returned when the unique requirement of a username is violated ErrUsernameExists = errors.New("DB: Username exists") )
Functions ¶
This section is empty.
Types ¶
type GroupMember ¶
A GroupMember is a member of a group
type PGStore ¶
type PGStore struct {
// contains filtered or unexported fields
}
A PGStore implements storage against PostGres
func NewPGStore ¶
NewPGStore connects to a postgres database
func (*PGStore) AddUser ¶
AddUser adds a user to the users table of the database, hashing the password with bcrypt
func (*PGStore) DeleteAlbumBySlug ¶
DeleteAlbumBySlug deletes the album, and all photos in it, matching the slug
func (*PGStore) DeletePhotoByID ¶
DeletePhotoByID deletes the photo at the provided ID
func (*PGStore) Exec ¶
Exec executes a raw query against the DB, returns the result, and closes the connection
func (*PGStore) ExecuteSchema ¶
ExecuteSchema runs all the sql commands int he given file to initialize the database
func (*PGStore) GetAlbumBySlug ¶
GetAlbum returns an album, if it exists and matches the provided id
func (*PGStore) GetAlbumIDByPhotoID ¶
GetAlbumIDByPhotoID returns the album slug a photo belongs to
func (*PGStore) GetAlbumPhotosByID ¶
GetAlbumPhotos returns a list of all photos in an album
func (*PGStore) GetAlbumSlugByID ¶
GetAlbumSlugByID returns the slug matching the provided ID
func (*PGStore) GetAllAlbums ¶
GetAlbums returns a list of all Albums
func (*PGStore) GetAllUsers ¶
GetAllUsers returns a slice of Users
func (*PGStore) GetGroupByID ¶
func (pg *PGStore) GetGroupByID(id string) (Group, []GroupMember, error)
GetGroupByID returns a group and a list of all its members
func (*PGStore) GetGroupsForUser ¶
GetGroupsForUser returns all the groups a user can access
func (*PGStore) GetPhotoByID ¶
GetPhotoByID returns a photo object for that ID.
func (*PGStore) GetUserByUsername ¶
GetUserByUsername returns the DB user information for a user if that user exists
func (*PGStore) RemoveUser ¶
RemoveUser removes a user from the database.
func (*PGStore) RenameAlbumByID ¶
RenameAlbum renames an album
func (*PGStore) RevokeSession ¶
RevokeSession removes a user's session from the sessions table
func (*PGStore) SessionGet ¶
SessionGet checks the database for a session and returns it if found If the session is absent, an error is returned. SessionGet will not return an expired session.
func (*PGStore) UpdatePhotoAlbum ¶
UpdatePhotoAlbum changes the album a photo belongs to
func (*PGStore) UpdatePhotoCaptionByID ¶
UpdatePhotoCaptionByID updates the photo's caption
type Store ¶
type Store interface { ExecuteSchema(filename string) error AddUser(username string, hash []byte) error RemoveUser(username string) error GetAllUsers() ([]User, error) GetUserByUsername(username string) (*User, error) UserAddSession(user User, session string, expires time.Time) error // // Album Methods // These are methods used to primarily access the albums tabl GetAllAlbums() ([]Album, error) GetAlbumBySlug(slug string) (*Album, error) GetAlbumPhotosByID(id string) ([]Photo, error) GetAlbumSlugByID(id string) (string, error) AddAlbum(name string) error RenameAlbumByID(id, newName string) error DeleteAlbumBySlug(slug string) error // // Photo Methods // These are methods used to primarily access the photos table AddPhoto(p Photo, albumID string) error GetPhotoByID(id string) (*Photo, error) GetAlbumIDByPhotoID(id string) (string, error) UpdatePhotoCaptionByID(id, newCaption string) error UpdatePhotoAlbum(photoID, albumID string) error DeletePhotoByID(id string) error // // Group Methods GetGroupsForUser(u User) ([]Group, error) GetGroupByID(id string) (Group, []GroupMember, error) // SessionGet returns a valid session if one exists. // Guranteed to not return expired sessinos. // If a valid session is found, extend it! I don't recommend passing // in a time that's past, though. SessionGet(session string, newExpiration time.Time) (*Session, error) RevokeSession(session string) error }
A Store provides the methods required to access the database.