common

package
v0.0.0-...-b57e8ac Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrBadValue          = ErrorCode(2)     // BadValue
	ErrNamespaceNotFound = ErrorCode(26)    // NamespaceNotFound
	ErrNamespaceExists   = ErrorCode(48)    // NamespaceExists
	ErrCommandNotFound   = ErrorCode(59)    // CommandNotFound
	ErrNotImplemented    = ErrorCode(238)   // NotImplemented
	ErrSortBadValue      = ErrorCode(15974) // SortBadValue
	ErrProjectionInEx    = ErrorCode(31253) // Location31253
	ErrProjectionExIn    = ErrorCode(31254) // Location31254
	ErrRegexOptions      = ErrorCode(51075) // Location51075
)

for complete list of MongoDB error codes see: https://github.com/mongodb/mongo/blob/master/src/mongo/base/error_codes.yml

Variables

This section is empty.

Functions

func CreateWhereClause

func CreateWhereClause(filter types.Document) (sql string, err error)

CreateWhereClause creates the WHERE-clause of the SQL statement.

func GetUpdateValue

func GetUpdateValue(value any) (updateValue string, err error)

getUpdateValue prepares the value for SQL statement.

func Ignored

func Ignored(doc *types.Document, l *zap.Logger, fields ...string)

Ignored logs a message if doc has any of the given fields.

func IsIdUnique

func IsIdUnique(id any, db, collection string, ctx context.Context, hanapool *hana.Hpool) (unique bool, errMsg error, err error)

IsIdUnique will check if _id for a document is unique before insertion. - err is an error thrown by a function used. - errMsg is the error message used if id is not unique.

func NewError

func NewError(code ErrorCode, err error) error

NewError creates a new wire protocol error.

Code can't be zero, err can't be nil.

func NewErrorMessage

func NewErrorMessage(code ErrorCode, msg string, args ...any) error

NewErrorMessage creates a new wire protocol error with message.

Code can't be zero, message can't be empty.

func NoError

func NoError(err error)

func NotFail

func NotFail[T any](res T, err error) T

func PrepareArrayForSQL

func PrepareArrayForSQL(a *types.Array) (sqlArray string, err error)

PrepareArrayForSQL prepares an array which is inside of a document for SQL.

func ProjectDocuments

func ProjectDocuments(docs *types.Array, projection types.Document) (err error)

ProjectDocuments will be used if it is an exclusion to performs the exclusion on each document together with the function projectDocument.

func Projection

func Projection(projection types.Document) (sql string, exclusion bool, err error)

Projection checks if projection is an inclusion or exclusion. If inclusion then the sql needed to perform inclusion is created. If exclusion then the removal of fields will first happen after retrieval of documents.

func Unimplemented

func Unimplemented(doc *types.Document, fields ...string) error

Unimplemented returns ErrNotImplemented if doc has any of the given fields.

func Update

func Update(updateDoc types.Document) (updateSQL string, notWhereSQL string, err error)

Update creates needed SQL parts for SQL update statement.

func Upsert

func Upsert(updateDoc *types.Document, filter *types.Document, replace bool) (*types.Document, error)

Types

type Error

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

Error represents wire protocol error.

func ProtocolError

func ProtocolError(err error) (*Error, bool)

ProtocolError converts any error to wire protocol error.

Nil panics, *Error (possibly wrapped) is returned unwrapped with true, any other value is wrapped with InternalError and returned with false.

func (*Error) Document

func (e *Error) Document() types.Document

Document returns wire protocol error document.

func (*Error) Error

func (e *Error) Error() string

Error implements error interface.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap implements standard error unwrapping interface.

type ErrorCode

type ErrorCode int32

ErrorCode represents wire protocol error code.

func (ErrorCode) String

func (i ErrorCode) String() string

type Storage

type Storage interface {
	MsgCreateIndexes(context.Context, *wire.OpMsg) (*wire.OpMsg, error)
	MsgDelete(context.Context, *wire.OpMsg) (*wire.OpMsg, error)
	MsgFindOrCount(context.Context, *wire.OpMsg) (*wire.OpMsg, error)
	MsgFindAndModify(context.Context, *wire.OpMsg) (*wire.OpMsg, error)
	MsgInsert(context.Context, *wire.OpMsg) (*wire.OpMsg, error)
	MsgUpdate(context.Context, *wire.OpMsg) (*wire.OpMsg, error)
}

Jump to

Keyboard shortcuts

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