package officialWebsitemod import ( "time" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo/options" ) // Video 创作者视频 // 表: official_website_video type Video struct { ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` AlbumID primitive.ObjectID `json:"albumId" bson:"albumId"` HeroID primitive.ObjectID `json:"heroId" bson:"heroId"` //创作者ID Title string `json:"title" bson:"title"` SeoSlug string `json:"seoSlug" bson:"seoSlug,omitempty"` // SEO 语义化唯一标识(纯小写字母) Description string `json:"description" bson:"description"` Cover string `json:"cover" bson:"cover"` Url string `json:"url" bson:"url"` Tags []Tag `json:"tags" bson:"tags"` IsHot bool `json:"isHot" bson:"isHot"` WatchCount int64 `json:"watchCount" bson:"watchCount"` LikeCount int64 `json:"likeCount" bson:"likeCount"` CommentCount int64 `json:"commentCount" bson:"commentCount"` CollectCount int64 `json:"collectCount" bson:"collectCount"` SortModel `bson:",inline"` BaseModel `bson:",inline"` } func (v *Video) tableName() string { return tableVideo } func (v *Video) FindOne(filter M) error { return findOneByTable(v.tableName(), &v, filter) } func (v *Video) FindMany(filter M, opts ...*options.FindOptions) ([]Video, error) { out := make([]Video, 0) err := findManyByTable(v.tableName(), &out, filter, opts...) return out, err } func (v *Video) Count(filter M) (int64, error) { return countByTable(v.tableName(), filter) } func (v *Video) Create() error { v.CreatedAt = time.Now().UTC() v.UpdatedAt = v.CreatedAt id, err := createByTable(v.tableName(), v) if err != nil { return err } v.ID = id return nil } func (v *Video) InsertMany(videos []Video) (ids []primitive.ObjectID, err error) { //var docs []interface{} //for _, video := range videos { // docs = append(docs, video) //} return createManyByTable(v.tableName(), videos) } func (v *Video) Update(filter M, update M) (int64, error) { return updateByTable(v.tableName(), filter, update) } func (v *Video) UpdateMany(filter M, update M) (int64, error) { return updateManyByTable(v.tableName(), filter, update) } func (v *Video) Delete(filter M) (int64, error) { return deleteByTable(v.tableName(), filter) }