database

package
v0.0.0-...-e474068 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2017 License: AGPL-3.0 Imports: 11 Imported by: 0

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

View Source
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.

func (Conflict) Code

func (e Conflict) Code() int

Code returns Conflict's corresponding error code

func (Conflict) Error

func (e Conflict) Error() string

func (Conflict) String

func (e Conflict) String() string

type DB

type DB struct {
	Connection string
	Type       string
	// contains filtered or unexported fields
}

DB represents a connectin to a SQL database

func NewDB

func NewDB(dbType, conn string) (db *DB, err error)

NewDB creates a new DB instance

func (*DB) Authenticate

func (db *DB) Authenticate(username, password string) (user models.User, err error)

Authenticate a user and return its respective User model if successful

func (*DB) Categories

func (db *DB) Categories(user *models.User) (categories []models.Category)

Categories returns a list of all Categories owned by user

func (*DB) Category

func (db *DB) Category(id string, user *models.User) (ctg models.Category, err error)

Category returns a Category with id and owned by user

func (*DB) CategoryStats

func (db *DB) CategoryStats(id string, user *models.User) (stats models.Stats, err error)

CategoryStats returns all Stats for a Category with the given id and that is owned by user

func (*DB) ChangeFeedCategory

func (db *DB) ChangeFeedCategory(feedID string, ctgID string, user *models.User) error

ChangeFeedCategory changes the category a feed belongs to

func (*DB) ChangeUserName

func (db *DB) ChangeUserName(userID, newName string) error

ChangeUserName for user with userID

func (*DB) ChangeUserPassword

func (db *DB) ChangeUserPassword(userID, newPassword string) error

ChangeUserPassword for user with userID

func (*DB) Close

func (db *DB) Close() error

Close ends connections with the database

func (*DB) DeleteAll

func (db *DB) DeleteAll()

DeleteAll records in the database

func (*DB) DeleteCategory

func (db *DB) DeleteCategory(id string, user *models.User) error

DeleteCategory with id and owned by user

func (*DB) DeleteFeed

func (db *DB) DeleteFeed(id string, user *models.User) error

DeleteFeed with id and owned by user

func (*DB) DeleteUser

func (db *DB) DeleteUser(userID string) error

DeleteUser deletes a User object

func (*DB) EditCategory

func (db *DB) EditCategory(ctg *models.Category, user *models.User) error

EditCategory owned by user

func (*DB) EditFeed

func (db *DB) EditFeed(feed *models.Feed, user *models.User) error

EditFeed 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) Entry

func (db *DB) Entry(id string, user *models.User) (entry models.Entry, err error)

Entry returns an Entry with id and owned by user

func (*DB) EntryWithGUIDExists

func (db *DB) EntryWithGUIDExists(guid string, user *models.User) bool

EntryWithGUIDExists returns true if an Entry exists with the given guid and is owned by user

func (*DB) Feed

func (db *DB) Feed(id string, user *models.User) (feed models.Feed, err error)

Feed returns a Feed with id and owned by user

func (*DB) FeedStats

func (db *DB) FeedStats(id string, user *models.User) (stats models.Stats, err error)

FeedStats returns all Stats for a Feed with the given id and that is owned by user

func (*DB) Feeds

func (db *DB) Feeds(user *models.User) (feeds []models.Feed)

Feeds returns a list of all Feeds owned by a 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

func (db *DB) KeyBelongsToUser(key *models.APIKey, user *models.User) (bool, error)

KeyBelongsToUser returns true if the given APIKey is owned by user

func (*DB) MarkCategory

func (db *DB) MarkCategory(id string, marker models.Marker, user *models.User) error

MarkCategory applies marker to a category with id and owned by user

func (*DB) MarkEntry

func (db *DB) MarkEntry(id string, marker models.Marker, user *models.User) error

MarkEntry applies marker to an entry with id and owned by user

func (*DB) MarkFeed

func (db *DB) MarkFeed(id string, marker models.Marker, user *models.User) error

MarkFeed applies marker to a Feed with id and owned by user

func (*DB) NewAPIKey

func (db *DB) NewAPIKey(secret string, user *models.User) (models.APIKey, error)

NewAPIKey creates a new APIKey object owned by user

func (*DB) NewCategory

func (db *DB) NewCategory(ctg *models.Category, user *models.User) error

NewCategory creates a new Category object owned by user

func (*DB) NewEntries

func (db *DB) NewEntries(entries []models.Entry, feed models.Feed, user *models.User) error

NewEntries creates multiple new Entry objects which are all owned by feed with feedUUID and user

func (*DB) NewEntry

func (db *DB) NewEntry(entry *models.Entry, user *models.User) error

NewEntry creates a new Entry object owned by user

func (*DB) NewFeed

func (db *DB) NewFeed(feed *models.Feed, user *models.User) error

NewFeed creates a new Feed object owned by user

func (*DB) NewUser

func (db *DB) NewUser(username, password string) error

NewUser creates a new User object

func (*DB) Stats

func (db *DB) Stats(user *models.User) (stats models.Stats)

Stats returns all Stats for the given user

func (*DB) UserPrimaryKey

func (db *DB) UserPrimaryKey(uuid string) (uint, error)

UserPrimaryKey returns the SQL primary key of a User with a uuid

func (*DB) UserWithName

func (db *DB) UserWithName(username string) (user models.User, err error)

UserWithName returns a User with username

func (*DB) UserWithUUID

func (db *DB) UserWithUUID(uuid string) (user models.User, err error)

UserWithUUID returns a User with id

func (*DB) Users

func (db *DB) Users(fields ...string) (users []models.User)

Users returns a list of all User entries. The parameter fields provides a way to select which fields are populated in the returned models.

type DBError

type DBError interface {
	String() string
	Code() int
	Error() string
}

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.

func (NotFound) Code

func (e NotFound) Code() int

Code returns NotFound's corresponding error code

func (NotFound) Error

func (e NotFound) Error() string

func (NotFound) String

func (e NotFound) String() string

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

Jump to

Keyboard shortcuts

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