database

package
v0.0.0-...-4711403 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2023 License: MPL-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateNullInt64

func CreateNullInt64(i int64) sql.NullInt64

func CreateNullString

func CreateNullString(s string) sql.NullString

func FormatComparator

func FormatComparator(field string, value string) string

func FormatGif

func FormatGif(gif string) string

func FormatNsfw

func FormatNsfw(isNfw string) string

func FormatNsfwTags

func FormatNsfwTags(isNsfw string, includedTags []string, parameters *[]any) string

func FormatOrderBy

func FormatOrderBy(orderBy string, prefix string, randomEnabled bool) string

func FormatOrientation

func FormatOrientation(orientation string) string

Types

type Database

type Database struct {
	Db *sql.DB
	// contains filtered or unexported fields
}

func InitDatabase

func InitDatabase(config config.Configuration) Database

func (Database) DeleteImageFromFav

func (database Database) DeleteImageFromFav(userId int64, imageId int64) error

func (Database) FetchImages

func (database Database) FetchImages(
	isNsfw string,
	includedTags []string,
	excludedTags []string,
	includedFiles []string,
	excludedFiles []string,
	gif string,
	orderBy string,
	orientation string,
	many bool,
	full bool,
	width string,
	height string,
	byteSize string,
	userId int64,
) (ImageRows, time.Duration, error)

FetchImages this method is charged of generating the appropriate query based on the user query params (after binding) and querying the database

func (Database) GetMissingPermissions

func (database Database) GetMissingPermissions(userId int64, targetUserId int64, permissions []string) ([]string, error)

GetMissingPermissions Provide a user id, an optional target user id, and permissions checks for all provided permissions that a user has the permissions globally or for the target if provided. Some might argue that performing a query for each permission might not be a good idea ,however fetching permissions position before might be a bit of a hassle and conduct to more query for the most command case : /fav , that only needs one permission. feel free to share your opinion if you have a better idea.

func (Database) GetTags

func (database Database) GetTags() ([]models.Tag, error)

func (Database) GetUserInformationFromId

func (database Database) GetUserInformationFromId(userId int64) (models.User, error)

func (Database) GetUserInformationFromToken

func (database Database) GetUserInformationFromToken(token string) (models.User, error)

func (Database) InsertImageToFav

func (database Database) InsertImageToFav(userId int64, imageId int64) error

func (Database) InsertUser

func (database Database) InsertUser(user ipc.User) error

func (Database) LogRequest

func (database Database) LogRequest(ip string, url string, userAgent string, userId int64, version string, execTime int64, headers string, responseBody string, statusCode int)

func (Database) Report

func (database Database) Report(userId int64, imageId int64, description *string) (ReportRes, error)

func (Database) ToggleImageInFav

func (database Database) ToggleImageInFav(userId int64, imageId int64) (string, error)

type ImageRow

type ImageRow struct {
	Signature        string  `field:"signature" json:"signature"`
	Extension        string  `field:"extension" json:"extension"`
	ImageId          int64   `field:"image_id" json:"image_id"`
	Favorites        int64   `field:"favorites" json:"favorites"`
	DominantColor    string  `field:"dominant_color" json:"dominant_color"`
	Source           *string `field:"source" json:"source"`
	UploadedAt       string  `field:"uploaded_at" json:"uploaded_at"`
	LikedAt          *string `field:"liked_at" json:"liked_at"`
	IsNsfw           bool    `field:"is_nsfw" json:"is_nsfw"`
	Width            int64   `field:"width" json:"width"`
	Height           int64   `field:"height" json:"height"`
	ByteSize         int64   `field:"byte_size" json:"byte_size"`
	TagId            int64   `field:"tag_id" json:"tag_id"`
	TagName          string  `field:"tag_name" json:"tag_name"`
	TagDescription   string  `field:"tag_description" json:"tag_description"`
	TagIsNsfw        bool    `field:"tag_is_nsfw" json:"tag_is_nsfw"`
	ArtistId         *int64  `field:"artist_id" json:"artist_id"`
	ArtistName       *string `field:"artist_name" json:"artist_name"`
	ArtistPatreon    *string `field:"artist_patreon" json:"artist_patreon"`
	ArtistTwitter    *string `field:"artist_twitter" json:"artist_twitter"`
	ArtistDeviantArt *string `field:"artist_deviant_art" json:"artist_deviant_art"`
	ArtistPixiv      *string `field:"artist_pixiv" json:"artist_pixiv"`
}

ImageRow Represent a row when retrieving images (likedAt may not be present)

type ImageRows

type ImageRows struct {
	Configuration config.Configuration
	Rows          []ImageRow
}

ImageRows Represent multiple rows

func (ImageRows) GetImage

func (ir ImageRows) GetImage(ImageId int64) models.Image

type PermissionsInformation

type PermissionsInformation struct {
	UserId   int64
	TargetId *int64
	Position int
	Name     string
}

PermissionsInformation a struct used to retrieve and a row from the database

type ReportRes

type ReportRes struct {
	ImageId     int64   `json:"image_id" field:"image_id" `
	AuthorId    int64   `json:"author_id" field:"author_id"`
	Description *string `json:"description" field:"description"`
	Existed     bool    `json:"existed" field:"existed"`
}

Jump to

Keyboard shortcuts

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