shimmiedb

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2020 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tx

func Tx(db *sql.DB, txFunc func(*sql.Tx) error) (err error)

Tx allows to perform a function in a transaction. It detects error and panic and in that case it rollbacks otherwise it commits the transaction.

Types

type DB

type DB struct {
	*sql.DB
}

DB has methods for most operations needed in the shimmie database.

func Open

func Open(dataSource string, pingRetries int) (*DB, error)

Open creates a database connection for the given driver and configuration.

func (*DB) Autocomplete

func (db *DB) Autocomplete(q string, limit, offset int) ([]*shimmie.Autocomplete, error)

Autocomplete searches tags and tag alias for a term and returns suggestions tags to be used for a UI autocomplete.

func (*DB) CountAlias

func (db *DB) CountAlias() (int, error)

CountAlias returns how many alias entries exist in the database.

func (*DB) CountUsers

func (db *DB) CountUsers() (int, error)

CountUsers returns how many user entries exist in the database.

func (*DB) CreateAlias

func (db *DB) CreateAlias(alias *shimmie.Alias) error

CreateAlias creates a new alias.

func (*DB) CreateImage

func (db *DB) CreateImage(ctx context.Context, img shimmie.Image) (int64, error)

CreateImage inserts a new image to the database.

func (*DB) CreatePM

func (db *DB) CreatePM(pm *shimmie.PM) error

CreatePM inserts a new private message.

func (*DB) CreateTag

func (db *DB) CreateTag(t *shimmie.Tag) error

CreateTag inserts an image tag to the db.

func (*DB) CreateTagHistory

func (db *DB) CreateTagHistory(ctx context.Context, th shimmie.TagHistory) (int64, error)

CreateTagHistory inserts a new tag history for an image in the db.

func (*DB) CreateUser

func (db *DB) CreateUser(u *shimmie.User) error

CreateUser creates a new user and returns their ID.

func (*DB) DeleteAlias

func (db *DB) DeleteAlias(oldTag string) error

DeleteAlias deletes an alias based on its old tag.

func (*DB) DeleteTag

func (db *DB) DeleteTag(name string) error

DeleteTag deletes an image tag.

func (*DB) DeleteUser

func (db *DB) DeleteUser(id int64) error

DeleteUser deletes a user based on their ID.

func (*DB) FindAlias

func (db *DB) FindAlias(oldTag, newTag string) ([]shimmie.Alias, error)

FindAlias returns all alias matching an oldTag or a newTag or both.

func (*DB) GetAlias

func (db *DB) GetAlias(oldTag string) (*shimmie.Alias, error)

GetAlias returns an alias based on its old tag.

func (*DB) GetAllAlias

func (db *DB) GetAllAlias(limit, offset int) ([]shimmie.Alias, error)

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

func (db *DB) GetAllTags(limit, offset int) ([]*shimmie.Tag, error)

GetAllTags returns all stored tags.

func (*DB) GetAllUsers

func (db *DB) GetAllUsers(limit, offset int) ([]shimmie.User, error)

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) GetCommon

func (db *DB) GetCommon() (*shimmie.Common, error)

GetCommon gets common configuration values.

func (*DB) GetConfig

func (db *DB) GetConfig(keys ...string) (map[string]string, error)

GetConfig gets shimmie config values.

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) GetImage

func (db *DB) GetImage(id int) (*shimmie.Image, error)

GetImage gets a shimmie Image metadata (not it's bytes).

func (*DB) GetImageTagHistory

func (db *DB) GetImageTagHistory(imageID int) ([]shimmie.TagHistory, error)

GetImageTagHistory returns the previous tags of an image.

func (*DB) GetPMs

func (db *DB) GetPMs(from, to string, choice shimmie.PMChoice) ([]*shimmie.PM, error)

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) GetTag

func (db *DB) GetTag(oldTag string) (*shimmie.Tag, error)

GetTag returns an image tag.

func (*DB) GetTagHistory

func (db *DB) GetTagHistory(id int) (*shimmie.TagHistory, error)

GetTagHistory returns a tag_history row.

func (*DB) GetUser

func (db *DB) GetUser(userID int64) (*shimmie.User, error)

GetUser gets a user by ID.

func (*DB) GetUserByName

func (db *DB) GetUserByName(username string) (*shimmie.User, error)

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) LogRating

func (db *DB) LogRating(imgID int, imgRating, username, userIP string) error

LogRating logs when an image rating is set.

func (*DB) MostImageUploads

func (db *DB) MostImageUploads(limit int) ([]shimmie.UserScore, error)

MostImageUploads can be used to find which users have the highest number of image uploads.

func (*DB) MostTagEdits

func (db *DB) MostTagEdits(limit int) ([]shimmie.UserScore, error)

MostTagEdits can be used to find which users have the highest number of tag edits.

func (*DB) RateImage

func (db *DB) RateImage(id int, rating string) error

RateImage sets the rating for an image.

func (*DB) Verify

func (db *DB) Verify(username, password string) (*shimmie.User, error)

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.

func (*DB) WriteImageFile

func (db *DB) WriteImageFile(w io.Writer, path, hash string) error

WriteImageFile reads a shimmie image file (image or thumb) which exists under a path and has a hash and then writes to w.

type Schema

type Schema struct {
	*sql.DB
}

Schema has methods which allow to create the db schema as well as truncate all tables.

func NewSchemer

func NewSchemer(dataSource string, pingRetries int) (*Schema, error)

NewSchemer returns an implementation of Schemer that allows to easily create and drop the database schema.

func (Schema) Create

func (db Schema) Create() error

Create creates the database schema.

func (Schema) TruncateTables

func (db Schema) TruncateTables(ctx context.Context) error

TruncateTables truncates all the database tables.

Jump to

Keyboard shortcuts

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