Documentation
¶
Index ¶
- func Collect(result neo4j.Result, err error) ([]neo4j.Record, neo4j.ResultSummary, error)
- func GenerateOrderByExp(source string, dict PropertyDict) 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 LoggerLogger
- type LoggerOption
- type LogrusLogger
- 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) Target() url.URL
- func (p *Pool) VerifyConnectivity() error
- type PropertyDict
- type PropertyValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Collect ¶
Collect loops through the result stream, collects records into a slice and returns the resulting slice with result summary.
Cypher manual refers to https://neo4j.com/docs/cypher-manual/3.5/syntax/. Neo4j go driver refers to https://github.com/neo4j/neo4j-go-driver/tree/1.8.
Example:
cypher := "MATCH p = ()-[r :FRIEND]->(n) RETURN r, n" records, summary, err := xneo4j.Collect(session.Run(cypher, nil)) // err contains connect and execute error for _, record := range records { // records is a slice of neo4j.Record // record is the returned values, each value can be get by `Get` or `GetByIndex` methods rel := xneo4j.GetRel(record.GetByIndex(0)) // neo4j.Relationship node := xneo4j.GetNode(record.GetByIndex(1)) // neo4j.Node }
func GenerateOrderByExp ¶
func GenerateOrderByExp(source string, dict PropertyDict) string
GenerateOrderByExp returns a generated orderBy expresion by given source dto order string (split by ",", such as "name desc, age asc") and PropertyDict. The generated expression is in mysql-sql and neo4j-cypher style, that is "xx ASC", "xx 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 ¶
type DialHandler func(driver neo4j.Driver, accessMode neo4j.AccessMode, bookmarks ...string) (neo4j.Session, error)
DialHandler represents a neo4j.Session dial function, used to get a session from neo4j.Driver.
type LoggerLogger ¶
LoggerLogger represents a neo4j.Session, used to log neo4j cypher executing message to logrus.StdLogger.
func NewLoggerLogger ¶
func NewLoggerLogger(session neo4j.Session, logger logrus.StdLogger, options ...LoggerOption) *LoggerLogger
NewLoggerLogger creates a new LoggerLogger using given log.Logger and LoggerOption-s. Example:
driver, err := neo4j.NewDriver(target, auth) session, err := driver.Session(neo4j.AccessModeRead) l := log.New(os.Stderr, "", log.LstdFlags) session = NewLoggerLogger(session, l) // with default skip 1
func (*LoggerLogger) Run ¶
func (l *LoggerLogger) Run(cypher string, params map[string]interface{}, configurers ...func(*neo4j.TransactionConfig)) (neo4j.Result, error)
Run executes given cypher and params, and logs to logrus.StdLogger.
type LoggerOption ¶
type LoggerOption func(*loggerOptions)
LoggerOption represents an option for logger, created by WithXXX functions.
func WithCounterField ¶
func WithCounterField(switcher bool) LoggerOption
WithCounterField returns a LoggerOption with counter fields switcher, defaults to false.
func WithSkip ¶
func WithSkip(skip int) LoggerOption
WithSkip returns a LoggerOption with runtime skip to get runtime information, defaults to 1.
type LogrusLogger ¶
LogrusLogger represents a neo4j.Session, used to log neo4j cypher 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(target, auth) session, err := driver.Session(neo4j.AccessModeRead) l := logrus.New() l.SetFormatter(&logrus.TextFormatter{}) session = NewLogrusLogger(session, l) // with default skip 1
func (*LogrusLogger) Run ¶
func (l *LogrusLogger) Run(cypher string, params map[string]interface{}, configurers ...func(*neo4j.TransactionConfig)) (neo4j.Result, error)
Run executes given cypher and params, and logs to logrus.Logger.
type P ¶
type P map[string]interface{}
P represents the cypher parameter type, equals to "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, actually this is a neo4j.Driver wrapper container with a custom DialHandler.
Some notes:
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, uses default DialHandler when giving nil value. Also see neo4j.NewDriver, neo4j.Config, neo4j.SessionConfig.
Example:
driver, _ := neo4j.NewDriver(uri, neo4j.BasicAuth(username, password, realm), func(config *neo4j.Config) { config.MaxConnectionPoolSize = 10 }) pool := xneo4j.NewPool(driver, func(driver neo4j.Driver, accessMode neo4j.AccessMode, bookmarks ...string) (neo4j.Session, error) { return driver.NewSession(neo4j.SessionConfig{ AccessMode: accessMode, Bookmarks: bookmarks, DatabaseName: database, // custom config }) })
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) 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 = orderby.PropertyDict
PropertyDict represents a DTO-PO PropertyValue dictionary, used in GenerateOrderByExp.
type PropertyValue ¶
type PropertyValue = orderby.PropertyValue
PropertyValue represents a PO entity's property mapping rule.
func NewPropertyValue ¶
func NewPropertyValue(reverse bool, destinations ...string) *PropertyValue
NewPropertyValue creates a PropertyValue by given reverse and destinations.