utils

package
v0.0.0-...-1ea3783 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 32 Imported by: 97

Documentation

Index

Constants

View Source
const (
	ShortDuration  = 500 * time.Millisecond
	MediumDuration = 2 * time.Second
	LongDuration   = 20 * time.Second
)
View Source
const (
	TagKey                  = "neo4jDb"
	TagLookupName           = "lookupName"
	TagProperty             = "property"
	TagSupportCaseSensitive = "supportCaseSensitive"
)

Variables

This section is empty.

Functions

func AddOneMonthFallbackToLastDayOfMonth

func AddOneMonthFallbackToLastDayOfMonth(date time.Time) time.Time

func AddToListIfNotExists

func AddToListIfNotExists(arr []string, valueToAdd string) []string

func AnySliceToStringSlice

func AnySliceToStringSlice(input []any) ([]string, error)

func BackOffConfig

func BackOffConfig(initialInterval time.Duration, multiplier float64, maxInterval time.Duration, maxElapsedTime time.Duration, maxRetries uint64) backoff.BackOff

func BackOffExponentialDelay

func BackOffExponentialDelay(attempt int) time.Duration

Implement a backoffDelay function that calculates the delay before the next retry.

func BackOffForInvokingEventsPlatformGrpcClient

func BackOffForInvokingEventsPlatformGrpcClient() backoff.BackOff

func BackOffIncrementalDelay

func BackOffIncrementalDelay(attempt int) time.Duration

func BoolPtr

func BoolPtr(b bool) *bool

func CallEventsPlatformGRPCWithRetry

func CallEventsPlatformGRPCWithRetry[T any](operation func() (T, error)) (T, error)

func CapitalizeAllParts

func CapitalizeAllParts(str string, delimiters []string) string

func Contains

func Contains(slice []string, value string) bool

func ContainsAll

func ContainsAll(sourceSlice, itemsToCheck []string) bool

func ContainsElement

func ContainsElement[T comparable](slice []T, value T) bool

func ConvertTimeToTimestampPtr

func ConvertTimeToTimestampPtr(input *time.Time) *timestamppb.Timestamp

func EndOfDayInUTC

func EndOfDayInUTC(t time.Time) time.Time

func EnforceSingleValue

func EnforceSingleValue(slice []string, value string)

func EnsureEmailRfcId

func EnsureEmailRfcId(id string) string

func EnsureEmailRfcIds

func EnsureEmailRfcIds(to []string) []string

func ExecuteQuery

func ExecuteQuery(ctx context.Context, driver neo4j.DriverWithContext, database, cypher string, params map[string]any, traceError func(err error)) (*neo4j.EagerResult, error)

func ExecuteQueryInTx

func ExecuteQueryInTx(ctx context.Context, tx neo4j.ManagedTransaction, query string, params map[string]any) error

func ExecuteWriteQuery

func ExecuteWriteQuery(ctx context.Context, driver neo4j.DriverWithContext, cypher string, params map[string]any) error

func ExecuteWriteQueryOnDb

func ExecuteWriteQueryOnDb(ctx context.Context, driver neo4j.DriverWithContext, database, cypher string, params map[string]any) error

func ExtractAfterColon

func ExtractAfterColon(s string) string

func ExtractAllRecordsAsString

func ExtractAllRecordsAsString(ctx context.Context, result neo4j.ResultWithContext, err error) ([]string, error)

func ExtractAllRecordsFirstValueAsDbNodePtrs

func ExtractAllRecordsFirstValueAsDbNodePtrs(ctx context.Context, result neo4j.ResultWithContext, err error) ([]*dbtype.Node, error)

func ExtractDomain

func ExtractDomain(input string) string

func ExtractFirstPart

func ExtractFirstPart(str, delimiter string) string

func ExtractFirstRecordFirstValueAsDbNodePtr

func ExtractFirstRecordFirstValueAsDbNodePtr(ctx context.Context, result neo4j.ResultWithContext, err error) (*dbtype.Node, error)

func ExtractJsonFromString

func ExtractJsonFromString(str string) (string, error)

func ExtractName

func ExtractName(email string) string

func ExtractSingleRecordAsNodeFromEagerResult

func ExtractSingleRecordAsNodeFromEagerResult(result *neo4j.EagerResult) (*dbtype.Node, error)

func ExtractSingleRecordFirstValue

func ExtractSingleRecordFirstValue(ctx context.Context, result neo4j.ResultWithContext, err error) (any, error)

func ExtractSingleRecordFirstValueAsNode

