Documentation
¶
Index ¶
- Constants
- Variables
- func Auth(cred string) (neo4j.AuthToken, string)
- func IsConnected() bool
- type Conn
- func (c *Conn) Close() (err error)
- func (c *Conn) Commit() (done bool, err error)
- func (c *Conn) GetTransaction() (tx neo4j.Transaction, created bool, err error)
- func (c *Conn) Rollback() (done bool, err error)
- func (c *Conn) Session() neo4j.Session
- func (c *Conn) UseDB(dbName string) (err error)
- func (c *Conn) Username() string
- type Mapper
- type Request
- type Result
- type Template
Constants ¶
const ( ID = "@id" Label = "@label" Labels = "@labels" Type = "@type" StartID = "@startId" EndID = "@endId" )
const SystemDB = "system"
Variables ¶
var ErrEmpty = errors.New("empty")
ErrEmpty indicates that a query returned no result.
var ErrMultiple = errors.New("multiple")
ErrMultiple indicates that a query returned more Records than expected.
Functions ¶
func Auth ¶
Auth parses the credentials and creates a new AuthToken. The credentials shall be prefixed with a colon (":") to designate the type. If it does not contain a valid authentication scheme, it falls back to Basic authentication. If the username can be derived from the credentials, it is returned together with the AuthToken.
func IsConnected ¶
func IsConnected() bool
IsConnected returns whether the database connection is established.
Types ¶
type Conn ¶
type Conn struct { Driver neo4j.Driver DBName string Tx neo4j.Transaction Params map[string]any // contains filtered or unexported fields }
Conn represents a database connection, which can open multiple Sessions.
func GetConn ¶
func GetConn() *Conn
GetConn returns the default connection, regardless of its connection state. It panics if there is no connection.
func NewConn ¶
func NewConn(addr string, user string, auth neo4j.AuthToken, dbName string, opts ...func(config *neo4j.Config)) (*Conn, error)
NewConn creates a new Neo4j Driver and returns the new Conn.
func (*Conn) Commit ¶
Commit commits the current Transaction. If there is no active Transaction, false is returned.
func (*Conn) GetTransaction ¶
func (c *Conn) GetTransaction() (tx neo4j.Transaction, created bool, err error)
GetTransaction returns the current Transaction or creates a new one.
func (*Conn) Rollback ¶
Rollback rolls back the current Transaction. If there is no active Transaction, false is returned.
type Mapper ¶
Mapper is used by Template for mapping results on a per-record basis. Implementations of this type perform the actual work of mapping each Record to a type, but don't need to worry about error handling. Errors will be handled by the calling Template.
func NewRawResultMapper ¶
NewRawResultMapper creates a new Mapper that extracts all columns to key-value pairs as they are returned.
func NewResultMapper ¶
NewResultMapper creates a new Mapper that converts Records to Results. For each Node and Relationship, its properties are extracted into a map. Additionally, IDs, labels and types are added so that specific modifications can be applied by the caller.
func NewSingleValueMapper ¶
NewSingleValueMapper creates a new Mapper that converts a single column into a single result value per record. The type of the result value for each record can be specified. The value for the single column will be extracted from the Record and cast to the specified target type.
type Result ¶
Result is an alias for Record with additional convenience methods.
type Template ¶
type Template[T any] struct { // contains filtered or unexported fields }
Template simplifies the use of Neo4j and helps to avoid common errors. It executes core Neo4j workflow, leaving application code to provide Cypher and extract results. Template executes Cypher queries or updates, initiating iteration over Results and catching errors. Callers need only to implement callback functions, giving them a clearly defined contract. All Neo4j operations performed are logged at debug level, using the Logger.
func NewTemplate ¶
NewTemplate creates a new Template with the given connection.
func (Template[T]) Query ¶
func (t Template[T]) Query(r Request, m Mapper[T]) ( list []T, summary neo4j.ResultSummary, err error)
Query executes the given Cypher with list of parameters to bind to the query, mapping each record to a value via a RowMapper. If there is no Transaction on this Session, then an explicit transaction is started and committed afterwards.