Documentation ¶
Overview ¶
Package database provides wrapper functions that create and modify objects based on models in an SQL database. See the models package for more information on the types of objects database operates on.
Index ¶
- Constants
- type BadRequest
- type Conflict
- type DB
- func (db *DB) Authenticate(username, password string) (user models.User, err error)
- func (db *DB) Categories(user *models.User) (categories []models.Category)
- func (db *DB) Category(id string, user *models.User) (ctg models.Category, err error)
- func (db *DB) CategoryStats(id string, user *models.User) (stats models.Stats, err error)
- func (db *DB) ChangeFeedCategory(feedID string, ctgID string, user *models.User) error
- func (db *DB) ChangeUserName(userID, newName string) error
- func (db *DB) ChangeUserPassword(userID, newPassword string) error
- func (db *DB) Close() error
- func (db *DB) DeleteAll()
- func (db *DB) DeleteCategory(id string, user *models.User) error
- func (db *DB) DeleteFeed(id string, user *models.User) error
- func (db *DB) DeleteUser(userID string) error
- func (db *DB) EditCategory(ctg *models.Category, user *models.User) error
- func (db *DB) EditFeed(feed *models.Feed, user *models.User) error
- func (db *DB) Entries(orderByDesc bool, marker models.Marker, user *models.User) (entries []models.Entry, err error)
- func (db *DB) EntriesFromCategory(categoryID string, orderByDesc bool, marker models.Marker, user *models.User) (entries []models.Entry, err error)
- func (db *DB) EntriesFromFeed(feedID string, orderByDesc bool, marker models.Marker, user *models.User) (entries []models.Entry, err error)
- func (db *DB) EntriesFromTag(tagID string, makrer models.Marker, orderByDesc bool, user *models.User) (entries []models.Entry, err error)
- func (db *DB) Entry(id string, user *models.User) (entry models.Entry, err error)
- func (db *DB) EntryWithGUIDExists(guid string, user *models.User) bool
- func (db *DB) Feed(id string, user *models.User) (feed models.Feed, err error)
- func (db *DB) FeedStats(id string, user *models.User) (stats models.Stats, err error)
- func (db *DB) Feeds(user *models.User) (feeds []models.Feed)
- func (db *DB) FeedsFromCategory(categoryID string, user *models.User) (feeds []models.Feed, err error)
- func (db *DB) KeyBelongsToUser(key *models.APIKey, user *models.User) (bool, error)
- func (db *DB) MarkCategory(id string, marker models.Marker, user *models.User) error
- func (db *DB) MarkEntry(id string, marker models.Marker, user *models.User) error
- func (db *DB) MarkFeed(id string, marker models.Marker, user *models.User) error
- func (db *DB) NewAPIKey(secret string, user *models.User) (models.APIKey, error)
- func (db *DB) NewCategory(ctg *models.Category, user *models.User) error
- func (db *DB) NewEntries(entries []models.Entry, feed models.Feed, user *models.User) error
- func (db *DB) NewEntry(entry *models.Entry, user *models.User) error
- func (db *DB) NewFeed(feed *models.Feed, user *models.User) error
- func (db *DB) NewUser(username, password string) error
- func (db *DB) Stats(user *models.User) (stats models.Stats)
- func (db *DB) UserPrimaryKey(uuid string) (uint, error)
- func (db *DB) UserWithName(username string) (user models.User, err error)
- func (db *DB) UserWithUUID(uuid string) (user models.User, err error)
- func (db *DB) Users(fields ...string) (users []models.User)
- type DBError
- type NotFound
- type Unauthorized
Constants ¶
const ( PWSaltBytes = 32 PWHashBytes = 64 )
Password salt and Hash byte sizes
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BadRequest ¶
type BadRequest struct {
// contains filtered or unexported fields
}
BadRequest is a DBError returned when an operation is malformed.
func (BadRequest) Code ¶
func (e BadRequest) Code() int
Code returns BadRequest's corresponding error code
func (BadRequest) Error ¶
func (e BadRequest) Error() string
func (BadRequest) String ¶
func (e BadRequest) String() string
type Conflict ¶
type Conflict struct {
// contains filtered or unexported fields
}
Conflict is a DBError returned when a database operation cannot be carried out because it conflicts with a previous operation.
type DB ¶
DB represents a connectin to a SQL database
func (*DB) Authenticate ¶
Authenticate a user and return its respective User model if successful
func (*DB) Categories ¶
Categories returns a list of all Categories owned by user
func (*DB) CategoryStats ¶
CategoryStats returns all Stats for a Category with the given id and that is owned by user
func (*DB) ChangeFeedCategory ¶
ChangeFeedCategory changes the category a feed belongs to
func (*DB) ChangeUserName ¶
ChangeUserName for user with userID
func (*DB) ChangeUserPassword ¶
ChangeUserPassword for user with userID
func (*DB) DeleteCategory ¶
DeleteCategory with id and owned by user
func (*DB) DeleteFeed ¶
DeleteFeed with id and owned by user
func (*DB) DeleteUser ¶
DeleteUser deletes a User object
func (*DB) EditCategory ¶
EditCategory owned by user
func (*DB) Entries ¶
func (db *DB) Entries(orderByDesc bool, marker models.Marker, user *models.User) (entries []models.Entry, err error)
Entries returns a list of all entries owned by user
func (*DB) EntriesFromCategory ¶
func (db *DB) EntriesFromCategory(categoryID string, orderByDesc bool, marker models.Marker, user *models.User) (entries []models.Entry, err error)
EntriesFromCategory returns all Entries that are related to a Category with categoryID by the entries' owning Feed
func (*DB) EntriesFromFeed ¶
func (db *DB) EntriesFromFeed(feedID string, orderByDesc bool, marker models.Marker, user *models.User) (entries []models.Entry, err error)
EntriesFromFeed returns all Entries that belong to a feed with feedID
func (*DB) EntriesFromTag ¶
func (db *DB) EntriesFromTag(tagID string, makrer models.Marker, orderByDesc bool, user *models.User) (entries []models.Entry, err error)
EntriesFromTag returns all Entries which are tagged with tagID
func (*DB) EntryWithGUIDExists ¶
EntryWithGUIDExists returns true if an Entry exists with the given guid and is owned by user
func (*DB) FeedStats ¶
FeedStats returns all Stats for a Feed with the given id and that is owned by user
func (*DB) FeedsFromCategory ¶
func (db *DB) FeedsFromCategory(categoryID string, user *models.User) (feeds []models.Feed, err error)
FeedsFromCategory returns all Feeds that belong to a category with categoryID
func (*DB) KeyBelongsToUser ¶
KeyBelongsToUser returns true if the given APIKey is owned by user
func (*DB) MarkCategory ¶
MarkCategory applies marker to a category with id and owned by user
func (*DB) NewCategory ¶
NewCategory creates a new Category object owned by user
func (*DB) NewEntries ¶
NewEntries creates multiple new Entry objects which are all owned by feed with feedUUID and user
func (*DB) UserPrimaryKey ¶
UserPrimaryKey returns the SQL primary key of a User with a uuid
func (*DB) UserWithName ¶
UserWithName returns a User with username
func (*DB) UserWithUUID ¶
UserWithUUID returns a User with id
type DBError ¶
DBError is the error type returned when any database operation does not return expected result or cannot be carried out.
type NotFound ¶
type NotFound struct {
// contains filtered or unexported fields
}
NotFound is DBError returned when an object cannot be found in the database.
type Unauthorized ¶
type Unauthorized struct {
// contains filtered or unexported fields
}
Unauthorized is a DBError returned when a client does not have the permissions to carry out an operation
func (Unauthorized) Code ¶
func (e Unauthorized) Code() int
Code returns Unauthorized's corresponding error code
func (Unauthorized) Error ¶
func (e Unauthorized) Error() string
func (Unauthorized) String ¶
func (e Unauthorized) String() string