func ExtractSingleRecordFirstValueAsNode(ctx context.Context, result neo4j.ResultWithContext, err error) (*dbtype.Node, error)

func ExtractSingleRecordFirstValueAsString

func ExtractSingleRecordFirstValueAsString(ctx context.Context, result neo4j.ResultWithContext, err error) (string, error)

func ExtractSingleRecordFirstValueAsType

func ExtractSingleRecordFirstValueAsType[T any](ctx context.Context, result neo4j.ResultWithContext, err error) (T, error)

func ExtractSingleRecordNodeAndRelationship

func ExtractSingleRecordNodeAndRelationship(ctx context.Context, result neo4j.ResultWithContext, err error) (*dbtype.Node, *dbtype.Relationship, error)

func FirstNotEmpty

func FirstNotEmpty(input ...string) *string

func FirstTimeOfMonth

func FirstTimeOfMonth(year, month int) time.Time

func Float64Ptr

func Float64Ptr(f float64) *float64

func Float64PtrEquals

func Float64PtrEquals(a, b *float64) bool

func FloatToString

func FloatToString(num *float64) string

func FormatAmount

func FormatAmount(amount float64, decimals int) string

func GenerateRandomStringFromCharset

func GenerateRandomStringFromCharset(length int, charset string) string

func GenerateUUID

func GenerateUUID() (string, error)

func GetBoolPropOrFalse

func GetBoolPropOrFalse(props map[string]any, key string) bool

func GetBoolPropOrNil

func GetBoolPropOrNil(props map[string]any, key string) *bool

func GetEpochStart

func GetEpochStart() time.Time

func GetFileType

func GetFileType(head []byte) (types.Type, error)

func GetFileTypeHeadFromBytes

func GetFileTypeHeadFromBytes(bytes *[]byte) ([]byte, error)

func GetFileTypeHeadFromMultipart

func GetFileTypeHeadFromMultipart(file multipart.File) ([]byte, error)

func GetFloatPropOrNil

func GetFloatPropOrNil(props map[string]any, key string) *float64

func GetFloatPropOrZero

func GetFloatPropOrZero(props map[string]any, key string) float64

func GetFunctionName

func GetFunctionName() string

func GetInt64PropOrDefault

func GetInt64PropOrDefault(props map[string]any, key string, defaultVal int64) int64

func GetInt64PropOrNil

func GetInt64PropOrNil(props map[string]any, key string) *int64

func GetInt64PropOrZero

func GetInt64PropOrZero(props map[string]any, key string) int64

func GetIntPropOrMinusOne

func GetIntPropOrMinusOne(props map[string]any, key string) int64

func GetListStringPropOrEmpty

func GetListStringPropOrEmpty(props map[string]any, key string) []string

func GetLongLivedContext

func GetLongLivedContext(ctx context.Context) (context.Context, context.CancelFunc)

func GetMediumLivedContext

func GetMediumLivedContext(ctx context.Context) (context.Context, context.CancelFunc)

func GetPropertyDetailsByLookupName

func GetPropertyDetailsByLookupName(T reflect.Type, lookupName string) (map[string]string, error)

func GetPropsFromNode

func GetPropsFromNode(node dbtype.Node) map[string]any

func GetPropsFromRelationship

func GetPropsFromRelationship(rel dbtype.Relationship) map[string]any

func GetShortLivedContext

func GetShortLivedContext(ctx context.Context) (context.Context, context.CancelFunc)

func GetStringPropOrEmpty

func GetStringPropOrEmpty(props map[string]any, key string) string

func GetStringPropOrNil

func GetStringPropOrNil(props map[string]any, key string) *string

func GetTimePropFromNeo4jOrZeroTime

func GetTimePropFromNeo4jOrZeroTime(valueToExtract any) time.Time

func GetTimePropOrEpochStart

func GetTimePropOrEpochStart(props map[string]any, key string) time.Time

func GetTimePropOrNil

func GetTimePropOrNil(props map[string]any, key string) *time.Time

func GetTimePropOrNow

func GetTimePropOrNow(props map[string]any, key string) time.Time

func GetTimePropOrZeroTime

func GetTimePropOrZeroTime(props map[string]any, key string) time.Time

func Hmac

func Hmac(body []byte, key []byte) *string

func IfNotNilBool

func IfNotNilBool(check any, valueExtractor ...func() bool) bool

func IfNotNilFloat64

func IfNotNilFloat64(check any, valueExtractor ...func() float64) float64

func IfNotNilInt64

