Documentation
¶
Index ¶
- Constants
- Variables
- func Collect(result neo4j.Result, err error) ([]neo4j.Record, neo4j.ResultSummary, error)
- func DisableLogger()
- func EnableLogger()
- func GenerateOrderByExpr(querySource string, dict PropertyDict, options ...OrderByOption) string
- func GetBoolean(data interface{}) bool
- func GetByteArray(data interface{}) []byte
- func GetDate(data interface{}) neo4j.Date
- func GetDateTime(data interface{}) time.Time
- func GetDuration(data interface{}) neo4j.Duration
- func GetFloat(data interface{}) float64
- func GetInteger(data interface{}) int64
- func GetList(data interface{}) []interface{}
- func GetLocalDateTime(data interface{}) neo4j.LocalDateTime
- func GetLocalTime(data interface{}) neo4j.LocalTime
- func GetMap(data interface{}) map[string]interface{}
- func GetNode(data interface{}) neo4j.Node
- func GetPath(data interface{}) neo4j.Path
- func GetPoint(data interface{}) neo4j.Point
- func GetRel(data interface{}) neo4j.Relationship
- func GetString(data interface{}) string
- func GetTime(data interface{}) neo4j.OffsetTime
- type DialHandler
- type DriverOption
- func WithAddressResolver(resolver neo4j.ServerAddressResolver) DriverOption
- func WithConnectionAcquisitionTimeout(t time.Duration) DriverOption
- func WithEncrypted(encrypted bool) DriverOption
- func WithLog(l neo4j.Logging) DriverOption
- func WithMaxConnectionLifetime(t time.Duration) DriverOption
- func WithMaxConnectionPoolSize(size int) DriverOption
- func WithMaxTransactionRetryTime(t time.Duration) DriverOption
- func WithSocketConnectTimeout(t time.Duration) DriverOption
- func WithSocketKeepalive(keepalive bool) DriverOption
- func WithTrustStrategy(e neo4j.TrustStrategy) DriverOption
- type LoggerOption
- type LoggerParam
- type LogrusLogger
- type OrderByOption
- func WithOrderBySourceProcessor(processor func(source string) (field string, asc bool)) OrderByOption
- func WithOrderBySourceSeparator(separator string) OrderByOption
- func WithOrderByTargetProcessor(processor func(destination string, asc bool) (target string)) OrderByOption
- func WithOrderByTargetSeparator(separator string) OrderByOption
- type P
- type Pool
- func (p *Pool) Close() error
- func (p *Pool) Dial(mode neo4j.AccessMode, bookmarks ...string) (neo4j.Session, error)
- func (p *Pool) DialReadMode(bookmarks ...string) (neo4j.Session, error)
- func (p *Pool) DialWriteMode(bookmarks ...string) (neo4j.Session, error)
- func (p *Pool) Driver() neo4j.Driver
- func (p *Pool) NewSession(config neo4j.SessionConfig) (neo4j.Session, error)
- func (p *Pool) Session(mode neo4j.AccessMode, bookmarks ...string) (neo4j.Session, error)
- func (p *Pool) Target() url.URL
- func (p *Pool) VerifyConnectivity() error
- type PropertyDict
- type PropertyValue
- type StdLogger
Constants ¶
const ( // NAME represents ahlib-mx/xneo4j package's name. NAME = "ahlib-mx/xneo4j" // VERSION represents ahlib-mx/xneo4j package's current version. VERSION = "1.6.0" )
const DefaultDatabase = ""
DefaultDatabase is a marker for using the default database instance.
Variables ¶
var ( // FormatLoggerFunc is a custom LoggerParam's format function for LogrusLogger and StdLogger. FormatLoggerFunc func(p *LoggerParam) string // FieldifyLoggerFunc is a custom LoggerParam's fieldify function for LogrusLogger. FieldifyLoggerFunc func(p *LoggerParam) logrus.Fields )
Functions ¶
func Collect ¶
Collect loops through the result stream, collects records and returns the neo4j.Record slice with neo4j.ResultSummary.
Example:
cypher := "MATCH p = ()-[r :FRIEND]->(n) RETURN r, n" records, summary, err := xneo4j.Collect(session.Run(cypher, nil)) // err contains the connection and execution error for _, record := range records { // records is a slice of neo4j.Record // record is returned values, each value can be got by `Get` or `GetByIndex` methods rel := xneo4j.GetRel(record.GetByIndex(0)) // neo4j.Relationship node := xneo4j.GetNode(record.GetByIndex(1)) // neo4j.Node }
func EnableLogger ¶
func EnableLogger()
EnableLogger enables LogrusLogger and StdLogger to do any log.
func GenerateOrderByExpr ¶
func GenerateOrderByExpr(querySource string, dict PropertyDict, options ...OrderByOption) string
GenerateOrderByExpr returns a generated order-by expression by given order-by query source string (such as "name desc, age asc") and PropertyDict, with some OrderByOption-s. The generated expression will be in mysql-sql (such as "xxx ASC") or neo4j-cypher style (such as "xxx.yyy DESC").
Example:
dict := PropertyDict{ "uid": NewPropertyValue(false, "p.uid"), "name": NewPropertyValue(false, "p.firstname", "p.lastname"), "age": NewPropertyValue(true, "u.birthday"), } _ = GenerateOrderByExpr(`uid, age desc`, dict) // => p.uid ASC, u.birthday ASC _ = GenerateOrderByExpr(`age, username desc`, dict) // => u.birthday DESC, p.firstname DESC, p.lastname DESC
func GetBoolean ¶
func GetBoolean(data interface{}) bool
GetBoolean returns neo4j Boolean value (bool) from given data.
func GetByteArray ¶
func GetByteArray(data interface{}) []byte
GetByteArray returns neo4j ByteArray value ([]byte) from given data.
func GetDateTime ¶
GetDateTime returns neo4j DateTime value (time.Time) from given data.
func GetDuration ¶
GetDuration returns neo4j Duration value (neo4j.Duration) from given data.
func GetFloat ¶
func GetFloat(data interface{}) float64
GetFloat returns neo4j Float value (float64) from given data.
func GetInteger ¶
func GetInteger(data interface{}) int64
GetInteger returns neo4j Integer value (int64) from given data.
func GetList ¶
func GetList(data interface{}) []interface{}
GetList returns neo4j List value ([]interface{}) from given data.
func GetLocalDateTime ¶
func GetLocalDateTime(data interface{}) neo4j.LocalDateTime
GetLocalDateTime returns neo4j LocalDateTime value (neo4j.LocalDateTime) from given data.
func GetLocalTime ¶
GetLocalTime returns neo4j LocalTime value (neo4j.LocalTime) from given data.
func GetMap ¶
func GetMap(data interface{}) map[string]interface{}
GetMap returns neo4j Map value (map[string]interface{}) from given data.
func GetRel ¶
func GetRel(data interface{}) neo4j.Relationship
GetRel returns neo4j Relationship value (neo4j.Relationship) from given data.
func GetString ¶
func GetString(data interface{}) string
GetString returns neo4j String value (string) from given data.
func GetTime ¶
func GetTime(data interface{}) neo4j.OffsetTime
GetTime returns neo4j Time value (neo4j.OffsetTime) from given data.
Types ¶
type DialHandler ¶
DialHandler represents a neo4j.Session dial function, used to get a session from neo4j.Driver.
type DriverOption ¶
DriverOption represents an option type for neo4j.NewDriver's option, can be created by WithXXX functions.
func WithAddressResolver ¶
func WithAddressResolver(resolver neo4j.ServerAddressResolver) DriverOption
WithAddressResolver creates an DriverOption function to specify address resolver for neo4j.Driver, defaults to nil.
func WithConnectionAcquisitionTimeout ¶
func WithConnectionAcquisitionTimeout(t time.Duration) DriverOption
WithConnectionAcquisitionTimeout creates an DriverOption function to specify connection acquisition timeout for neo4j.Driver, defaults to 1min.
func WithEncrypted ¶
func WithEncrypted(encrypted bool) DriverOption
WithEncrypted creates an DriverOption function to specify encrypted flag for neo4j.Driver, defaults to true.
func WithLog ¶
func WithLog(l neo4j.Logging) DriverOption
WithLog creates an DriverOption function to specify log function for neo4j.Driver, defaults to neo4j.NoOpLogger.
func WithMaxConnectionLifetime ¶
func WithMaxConnectionLifetime(t time.Duration) DriverOption
WithMaxConnectionLifetime creates an DriverOption function to specify max connection lifetime for neo4j.Driver, defaults to 1h.
func WithMaxConnectionPoolSize ¶
func WithMaxConnectionPoolSize(size int) DriverOption
WithMaxConnectionPoolSize creates an DriverOption function to specify max connection pool size for neo4j.Driver, defaults to 100.
func WithMaxTransactionRetryTime ¶
func WithMaxTransactionRetryTime(t time.Duration) DriverOption
WithMaxTransactionRetryTime creates an DriverOption function to specify max transaction retry time for neo4j.Driver, defaults to 30s.
func WithSocketConnectTimeout ¶
func WithSocketConnectTimeout(t time.Duration) DriverOption
WithSocketConnectTimeout creates an DriverOption function to specify socket connect timeout for neo4j.Driver, defaults to 5s.
func WithSocketKeepalive ¶
func WithSocketKeepalive(keepalive bool) DriverOption
WithSocketKeepalive creates an DriverOption function to specify socket keepalive flag for neo4j.Driver, defaults to true.
func WithTrustStrategy ¶
func WithTrustStrategy(e neo4j.TrustStrategy) DriverOption
WithTrustStrategy creates an DriverOption function to specify trust strategy for neo4j.Driver, defaults to neo4j.TrustAny(false).
type LoggerOption ¶
type LoggerOption func(*loggerOptions)
LoggerOption represents an option type for LogrusLogger and StdLogger's option, can be created by WithXXX functions.
func WithCounterFields ¶
func WithCounterFields(flag bool) LoggerOption
WithCounterFields creates a LoggerOption to decide whether to do store counter fields to logrus.Fields or not, defaults to false.
func WithLogCypher ¶
func WithLogCypher(log bool) LoggerOption
WithLogCypher creates a LoggerOption to decide whether to do log for cyphers or not, defaults to true.
func WithLogErr ¶
func WithLogErr(log bool) LoggerOption
WithLogErr creates a LoggerOption to decide whether to do log for errors or not, defaults to true.
func WithSkip ¶
func WithSkip(skip int) LoggerOption
WithSkip creates a LoggerOption to specify runtime skip for getting runtime information, defaults to 1.
func WithSlowThreshold ¶
func WithSlowThreshold(threshold time.Duration) LoggerOption
WithSlowThreshold creates a LoggerOption to specify a slow operation's duration used to highlight loggers, defaults to 0ms, means no highlight.
type LoggerParam ¶
type LoggerParam struct { Type string Cypher string Duration time.Duration Slow bool Source string Counter neo4j.Counters ErrorMsg string }
LoggerParam stores some logger parameters and is used by LogrusLogger and StdLogger.
type LogrusLogger ¶
LogrusLogger represents a neo4j.Session as neo4j's logger, used to log neo4j's executing message to logrus.Logger.
func NewLogrusLogger ¶
func NewLogrusLogger(session neo4j.Session, logger *logrus.Logger, options ...LoggerOption) *LogrusLogger
NewLogrusLogger creates a new LogrusLogger using given logrus.Logger and LoggerOption-s.
Example:
driver, err := neo4j.NewDriver(...) sess, err := driver.Session(neo4j.AccessModeRead) l := logrus.New() l.SetFormatter(&logrus.TextFormatter{}) sess = NewLogrusLogger(sess, l)
func (*LogrusLogger) Run ¶
func (l *LogrusLogger) Run(cypher string, params map[string]interface{}, configurers ...func(*neo4j.TransactionConfig)) (neo4j.Result, error)
Run implements neo4j.Session interface, it executes given cypher and params, and logs neo4j's message to logrus.Logger.
type OrderByOption ¶
type OrderByOption = xdbutils_orderby.OrderByOption
OrderByOption represents an option type for GenerateOrderByExpr's option, can be created by WithXXX functions.
func WithOrderBySourceProcessor ¶
func WithOrderBySourceProcessor(processor func(source string) (field string, asc bool)) OrderByOption
WithOrderBySourceProcessor creates an OrderByOption to specify the source processor for extracting field name and ascending flag from given source, defaults to use the "field asc" or "field desc" format (case-insensitive) to extract information.
func WithOrderBySourceSeparator ¶
func WithOrderBySourceSeparator(separator string) OrderByOption
WithOrderBySourceSeparator creates an OrderByOption to specify the source order-by expression fields separator, defaults to ",".
func WithOrderByTargetProcessor ¶
func WithOrderByTargetProcessor(processor func(destination string, asc bool) (target string)) OrderByOption
WithOrderByTargetProcessor creates an OrderByOption to specify the target processor for combining field name and ascending flag to target expression, defaults to generate the target with "destination ASC" or "destination DESC" format.
func WithOrderByTargetSeparator ¶
func WithOrderByTargetSeparator(separator string) OrderByOption
WithOrderByTargetSeparator creates an OrderByOption to specify the target order-by expression fields separator, defaults to ", ".
type P ¶
type P = map[string]interface{}
P is a cypher parameters type, is always same as `map[string]interface{}`.
Example:
session.Run(`MATCH (n {id: $id}) RETURN n`, xneo4j.P{"id": 2})
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool represents a neo4j.Session pool, implements neo4j.Driver interface. Actually this is a neo4j.Driver wrapper container with a DialHandler with custom neo4j.Session config.
Some tips:
1. Each neo4j.Driver instance maintains a pool of connections inside, as a result, it is recommended to only use one driver per application.
2. It is considerably cheap to create new neo4j.Session and neo4j.Transaction, as neo4j.Session and neo4j.Transaction do not create new connections as long as there are free connections available in the connection pool.
3. The neo4j.Driver is thread-safe, while the neo4j.Session or the neo4j.Transaction is not thread-safe.
func NewPool ¶
func NewPool(driver neo4j.Driver, dial DialHandler) *Pool
NewPool creates a Pool using given neo4j.Driver and DialHandler, panics when using nil neo4j.Driver. Also see neo4j.NewDriver, neo4j.Config and neo4j.SessionConfig.
Example:
driver, _ := neo4j.NewDriver(uri, neo4j.BasicAuth(username, password, realm), xneo4j.WithMaxConnectionPoolSize(10)) pool := xneo4j.NewPool(driver, func(driver neo4j.Driver, config *neo4j.SessionConfig) (neo4j.Session, error) { return driver.Session(config.AccessMode, config.Bookmarks...) // use default database })
func (*Pool) DialReadMode ¶
DialReadMode dials and returns a new neo4j.Session with neo4j.AccessModeRead from neo4j.Driver's pool.
func (*Pool) DialWriteMode ¶
DialWriteMode dials and returns a new neo4j.Session with neo4j.AccessModeWrite from neo4j.Driver's pool.
func (*Pool) NewSession ¶
NewSession dials and returns a new neo4j.Session from neo4j.Driver's pool.
func (*Pool) VerifyConnectivity ¶
VerifyConnectivity verifies the driver can connect to a remote server or cluster by establishing a network connection with the remote.
type PropertyDict ¶
type PropertyDict = xdbutils_orderby.PropertyDict
PropertyDict is used to store PropertyValue-s for data transfer object (dto) to entity's property mapping rule, is used in GenerateOrderByExpr.
type PropertyValue ¶
type PropertyValue = xdbutils_orderby.PropertyValue
PropertyValue represents database single entity's property mapping rule, is used in GenerateOrderByExpr.
func NewPropertyValue ¶
func NewPropertyValue(reverse bool, destinations ...string) *PropertyValue
NewPropertyValue creates a PropertyValue by given reverse and destinations, is used to describe database single entity's property mapping rule.
Here: 1. `destinations` represents mapping property destination list, use `property_name` directly for sql, use `returned_name.property_name` for cypher. 2. `reverse` represents the flag whether you need to revert the order or not.
type StdLogger ¶
StdLogger represents a neo4j.Session as neo4j's logger, used to log neo4j's executing message to logrus.StdLogger.
func NewStdLogger ¶
func NewStdLogger(session neo4j.Session, logger logrus.StdLogger, options ...LoggerOption) *StdLogger
NewStdLogger creates a new StdLogger using given log.Logger and LoggerOption-s.
Example:
driver, err := neo4j.NewDriver(...) sess, err := driver.Session(neo4j.AccessModeRead) l := log.Default() sess = NewStdLogger(sess, l)