Documentation
¶
Index ¶
- Variables
- func FeedbackTypeExpressionToMongo(e expression.FeedbackTypeExpression) bson.M
- func FeedbackTypeExpressionToSQL(db *gorm.DB, e expression.FeedbackTypeExpression) *gorm.DB
- func Register(prefixes []string, creator Creator)
- func SortFeedbacks(feedback []Feedback)
- func ValidateLabels(o any) error
- type ClickHouseItem
- type ClickhouseUser
- type Creator
- type Database
- type Feedback
- type FeedbackKey
- type Item
- type ItemFeedback
- type ItemPatch
- type MongoDB
- func (db *MongoDB) BatchGetItems(ctx context.Context, itemIds []string) ([]Item, error)
- func (db *MongoDB) BatchInsertFeedback(ctx context.Context, feedback []Feedback, ...) error
- func (db *MongoDB) BatchInsertItems(ctx context.Context, items []Item) error
- func (db *MongoDB) BatchInsertUsers(ctx context.Context, users []User) error
- func (db *MongoDB) Close() error
- func (db *MongoDB) CountFeedback(ctx context.Context) (int, error)
- func (db *MongoDB) CountItems(ctx context.Context) (int, error)
- func (db *MongoDB) CountUsers(ctx context.Context) (int, error)
- func (db *MongoDB) DeleteItem(ctx context.Context, itemId string) error
- func (db *MongoDB) DeleteUser(ctx context.Context, userId string) error
- func (db *MongoDB) DeleteUserItemFeedback(ctx context.Context, userId, itemId string, feedbackTypes ...string) (int, error)
- func (db *MongoDB) GetFeedback(ctx context.Context, cursor string, n int, beginTime, endTime *time.Time, ...) (string, []Feedback, error)
- func (db *MongoDB) GetFeedbackStream(ctx context.Context, batchSize int, scanOptions ...ScanOption) (chan []Feedback, chan error)
- func (db *MongoDB) GetItem(ctx context.Context, itemId string) (item Item, err error)
- func (db *MongoDB) GetItemFeedback(ctx context.Context, itemId string, feedbackTypes ...string) ([]Feedback, error)
- func (db *MongoDB) GetItemStream(ctx context.Context, batchSize int, timeLimit *time.Time) (chan []Item, chan error)
- func (db *MongoDB) GetItems(ctx context.Context, cursor string, n int, timeLimit *time.Time) (string, []Item, error)
- func (db *MongoDB) GetLatestItems(ctx context.Context, n int, categories []string) ([]Item, error)
- func (db *MongoDB) GetUser(ctx context.Context, userId string) (user User, err error)
- func (db *MongoDB) GetUserFeedback(ctx context.Context, userId string, endTime *time.Time, ...) ([]Feedback, error)
- func (db *MongoDB) GetUserItemFeedback(ctx context.Context, userId, itemId string, feedbackTypes ...string) ([]Feedback, error)
- func (db *MongoDB) GetUserStream(ctx context.Context, batchSize int) (chan []User, chan error)
- func (db *MongoDB) GetUsers(ctx context.Context, cursor string, n int) (string, []User, error)
- func (db *MongoDB) Init() error
- func (db *MongoDB) ModifyItem(ctx context.Context, itemId string, patch ItemPatch) error
- func (db *MongoDB) ModifyUser(ctx context.Context, userId string, patch UserPatch) error
- func (db *MongoDB) Optimize() error
- func (db *MongoDB) Ping() error
- func (db *MongoDB) Purge() error
- type NoDatabase
- func (NoDatabase) BatchGetItems(_ context.Context, _ []string) ([]Item, error)
- func (NoDatabase) BatchInsertFeedback(_ context.Context, _ []Feedback, _, _, _ bool) error
- func (NoDatabase) BatchInsertItems(_ context.Context, _ []Item) error
- func (NoDatabase) BatchInsertUsers(_ context.Context, _ []User) error
- func (NoDatabase) Close() error
- func (d NoDatabase) CountFeedback(_ context.Context) (int, error)
- func (d NoDatabase) CountItems(_ context.Context) (int, error)
- func (d NoDatabase) CountUsers(_ context.Context) (int, error)
- func (NoDatabase) DeleteItem(_ context.Context, _ string) error
- func (NoDatabase) DeleteUser(_ context.Context, _ string) error
- func (NoDatabase) DeleteUserItemFeedback(_ context.Context, _, _ string, _ ...string) (int, error)
- func (NoDatabase) GetFeedback(_ context.Context, _ string, _ int, _, _ *time.Time, _ ...string) (string, []Feedback, error)
- func (NoDatabase) GetFeedbackStream(_ context.Context, _ int, _ ...ScanOption) (chan []Feedback, chan error)
- func (NoDatabase) GetItem(_ context.Context, _ string) (Item, error)
- func (NoDatabase) GetItemFeedback(_ context.Context, _ string, _ ...string) ([]Feedback, error)
- func (NoDatabase) GetItemStream(_ context.Context, _ int, _ *time.Time) (chan []Item, chan error)
- func (NoDatabase) GetItems(_ context.Context, _ string, _ int, _ *time.Time) (string, []Item, error)
- func (NoDatabase) GetLatestItems(_ context.Context, _ int, _ []string) ([]Item, error)
- func (NoDatabase) GetUser(_ context.Context, _ string) (User, error)
- func (NoDatabase) GetUserFeedback(context.Context, string, *time.Time, ...expression.FeedbackTypeExpression) ([]Feedback, error)
- func (NoDatabase) GetUserItemFeedback(_ context.Context, _, _ string, _ ...string) ([]Feedback, error)
- func (NoDatabase) GetUserStream(_ context.Context, _ int) (chan []User, chan error)
- func (NoDatabase) GetUsers(_ context.Context, _ string, _ int) (string, []User, error)
- func (NoDatabase) Init() error
- func (d NoDatabase) ModifyItem(_ context.Context, _ string, _ ItemPatch) error
- func (d NoDatabase) ModifyUser(_ context.Context, _ string, _ UserPatch) error
- func (NoDatabase) Optimize() error
- func (NoDatabase) Ping() error
- func (NoDatabase) Purge() error
- type ProxyClient
- func (p ProxyClient) BatchGetItems(ctx context.Context, itemIds []string) ([]Item, error)
- func (p ProxyClient) BatchInsertFeedback(ctx context.Context, feedback []Feedback, ...) error
- func (p ProxyClient) BatchInsertItems(ctx context.Context, items []Item) error
- func (p ProxyClient) BatchInsertUsers(ctx context.Context, users []User) error
- func (p ProxyClient) Close() error
- func (p ProxyClient) CountFeedback(ctx context.Context) (int, error)
- func (p ProxyClient) CountItems(ctx context.Context) (int, error)
- func (p ProxyClient) CountUsers(ctx context.Context) (int, error)
- func (p ProxyClient) DeleteItem(ctx context.Context, itemId string) error
- func (p ProxyClient) DeleteUser(ctx context.Context, userId string) error
- func (p ProxyClient) DeleteUserItemFeedback(ctx context.Context, userId, itemId string, feedbackTypes ...string) (int, error)
- func (p ProxyClient) GetFeedback(ctx context.Context, cursor string, n int, beginTime, endTime *time.Time, ...) (string, []Feedback, error)
- func (p ProxyClient) GetFeedbackStream(ctx context.Context, batchSize int, options ...ScanOption) (chan []Feedback, chan error)
- func (p ProxyClient) GetItem(ctx context.Context, itemId string) (Item, error)
- func (p ProxyClient) GetItemFeedback(ctx context.Context, itemId string, feedbackTypes ...string) ([]Feedback, error)
- func (p ProxyClient) GetItemStream(ctx context.Context, batchSize int, timeLimit *time.Time) (chan []Item, chan error)
- func (p ProxyClient) GetItems(ctx context.Context, cursor string, n int, beginTime *time.Time) (string, []Item, error)
- func (p ProxyClient) GetLatestItems(ctx context.Context, n int, categories []string) ([]Item, error)
- func (p ProxyClient) GetUser(ctx context.Context, userId string) (User, error)
- func (p ProxyClient) GetUserFeedback(ctx context.Context, userId string, endTime *time.Time, ...) ([]Feedback, error)
- func (p ProxyClient) GetUserItemFeedback(ctx context.Context, userId, itemId string, feedbackTypes ...string) ([]Feedback, error)
- func (p ProxyClient) GetUserStream(ctx context.Context, batchSize int) (chan []User, chan error)
- func (p ProxyClient) GetUsers(ctx context.Context, cursor string, n int) (string, []User, error)
- func (p ProxyClient) Init() error
- func (p ProxyClient) ModifyItem(ctx context.Context, itemId string, patch ItemPatch) error
- func (p ProxyClient) ModifyUser(ctx context.Context, userId string, patch UserPatch) error
- func (p ProxyClient) Optimize() error
- func (p ProxyClient) Ping() error
- func (p ProxyClient) Purge() error
- type ProxyServer
- func (p *ProxyServer) BatchGetItems(ctx context.Context, in *protocol.BatchGetItemsRequest) (*protocol.BatchGetItemsResponse, error)
- func (p *ProxyServer) BatchInsertFeedback(ctx context.Context, in *protocol.BatchInsertFeedbackRequest) (*protocol.BatchInsertFeedbackResponse, error)
- func (p *ProxyServer) BatchInsertItems(ctx context.Context, in *protocol.BatchInsertItemsRequest) (*protocol.BatchInsertItemsResponse, error)
- func (p *ProxyServer) BatchInsertUsers(ctx context.Context, in *protocol.BatchInsertUsersRequest) (*protocol.BatchInsertUsersResponse, error)
- func (p *ProxyServer) CountFeedback(ctx context.Context, in *protocol.CountFeedbackRequest) (*protocol.CountFeedbackResponse, error)
- func (p *ProxyServer) CountItems(ctx context.Context, in *protocol.CountItemsRequest) (*protocol.CountItemsResponse, error)
- func (p *ProxyServer) CountUsers(ctx context.Context, in *protocol.CountUsersRequest) (*protocol.CountUsersResponse, error)
- func (p *ProxyServer) DeleteItem(ctx context.Context, in *protocol.DeleteItemRequest) (*protocol.DeleteItemResponse, error)
- func (p *ProxyServer) DeleteUser(ctx context.Context, in *protocol.DeleteUserRequest) (*protocol.DeleteUserResponse, error)
- func (p *ProxyServer) DeleteUserItemFeedback(ctx context.Context, in *protocol.DeleteUserItemFeedbackRequest) (*protocol.DeleteUserItemFeedbackResponse, error)
- func (p *ProxyServer) GetFeedback(ctx context.Context, in *protocol.GetFeedbackRequest) (*protocol.GetFeedbackResponse, error)
- func (p *ProxyServer) GetFeedbackStream(in *protocol.GetFeedbackStreamRequest, ...) error
- func (p *ProxyServer) GetItem(ctx context.Context, in *protocol.GetItemRequest) (*protocol.GetItemResponse, error)
- func (p *ProxyServer) GetItemFeedback(ctx context.Context, in *protocol.GetItemFeedbackRequest) (*protocol.GetFeedbackResponse, error)
- func (p *ProxyServer) GetItemStream(in *protocol.GetItemStreamRequest, ...) error
- func (p *ProxyServer) GetItems(ctx context.Context, in *protocol.GetItemsRequest) (*protocol.GetItemsResponse, error)
- func (p *ProxyServer) GetLatestItems(ctx context.Context, in *protocol.GetLatestItemsRequest) (*protocol.GetLatestItemsResponse, error)
- func (p *ProxyServer) GetUser(ctx context.Context, in *protocol.GetUserRequest) (*protocol.GetUserResponse, error)
- func (p *ProxyServer) GetUserFeedback(ctx context.Context, in *protocol.GetUserFeedbackRequest) (*protocol.GetFeedbackResponse, error)
- func (p *ProxyServer) GetUserItemFeedback(ctx context.Context, in *protocol.GetUserItemFeedbackRequest) (*protocol.GetFeedbackResponse, error)
- func (p *ProxyServer) GetUserStream(in *protocol.GetUserStreamRequest, ...) error
- func (p *ProxyServer) GetUsers(ctx context.Context, in *protocol.GetUsersRequest) (*protocol.GetUsersResponse, error)
- func (p *ProxyServer) ModifyItem(ctx context.Context, in *protocol.ModifyItemRequest) (*protocol.ModifyItemResponse, error)
- func (p *ProxyServer) ModifyUser(ctx context.Context, in *protocol.ModifyUserRequest) (*protocol.ModifyUserResponse, error)
- func (p *ProxyServer) Ping(_ context.Context, _ *protocol.PingRequest) (*protocol.PingResponse, error)
- func (p *ProxyServer) Serve(lis net.Listener) error
- func (p *ProxyServer) Stop()
- type SQLDatabase
- func (d *SQLDatabase) BatchGetItems(ctx context.Context, itemIds []string) ([]Item, error)
- func (d *SQLDatabase) BatchInsertFeedback(ctx context.Context, feedback []Feedback, ...) error
- func (d *SQLDatabase) BatchInsertItems(ctx context.Context, items []Item) error
- func (d *SQLDatabase) BatchInsertUsers(ctx context.Context, users []User) error
- func (d *SQLDatabase) Close() error
- func (d *SQLDatabase) CountFeedback(ctx context.Context) (int, error)
- func (d *SQLDatabase) CountItems(ctx context.Context) (int, error)
- func (d *SQLDatabase) CountUsers(ctx context.Context) (int, error)
- func (d *SQLDatabase) DeleteItem(ctx context.Context, itemId string) error
- func (d *SQLDatabase) DeleteUser(ctx context.Context, userId string) error
- func (d *SQLDatabase) DeleteUserItemFeedback(ctx context.Context, userId, itemId string, feedbackTypes ...string) (int, error)
- func (d *SQLDatabase) GetFeedback(ctx context.Context, cursor string, n int, beginTime, endTime *time.Time, ...) (string, []Feedback, error)
- func (d *SQLDatabase) GetFeedbackStream(ctx context.Context, batchSize int, scanOptions ...ScanOption) (chan []Feedback, chan error)
- func (d *SQLDatabase) GetItem(ctx context.Context, itemId string) (Item, error)
- func (d *SQLDatabase) GetItemFeedback(ctx context.Context, itemId string, feedbackTypes ...string) ([]Feedback, error)
- func (d *SQLDatabase) GetItemStream(ctx context.Context, batchSize int, timeLimit *time.Time) (chan []Item, chan error)
- func (d *SQLDatabase) GetItems(ctx context.Context, cursor string, n int, timeLimit *time.Time) (string, []Item, error)
- func (d *SQLDatabase) GetLatestItems(ctx context.Context, n int, categories []string) ([]Item, error)
- func (d *SQLDatabase) GetUser(ctx context.Context, userId string) (User, error)
- func (d *SQLDatabase) GetUserFeedback(ctx context.Context, userId string, endTime *time.Time, ...) ([]Feedback, error)
- func (d *SQLDatabase) GetUserItemFeedback(ctx context.Context, userId, itemId string, feedbackTypes ...string) ([]Feedback, error)
- func (d *SQLDatabase) GetUserStream(ctx context.Context, batchSize int) (chan []User, chan error)
- func (d *SQLDatabase) GetUsers(ctx context.Context, cursor string, n int) (string, []User, error)
- func (d *SQLDatabase) Init() error
- func (d *SQLDatabase) ModifyItem(ctx context.Context, itemId string, patch ItemPatch) error
- func (d *SQLDatabase) ModifyUser(ctx context.Context, userId string, patch UserPatch) error
- func (d *SQLDatabase) Optimize() error
- func (d *SQLDatabase) Ping() error
- func (d *SQLDatabase) Purge() error
- type SQLDriver
- type SQLItem
- type SQLUser
- type ScanOption
- func WithBeginItemId(itemId string) ScanOption
- func WithBeginTime(t time.Time) ScanOption
- func WithBeginUserId(userId string) ScanOption
- func WithEndItemId(itemId string) ScanOption
- func WithEndTime(t time.Time) ScanOption
- func WithEndUserId(userId string) ScanOption
- func WithFeedbackTypes(feedbackTypes ...expression.FeedbackTypeExpression) ScanOption
- func WithOrderByItemId() ScanOption
- type ScanOptions
- type User
- type UserFeedback
- type UserPatch
Constants ¶
This section is empty.
Variables ¶
var ( ErrUserNotExist = errors.NotFoundf("user") ErrItemNotExist = errors.NotFoundf("item") ErrNoDatabase = errors.NotAssignedf("database") )
Functions ¶
func FeedbackTypeExpressionToMongo ¶
func FeedbackTypeExpressionToMongo(e expression.FeedbackTypeExpression) bson.M
func FeedbackTypeExpressionToSQL ¶
func FeedbackTypeExpressionToSQL(db *gorm.DB, e expression.FeedbackTypeExpression) *gorm.DB
func SortFeedbacks ¶
func SortFeedbacks(feedback []Feedback)
SortFeedbacks sorts feedback from latest to oldest.
func ValidateLabels ¶
ValidateLabels checks if labels are valid. Labels are valid if consists of: - []string slice of strings - []float64 slice of numbers - map[string]any map of strings to valid labels or float64
Types ¶
type ClickHouseItem ¶
func NewClickHouseItem ¶
func NewClickHouseItem(item Item) (clickHouseItem ClickHouseItem)
type ClickhouseUser ¶
func NewClickhouseUser ¶
func NewClickhouseUser(user User) (clickhouseUser ClickhouseUser)
type Database ¶
type Database interface {
Init() error
Ping() error
Close() error
Optimize() error
Purge() error
BatchInsertItems(ctx context.Context, items []Item) error
BatchGetItems(ctx context.Context, itemIds []string) ([]Item, error)
DeleteItem(ctx context.Context, itemId string) error
GetItem(ctx context.Context, itemId string) (Item, error)
ModifyItem(ctx context.Context, itemId string, patch ItemPatch) error
GetItems(ctx context.Context, cursor string, n int, beginTime *time.Time) (string, []Item, error)
GetLatestItems(ctx context.Context, n int, categories []string) ([]Item, error)
GetItemFeedback(ctx context.Context, itemId string, feedbackTypes ...string) ([]Feedback, error)
BatchInsertUsers(ctx context.Context, users []User) error
DeleteUser(ctx context.Context, userId string) error
GetUser(ctx context.Context, userId string) (User, error)
ModifyUser(ctx context.Context, userId string, patch UserPatch) error
GetUsers(ctx context.Context, cursor string, n int) (string, []User, error)
GetUserFeedback(ctx context.Context, userId string, endTime *time.Time, feedbackTypes ...expression.FeedbackTypeExpression) ([]Feedback, error)
GetUserItemFeedback(ctx context.Context, userId, itemId string, feedbackTypes ...string) ([]Feedback, error)
DeleteUserItemFeedback(ctx context.Context, userId, itemId string, feedbackTypes ...string) (int, error)
BatchInsertFeedback(ctx context.Context, feedback []Feedback, insertUser, insertItem, overwrite bool) error
GetFeedback(ctx context.Context, cursor string, n int, beginTime, endTime *time.Time, feedbackTypes ...string) (string, []Feedback, error)
GetUserStream(ctx context.Context, batchSize int) (chan []User, chan error)
GetItemStream(ctx context.Context, batchSize int, timeLimit *time.Time) (chan []Item, chan error)
GetFeedbackStream(ctx context.Context, batchSize int, options ...ScanOption) (chan []Feedback, chan error)
CountUsers(ctx context.Context) (int, error)
CountItems(ctx context.Context) (int, error)
CountFeedback(ctx context.Context) (int, error)
}
type Feedback ¶
type Feedback struct {
FeedbackKey `gorm:"embedded" mapstructure:",squash"`
Value float64 `gorm:"column:value" mapstructure:"value"`
Timestamp time.Time `gorm:"column:time_stamp" mapsstructure:"timestamp"`
Updated time.Time `gorm:"column:updated" mapstructure:"updated"`
Comment string `gorm:"column:comment" mapsstructure:"comment"`
}
Feedback stores feedback.
type FeedbackKey ¶
type FeedbackKey struct {
FeedbackType string `gorm:"column:feedback_type" mapstructure:"feedback_type"`
UserId string `gorm:"column:user_id" mapstructure:"user_id"`
ItemId string `gorm:"column:item_id" mapstructure:"item_id"`
}
FeedbackKey identifies feedback.
type Item ¶
type Item struct {
ItemId string `gorm:"primaryKey" mapstructure:"item_id"`
IsHidden bool `mapstructure:"is_hidden"`
Categories []string `gorm:"serializer:json" mapstructure:"categories"`
Timestamp time.Time `gorm:"column:time_stamp" mapstructure:"timestamp"`
Labels any `gorm:"serializer:json" mapstructure:"labels"`
Comment string `mapsstructure:"comment"`
}
Item stores meta data about item.
type ItemFeedback ¶
type ItemFeedback Feedback
type ItemPatch ¶
type ItemPatch struct {
IsHidden *bool
Categories []string
Timestamp *time.Time
Labels any
Comment *string
}
ItemPatch is the modification on an item.
type MongoDB ¶
type MongoDB struct {
storage.TablePrefix
// contains filtered or unexported fields
}
MongoDB is the data storage based on MongoDB.
func (*MongoDB) BatchGetItems ¶
func (*MongoDB) BatchInsertFeedback ¶
func (db *MongoDB) BatchInsertFeedback(ctx context.Context, feedback []Feedback, insertUser, insertItem, overwrite bool) error
BatchInsertFeedback returns multiple feedback into MongoDB.
func (*MongoDB) BatchInsertItems ¶
BatchInsertItems insert items into MongoDB.
func (*MongoDB) BatchInsertUsers ¶
BatchInsertUsers inserts a user into MongoDB.
func (*MongoDB) DeleteItem ¶
DeleteItem deletes a item from MongoDB.
func (*MongoDB) DeleteUser ¶
DeleteUser deletes a user from MongoDB.
func (*MongoDB) DeleteUserItemFeedback ¶
func (db *MongoDB) DeleteUserItemFeedback(ctx context.Context, userId, itemId string, feedbackTypes ...string) (int, error)
DeleteUserItemFeedback deletes a feedback return the user id and item id from MongoDB.
func (*MongoDB) GetFeedback ¶
func (db *MongoDB) GetFeedback(ctx context.Context, cursor string, n int, beginTime, endTime *time.Time, feedbackTypes ...string) (string, []Feedback, error)
GetFeedback returns multiple feedback from MongoDB.
func (*MongoDB) GetFeedbackStream ¶
func (db *MongoDB) GetFeedbackStream(ctx context.Context, batchSize int, scanOptions ...ScanOption) (chan []Feedback, chan error)
GetFeedbackStream reads feedback from MongoDB by stream.
func (*MongoDB) GetItemFeedback ¶
func (db *MongoDB) GetItemFeedback(ctx context.Context, itemId string, feedbackTypes ...string) ([]Feedback, error)
GetItemFeedback returns feedback of a item from MongoDB.
func (*MongoDB) GetItemStream ¶
func (db *MongoDB) GetItemStream(ctx context.Context, batchSize int, timeLimit *time.Time) (chan []Item, chan error)
GetItemStream read items from MongoDB by stream.
func (*MongoDB) GetItems ¶
func (db *MongoDB) GetItems(ctx context.Context, cursor string, n int, timeLimit *time.Time) (string, []Item, error)
GetItems returns items from MongoDB.
func (*MongoDB) GetLatestItems ¶
GetLatestItems returns the latest items from MongoDB.
func (*MongoDB) GetUserFeedback ¶
func (db *MongoDB) GetUserFeedback(ctx context.Context, userId string, endTime *time.Time, feedbackTypes ...expression.FeedbackTypeExpression) ([]Feedback, error)
GetUserFeedback returns feedback of a user from MongoDB.
func (*MongoDB) GetUserItemFeedback ¶
func (db *MongoDB) GetUserItemFeedback(ctx context.Context, userId, itemId string, feedbackTypes ...string) ([]Feedback, error)
GetUserItemFeedback returns a feedback return the user id and item id from MongoDB.
func (*MongoDB) GetUserStream ¶
GetUserStream reads users from MongoDB by stream.
func (*MongoDB) ModifyItem ¶
ModifyItem modify an item in MongoDB.
func (*MongoDB) ModifyUser ¶
ModifyUser modify a user in MongoDB.
type NoDatabase ¶
type NoDatabase struct{}
NoDatabase means that no database used.
func (NoDatabase) BatchGetItems ¶
BatchGetItems method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) BatchInsertFeedback ¶
BatchInsertFeedback method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) BatchInsertItems ¶
func (NoDatabase) BatchInsertItems(_ context.Context, _ []Item) error
BatchInsertItems method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) BatchInsertUsers ¶
func (NoDatabase) BatchInsertUsers(_ context.Context, _ []User) error
BatchInsertUsers method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) Close ¶
func (NoDatabase) Close() error
Close method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) CountFeedback ¶
func (d NoDatabase) CountFeedback(_ context.Context) (int, error)
func (NoDatabase) CountItems ¶
func (d NoDatabase) CountItems(_ context.Context) (int, error)
func (NoDatabase) CountUsers ¶
func (d NoDatabase) CountUsers(_ context.Context) (int, error)
func (NoDatabase) DeleteItem ¶
func (NoDatabase) DeleteItem(_ context.Context, _ string) error
DeleteItem method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) DeleteUser ¶
func (NoDatabase) DeleteUser(_ context.Context, _ string) error
DeleteUser method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) DeleteUserItemFeedback ¶
DeleteUserItemFeedback method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetFeedback ¶
func (NoDatabase) GetFeedback(_ context.Context, _ string, _ int, _, _ *time.Time, _ ...string) (string, []Feedback, error)
GetFeedback method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetFeedbackStream ¶
func (NoDatabase) GetFeedbackStream(_ context.Context, _ int, _ ...ScanOption) (chan []Feedback, chan error)
GetFeedbackStream method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetItemFeedback ¶
GetItemFeedback method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetItemStream ¶
GetItemStream method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetItems ¶
func (NoDatabase) GetItems(_ context.Context, _ string, _ int, _ *time.Time) (string, []Item, error)
GetItems method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetLatestItems ¶
GetLatestItems method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetUserFeedback ¶
func (NoDatabase) GetUserFeedback(context.Context, string, *time.Time, ...expression.FeedbackTypeExpression) ([]Feedback, error)
GetUserFeedback method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetUserItemFeedback ¶
func (NoDatabase) GetUserItemFeedback(_ context.Context, _, _ string, _ ...string) ([]Feedback, error)
GetUserItemFeedback method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetUserStream ¶
GetUserStream method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) Init ¶
func (NoDatabase) Init() error
Init method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) ModifyItem ¶
func (NoDatabase) ModifyUser ¶
func (NoDatabase) Optimize ¶
func (NoDatabase) Optimize() error
Optimize is used by ClickHouse only.
func (NoDatabase) Ping ¶
func (NoDatabase) Ping() error
func (NoDatabase) Purge ¶
func (NoDatabase) Purge() error
type ProxyClient ¶
type ProxyClient struct {
protocol.DataStoreClient
}
func NewProxyClient ¶
func NewProxyClient(conn *grpc.ClientConn) *ProxyClient
func (ProxyClient) BatchGetItems ¶
func (ProxyClient) BatchInsertFeedback ¶
func (ProxyClient) BatchInsertItems ¶
func (p ProxyClient) BatchInsertItems(ctx context.Context, items []Item) error
func (ProxyClient) BatchInsertUsers ¶
func (p ProxyClient) BatchInsertUsers(ctx context.Context, users []User) error
func (ProxyClient) Close ¶
func (p ProxyClient) Close() error
func (ProxyClient) CountFeedback ¶
func (p ProxyClient) CountFeedback(ctx context.Context) (int, error)
func (ProxyClient) CountItems ¶
func (p ProxyClient) CountItems(ctx context.Context) (int, error)
func (ProxyClient) CountUsers ¶
func (p ProxyClient) CountUsers(ctx context.Context) (int, error)
func (ProxyClient) DeleteItem ¶
func (p ProxyClient) DeleteItem(ctx context.Context, itemId string) error
func (ProxyClient) DeleteUser ¶
func (p ProxyClient) DeleteUser(ctx context.Context, userId string) error
func (ProxyClient) DeleteUserItemFeedback ¶
func (ProxyClient) GetFeedback ¶
func (ProxyClient) GetFeedbackStream ¶
func (p ProxyClient) GetFeedbackStream(ctx context.Context, batchSize int, options ...ScanOption) (chan []Feedback, chan error)
func (ProxyClient) GetItemFeedback ¶
func (ProxyClient) GetItemStream ¶
func (ProxyClient) GetLatestItems ¶
func (ProxyClient) GetUserFeedback ¶
func (p ProxyClient) GetUserFeedback(ctx context.Context, userId string, endTime *time.Time, feedbackTypes ...expression.FeedbackTypeExpression) ([]Feedback, error)
func (ProxyClient) GetUserItemFeedback ¶
func (ProxyClient) GetUserStream ¶
func (ProxyClient) Init ¶
func (p ProxyClient) Init() error
func (ProxyClient) ModifyItem ¶
func (ProxyClient) ModifyUser ¶
func (ProxyClient) Optimize ¶
func (p ProxyClient) Optimize() error
func (ProxyClient) Ping ¶
func (p ProxyClient) Ping() error
func (ProxyClient) Purge ¶
func (p ProxyClient) Purge() error
type ProxyServer ¶
type ProxyServer struct {
protocol.UnimplementedDataStoreServer
// contains filtered or unexported fields
}
func NewProxyServer ¶
func NewProxyServer(database Database) *ProxyServer
func (*ProxyServer) BatchGetItems ¶
func (p *ProxyServer) BatchGetItems(ctx context.Context, in *protocol.BatchGetItemsRequest) (*protocol.BatchGetItemsResponse, error)
func (*ProxyServer) BatchInsertFeedback ¶
func (p *ProxyServer) BatchInsertFeedback(ctx context.Context, in *protocol.BatchInsertFeedbackRequest) (*protocol.BatchInsertFeedbackResponse, error)
func (*ProxyServer) BatchInsertItems ¶
func (p *ProxyServer) BatchInsertItems(ctx context.Context, in *protocol.BatchInsertItemsRequest) (*protocol.BatchInsertItemsResponse, error)
func (*ProxyServer) BatchInsertUsers ¶
func (p *ProxyServer) BatchInsertUsers(ctx context.Context, in *protocol.BatchInsertUsersRequest) (*protocol.BatchInsertUsersResponse, error)
func (*ProxyServer) CountFeedback ¶
func (p *ProxyServer) CountFeedback(ctx context.Context, in *protocol.CountFeedbackRequest) (*protocol.CountFeedbackResponse, error)
func (*ProxyServer) CountItems ¶
func (p *ProxyServer) CountItems(ctx context.Context, in *protocol.CountItemsRequest) (*protocol.CountItemsResponse, error)
func (*ProxyServer) CountUsers ¶
func (p *ProxyServer) CountUsers(ctx context.Context, in *protocol.CountUsersRequest) (*protocol.CountUsersResponse, error)
func (*ProxyServer) DeleteItem ¶
func (p *ProxyServer) DeleteItem(ctx context.Context, in *protocol.DeleteItemRequest) (*protocol.DeleteItemResponse, error)
func (*ProxyServer) DeleteUser ¶
func (p *ProxyServer) DeleteUser(ctx context.Context, in *protocol.DeleteUserRequest) (*protocol.DeleteUserResponse, error)
func (*ProxyServer) DeleteUserItemFeedback ¶
func (p *ProxyServer) DeleteUserItemFeedback(ctx context.Context, in *protocol.DeleteUserItemFeedbackRequest) (*protocol.DeleteUserItemFeedbackResponse, error)
func (*ProxyServer) GetFeedback ¶
func (p *ProxyServer) GetFeedback(ctx context.Context, in *protocol.GetFeedbackRequest) (*protocol.GetFeedbackResponse, error)
func (*ProxyServer) GetFeedbackStream ¶
func (p *ProxyServer) GetFeedbackStream(in *protocol.GetFeedbackStreamRequest, stream grpc.ServerStreamingServer[protocol.GetFeedbackStreamResponse]) error
func (*ProxyServer) GetItem ¶
func (p *ProxyServer) GetItem(ctx context.Context, in *protocol.GetItemRequest) (*protocol.GetItemResponse, error)
func (*ProxyServer) GetItemFeedback ¶
func (p *ProxyServer) GetItemFeedback(ctx context.Context, in *protocol.GetItemFeedbackRequest) (*protocol.GetFeedbackResponse, error)
func (*ProxyServer) GetItemStream ¶
func (p *ProxyServer) GetItemStream(in *protocol.GetItemStreamRequest, stream grpc.ServerStreamingServer[protocol.GetItemStreamResponse]) error
func (*ProxyServer) GetItems ¶
func (p *ProxyServer) GetItems(ctx context.Context, in *protocol.GetItemsRequest) (*protocol.GetItemsResponse, error)
func (*ProxyServer) GetLatestItems ¶
func (p *ProxyServer) GetLatestItems(ctx context.Context, in *protocol.GetLatestItemsRequest) (*protocol.GetLatestItemsResponse, error)
func (*ProxyServer) GetUser ¶
func (p *ProxyServer) GetUser(ctx context.Context, in *protocol.GetUserRequest) (*protocol.GetUserResponse, error)
func (*ProxyServer) GetUserFeedback ¶
func (p *ProxyServer) GetUserFeedback(ctx context.Context, in *protocol.GetUserFeedbackRequest) (*protocol.GetFeedbackResponse, error)
func (*ProxyServer) GetUserItemFeedback ¶
func (p *ProxyServer) GetUserItemFeedback(ctx context.Context, in *protocol.GetUserItemFeedbackRequest) (*protocol.GetFeedbackResponse, error)
func (*ProxyServer) GetUserStream ¶
func (p *ProxyServer) GetUserStream(in *protocol.GetUserStreamRequest, stream grpc.ServerStreamingServer[protocol.GetUserStreamResponse]) error
func (*ProxyServer) GetUsers ¶
func (p *ProxyServer) GetUsers(ctx context.Context, in *protocol.GetUsersRequest) (*protocol.GetUsersResponse, error)
func (*ProxyServer) ModifyItem ¶
func (p *ProxyServer) ModifyItem(ctx context.Context, in *protocol.ModifyItemRequest) (*protocol.ModifyItemResponse, error)
func (*ProxyServer) ModifyUser ¶
func (p *ProxyServer) ModifyUser(ctx context.Context, in *protocol.ModifyUserRequest) (*protocol.ModifyUserResponse, error)
func (*ProxyServer) Ping ¶
func (p *ProxyServer) Ping(_ context.Context, _ *protocol.PingRequest) (*protocol.PingResponse, error)
func (*ProxyServer) Stop ¶
func (p *ProxyServer) Stop()
type SQLDatabase ¶
type SQLDatabase struct {
storage.TablePrefix
// contains filtered or unexported fields
}
SQLDatabase use MySQL as data storage.
func (*SQLDatabase) BatchGetItems ¶
func (*SQLDatabase) BatchInsertFeedback ¶
func (d *SQLDatabase) BatchInsertFeedback(ctx context.Context, feedback []Feedback, insertUser, insertItem, overwrite bool) error
BatchInsertFeedback insert a batch feedback into MySQL. If insertUser set, new users will be inserted to user table. If insertItem set, new items will be inserted to item table.
func (*SQLDatabase) BatchInsertItems ¶
func (d *SQLDatabase) BatchInsertItems(ctx context.Context, items []Item) error
BatchInsertItems inserts a batch of items into MySQL.
func (*SQLDatabase) BatchInsertUsers ¶
func (d *SQLDatabase) BatchInsertUsers(ctx context.Context, users []User) error
BatchInsertUsers inserts users into MySQL.
func (*SQLDatabase) CountFeedback ¶
func (d *SQLDatabase) CountFeedback(ctx context.Context) (int, error)
func (*SQLDatabase) CountItems ¶
func (d *SQLDatabase) CountItems(ctx context.Context) (int, error)
func (*SQLDatabase) CountUsers ¶
func (d *SQLDatabase) CountUsers(ctx context.Context) (int, error)
func (*SQLDatabase) DeleteItem ¶
func (d *SQLDatabase) DeleteItem(ctx context.Context, itemId string) error
DeleteItem deletes a item from MySQL.
func (*SQLDatabase) DeleteUser ¶
func (d *SQLDatabase) DeleteUser(ctx context.Context, userId string) error
DeleteUser deletes a user from MySQL.
func (*SQLDatabase) DeleteUserItemFeedback ¶
func (d *SQLDatabase) DeleteUserItemFeedback(ctx context.Context, userId, itemId string, feedbackTypes ...string) (int, error)
DeleteUserItemFeedback deletes a feedback by user id and item id from MySQL.
func (*SQLDatabase) GetFeedback ¶
func (d *SQLDatabase) GetFeedback(ctx context.Context, cursor string, n int, beginTime, endTime *time.Time, feedbackTypes ...string) (string, []Feedback, error)
GetFeedback returns feedback from MySQL.
func (*SQLDatabase) GetFeedbackStream ¶
func (d *SQLDatabase) GetFeedbackStream(ctx context.Context, batchSize int, scanOptions ...ScanOption) (chan []Feedback, chan error)
GetFeedbackStream reads feedback by stream.
func (*SQLDatabase) GetItemFeedback ¶
func (d *SQLDatabase) GetItemFeedback(ctx context.Context, itemId string, feedbackTypes ...string) ([]Feedback, error)
GetItemFeedback returns feedback of a item from MySQL.
func (*SQLDatabase) GetItemStream ¶
func (d *SQLDatabase) GetItemStream(ctx context.Context, batchSize int, timeLimit *time.Time) (chan []Item, chan error)
GetItemStream reads items by stream.
func (*SQLDatabase) GetItems ¶
func (d *SQLDatabase) GetItems(ctx context.Context, cursor string, n int, timeLimit *time.Time) (string, []Item, error)
GetItems returns items from MySQL.
func (*SQLDatabase) GetLatestItems ¶
func (d *SQLDatabase) GetLatestItems(ctx context.Context, n int, categories []string) ([]Item, error)
GetLatestItems returns the latest items from the database.
func (*SQLDatabase) GetUserFeedback ¶
func (d *SQLDatabase) GetUserFeedback(ctx context.Context, userId string, endTime *time.Time, feedbackTypes ...expression.FeedbackTypeExpression) ([]Feedback, error)
GetUserFeedback returns feedback of a user from MySQL.
func (*SQLDatabase) GetUserItemFeedback ¶
func (d *SQLDatabase) GetUserItemFeedback(ctx context.Context, userId, itemId string, feedbackTypes ...string) ([]Feedback, error)
GetUserItemFeedback gets a feedback by user id and item id from MySQL.
func (*SQLDatabase) GetUserStream ¶
GetUserStream read users by stream.
func (*SQLDatabase) ModifyItem ¶
ModifyItem modify an item in MySQL.
func (*SQLDatabase) ModifyUser ¶
ModifyUser modify a user in MySQL.
func (*SQLDatabase) Optimize ¶
func (d *SQLDatabase) Optimize() error
Optimize is used by ClickHouse only.
func (*SQLDatabase) Ping ¶
func (d *SQLDatabase) Ping() error
func (*SQLDatabase) Purge ¶
func (d *SQLDatabase) Purge() error
type SQLItem ¶
type SQLItem struct {
ItemId string `gorm:"column:item_id;primaryKey"`
IsHidden bool `gorm:"column:is_hidden"`
Categories string `gorm:"column:categories"`
Timestamp time.Time `gorm:"column:time_stamp"`
Labels string `gorm:"column:labels"`
Comment string `gorm:"column:comment"`
}
func NewSQLItem ¶
type SQLUser ¶
type SQLUser struct {
UserId string `gorm:"column:user_id;primaryKey"`
Labels string `gorm:"column:labels"`
Comment string `gorm:"column:comment"`
}
func NewSQLUser ¶
type ScanOption ¶
type ScanOption func(options *ScanOptions)
func WithBeginItemId ¶
func WithBeginItemId(itemId string) ScanOption
WithBeginItemId sets the beginning item id. The beginning item id is included in the result.
func WithBeginTime ¶
func WithBeginTime(t time.Time) ScanOption
WithBeginTime sets the begin time. The begin time is included in the result.
func WithBeginUserId ¶
func WithBeginUserId(userId string) ScanOption
WithBeginUserId sets the begin user id. The begin user id is included in the result.
func WithEndItemId ¶
func WithEndItemId(itemId string) ScanOption
WithEndItemId sets the end item id. The end item id is included in the result.
func WithEndTime ¶
func WithEndTime(t time.Time) ScanOption
WithEndTime sets the end time. The end time is included in the result.
func WithEndUserId ¶
func WithEndUserId(userId string) ScanOption
WithEndUserId sets the end user id. The end user id is included in the result.
func WithFeedbackTypes ¶
func WithFeedbackTypes(feedbackTypes ...expression.FeedbackTypeExpression) ScanOption
WithFeedbackTypes sets the feedback types.
func WithOrderByItemId ¶
func WithOrderByItemId() ScanOption
WithOrderByItemId sets the order by item id.
type ScanOptions ¶
type ScanOptions struct {
BeginUserId *string
EndUserId *string
BeginItemId *string
EndItemId *string
BeginTime *time.Time
EndTime *time.Time
FeedbackTypes []expression.FeedbackTypeExpression
OrderByItemId bool
}
func NewScanOptions ¶
func NewScanOptions(opts ...ScanOption) ScanOptions
type User ¶
type User struct {
UserId string `gorm:"primaryKey" mapstructure:"user_id"`
Labels any `gorm:"serializer:json" mapstructure:"labels"`
Comment string `mapstructure:"comment"`
}
User stores meta data about user.
type UserFeedback ¶
type UserFeedback Feedback