Skip to content

Commit

Permalink
Update manual with 5.0 examples and add missing deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
fbiville authored Oct 11, 2022
1 parent e4b6e09 commit cb7db9e
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 201 deletions.
42 changes: 31 additions & 11 deletions neo4j/result_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,49 @@ func CollectT[T any](result Result, mapper func(*Record) (T, error)) ([]T, error
// Single returns one and only one record from the result stream. Any error passed in
// or reported while navigating the result stream is returned without any conversion.
// If the result stream contains zero or more than one records error is returned.
// record, err := neo4j.Single(session.Run(...))
//
// record, err := neo4j.Single(session.Run(...))
func Single(result Result, err error) (*Record, error) {
if err != nil {
return nil, err
}
return result.Single()
}

// Collect loops through the result stream, collects records into a slice and returns the
// resulting slice. Any error passed in or reported while navigating the result stream is
// returned without any conversion.
// records, err := neo4j.Collect(session.Run(...))
// Collect behaves similarly to CollectWithContext
//
// records, err := neo4j.Collect(session.Run(...))
//
// Deprecated: use CollectWithContext instead (the entry point of context-aware
// APIs is NewDriverWithContext)
func Collect(result Result, err error) ([]*Record, error) {
if err != nil {
return nil, err
}
return result.Collect()
}

// CollectWithContext loops through the result stream, collects records into a slice and returns the
// resulting slice. Any error passed in or reported while navigating the result stream is
// returned without any conversion.
//
// result, err := session.Run(...)
// records, err := neo4j.CollectWithContext(ctx, result, err)
//
// Note, you cannot write neo4j.CollectWithContext(ctx, session.Run(...)) due to Go limitations
func CollectWithContext(ctx context.Context, result ResultWithContext, err error) ([]*Record, error) {
if err != nil {
return nil, err
}
return result.Collect(ctx)
}

// AsRecords passes any existing error or casts from to a slice of records.
// Use in combination with Collect and transactional functions:
// records, err := neo4j.AsRecords(session.ExecuteRead(func (tx neo4j.Transaction) {
// return neo4j.Collect(tx.Run(...))
// }))
//
// records, err := neo4j.AsRecords(session.ExecuteRead(func (tx neo4j.Transaction) {
// return neo4j.Collect(tx.Run(...))
// }))
func AsRecords(from any, err error) ([]*Record, error) {
if err != nil {
return nil, err
Expand All @@ -106,9 +125,10 @@ func AsRecords(from any, err error) ([]*Record, error) {

// AsRecord passes any existing error or casts from to a record.
// Use in combination with Single and transactional functions:
// record, err := neo4j.AsRecord(session.ExecuteRead(func (tx neo4j.Transaction) {
// return neo4j.Single(tx.Run(...))
// }))
//
// record, err := neo4j.AsRecord(session.ExecuteRead(func (tx neo4j.Transaction) {
// return neo4j.Single(tx.Run(...))
// }))
func AsRecord(from any, err error) (*Record, error) {
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions neo4j/session_with_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import (

// TransactionWork represents a unit of work that will be executed against the provided
// transaction
// Deprecated: use ManagedTransactionWork instead.
// ManagedTransactionWork is created via the context-aware driver returned
// by NewDriverWithContext.
// TransactionWork will be removed in 6.0.
type TransactionWork func(tx Transaction) (any, error)

// ManagedTransactionWork represents a unit of work that will be executed against the provided
Expand Down
Loading

0 comments on commit cb7db9e

Please sign in to comment.