func IfNotNilInt64(check any, valueExtractor ...func() int64) int64

func IfNotNilString

func IfNotNilString(check any, valueExtractor ...func() string) string

func IfNotNilStringWithDefault

func IfNotNilStringWithDefault(check any, defaultValue string) string

func IfNotNilTimeWithDefault

func IfNotNilTimeWithDefault(check any, defaultValue time.Time) time.Time

func Int64Ptr

func Int64Ptr(i int64) *int64

func Int64PtrToIntPtr

func Int64PtrToIntPtr(v *int64) *int

func IntPtr

func IntPtr(i int) *int

func IntPtrToInt64Ptr

func IntPtrToInt64Ptr(v *int) *int64

func IsEmptyString

func IsEmptyString(s *string) bool

func IsEndOfMonth

func IsEndOfMonth(t time.Time) bool

func IsEqualTimePtr

func IsEqualTimePtr(t1, t2 *time.Time) bool

IsEqualTimePtr compares two *time.Time values and returns true if both are nil or if both point to the same time.

func IsValidTLD

func IsValidTLD(input string) bool

func JoinNonEmpty

func JoinNonEmpty(delimiter string, strs ...string) string

func LastDayOfMonth

func LastDayOfMonth(year, month int) time.Time

func LastTimeOfMonth

func LastTimeOfMonth(year, month int) time.Time

func LowercaseSliceOfStrings

func LowercaseSliceOfStrings(arr []string) []string

func LowercaseStrings deprecated

func LowercaseStrings(arr []string)

Deprecated: use LowercaseSliceOfStrings instead

func MergeMapToMap

func MergeMapToMap(src, dst map[string]any)

func MiddleTimeOfMonth

func MiddleTimeOfMonth(year, month int) time.Time

func NewUUIDIfEmpty

func NewUUIDIfEmpty(str string) string

func NodePtr

func NodePtr(node dbtype.Node) *dbtype.Node

func Now

func Now() time.Time

func NowPtr

func NowPtr() *time.Time

func ParseStringToFloat

func ParseStringToFloat(input string) *float64

func Ptr

func Ptr[T any](obj T) *T

func RelationshipPtr

func RelationshipPtr(relationship dbtype.Relationship) *dbtype.Relationship

func RemoveDuplicates

func RemoveDuplicates(arr []string) []string

func RemoveEmpties

func RemoveEmpties(arr []string) []string

func RemoveFromList

func RemoveFromList(arr []string, valueToRemove string) []string

func ReverseMap

func ReverseMap[K comparable, V comparable](in map[K]V) map[V]K

func RoundHalfUpFloat64

func RoundHalfUpFloat64(input float64, decimals int) float64

func StringFirstNonEmpty

func StringFirstNonEmpty(strs ...string) string

func StringPtr

func StringPtr(str string) *string

func StringPtrFirstNonEmpty

func StringPtrFirstNonEmpty(strs ...*string) string

func StringPtrFirstNonEmptyNillable

func StringPtrFirstNonEmptyNillable(strs ...string) *string

func StringPtrNillable

func StringPtrNillable(str string) *string

func SurroundWith

func SurroundWith(src, surround string) string

func SurroundWithRoundParentheses

func SurroundWithRoundParentheses(src string) string

func SurroundWithSpaces

func SurroundWithSpaces(src string) string

func TimePtr

func TimePtr(t time.Time) *time.Time

func TimePtrAsAny

func TimePtrAsAny(times ...*time.Time) interface{}

func TimestampProtoToTime

func TimestampProtoToTime(pbTime *timestamppb.Timestamp) time.Time

func TimestampProtoToTimePtr

func TimestampProtoToTimePtr(pbTime *timestamppb.Timestamp) *time.Time

func ToDate

func ToDate(t time.Time) time.Time

func ToDateAsAny

func ToDateAsAny(t *time.Time) interface{}

func ToDatePtr

func ToDatePtr(t *time.Time) *time.Time

func ToJson

func ToJson(obj any) (string, error)

func ToNeo4jDateAsAny

func ToNeo4jDateAsAny(t *time.Time) any

func ToPtr

func ToPtr[T any](obj T) *T

func Today

func Today() time.Time

func TruncateFloat64

func TruncateFloat64(input float64, decimals int) float64

func UnmarshalDateTime

func UnmarshalDateTime(input string) (*time.Time, error)

func ZeroTime

func ZeroTime() time.Time

Types

type BoltLogger

type BoltLogger interface {
	LogClientMessage(context string, msg string, args ...any)
	LogServerMessage(context string, msg string, args ...any)
}

