model

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilToken         = errors.New("token is nil")
	ErrNilUploadingSize = errors.New("uploading size is 0")
)
View Source
var (
	ErrNilMethodReceiver    = errors.New("method receiver is nil")
	ErrNilImageID           = errors.New("image is nil")
	ErrNilTag               = errors.New("tag is nil")
	ErrUnsupportedImageType = errors.New("image type is not supported now")
	ErrDuplicateImage       = errors.New("image is duplicated")
)
View Source
var (
	ErrNilMD5Sum = errors.New("md5 sum is nil. not valid")
)
View Source
var (
	ErrNilTagName = errors.New("no tag name specified")
)

Functions

func AddAuthToken

func AddAuthToken(ctx context.Context, token string) error

func AddTags

func AddTags(ctx context.Context, imageID string, tags []Tag) error

func AddUploadingBytes

func AddUploadingBytes(ctx context.Context, token string, bytes int64) error

func CheckImageExists

func CheckImageExists(ctx context.Context, md5 string) error

func CheckTokenExists

func CheckTokenExists(ctx context.Context, token string) error

func DeleteRichImage added in v0.1.2

func DeleteRichImage(ctx context.Context, imageID, token string) error

func DeleteTagsForImage

func DeleteTagsForImage(ctx context.Context, imageID string, tags []Tag) error

func GeneratePresignedUploadURL

func GeneratePresignedUploadURL(ctx context.Context, mime, md5 string) (imageID, uri string, err error)

func InsertRichImage

func InsertRichImage(ctx context.Context, token, imageID, md5 string, tags []Tag, imgBytes int64) error

func UpdateTagI18n added in v0.2.0

func UpdateTagI18n(ctx context.Context, tags []Tag) error

UpdateTagI19n - return update failed TagID

Types

type AuthToken

type AuthToken struct {
	CreatedAt time.Time      `json:"-"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`

	Token          string `gorm:"column:token;primaryKey"`
	UploadingBytes int64  `gorm:"column:uploading_bytes"`
}

func (*AuthToken) TableName

func (*AuthToken) TableName() string

type Image

type Image struct {
	CreatedAt time.Time
	UpdatedAt time.Time

	ImageID    string `gorm:"column:image_id;primaryKey"`
	ExternalID string `gorm:"column:external_id"`
	MD5Sum     string `gorm:"column:md5_sum;unique"` // for shrinking file duplication

	Owner string `gorm:"column:owner"`
}

func (*Image) TableName

func (*Image) TableName() string

type ImageTagRelation

type ImageTagRelation struct {
	ImageID string `gorm:"column:image_id;primaryKey"`
	// TagName string `gorm:"column:tag_name;primaryKey"`
	TagID int32 `gorm:"column:tag_id;primaryKey"`
}

func (*ImageTagRelation) TableName

func (*ImageTagRelation) TableName() string

type RichImage

type RichImage struct {
	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`

	ImageID    string        `gorm:"column:image_id;primaryKey" json:"image_id"`
	ExternalID string        `gorm:"column:external_id" json:"-"`
	MD5Sum     string        `gorm:"column:md5_sum;unique" json:"md5_sum"` // for shrinking file duplication
	TagIds     pq.Int32Array `gorm:"column:tag_ids;type:integer[]" json:"tag_ids"`
	Limit      int           `gorm:"-"`

	Tags []Tag `gorm:"-"`
}

func GetRandomImages added in v0.1.2

func GetRandomImages(ctx context.Context, tags []int32, limit int) ([]RichImage, error)

it is not efficient but suit for small dataset. for big dataset, using tablesample like below for efficiency

1) enable tsr extension: `CREATE EXTENSION tsm_system_rows` ~~2) make rich_image as a meterialed view~~ using natural join instead 3) replace below random select to this: `select * from rich_image tablesample system_rows(1);`

func GetRichImages

func GetRichImages(ctx context.Context, before time.Time, includeTagIds, excludeTagIds []int32, limit int) ([]RichImage, error)

func (*RichImage) TableName

func (*RichImage) TableName() string

type Tag

type Tag struct {
	ID        int32          `gorm:"column:id;primaryKey;autoIncrement"`
	CreatedAt time.Time      `json:"-"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`

	// Aliases pq.StringArray `gorm:"column:aliases;type:text[]" json:"aliases"`
	TagNameEN string `gorm:"column:tag_name_en"`
	TagNameCN string `gorm:"column:tag_name_cn"`
	TagNameJP string `gorm:"column:tag_name_jp"`
}

func GetAllTags added in v0.2.0

func GetAllTags(ctx context.Context) ([]Tag, error)

func (*Tag) TableName

func (*Tag) TableName() string

Jump to

Keyboard shortcuts

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