db

package
v0.0.0-...-82df24b Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCommentExists = errors.New("comment exists")
View Source
var ErrMemberNotFound = errors.New("member dose not exist")
View Source
var ErrVideoExists = errors.New("duplicate video")
View Source
var ErrVideoNotFound = errors.New("video dose not exist")
View Source
var ErrVideoURLExists = errors.New("duplicate video url")

Functions

func Init

func Init() error

Init connects to the database and migrate tables.

Types

type Comment

type Comment struct {
	Cid           string          `db:"cid" json:"cid"`
	VideoID       string          `db:"video_id" json:"video_id"`
	DiggCount     int64           `db:"digg_count" json:"digg_count"`
	Text          string          `db:"text" json:"text"`
	TextClean     string          `db:"text_clean" json:"text_clean"`
	TextExtra     json.RawMessage `db:"text_extra" json:"text_extra"`
	UserNickname  string          `db:"user_nickname" json:"user_nickname"`
	UserAvatarURI string          `db:"user_avatar_uri" json:"user_avatar_uri"`
	UserSecUID    string          `db:"user_sec_uid" json:"user_sec_uid"`
	CreatedAt     time.Time       `db:"created_at" json:"created_at"`
}

type CommentsStore

type CommentsStore interface {
	// Create creates a new comment with the given options.
	// If the comment already exists, it returns ErrCommentExists.
	Create(ctx context.Context, cid string, opts CreateCommentOptions) error
}
var Comments CommentsStore

func NewCommentsStore

func NewCommentsStore(db sqlbuilder.Database) CommentsStore

type CreateCommentOptions

type CreateCommentOptions struct {
	VideoID       string
	Text          string
	TextClean     string
	TextExtra     json.RawMessage
	UserNickname  string
	UserAvatarURI string
	UserSecUID    string
	CreatedAt     time.Time
}

type CreateStatisticOptions

type CreateStatisticOptions struct {
	Share   int64
	Forward int64
	Digg    int64
	Play    int64
	Comment int64
}

type CreateVideoOptions

type CreateVideoOptions struct {
	VID              string
	AuthorSecUID     model.MemberSecUID
	Description      string
	TextExtra        []string
	OriginCoverURLs  []string
	DynamicCoverURLs []string
	IsDynamicCover   bool
	VideoHeight      int
	VideoWidth       int
	VideoDuration    int64
	VideoRatio       string
}

type ListVideoOptions

type ListVideoOptions struct {
	Keyword string
	SecUIDs []string
	OrderBy string
	Order   string

	Page     int
	PageSize int
}

type Member

type Member struct {
	SecUID    model.MemberSecUID `db:"sec_uid" json:"sec_uid"`
	UID       string             `db:"uid" json:"uid"`
	UniqueID  string             `db:"unique_id" json:"unique_id"`
	ShortUID  string             `db:"short_id" json:"short_uid"`
	Name      string             `db:"name" json:"name"`
	AvatarURL string             `db:"avatar_url" json:"avatar_url"`
	Signature string             `db:"signature" json:"signature"`
}

type MembersStore

type MembersStore interface {
	// Upsert creates a new member profile record with the given options,
	// it updates the `name` `avatar_url` `signature` field if the member is exists.
	Upsert(ctx context.Context, opts UpsertMemberOptions) error
	// GetBySecID returns the latest member profile with the given SecUID.
	GetBySecID(ctx context.Context, secUID model.MemberSecUID) (*Member, error)
	// GetBySecIDs returns the members' profile with the given SecUIDs.
	// It will be ignored if the member does not exist.
	GetBySecIDs(ctx context.Context, secUIDs ...model.MemberSecUID) ([]*Member, error)
	// List returns all the members.
	List(ctx context.Context) ([]*Member, error)
}
var Members MembersStore

func NewMembersStore

func NewMembersStore(db sqlbuilder.Database) MembersStore

type Statistic

type Statistic struct {
	ID        string    `db:"id" json:"id"`
	Share     int64     `db:"share" json:"share"`
	Forward   int64     `db:"forward" json:"forward"`
	Digg      int64     `db:"digg" json:"digg"`
	Play      int64     `db:"play" json:"play"`
	Comment   int64     `db:"comment" json:"comment"`
	CreatedAt time.Time `db:"created_at" json:"-"`
}

type StatisticsStore