type ComparisonOperator

type ComparisonOperator int
const (
	C_NONE ComparisonOperator = iota
	IS_NULL
	IS_NOT_NULL
	EQUALS
	NOT_EQUALS
	CONTAINS
	STARTS_WITH
	LTE
	GTE
	IN
	BETWEEN
	IS_EMPTY
)

func (ComparisonOperator) CypherString

func (c ComparisonOperator) CypherString() string

func (ComparisonOperator) String

func (c ComparisonOperator) String() string

type ConsoleBoltNoLogger

type ConsoleBoltNoLogger struct {
}

func ConsoleBoltNoLoggerrr

func ConsoleBoltNoLoggerrr() *ConsoleBoltNoLogger

func (*ConsoleBoltNoLogger) LogClientMessage

func (cbl *ConsoleBoltNoLogger) LogClientMessage(id, msg string, args ...any)

func (*ConsoleBoltNoLogger) LogServerMessage

func (cbl *ConsoleBoltNoLogger) LogServerMessage(id, msg string, args ...any)

type Cypher

type Cypher string

func CypherPtr

func CypherPtr(cypher Cypher) *Cypher

type CypherFilter

type CypherFilter struct {
	Negate          bool
	LogicalOperator LogicalOperator
	Filters         []*CypherFilter
	Details         *CypherFilterItem
	// contains filtered or unexported fields
}

func CreateCypherFilter

func CreateCypherFilter(propertyName string, searchTerm any, comparator ComparisonOperator) *CypherFilter

func CreateCypherFilterEq

func CreateCypherFilterEq(propertyName string, value any) *CypherFilter

func CreateCypherFilterIn

func CreateCypherFilterIn(propertyName string, arrayValues any) *CypherFilter

func CreateCypherFilterIsNotNull

func CreateCypherFilterIsNotNull(propertyName string) *CypherFilter

func CreateCypherFilterIsNull

func CreateCypherFilterIsNull(propertyName string) *CypherFilter

func CreateCypherFilterNotEq

func CreateCypherFilterNotEq(propertyName string, value any) *CypherFilter

func CreateStringCypherFilter

func CreateStringCypherFilter(propertyName string, searchTerm any, comparator ComparisonOperator) *CypherFilter

func (*CypherFilter) BuildCypherFilterFragment

func (f *CypherFilter) BuildCypherFilterFragment(nodeAlias string) (string, map[string]any)

func (*CypherFilter) BuildCypherFilterFragmentWithParamName

func (f *CypherFilter) BuildCypherFilterFragmentWithParamName(nodeAlias string, customParamPrefix string) (string, map[string]any)

func (*CypherFilter) CypherFilterFragment

func (f *CypherFilter) CypherFilterFragment(nodeAlias string) (Cypher, map[string]any)

func (CypherFilter) String

func (f CypherFilter) String() string

type CypherFilterItem

type CypherFilterItem struct {
	NodeProperty         string
	SupportCaseSensitive bool
	CaseSensitive        bool
	Value                any
	DbNodePropertyProps  map[string]string
	ComparisonOperator   ComparisonOperator
}

func (CypherFilterItem) String

func (f CypherFilterItem) String() string

type CypherSort

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

func (*CypherSort) NewSortRule

func (s *CypherSort) NewSortRule(lookupName, direction string, caseSensitive bool, T reflect.Type) *OrderBy

func (*CypherSort) SortingCypherFragment

func (s *CypherSort) SortingCypherFragment(nodeAlias string) Cypher

func (*CypherSort) SortingCypherFragmentWithDefaultIfNil

func (s *CypherSort) SortingCypherFragmentWithDefaultIfNil(aliases, nodeAlias string, defaultValueIfNil string) Cypher

type DbNodeAndId

type DbNodeAndId struct {
	Node         *dbtype.Node
	LinkedNodeId string
}

func ExtractAllRecordsAsDbNodeAndId

func ExtractAllRecordsAsDbNodeAndId(ctx context.Context, result neo4j.ResultWithContext, err error) ([]*DbNodeAndId, error)

func ExtractAllRecordsAsDbNodeAndIdFromEagerResult

func ExtractAllRecordsAsDbNodeAndIdFromEagerResult(result *neo4j.EagerResult) []*DbNodeAndId

type DbNodeAndRelation

type DbNodeAndRelation struct {
	Node         *dbtype.Node
	Relationship *dbtype.Relationship
}

func ExtractAllRecordsAsDbNodeAndRelation

