Documentation
¶
Index ¶
- func Tx(db *sql.DB, txFunc func(*sql.Tx) error) (err error)
- type DB
- func (db *DB) Autocomplete(q string, limit, offset int) ([]*shimmie.Autocomplete, error)
- func (db *DB) CountAlias() (int, error)
- func (db *DB) CountUsers() (int, error)
- func (db *DB) CreateAlias(alias *shimmie.Alias) error
- func (db *DB) CreateImage(ctx context.Context, img shimmie.Image) (int64, error)
- func (db *DB) CreatePM(pm *shimmie.PM) error
- func (db *DB) CreateTag(t *shimmie.Tag) error
- func (db *DB) CreateTagHistory(ctx context.Context, th shimmie.TagHistory) (int64, error)
- func (db *DB) CreateUser(u *shimmie.User) error
- func (db *DB) DeleteAlias(oldTag string) error
- func (db *DB) DeleteTag(name string) error
- func (db *DB) DeleteUser(id int64) error
- func (db *DB) FindAlias(oldTag, newTag string) ([]shimmie.Alias, error)
- func (db *DB) GetAlias(oldTag string) (*shimmie.Alias, error)
- func (db *DB) GetAllAlias(limit, offset int) ([]shimmie.Alias, error)
- func (db *DB) GetAllTags(limit, offset int) ([]*shimmie.Tag, error)
- func (db *DB) GetAllUsers(limit, offset int) ([]shimmie.User, error)
- func (db *DB) GetCommon() (*shimmie.Common, error)
- func (db *DB) GetConfig(keys ...string) (map[string]string, error)
- func (db *DB) GetContributedTagHistory(imageOwnerUsername string) ([]shimmie.ContributedTagHistory, error)
- func (db *DB) GetImage(id int) (*shimmie.Image, error)
- func (db *DB) GetImageTagHistory(imageID int) ([]shimmie.TagHistory, error)
- func (db *DB) GetPMs(from, to string, choice shimmie.PMChoice) ([]*shimmie.PM, error)
- func (db *DB) GetRatedImages(username string) ([]shimmie.RatedImage, error)
- func (db *DB) GetTag(oldTag string) (*shimmie.Tag, error)
- func (db *DB) GetTagHistory(id int) (*shimmie.TagHistory, error)
- func (db *DB) GetUser(userID int64) (*shimmie.User, error)
- func (db *DB) GetUserByName(username string) (*shimmie.User, error)
- func (db *DB) Log(section, username, address string, priority int, message string) (*shimmie.SCoreLog, error)
- func (db *DB) LogRating(imgID int, imgRating, username, userIP string) error
- func (db *DB) MostImageUploads(limit int) ([]shimmie.UserScore, error)
- func (db *DB) MostTagEdits(limit int) ([]shimmie.UserScore, error)
- func (db *DB) RateImage(id int, rating string) error
- func (db *DB) Verify(username, password string) (*shimmie.User, error)
- func (db *DB) WriteImageFile(w io.Writer, path, hash string) error
- type Schema
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DB ¶
DB has methods for most operations needed in the shimmie database.
func (*DB) Autocomplete ¶
Autocomplete searches tags and tag alias for a term and returns suggestions tags to be used for a UI autocomplete.
func (*DB) CountAlias ¶
CountAlias returns how many alias entries exist in the database.
func (*DB) CountUsers ¶
CountUsers returns how many user entries exist in the database.
func (*DB) CreateAlias ¶
CreateAlias creates a new alias.
func (*DB) CreateImage ¶
CreateImage inserts a new image to the database.
func (*DB) CreateTagHistory ¶
CreateTagHistory inserts a new tag history for an image in the db.
func (*DB) CreateUser ¶
CreateUser creates a new user and returns their ID.
func (*DB) DeleteAlias ¶
DeleteAlias deletes an alias based on its old tag.
func (*DB) DeleteUser ¶
DeleteUser deletes a user based on their ID.
func (*DB) GetAllAlias ¶
GetAllAlias returns alias entries of the database based on a limit and an offset. If limit < 0, CountAlias will also be executed to get the maximum limit and return all alias entries. Offset still works in this case. For example, assuming 10 entries, GetAllAlias(-1, 0), will return all 10 entries and GetAllAlias(-1, 8) will return the last 2 entries.
func (*DB) GetAllTags ¶
GetAllTags returns all stored tags.
func (*DB) GetAllUsers ¶
GetAllUsers returns user entries of the database based on a limit and an offset. If limit < 0, CountUsers will also be executed to get the maximum limit and return all user entries. Offset still works in this case. For example, assuming 10 entries, GetAllUsers(-1, 0), will return all 10 entries and GetAllUsers(-1, 8) will return the last 2 entries.
func (*DB) GetContributedTagHistory ¶
func (db *DB) GetContributedTagHistory(imageOwnerUsername string) ([]shimmie.ContributedTagHistory, error)
GetContributedTagHistory returns the latest tag history i.e. tag changes that were done by a contributor on an owner's image, per image. It is used to fetch data for the "Tag Approval" page.
func (*DB) GetImageTagHistory ¶
func (db *DB) GetImageTagHistory(imageID int) ([]shimmie.TagHistory, error)
GetImageTagHistory returns the previous tags of an image.
func (*DB) GetPMs ¶
GetPMs returns the private messages exchanged from a user to another user. The arguments from and to are user names and either or both can be left empty.
func (*DB) GetRatedImages ¶
func (db *DB) GetRatedImages(username string) ([]shimmie.RatedImage, error)
GetRatedImages returns all the images that have been rated as safe ignoring the ones from username.
func (*DB) GetTagHistory ¶
func (db *DB) GetTagHistory(id int) (*shimmie.TagHistory, error)
GetTagHistory returns a tag_history row.
func (*DB) GetUserByName ¶
GetUserByName gets a user by unique username.
func (*DB) Log ¶
func (db *DB) Log(section, username, address string, priority int, message string) (*shimmie.SCoreLog, error)
Log stores a message on score_log table.
func (*DB) MostImageUploads ¶
MostImageUploads can be used to find which users have the highest number of image uploads.
func (*DB) MostTagEdits ¶
MostTagEdits can be used to find which users have the highest number of tag edits.
func (*DB) Verify ¶
Verify compares the provided username and password with the username and password hash stored in the shimmie database.
It can return:
- The shimmie User on success.
- ErrNotFound if the username does not exist.
- ErrWrongCredentials if the username and password do not match.
- An error if something goes wrong with the database.
type Schema ¶
Schema has methods which allow to create the db schema as well as truncate all tables.
func NewSchemer ¶
NewSchemer returns an implementation of Schemer that allows to easily create and drop the database schema.