article

package
v0.0.0-...-d13da26 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPossibleIncorrectAuthor = errors.New("用户在尝试操作非本人数据")

Functions

func InitCollections

func InitCollections(db *mongo.Database) error

Types

type Article

type Article struct {
	Id int64 `gorm:"primaryKey,autoIncrement" bson:"id,omitempty"`
	// 标题的长度
	// 正常都不会超过这个长度
	Title   string `gorm:"type=varchar(4096)" bson:"title,omitempty"`
	Content string `gorm:"type=BLOB" bson:"content,omitempty"`
	// 作者
	AuthorId int64 `gorm:"index" bson:"author_id,omitempty"`
	Status   uint8 `bson:"status,omitempty"`
	Ctime    int64 `bson:"ctime,omitempty"`
	Utime    int64 `bson:"utime,omitempty"`
}

type ArticleDAO

type ArticleDAO interface {
	Insert(ctx context.Context, art Article) (int64, error)
	UpdateById(ctx context.Context, art Article) error
	GetByAuthor(ctx context.Context, author int64, offset, limit int) ([]Article, error)
	GetById(ctx context.Context, id int64) (Article, error)
	GetPubById(ctx context.Context, id int64) (PublishedArticle, error)
	Sync(ctx context.Context, art Article) (int64, error)
	SyncStatus(ctx context.Context, author, id int64, status uint8) error
}

func NewGORMArticleDAO

func NewGORMArticleDAO(db *gorm.DB) ArticleDAO

func NewMongoDBDAO

func NewMongoDBDAO(db *mongo.Database, node *snowflake.Node) ArticleDAO

func NewMongoDBDAOV1

func NewMongoDBDAOV1(db *mongo.Database, idGen IDGenerator) ArticleDAO

func NewOssDAO

func NewOssDAO(oss *s3.S3, db *gorm.DB) ArticleDAO

NewOssDAO 因为组合 GORMArticleDAO 是一个内部实现细节 所以这里要直接传入 DB

type AuthorDAO

type AuthorDAO interface {
	Insert(ctx context.Context, art Article) (int64, error)
	UpdateById(ctx context.Context, article Article) error
}

func NewAuthorDAO

func NewAuthorDAO(db *gorm.DB) AuthorDAO

type GORMArticleDAO

type GORMArticleDAO struct {
	// contains filtered or unexported fields
}

func (*GORMArticleDAO) GetByAuthor

func (dao *GORMArticleDAO) GetByAuthor(ctx context.Context, author int64, offset, limit int) ([]Article, error)

func (*GORMArticleDAO) GetById

func (dao *GORMArticleDAO) GetById(ctx context.Context, id int64) (Article, error)

func (*GORMArticleDAO) GetPubById

func (dao *GORMArticleDAO) GetPubById(ctx context.Context, id int64) (PublishedArticle, error)

func (*GORMArticleDAO) Insert

func (dao *GORMArticleDAO) Insert(ctx context.Context,
	art Article) (int64, error)

func (*GORMArticleDAO) Sync

func (dao *GORMArticleDAO) Sync(ctx context.Context,
	art Article) (int64, error)

func (*GORMArticleDAO) SyncClosure

func (dao *GORMArticleDAO) SyncClosure(ctx context.Context,
	art Article) (int64, error)

func (*GORMArticleDAO) SyncStatus

func (dao *GORMArticleDAO) SyncStatus(ctx context.Context, author, id int64, status uint8) error

func (*GORMArticleDAO) UpdateById

func (dao *GORMArticleDAO) UpdateById(ctx context.Context,
	art Article) error

UpdateById 只更新标题、内容和状态

type IDGenerator

type IDGenerator func() int64

type MongoDBDAO

type MongoDBDAO struct {
	// contains filtered or unexported fields
}

func (*MongoDBDAO) GetByAuthor

func (m *MongoDBDAO) GetByAuthor(ctx context.Context, author int64, offset, limit int) ([]Article, error)

func (*MongoDBDAO) GetById

func (m *MongoDBDAO) GetById(ctx context.Context, id int64) (Article, error)

func (*MongoDBDAO) GetPubById

func (m *MongoDBDAO) GetPubById(ctx context.Context, id int64) (PublishedArticle, error)

func (*MongoDBDAO) Insert

func (m *MongoDBDAO) Insert(ctx context.Context, art Article) (int64, error)

func (*MongoDBDAO) Sync

func (m *MongoDBDAO) Sync(ctx context.Context, art Article) (int64, error)

func (*MongoDBDAO) SyncStatus

func (m *MongoDBDAO) SyncStatus(ctx context.Context, author, id int64, status uint8) error

func (*MongoDBDAO) UpdateById

func (m *MongoDBDAO) UpdateById(ctx context.Context, art Article) error

type PublishedArticle

type PublishedArticle Article

PublishedArticle 衍生类型,偷个懒

type PublishedArticleV1

type PublishedArticleV1 struct {
	Id       int64  `gorm:"primaryKey,autoIncrement" bson:"id,omitempty"`
	Title    string `gorm:"type=varchar(4096)" bson:"title,omitempty"`
	AuthorId int64  `gorm:"index" bson:"author_id,omitempty"`
	Status   uint8  `bson:"status,omitempty"`
	Ctime    int64  `bson:"ctime,omitempty"`
	Utime    int64  `bson:"utime,omitempty"`
}

type ReaderDAO

type ReaderDAO interface {
	Upsert(ctx context.Context, art Article) error
	UpsertV2(ctx context.Context, art PublishedArticle) error
}

func NewReaderDAO

func NewReaderDAO(db *gorm.DB) ReaderDAO

type S3DAO

type S3DAO struct {

	// 通过组合 GORMArticleDAO 来简化操作
	// 当然在实践中,你是不太会有组合的机会
	// 你操作制作库总是一样的
	// 你就是操作线上库的时候不一样
	GORMArticleDAO
	// contains filtered or unexported fields
}

func (*S3DAO) Sync

func (o *S3DAO) Sync(ctx context.Context, art Article) (int64, error)

func (*S3DAO) SyncStatus

func (o *S3DAO) SyncStatus(ctx context.Context, author, id int64, status uint8) error

Jump to

Keyboard shortcuts

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