abstr

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MulanPSL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = 5 * time.Second

数据库操作默认超时时间(5 秒)

Variables

This section is empty.

Functions

This section is empty.

Types

type DBConfig

type DBConfig struct {
	URI        string `yaml:"uri"`
	PoolSize   int    `yaml:"poolSize"`
	SSLEnabled bool   `yaml:"sslEnabled"`
	RootCA     string `yaml:"rootCAFile"`
	Timeout    string `yaml:"timeout"`
	VerifyPeer bool   `yaml:"verifyPeer"`
}

type DBHelper

type DBHelper interface {
	Aggregate(ctx context.Context, collname string, pipeline []map[string]interface{}, value interface{}) error
	CountDocuments(ctx context.Context, collname string, filter map[string]interface{}) (int64, error)
	CreateOne(ctx context.Context, collname string, rec interface{}) error
	CreateMany(ctx context.Context, collname string, recs ...interface{}) error
	FindOne(ctx context.Context, collname string, value interface{}, options ...FindOption) error
	FindOneAndDelete(ctx context.Context, collname string, filter map[string]interface{}, value interface{}, options ...FindOption) error
	List(ctx context.Context, collname string, value interface{}, options ...FindOption) (*Page, error)
	// $pull
	Pull(ctx context.Context, collname string, filter map[string]interface{}, value interface{}) error
	RemoveMany(ctx context.Context, collname string, filter map[string]interface{}) error
	// $unset
	Unmark(ctx context.Context, collname string, filter map[string]interface{}, value interface{}) error
	UpdateMany(ctx context.Context, collname string, filter interface{}, update interface{}) (*mongo.UpdateResult, error)
	UpdateOne(ctx context.Context, collname string, filter map[string]interface{}, value interface{}, options ...FindOption) error
	// 对 UpdateOne 的扩展,允许使用 $set 之外的操作符
	UpdateOneMore(ctx context.Context, collname string, filter map[string]interface{}, value interface{}, options ...FindOption) error
}

type Decrypt

type Decrypt func(src string) string

Decrypt decrypt db config

type FindOption

type FindOption func(*FindOptions)

FindOption is functional option to find key value

func WithExactLabels

func WithExactLabels() FindOption

WithExactLabels tell model service to return only one kv matches the labels

func WithFilters

func WithFilters(filter map[string]interface{}) FindOption

WithFilters filters

func WithLabels

func WithLabels(labels map[string]string) FindOption

WithLabels find kv by labels

func WithLimit

func WithLimit(limit int64) FindOption

WithLimit tells service paging limit

func WithOffset

func WithOffset(offset int64) FindOption

WithOffset tells service paging offset

func WithProjection

func WithProjection(projection map[string]interface{}) FindOption

WithProjection include or exclude fileds

func WithSort

func WithSort(sort map[string]int32) FindOption

WithSort sort

func WithTimeout

func WithTimeout(d time.Duration) FindOption

WithTimeout will return err if execution take too long

type FindOptions

type FindOptions struct {
	ExactLabels bool
	Projection  map[string]interface{}
	Filters     map[string]interface{}
	Labels      map[string]string
	Timeout     time.Duration
	Offset      int64
	Limit       int64
	Sort        map[string]int32
}

FindOptions is option to find key value

func NewDefaultFindOpts

func NewDefaultFindOpts() FindOptions

NewDefaultFindOpts return default options

type Init

type Init func(dbc DBConfig, t ...reflect.Type) error

Init init db session

t  要注册的类型

type Page

type Page struct {
	Total    int64 `json:"total"`    // 总记录数
	PageNum  int64 `json:"pageNum"`  // 当前页数
	PageSize int64 `json:"pageSize"` // 每页项数
	Pages    int64 `json:"pages"`    // 总的页数
}

Page 分页

func (*Page) CorrectPagination

func (r *Page) CorrectPagination(offset, limit int64, count int)

CorrectPagination 纠正分页

func (*Page) StartRecord

func (r *Page) StartRecord() int64

StartRecord 设置分页查询时起始位置

Jump to

Keyboard shortcuts

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