type StatisticsStore interface {
	// Create creates a new statistic record with the given options.
	Create(ctx context.Context, id string, opts CreateStatisticOptions) error
}
var Statistics StatisticsStore

func NewStatisticsStore

func NewStatisticsStore(db sqlbuilder.Database) StatisticsStore

type UpdateVideoOptions

type UpdateVideoOptions struct {
	VID              string
	IsDynamicCover   bool
	OriginCoverURLs  []string
	DynamicCoverURLs []string
	FacePoints       json.RawMessage
	CoverHeight      int
	CoverWidth       int
	CreatedAt        time.Time
}

type UpsertMemberOptions

type UpsertMemberOptions struct {
	SecUID    model.MemberSecUID
	UID       string
	UniqueID  string
	ShortUID  string
	Name      string
	AvatarURL string
	Signature string
}

type Video

type Video struct {
	ID               string             `db:"id" json:"id"`
	VID              string             `db:"vid" json:"vid"`
	AuthorSecUID     model.MemberSecUID `db:"author_sec_id" json:"author_sec_uid"`
	Author           *Member            `db:",inline" json:"author"`
	Statistic        model.Statistic    `db:",inline" json:"statistic"`
	Description      string             `db:"description" json:"description"`
	TextExtra        []string           `db:"text_extra" json:"text_extra"`
	OriginCoverURLs  []string           `db:"origin_cover_urls" json:"origin_cover_urls"`
	DynamicCoverURLs []string           `db:"dynamic_cover_urls" json:"dynamic_cover_urls"`
	IsDynamicCover   bool               `db:"is_dynamic_cover" json:"is_dynamic_cover"`
	FacePoints       *dbutil.JSON       `db:"face_points" json:"face_points"`
	CoverHeight      int                `db:"cover_height" json:"cover_height"`
	CoverWidth       int                `db:"cover_width" json:"cover_width"`
	VideoHeight      int                `db:"video_height" json:"video_height"`
	VideoWidth       int                `db:"video_width" json:"video_width"`
	VideoDuration    int64              `db:"video_duration" json:"video_duration"`
	VideoRatio       string             `db:"video_ratio" json:"video_ratio"`
	CreatedAt        time.Time          `db:"created_at" json:"created_at"`
}

type VideoStatus

type VideoStatus string
var (
	VideoStatusAvailable   VideoStatus = "available"
	VideoStatusUnavailable VideoStatus = "unavailable"
)

type VideoURL

type VideoURL struct {
	VideoID     string    `db:"video_id"`
	URL         string    `db:"url"`
	Status      string    `db:"status"`
	LastCheckAt time.Time `db:"last_check_at"`
}

type VideoURLsStore

type VideoURLsStore interface {
	// Create creates a new video url with the given video ID and url.
	Create(ctx context.Context, videoID, url string) error
	// GetByVideoID returns the available video urls with the given video ID.
	GetByVideoID(ctx context.Context, videoID string) ([]string, error)
	// GetAvailableVideoURLs returns all the available video urls.
	GetAvailableVideoURLs(ctx context.Context) ([]string, error)
	// SetStatus set the video url status.
	SetStatus(ctx context.Context, videoURL string, status VideoStatus) error
}
var VideoURLs VideoURLsStore

func NewVideoURLsStore

func NewVideoURLsStore(db sqlbuilder.Database) VideoURLsStore

type VideosStore

type VideosStore interface {
	// Create creates a new video record with the given options.
	Create(ctx context.Context, id string, opts CreateVideoOptions) error
	// Update updates the video with the given options.
	Update(ctx context.Context, id string, opts UpdateVideoOptions) error
	// GetByID returns video with the given id, it returns `ErrVideoNotFound` error if video does not exist.
	GetByID(ctx context.Context, id string) (*Video, error)
	// List returns the video list.
	List(ctx context.Context, opts ListVideoOptions) ([]*Video, error)
	// ListIDs returns all the video IDs.
	ListIDs(ctx context.Context) ([]string, error)
	// Random returns a video randomly.
	Random(ctx context.Context) (*Video, error)
	// Refresh refreshes the materialized view.
	Refresh(ctx context.Context) error
}
var Videos VideosStore

func NewVideosStore

func NewVideosStore(db sqlbuilder.Database) VideosStore

Jump to

Keyboard shortcuts

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