database

package module
v1.0.0-...-dc35c6f Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

README

PaySuper MongoDB Driver

Build Status codecov go report

Environment variables:

Name Required Default Description
MONGO_DIAL_TIMEOUT - 10 MongoBD dial timeout in seconds
MONGO_DSN true - MongoBD DSN connection string

Contributing

We feel that a welcoming community is important and we ask that you follow PaySuper's Open Source Code of Conduct in all interactions with the community.

PaySuper welcomes contributions from anyone and everyone. Please refer to each project's style and contribution guidelines for submitting patches and additions. In general, we follow the "fork-and-pull" Git workflow.

The master branch of this repository contains the latest stable release of this component.

Documentation

Index

Constants

View Source
const (
	CodeDuplicateKeyErrorCollection = 11000
)

Variables

View Source
var (
	ErrorSessionNotInit   = errors.New("database session not init")
	ErrorDatabaseNotFound = errors.New("database name not found in DSN connection string")
)
View Source
var (
	ErrorProtocolNotFound = errors.New("protocol not found")
	ErrorHostsNotFound    = errors.New("hosts not found")
)

Functions

func GetObjectIDCounter

func GetObjectIDCounter(objectID primitive.ObjectID) int64

func IsDuplicate

func IsDuplicate(err error) bool

func ToSortOption

func ToSortOption(fields []string) interface{}

Types

type Auth

type Auth struct {
	User     string
	Password string
}

type DSN

type DSN struct {
	Dsn      string
	Protocol string
	*Auth
	Hosts    []*Host
	Database string
	Options  map[string]string
}

func NewDSN

func NewDSN(dsn string) (*DSN, error)

type Host

type Host struct {
	Host string
	Port string
}

type Option

type Option func(*Options)

func Context

func Context(ctx context.Context) Option

func Dsn

func Dsn(dsn string) Option

func Mode

func Mode(mode string) Option

type Options

type Options struct {
	Dsn     string `envconfig:"MONGO_DSN" default:"mongodb://localhost:27017/test"`
	Mode    string `envconfig:"MONGO_MODE" default:"primary"`
	Context context.Context
}

func (Options) String

func (c Options) String() (s string)

type Source

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

func NewDatabase

func NewDatabase(options ...Option) (*Source, error)

func (*Source) Close

func (s *Source) Close() error

func (*Source) Collection

func (s *Source) Collection(name string) *mongo.Collection

func (*Source) Drop

func (s *Source) Drop() error

func (*Source) Open

func (s *Source) Open(conn *Options) error

func (*Source) Ping

func (s *Source) Ping() error

Jump to

Keyboard shortcuts

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