Documentation
¶
Index ¶
- type Client
- func (c *Client) CheckConnect() bool
- func (c *Client) Close()
- func (c *Client) Count(ctx context.Context, collection string, filter interface{}) (int64, error)
- func (c *Client) DeleteMany(ctx context.Context, collection string, filter interface{}) (*mongoV2.DeleteResult, error)
- func (c *Client) DeleteOne(ctx context.Context, collection string, filter interface{}) (*mongoV2.DeleteResult, error)
- func (c *Client) Exist(ctx context.Context, collection string, filter interface{}) (bool, error)
- func (c *Client) Find(ctx context.Context, collection string, filter interface{}, ...) error
- func (c *Client) FindOne(ctx context.Context, collection string, filter interface{}, result interface{}) error
- func (c *Client) FindOneAndUpdate(ctx context.Context, collection string, filter, update interface{}, ...) error
- func (c *Client) InsertMany(ctx context.Context, collection string, documents []interface{}) (*mongoV2.InsertManyResult, error)
- func (c *Client) InsertOne(ctx context.Context, collection string, document interface{}) (*mongoV2.InsertOneResult, error)
- func (c *Client) UpdateMany(ctx context.Context, collection string, filter, update interface{}) (*mongoV2.UpdateResult, error)
- func (c *Client) UpdateOne(ctx context.Context, collection string, filter, update interface{}) (*mongoV2.UpdateResult, error)
- type Option
- func WithBSONOptions(opt *optionsV2.BSONOptions) Option
- func WithConnectTimeout(connectTimeout time.Duration) Option
- func WithCredentials(username, password string) Option
- func WithDatabase(database string) Option
- func WithHeartbeatInterval(interval time.Duration) Option
- func WithLocalThreshold(threshold time.Duration) Option
- func WithLogger(logger log.Logger) Option
- func WithMaxConnIdleTime(maxIdleTime time.Duration) Option
- func WithServerSelectionTimeout(serverSelectionTimeout time.Duration) Option
- func WithTLSConfig(tlsConfig *tls.Config) Option
- func WithTimeout(timeout time.Duration) Option
- func WithURI(uri string) Option
- type Repository
- func (r *Repository[DTO, ENTITY]) BatchCreate(ctx context.Context, dtos []*DTO) ([]*DTO, error)
- func (r *Repository[DTO, ENTITY]) Count(ctx context.Context, qb *query.Builder) (int64, error)
- func (r *Repository[DTO, ENTITY]) Create(ctx context.Context, dto *DTO) (*DTO, error)
- func (r *Repository[DTO, ENTITY]) Delete(ctx context.Context, qb *query.Builder) (int64, error)
- func (r *Repository[DTO, ENTITY]) Exists(ctx context.Context, qb *query.Builder) (bool, error)
- func (r *Repository[DTO, ENTITY]) Get(ctx context.Context, qb *query.Builder, viewMask *fieldmaskpb.FieldMask) (*DTO, error)
- func (r *Repository[DTO, ENTITY]) ListWithPagination(ctx context.Context, req *paginationV1.PaginationRequest) ([]*DTO, int64, error)
- func (r *Repository[DTO, ENTITY]) ListWithPaging(ctx context.Context, req *paginationV1.PagingRequest) ([]*DTO, int64, error)
- func (r *Repository[DTO, ENTITY]) Update(ctx context.Context, qb *query.Builder, updateDoc interface{}) (*DTO, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) DeleteMany ¶
func (c *Client) DeleteMany(ctx context.Context, collection string, filter interface{}) (*mongoV2.DeleteResult, error)
DeleteMany 删除多个文档
func (*Client) DeleteOne ¶
func (c *Client) DeleteOne(ctx context.Context, collection string, filter interface{}) (*mongoV2.DeleteResult, error)
DeleteOne 删除单个文档
func (*Client) Exist ¶
Exist 检查集合中是否存在满足 filter 的文档,返回布尔值和可能的错误。 使用 Client 的超时配置,客户端未初始化时返回 mongoV2.ErrClientDisconnected。
func (*Client) Find ¶
func (c *Client) Find(ctx context.Context, collection string, filter interface{}, results interface{}) error
Find 查询多个文档
func (*Client) FindOne ¶
func (c *Client) FindOne(ctx context.Context, collection string, filter interface{}, result interface{}) error
FindOne 查询单个文档
func (*Client) FindOneAndUpdate ¶
func (c *Client) FindOneAndUpdate(ctx context.Context, collection string, filter, update interface{}, result interface{}, opts ...optionsV2.Lister[optionsV2.FindOneAndUpdateOptions]) error
FindOneAndUpdate 在集合中查找并更新单个文档,结果 Decode 到 result 参数。 可传入可选的 *optionsV2.FindOneAndUpdateOptions。
func (*Client) InsertMany ¶
func (c *Client) InsertMany(ctx context.Context, collection string, documents []interface{}) (*mongoV2.InsertManyResult, error)
InsertMany 插入多个文档
func (*Client) InsertOne ¶
func (c *Client) InsertOne(ctx context.Context, collection string, document interface{}) (*mongoV2.InsertOneResult, error)
InsertOne 插入单个文档
func (*Client) UpdateMany ¶
func (c *Client) UpdateMany(ctx context.Context, collection string, filter, update interface{}) (*mongoV2.UpdateResult, error)
UpdateMany 更新多个文档
type Option ¶
type Option func(o *Client)
func WithBSONOptions ¶
func WithBSONOptions(opt *optionsV2.BSONOptions) Option
func WithConnectTimeout ¶
func WithCredentials ¶
func WithDatabase ¶
func WithHeartbeatInterval ¶
func WithLocalThreshold ¶
func WithLogger ¶
func WithMaxConnIdleTime ¶
func WithTLSConfig ¶
func WithTimeout ¶
type Repository ¶
Repository MongoDB 版仓库(泛型)
func NewRepository ¶
func NewRepository[DTO any, ENTITY any](client *Client, collection string, mapper *mapper.CopierMapper[DTO, ENTITY], logger *log.Helper) *Repository[DTO, ENTITY]
func (*Repository[DTO, ENTITY]) BatchCreate ¶
func (r *Repository[DTO, ENTITY]) BatchCreate(ctx context.Context, dtos []*DTO) ([]*DTO, error)
BatchCreate 批量插入
func (*Repository[DTO, ENTITY]) Create ¶
func (r *Repository[DTO, ENTITY]) Create(ctx context.Context, dto *DTO) (*DTO, error)
Create 插入一条记录
func (*Repository[DTO, ENTITY]) Get ¶
func (r *Repository[DTO, ENTITY]) Get(ctx context.Context, qb *query.Builder, viewMask *fieldmaskpb.FieldMask) (*DTO, error)
Get 根据过滤条件返回单条记录(使用 FilterExpr 或 Query/OrQuery 前置构建 qb)
func (*Repository[DTO, ENTITY]) ListWithPagination ¶
func (r *Repository[DTO, ENTITY]) ListWithPagination(ctx context.Context, req *paginationV1.PaginationRequest) ([]*DTO, int64, error)
ListWithPagination 针对 paginationV1.PaginationRequest 的列表查询
func (*Repository[DTO, ENTITY]) ListWithPaging ¶
func (r *Repository[DTO, ENTITY]) ListWithPaging(ctx context.Context, req *paginationV1.PagingRequest) ([]*DTO, int64, error)
ListWithPaging 针对 paginationV1.PagingRequest 的列表查询(兼容 Query/OrQuery/FilterExpr)
Click to show internal directories.
Click to hide internal directories.