Documentation
¶
Overview ¶
Package util provides APOC utility functions.
This package implements all apoc.util.* functions for general utility operations in Cypher queries.
Index ¶
- func Case(conditions []interface{}, defaultValue interface{}) interface{}
- func Coalesce(values ...interface{}) interface{}
- func Compress(text string) []byte
- func CompressWithAlgorithm(text, algorithm string) []byte
- func DecodeBase64(encoded string) string
- func DecodeURL(encoded string) string
- func Decompress(data []byte) string
- func DecompressWithAlgorithm(data []byte, algorithm string) string
- func EncodeBase64(text string) string
- func EncodeURL(text string) string
- func FormatTimestamp(timestamp int64) string
- func IsNode(value interface{}) bool
- func IsPath(value interface{}) bool
- func IsRelationship(value interface{}) bool
- func MD5(value interface{}) string
- func Md5Base64(value interface{}) string
- func Md5Hex(value interface{}) string
- func Merge(value1, value2 interface{}) interface{}
- func Now() int64
- func NowInSeconds() int64
- func ParseTimestamp(dateStr string) int64
- func Partition(list []interface{}, predicate func(interface{}) bool) [][]interface{}
- func RandomUUID() string
- func Range(start, end, step int64) []int64
- func Repeat(value interface{}, count int) []interface{}
- func SHA1(value interface{}) string
- func SHA256(value interface{}) string
- func Sha1Base64(value interface{}) string
- func Sha1Hex(value interface{}) string
- func Sha256Base64(value interface{}) string
- func Sha256Hex(value interface{}) string
- func Sleep(milliseconds int64)
- func Timestamp() int64
- func TypeOf(value interface{}) string
- func UUID() string
- func Validate(condition bool, message string, params []interface{}) error
- func ValidatePattern(text, pattern string) bool
- func When(condition bool, trueValue, falseValue interface{}) interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Case ¶
func Case(conditions []interface{}, defaultValue interface{}) interface{}
Case implements a case/switch statement.
Example:
apoc.util.case([x=1, 'one', x=2, 'two'], 'other')
func Coalesce ¶
func Coalesce(values ...interface{}) interface{}
Coalesce returns the first non-null value.
Example:
apoc.util.coalesce(null, null, 'default') => 'default'
func Compress ¶
Compress compresses a string.
Example:
apoc.util.compress('hello world') => compressed bytes
func CompressWithAlgorithm ¶
Compress compresses a string using a specific algorithm.
Example:
apoc.util.compress('hello', 'gzip') => compressed data
func DecodeBase64 ¶
DecodeBase64 decodes a base64 string.
Example:
apoc.util.decodeBase64('aGVsbG8=') => 'hello'
func DecodeURL ¶
DecodeURL decodes a URL-encoded string.
Example:
apoc.util.decodeURL('hello+world') => 'hello world'
func Decompress ¶
Decompress decompresses bytes to a string.
Example:
apoc.util.decompress(compressed) => 'hello world'
func DecompressWithAlgorithm ¶
Decompress decompresses data using a specific algorithm.
Example:
apoc.util.decompress(data, 'gzip') => 'hello'
func EncodeBase64 ¶
EncodeBase64 encodes a string to base64.
Example:
apoc.util.encodeBase64('hello') => 'aGVsbG8='
func EncodeURL ¶
EncodeURL encodes a string for use in URLs.
Example:
apoc.util.encodeURL('hello world') => 'hello+world'
func FormatTimestamp ¶
FormatTimestamp formats a timestamp as a string.
Example:
apoc.util.formatTimestamp(1705316400) => '2024-01-15T10:30:00Z'
func IsNode ¶
func IsNode(value interface{}) bool
IsNode checks if a value is a node.
Example:
apoc.util.isNode(value) => true
func IsPath ¶
func IsPath(value interface{}) bool
IsPath checks if a value is a path.
Example:
apoc.util.isPath(value) => true
func IsRelationship ¶
func IsRelationship(value interface{}) bool
IsRelationship checks if a value is a relationship.
Example:
apoc.util.isRelationship(value) => true
func MD5 ¶
func MD5(value interface{}) string
MD5 computes the MD5 hash of a value.
SECURITY NOTE: MD5 is cryptographically weak and should NOT be used for password hashing or security-critical applications. This function exists for Neo4j APOC compatibility and data fingerprinting use cases only. For secure hashing, use SHA256 or stronger algorithms.
Example:
apoc.util.md5('hello') => '5d41402abc4b2a76b9719d911017c592'
func Md5Base64 ¶
func Md5Base64(value interface{}) string
Md5Base64 computes MD5 and encodes as base64.
Example:
apoc.util.md5Base64('hello') => base64 encoded hash
func Md5Hex ¶
func Md5Hex(value interface{}) string
Md5Hex computes MD5 as hex string (alias for MD5).
Example:
apoc.util.md5Hex('hello') => hex encoded hash
func Merge ¶
func Merge(value1, value2 interface{}) interface{}
Merge merges two values based on a strategy.
Example:
apoc.util.merge({a:1}, {b:2}) => {a:1, b:2}
func Now ¶
func Now() int64
Now returns the current timestamp in milliseconds.
Example:
apoc.util.now() => 1705276800000
func NowInSeconds ¶
func NowInSeconds() int64
NowInSeconds returns the current timestamp in seconds.
Example:
apoc.util.nowInSeconds() => 1705276800
func ParseTimestamp ¶
ParseTimestamp parses a timestamp string.
Example:
apoc.util.parseTimestamp('2024-01-15T10:30:00Z') => 1705316400
func Partition ¶
func Partition(list []interface{}, predicate func(interface{}) bool) [][]interface{}
Partition partitions a list based on a predicate.
Example:
apoc.util.partition([1,2,3,4,5], 'x > 3') => [[4,5], [1,2,3]]
func RandomUUID ¶
func RandomUUID() string
RandomUUID generates a random UUID (alias for UUID).
Example:
apoc.util.randomUUID() => '550e8400-e29b-41d4-a716-446655440000'
func Repeat ¶
func Repeat(value interface{}, count int) []interface{}
Repeat repeats an operation n times.
Example:
apoc.util.repeat('hello', 3) => ['hello', 'hello', 'hello']
func SHA1 ¶
func SHA1(value interface{}) string
SHA1 computes the SHA1 hash of a value.
SECURITY NOTE: SHA1 is cryptographically weak and should NOT be used for password hashing or security-critical applications. This function exists for Neo4j APOC compatibility and data fingerprinting use cases only. For secure hashing, use SHA256 or stronger algorithms.
Example:
apoc.util.sha1('hello') => 'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d'
func SHA256 ¶
func SHA256(value interface{}) string
SHA256 computes the SHA256 hash of a value.
Example:
apoc.util.sha256('hello') => '2cf24dba5fb0a30e...'
func Sha1Base64 ¶
func Sha1Base64(value interface{}) string
Sha1Base64 computes SHA1 and encodes as base64.
Example:
apoc.util.sha1Base64('hello') => base64 encoded hash
func Sha1Hex ¶
func Sha1Hex(value interface{}) string
Sha1Hex computes SHA1 as hex string (alias for SHA1).
Example:
apoc.util.sha1Hex('hello') => hex encoded hash
func Sha256Base64 ¶
func Sha256Base64(value interface{}) string
Sha256Base64 computes SHA256 and encodes as base64.
Example:
apoc.util.sha256Base64('hello') => base64 encoded hash
func Sha256Hex ¶
func Sha256Hex(value interface{}) string
Sha256Hex computes SHA256 as hex string (alias for SHA256).
Example:
apoc.util.sha256Hex('hello') => hex encoded hash
func Sleep ¶
func Sleep(milliseconds int64)
Sleep pauses execution for a duration in milliseconds.
Example:
apoc.util.sleep(1000) // Sleep for 1 second
func Timestamp ¶
func Timestamp() int64
Timestamp returns the current timestamp (alias for Now).
Example:
apoc.util.timestamp() => 1705276800000
func TypeOf ¶
func TypeOf(value interface{}) string
TypeOf returns the type of a value.
Example:
apoc.util.typeOf('hello') => 'STRING'
apoc.util.typeOf(42) => 'INTEGER'
func UUID ¶
func UUID() string
UUID generates a random UUID.
Example:
apoc.util.uuid() => '550e8400-e29b-41d4-a716-446655440000'
func Validate ¶
Validate validates a value against a predicate.
Example:
apoc.util.validate(age > 0, 'Age must be positive', [age])
func ValidatePattern ¶
ValidatePattern validates a string against a regex pattern.
Example:
apoc.util.validatePattern('test@example.com', '.*@.*\\..*')
Types ¶
This section is empty.