Documentation ¶
Overview ¶
Database access
Index ¶
- Constants
- Variables
- func InitCollection(mdb *mongo.Database) error
- func InitTable(db *gorm.DB) error
- type Article
- type ArticleAuthorDAO
- type ArticleDAO
- type ArticleGORMAuthorDAO
- type ArticleGORMReaderDAO
- type ArticleReaderDAO
- type AsyncSMSDAO
- type GORMArticleDAO
- func (a *GORMArticleDAO) GetByAuthor(ctx context.Context, uid int64, offset int, limit int) ([]Article, error)
- func (a *GORMArticleDAO) GetByID(ctx context.Context, id int64) (Article, error)
- func (a *GORMArticleDAO) GetPubByID(ctx context.Context, id int64) (PublishedArticle, error)
- func (a *GORMArticleDAO) Insert(ctx context.Context, article Article) (int64, error)
- func (a *GORMArticleDAO) Sync(ctx context.Context, article Article) (int64, error)
- func (a *GORMArticleDAO) SyncV1(ctx context.Context, article Article) (int64, error)
- func (a *GORMArticleDAO) Transaction(ctx context.Context, fn func(ctx context.Context, tx any) (any, error)) (any, error)
- func (a *GORMArticleDAO) UpdateByID(ctx context.Context, article Article) error
- func (a *GORMArticleDAO) UpdateStatusByID(ctx context.Context, model any, userID int64, articleID int64, status uint8) error
- func (a *GORMArticleDAO) Upsert(ctx context.Context, article PublishedArticle) error
- type GORMAsyncSMSDAO
- type GORMInteractiveDAO
- func (g *GORMInteractiveDAO) DeleteCollectionBiz(ctx context.Context, cb UserCollectionBiz) error
- func (g *GORMInteractiveDAO) DeleteLikeInfo(ctx context.Context, biz string, bizID int64, uid int64) error
- func (g *GORMInteractiveDAO) Get(ctx context.Context, biz string, bizID int64) (Interactive, error)
- func (g *GORMInteractiveDAO) GetCollectInfo(ctx context.Context, biz string, bizID int64, uid int64) (UserCollectionBiz, error)
- func (g *GORMInteractiveDAO) GetLikeInfo(ctx context.Context, biz string, bizID int64, uid int64) (UserLikeBiz, error)
- func (g *GORMInteractiveDAO) IncrReadCnt(ctx context.Context, biz string, bizID int64) error
- func (g *GORMInteractiveDAO) InsertCollectionBiz(ctx context.Context, cb UserCollectionBiz) error
- func (g *GORMInteractiveDAO) InsertLikeInfo(ctx context.Context, biz string, bizID int64, uid int64) error
- type GORMUserDAO
- func (dao *GORMUserDAO) FindByEmail(ctx context.Context, email string) (User, error)
- func (dao *GORMUserDAO) FindByID(ctx context.Context, id int64) (User, error)
- func (dao *GORMUserDAO) FindByPhone(ctx context.Context, phone string) (User, error)
- func (dao *GORMUserDAO) Insert(ctx context.Context, u User) (User, error)
- func (dao *GORMUserDAO) UpdateProfile(ctx context.Context, user User) error
- type Interactive
- type InteractiveDAO
- type MongoDBArticleDAO
- func (m *MongoDBArticleDAO) GetByAuthor(ctx context.Context, uid int64, offset int, limit int) ([]Article, error)
- func (m *MongoDBArticleDAO) GetByID(ctx context.Context, id int64) (Article, error)
- func (m *MongoDBArticleDAO) GetPubByID(ctx context.Context, id int64) (PublishedArticle, error)
- func (m *MongoDBArticleDAO) Insert(ctx context.Context, article Article) (int64, error)
- func (m *MongoDBArticleDAO) Sync(ctx context.Context, article Article) (int64, error)
- func (m *MongoDBArticleDAO) Transaction(ctx context.Context, fn func(ctx context.Context, tx any) (any, error)) (any, error)
- func (m *MongoDBArticleDAO) UpdateByID(ctx context.Context, article Article) error
- func (m *MongoDBArticleDAO) UpdateStatusByID(ctx context.Context, model any, userID int64, articleID int64, status uint8) error
- func (m *MongoDBArticleDAO) Upsert(ctx context.Context, article PublishedArticle) error
- type PublishedArticle
- type SMSInfo
- type User
- type UserCollectionBiz
- type UserDAO
- type UserLikeBiz
Constants ¶
View Source
const ( ArticleCollName = "articles" PublishedArticleCollName = "published_articles" DatabaseName = "wetravel" )
Variables ¶
View Source
var ( ErrDuplicatedUser = errors.New("email already exists") ErrRecordNotFound = gorm.ErrRecordNotFound )
View Source
var ErrArticleNotFound = errors.New("article not found")
View Source
var ErrDuplicatedSMS = errors.New("sms already exists")
Functions ¶
func InitCollection ¶
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 ArticleAuthorDAO ¶
type ArticleAuthorDAO interface { Create(ctx context.Context, article Article) (int64, error) UpdateByID(ctx context.Context, article Article) error }
func NewArticleGORMAuthorDAO ¶
func NewArticleGORMAuthorDAO(db *gorm.DB) ArticleAuthorDAO
type ArticleDAO ¶
type ArticleDAO interface { Insert(ctx context.Context, article Article) (int64, error) UpdateByID(ctx context.Context, article Article) error Sync(ctx context.Context, article Article) (int64, error) Transaction(ctx context.Context, fn func(ctx context.Context, tx any) (any, error)) (any, error) Upsert(ctx context.Context, article PublishedArticle) error // model is like &Article{} or &PublishedArticle{} UpdateStatusByID( ctx context.Context, model any, userID int64, articleID int64, status uint8, ) error GetByAuthor(ctx context.Context, uid int64, offset int, limit int) ([]Article, error) GetByID(ctx context.Context, id int64) (Article, error) GetPubByID(ctx context.Context, id int64) (PublishedArticle, error) }
func NewArticleDAO ¶
func NewArticleDAO(db *gorm.DB) ArticleDAO
func NewMongoDBArticleDAO ¶
func NewMongoDBArticleDAO(client *mongo.Client, node *snowflake.Node) ArticleDAO
type ArticleGORMAuthorDAO ¶
type ArticleGORMAuthorDAO struct {
// contains filtered or unexported fields
}
func (*ArticleGORMAuthorDAO) UpdateByID ¶
func (a *ArticleGORMAuthorDAO) UpdateByID(ctx context.Context, article Article) error
type ArticleGORMReaderDAO ¶
type ArticleGORMReaderDAO struct {
// contains filtered or unexported fields
}
func (*ArticleGORMReaderDAO) Upsert ¶
func (a *ArticleGORMReaderDAO) Upsert(ctx context.Context, article Article) error
func (*ArticleGORMReaderDAO) UpsertV2 ¶
func (a *ArticleGORMReaderDAO) UpsertV2(ctx context.Context, article PublishedArticle) error
type ArticleReaderDAO ¶
type ArticleReaderDAO interface { // Insert and Update Upsert(ctx context.Context, article Article) error UpsertV2(ctx context.Context, article PublishedArticle) error }
func NewArticleGORMReaderDAO ¶
func NewArticleGORMReaderDAO(db *gorm.DB) ArticleReaderDAO
type AsyncSMSDAO ¶
type AsyncSMSDAO interface { Insert(ctx context.Context, s SMSInfo) error Update(ctx context.Context, s SMSInfo) error GetFirst(ctx context.Context) (SMSInfo, error) Delete(ctx context.Context, smsInfo SMSInfo) error }
func NewAsyncSMSDAO ¶
func NewAsyncSMSDAO(db *gorm.DB) AsyncSMSDAO
type GORMArticleDAO ¶
type GORMArticleDAO struct {
// contains filtered or unexported fields
}
func (*GORMArticleDAO) GetByAuthor ¶
func (a *GORMArticleDAO) GetByAuthor( ctx context.Context, uid int64, offset int, limit int, ) ([]Article, error)
GetByAuthor implements ArticleDAO.
func (*GORMArticleDAO) GetPubByID ¶
func (a *GORMArticleDAO) GetPubByID(ctx context.Context, id int64) (PublishedArticle, error)
GetPubByID implements ArticleDAO.
func (*GORMArticleDAO) Transaction ¶
func (*GORMArticleDAO) UpdateByID ¶
func (a *GORMArticleDAO) UpdateByID(ctx context.Context, article Article) error
func (*GORMArticleDAO) UpdateStatusByID ¶
func (*GORMArticleDAO) Upsert ¶
func (a *GORMArticleDAO) Upsert(ctx context.Context, article PublishedArticle) error
type GORMAsyncSMSDAO ¶
type GORMAsyncSMSDAO struct {
// contains filtered or unexported fields
}
func (*GORMAsyncSMSDAO) Delete ¶
func (dao *GORMAsyncSMSDAO) Delete(ctx context.Context, smsInfo SMSInfo) error
func (*GORMAsyncSMSDAO) GetFirst ¶
func (dao *GORMAsyncSMSDAO) GetFirst(ctx context.Context) (SMSInfo, error)
type GORMInteractiveDAO ¶
type GORMInteractiveDAO struct {
// contains filtered or unexported fields
}
func (*GORMInteractiveDAO) DeleteCollectionBiz ¶
func (g *GORMInteractiveDAO) DeleteCollectionBiz(ctx context.Context, cb UserCollectionBiz) error
DeleteCollectionBiz implements InteractiveDAO.
func (*GORMInteractiveDAO) DeleteLikeInfo ¶
func (g *GORMInteractiveDAO) DeleteLikeInfo( ctx context.Context, biz string, bizID int64, uid int64, ) error
DeleteLikeInfo implements InteractiveDAO.
func (*GORMInteractiveDAO) Get ¶
func (g *GORMInteractiveDAO) Get( ctx context.Context, biz string, bizID int64, ) (Interactive, error)
Get implements InteractiveDAO.
func (*GORMInteractiveDAO) GetCollectInfo ¶
func (g *GORMInteractiveDAO) GetCollectInfo( ctx context.Context, biz string, bizID int64, uid int64, ) (UserCollectionBiz, error)
func (*GORMInteractiveDAO) GetLikeInfo ¶
func (g *GORMInteractiveDAO) GetLikeInfo( ctx context.Context, biz string, bizID int64, uid int64, ) (UserLikeBiz, error)
GetLikeInfo implements InteractiveDAO.
func (*GORMInteractiveDAO) IncrReadCnt ¶
IncrReadCnt implements InteractiveDAO.
func (*GORMInteractiveDAO) InsertCollectionBiz ¶
func (g *GORMInteractiveDAO) InsertCollectionBiz(ctx context.Context, cb UserCollectionBiz) error
InsertCollectionBiz implements InteractiveDAO.
func (*GORMInteractiveDAO) InsertLikeInfo ¶
func (g *GORMInteractiveDAO) InsertLikeInfo( ctx context.Context, biz string, bizID int64, uid int64, ) error
InsertLikeInfo implements InteractiveDAO.
type GORMUserDAO ¶
type GORMUserDAO struct {
// contains filtered or unexported fields
}
func (*GORMUserDAO) FindByEmail ¶
func (*GORMUserDAO) FindByPhone ¶
func (*GORMUserDAO) UpdateProfile ¶
func (dao *GORMUserDAO) UpdateProfile(ctx context.Context, user User) error
type Interactive ¶
type InteractiveDAO ¶
type InteractiveDAO interface { IncrReadCnt(ctx context.Context, biz string, bizID int64) error InsertLikeInfo(ctx context.Context, biz string, bizID int64, uid int64) error DeleteLikeInfo(ctx context.Context, biz string, bizID int64, uid int64) error InsertCollectionBiz(ctx context.Context, cb UserCollectionBiz) error DeleteCollectionBiz(ctx context.Context, cb UserCollectionBiz) error Get(ctx context.Context, biz string, bizID int64) (Interactive, error) GetLikeInfo(ctx context.Context, biz string, bizID int64, uid int64) (UserLikeBiz, error) GetCollectInfo( ctx context.Context, biz string, bizID int64, uid int64, ) (UserCollectionBiz, error) }
func NewGORMInteractiveDAO ¶
func NewGORMInteractiveDAO(db *gorm.DB) InteractiveDAO
type MongoDBArticleDAO ¶
type MongoDBArticleDAO struct {
// contains filtered or unexported fields
}
func (*MongoDBArticleDAO) GetByAuthor ¶
func (m *MongoDBArticleDAO) GetByAuthor( ctx context.Context, uid int64, offset int, limit int, ) ([]Article, error)
GetByAuthor implements ArticleDAO.
func (*MongoDBArticleDAO) GetPubByID ¶
func (m *MongoDBArticleDAO) GetPubByID(ctx context.Context, id int64) (PublishedArticle, error)
GetPubByID implements ArticleDAO.
func (*MongoDBArticleDAO) Transaction ¶
func (m *MongoDBArticleDAO) Transaction( ctx context.Context, fn func(ctx context.Context, tx any) (any, error), ) (any, error)
Transaction implements ArticleDAO.
func (*MongoDBArticleDAO) UpdateByID ¶
func (m *MongoDBArticleDAO) UpdateByID(ctx context.Context, article Article) error
UpdateByID implements ArticleDAO.
func (*MongoDBArticleDAO) UpdateStatusByID ¶
func (m *MongoDBArticleDAO) UpdateStatusByID( ctx context.Context, model any, userID int64, articleID int64, status uint8, ) error
UpdateStatusByID implements ArticleDAO.
func (*MongoDBArticleDAO) Upsert ¶
func (m *MongoDBArticleDAO) Upsert(ctx context.Context, article PublishedArticle) error
Upsert implements ArticleDAO.
type User ¶
type User struct { Password string Name string `gorm:"type=varchar(128)"` Profile string `gorm:"type=varchar(4096)"` Email sql.NullString `gorm:"unique"` Phone sql.NullString `gorm:"unique"` // NOTE: autoIncrement for performance: // 1. rows physically stored in key order // 2. Read-ahead ID int64 `gorm:"primaryKey,autoIncrement"` // NOTE: UTC-0 Ctime int64 Utime int64 Birthday int64 }
type UserCollectionBiz ¶
type UserCollectionBiz struct { ID int64 `gorm:"primaryKey,autoIncrement"` // One ressource can only be put into one collection. // Otherwise the composite index should include CID too UID int64 `gorm:"uniqueIndex:uid_biz_type_id"` BizID int64 `gorm:"uniqueIndex:uid_biz_type_id"` Biz string `gorm:"uniqueIndex:uid_biz_type_id,length:128"` // collection ID CID int64 `gorm:"index"` Utime int64 Ctime int64 }
type UserDAO ¶
type UserDAO interface { Insert(ctx context.Context, u User) (User, error) FindByEmail(ctx context.Context, email string) (User, error) FindByPhone(ctx context.Context, phone string) (User, error) FindByID(ctx context.Context, id int64) (User, error) UpdateProfile(ctx context.Context, user User) error }
func NewUserDAO ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.