xneo4j

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: MIT Imports: 11 Imported by: 0

README

xneo4j

Dependencies

  • github.com/neo4j/neo4j-go-driver
  • github.com/sirupsen/logrus

Documents

Types
  • type P map
  • type PropertyValue struct
  • type PropertyDict map
  • type DialHandler func
  • type Pool struct
  • type LoggerOption func
  • type LogrusLogger struct
  • type LoggerLogger struct
Variables
  • None
Constants
  • None
Functions
  • func Collect(result neo4j.Result, err error) ([]neo4j.Record, neo4j.ResultSummary, error)
  • func GetInteger(data interface{}) int64
  • func GetFloat(data interface{}) float64
  • func GetString(data interface{}) string
  • func GetBoolean(data interface{}) bool
  • func GetByteArray(data interface{}) []byte
  • func GetList(data interface{}) []interface{}
  • func GetMap(data interface{}) map[string]interface{}
  • func GetNode(data interface{}) neo4j.Node
  • func GetRel(data interface{}) neo4j.Relationship
  • func GetPath(data interface{}) neo4j.Path
  • func GetPoint(data interface{}) neo4j.Point
  • func GetDate(data interface{}) neo4j.Date
  • func GetTime(data interface{}) neo4j.OffsetTime
  • func GetDateTime(data interface{}) time.Time
  • func GetLocalTime(data interface{}) neo4j.LocalTime
  • func GetLocalDateTime(data interface{}) neo4j.LocalDateTime
  • func GetDuration(data interface{}) neo4j.Duration
  • func NewPropertyValue(reverse bool, destinations ...string) *PropertyValue
  • func GenerateOrderByExp(source string, dict PropertyDict) string
  • func NewPool(driver neo4j.Driver, dial DialHandler) *Pool
  • func WithSkip(skip int) LoggerOption
  • func WithCounterField(switcher bool) LoggerOption
  • func NewLogrusLogger(session neo4j.Session, logger *logrus.Logger, options ...LoggerOption) *LogrusLogger
  • func NewLoggerLogger(session neo4j.Session, logger logrus.StdLogger, options ...LoggerOption) *LoggerLogger
Methods
  • func (p *PropertyValue) Destinations() []string
  • func (p *PropertyValue) Reverse() bool
  • 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
  • func (p *Pool) Close() error
  • func (l *LogrusLogger) Run(cypher string, params map[string]interface{}, configurers ...func(*neo4j.TransactionConfig)) (neo4j.Result, error)
  • func (l *LoggerLogger) Run(cypher string, params map[string]interface{}, configurers ...func(*neo4j.TransactionConfig)) (neo4j.Result, error)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect(result neo4j.Result, err error) ([]neo4j.Record, neo4j.ResultSummary, error)

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 GetDate

func GetDate(data interface{}) neo4j.Date

GetDate returns neo4j Date value (neo4j.Date) from given data.

func GetDateTime

func GetDateTime(data interface{}) time.Time

GetDateTime returns neo4j DateTime value (time.Time) from given data.

func GetDuration

func GetDuration(data interface{}) neo4j.Duration

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

func GetLocalTime(data interface{}) neo4j.LocalTime

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 GetNode

func GetNode(data interface{}) neo4j.Node

GetNode returns neo4j Node value (neo4j.Node) from given data.

func GetPath

func GetPath(data interface{}) neo4j.Path

GetPath returns neo4j Path value (neo4j.Path) from given data.

func GetPoint

func GetPoint(data interface{}) *neo4j.Point

GetPoint returns neo4j Point value (neo4j.Point) 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

type LoggerLogger struct {
	neo4j.Session
	// contains filtered or unexported fields
}

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

type LogrusLogger struct {
	neo4j.Session
	// contains filtered or unexported fields
}

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) Close

func (p *Pool) Close() error

Close closes the neo4j.Driver and all underlying connections.

func (*Pool) Dial

func (p *Pool) Dial(mode neo4j.AccessMode, bookmarks ...string) (neo4j.Session, error)

Dial dials and returns a new neo4j.Session from neo4j.Driver's pool.

func (*Pool) DialReadMode

func (p *Pool) DialReadMode(bookmarks ...string) (neo4j.Session, error)

DialReadMode dials and returns a new neo4j.Session with neo4j.AccessModeRead from neo4j.Driver's pool.

func (*Pool) DialWriteMode

func (p *Pool) DialWriteMode(bookmarks ...string) (neo4j.Session, error)

DialWriteMode dials and returns a new neo4j.Session with neo4j.AccessModeWrite from neo4j.Driver's pool.

func (*Pool) Target

func (p *Pool) Target() url.URL

Target returned the url.URL that this driver is bootstrapped.

func (*Pool) VerifyConnectivity

func (p *Pool) VerifyConnectivity() error

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.

Jump to

Keyboard shortcuts

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