func ExtractAllRecordsAsDbNodeAndRelation(ctx context.Context, result neo4j.ResultWithContext, err error) ([]*DbNodeAndRelation, error)

type DbNodeAndTenant

type DbNodeAndTenant struct {
	Node   *dbtype.Node
	Tenant string
}

func ExtractAllRecordsAsDbNodeAndTenant

func ExtractAllRecordsAsDbNodeAndTenant(ctx context.Context, result neo4j.ResultWithContext, err error) ([]*DbNodeAndTenant, error)

type DbNodePairAndId

type DbNodePairAndId struct {
	Pair         Pair[*dbtype.Node, *dbtype.Node]
	LinkedNodeId string
}

func ExtractAllRecordsAsDbNodePairAndId

func ExtractAllRecordsAsDbNodePairAndId(ctx context.Context, result neo4j.ResultWithContext, err error) ([]*DbNodePairAndId, error)

type DbNodeWithRelationAndId

type DbNodeWithRelationAndId struct {
	Node         *dbtype.Node
	Relationship *dbtype.Relationship
	LinkedNodeId string
}

func ExtractAllRecordsAsDbNodeWithRelationAndId

func ExtractAllRecordsAsDbNodeWithRelationAndId(ctx context.Context, result neo4j.ResultWithContext, err error) ([]*DbNodeWithRelationAndId, error)

type DbNodeWithRelationIdAndTenant

type DbNodeWithRelationIdAndTenant struct {
	Node         *dbtype.Node
	Relationship *dbtype.Relationship
	LinkedNodeId string
	Tenant       string
}

func ExtractAllRecordsAsDbNodeWithRelationIdAndTenant

func ExtractAllRecordsAsDbNodeWithRelationIdAndTenant(ctx context.Context, result neo4j.ResultWithContext, err error) ([]*DbNodeWithRelationIdAndTenant, error)

type DbNodesWithTotalCount

type DbNodesWithTotalCount struct {
	Nodes []*dbtype.Node
	Count int64
}

type DbPropsAndId

type DbPropsAndId struct {
	Props        map[string]any
	LinkedNodeId string
}

func ExtractAllRecordsAsDbPropsAndId

func ExtractAllRecordsAsDbPropsAndId(ctx context.Context, result neo4j.ResultWithContext, err error) ([]*DbPropsAndId, error)

type LogicalOperator

type LogicalOperator int
const (
	L_NONE LogicalOperator = iota
	AND
	OR
)

func (LogicalOperator) String

func (l LogicalOperator) String() string

type OrderBy

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

func (*OrderBy) IsValid

func (ob *OrderBy) IsValid() bool

func (*OrderBy) WithAlias

func (ob *OrderBy) WithAlias(nodeAlias string) *OrderBy

func (*OrderBy) WithCoalesce

func (ob *OrderBy) WithCoalesce() *OrderBy

func (*OrderBy) WithDescending

func (ob *OrderBy) WithDescending() *OrderBy

type Pagination

type Pagination struct {
	Limit      int
	Page       int
	TotalRows  int64
	TotalPages int
	Rows       interface{}
}

func (*Pagination) GetLimit

func (p *Pagination) GetLimit() int

func (*Pagination) GetPage

func (p *Pagination) GetPage() int

func (*Pagination) GetSkip

func (p *Pagination) GetSkip() int

func (*Pagination) SetRows

func (p *Pagination) SetRows(rows interface{})

func (*Pagination) SetTotalRows

func (p *Pagination) SetTotalRows(totalRows int64)

type Pair

type Pair[T, U any] struct {
	First  T
	Second U
}

type PairDbNodesWithTotalCount

type PairDbNodesWithTotalCount struct {
	Pairs []*Pair[*dbtype.Node, *dbtype.Node]
	Count int64
}

type RecordsWithTotalCount

type RecordsWithTotalCount struct {
	Records []*db.Record
	Count   int64
}

type SessionConfigurationOption

type SessionConfigurationOption func(config *neo4j.SessionConfig)

func WithBoltLogger

func WithBoltLogger(logger log.BoltLogger) SessionConfigurationOption

func WithDatabaseName

func WithDatabaseName(databaseName string) SessionConfigurationOption

func WithFetchSize

func WithFetchSize(fetchSize int) SessionConfigurationOption

type YearMonth

type YearMonth struct {
	Year  int
	Month time.Month
}

func GenerateYearMonths

func GenerateYearMonths(start, end time.Time) []YearMonth

Jump to

Keyboard shortcuts

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