neo4j

package
v0.0.0-...-bf444b6 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoMoreRecords is returned by neo4j.Result.Next() when there are no
	// more records to be read, and the result has been fully consumed, but
	// we are still trying to read more.
	ErrNoMoreRecords = &neo4j.UsageError{
		Message: "Result contains no more records",
	}
)

Functions

func ExecuteAndConsumeResult

func ExecuteAndConsumeResult(ctx context.Context, tx neo4j.ManagedTransaction, query string, params map[string]any) error

ExecuteAndConsumeResult executes a query and consumes its result.

func ExecuteReadAndReadAll

func ExecuteReadAndReadAll[T any](ctx context.Context, db *Database, query string, params map[string]any, reader func(record *neo4j.Record) (T, error)) ([]T, error)

ExecuteReadAndReadAll executes a query and reads all results.

func ExecuteReadAndReadSingle

func ExecuteReadAndReadSingle[T any](ctx context.Context, db *Database, query string, params map[string]any, reader func(record *neo4j.Record) (*T, error)) (*T, error)

ExecuteReadAndReadSingle executes a query and reads a single result.

func ExecuteWriteAndConsume

func ExecuteWriteAndConsume(ctx context.Context, db *Database, query string, params map[string]any) error

ExecuteWriteAndConsume executes a query and consumes its result.

func ExecuteWriteAndReadAll

func ExecuteWriteAndReadAll[T any](ctx context.Context, db *Database, query string, params map[string]any, reader func(record *neo4j.Record) (T, error)) ([]T, error)

ExecuteWriteAndReadAll executes a query and reads all results.

func ExecuteWriteAndReadSingle

func ExecuteWriteAndReadSingle[T any](ctx context.Context, db *Database, query string, params map[string]any, reader func(record *neo4j.Record) (*T, error)) (*T, error)

ExecuteWriteAndReadSingle executes a query and reads a single result.

func NewDriver

NewDriver creates a new Neo4j driver.

func ParseIDsFromRecord

func ParseIDsFromRecord(record *neo4j.Record, key, label string) ([]model.ID, error)

ParseIDsFromRecord parses a list of IDs from a neo4j record.

func ParseValueFromRecord

func ParseValueFromRecord[T neo4j.RecordValue](record *neo4j.Record, key string) (T, error)

ParseValueFromRecord parses a value from a neo4j record.

func ScanIntoStruct

func ScanIntoStruct(n PropertyGetter, dst any, exclude []string) error

ScanIntoStruct parses a struct from a neo4j node or relationship.

Types

type AssignmentRepository

type AssignmentRepository struct {
	// contains filtered or unexported fields
}

AssignmentRepository is a repository for managing user assignments.

func NewAssignmentRepository

func NewAssignmentRepository(opts ...RepositoryOption) (*AssignmentRepository, error)

NewAssignmentRepository creates a new assignment baseRepository.

func (*AssignmentRepository) Create

func (r *AssignmentRepository) Create(ctx context.Context, assignment *model.Assignment) error

func (*AssignmentRepository) Delete

func (r *AssignmentRepository) Delete(ctx context.Context, id model.ID) error

func (*AssignmentRepository) Get

func (*AssignmentRepository) GetByResource

func (r *AssignmentRepository) GetByResource(ctx context.Context, resourceID model.ID, offset, limit int) ([]*model.Assignment, error)

func (*AssignmentRepository) GetByUser

func (r *AssignmentRepository) GetByUser(ctx context.Context, userID model.ID, offset, limit int) ([]*model.Assignment, error)

type AttachmentRepository

type AttachmentRepository struct {
	// contains filtered or unexported fields
}

AttachmentRepository is a repository for managing attachments.

func NewAttachmentRepository

func NewAttachmentRepository(opts ...RepositoryOption) (*AttachmentRepository, error)

NewAttachmentRepository creates a new attachment baseRepository.

func (*AttachmentRepository) Create

func (r *AttachmentRepository) Create(ctx context.Context, belongsTo model.ID, attachment *model.Attachment) error

func (*AttachmentRepository) Delete

func (r *AttachmentRepository) Delete(ctx context.Context, id model.ID) error

func (*AttachmentRepository) Get

func (*AttachmentRepository) GetAllBelongsTo

func (r *AttachmentRepository) GetAllBelongsTo(ctx context.Context, belongsTo model.ID, offset, limit int) ([]*model.Attachment, error)

func (*AttachmentRepository) Update

func (r *AttachmentRepository) Update(ctx context.Context, id model.ID, name string) (*model.Attachment, error)

type CommentRepository

type CommentRepository struct {
	// contains filtered or unexported fields
}

CommentRepository is a repository for managing comments.

func NewCommentRepository

func NewCommentRepository(opts ...RepositoryOption) (*CommentRepository, error)

NewCommentRepository creates a new comment baseRepository.

func (*CommentRepository) Create

func (r *CommentRepository) Create(ctx context.Context, belongsTo model.ID, comment *model.Comment) error

func (*CommentRepository) Delete

func (r *CommentRepository) Delete(ctx context.Context, id model.ID) error

func (*CommentRepository) Get

func (*CommentRepository) GetAllBelongsTo

func (r *CommentRepository) GetAllBelongsTo(ctx context.Context, belongsTo model.ID, offset, limit int) ([]*model.Comment, error)

func (*CommentRepository) Update

func (r *CommentRepository) Update(ctx context.Context, id model.ID, content string) (*model.Comment, error)

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database represents a Neo4j database, wrapping a Neo4j driver.

func NewDatabase

func NewDatabase(opts ...DatabaseOption) (*Database, error)

NewDatabase creates a new Neo4j database.

func (*Database) Close

func (db *Database) Close(ctx context.Context) error

Close closes the database connections.

func (*Database) GetReadSession

func (db *Database) GetReadSession(ctx context.Context) neo4j.SessionWithContext

GetReadSession returns a "read" session.

func (*Database) GetWriteSession

func (db *Database) GetWriteSession(ctx context.Context) neo4j.SessionWithContext

GetWriteSession returns a "write" session.

func (*Database) Ping

func (db *Database) Ping(ctx context.Context) error

Ping verifies the connection to the database.

type DatabaseOption

type DatabaseOption func(*Database)

DatabaseOption configures a Neo4j database.

func WithDatabaseLogger

func WithDatabaseLogger(logger log.Logger) DatabaseOption

WithDatabaseLogger sets the logger for a Neo4j database.

func WithDatabaseName

func WithDatabaseName(name string) DatabaseOption

WithDatabaseName sets the name for a Neo4j database.

func WithDatabaseTracer

func WithDatabaseTracer(tracer tracing.Tracer) DatabaseOption

WithDatabaseTracer sets the tracer for a Neo4j database.

func WithDriver

func WithDriver(driver neo4j.DriverWithContext) DatabaseOption

WithDriver sets the driver for a Neo4j database.

type DocumentRepository

type DocumentRepository struct {
	// contains filtered or unexported fields
}

DocumentRepository is a repository for managing documents.

func NewDocumentRepository

func NewDocumentRepository(opts ...RepositoryOption) (*DocumentRepository, error)

NewDocumentRepository creates a new document baseRepository.

func (*DocumentRepository) Create

func (r *DocumentRepository) Create(ctx context.Context, belongsTo model.ID, document *model.Document) error

func (*DocumentRepository) Delete

func (r *DocumentRepository) Delete(ctx context.Context, id model.ID) error

func (*DocumentRepository) Get

func (*DocumentRepository) GetAllBelongsTo

func (r *DocumentRepository) GetAllBelongsTo(ctx context.Context, belongsTo model.ID, offset, limit int) ([]*model.Document, error)

func (*DocumentRepository) GetByCreator

func (r *DocumentRepository) GetByCreator(ctx context.Context, createdBy model.ID, offset, limit int) ([]*model.Document, error)

func (*DocumentRepository) Update

func (r *DocumentRepository) Update(ctx context.Context, id model.ID, patch map[string]any) (*model.Document, error)

type EdgeKind

type EdgeKind uint8

EdgeKind is the kind of relation between two entities.

const (
	EdgeKindAssignedTo    EdgeKind = iota + 1 // a user is assigned to a resource
	EdgeKindBelongsTo                         // a resource belongs to another
	EdgeKindCommented                         // a user commented a resource
	EdgeKindCreated                           // a user created a resource
	EdgeKindHasAttachment                     // a resource has an attachment
	EdgeKindHasComment                        // a resource has a comment
	EdgeKindHasLabel                          // a resource is labeled by a label
	EdgeKindHasNamespace                      // an organization has a namespace
	EdgeKindHasPermission                     // a subject has permission on a resource
	EdgeKindHasProject                        // a namespace has a project
	EdgeKindHasTeam                           // an organization or project has a team
	EdgeKindInvited                           // a user invited another user
	EdgeKindKindOf                            // a resource is a kind of another
	EdgeKindMemberOf                          // a user is a member of a team
	EdgeKindRelatedTo                         // a resource is related to another
	EdgeKindSpeaks                            // a user speaks a language
	EdgeKindWatches                           // a user watches a resource
)

func (EdgeKind) String

func (k EdgeKind) String() string

String returns the string representation of the relation kind.

type IssueRepository

type IssueRepository struct {
	// contains filtered or unexported fields
}

IssueRepository is a repository for managing user issues.

func NewIssueRepository

func NewIssueRepository(opts ...RepositoryOption) (*IssueRepository, error)

NewIssueRepository creates a new issue baseRepository.

func (*IssueRepository) AddRelation

func (r *IssueRepository) AddRelation(ctx context.Context, relation *model.IssueRelation) error

func (*IssueRepository) AddWatcher

func (r *IssueRepository) AddWatcher(ctx context.Context, issue model.ID, user model.ID) error

func (*IssueRepository) Create

func (r *IssueRepository) Create(ctx context.Context, project model.ID, issue *model.Issue) error

func (*IssueRepository) Delete

func (r *IssueRepository) Delete(ctx context.Context, id model.ID) error

func (*IssueRepository) Get

func (r *IssueRepository) Get(ctx context.Context, id model.ID) (*model.Issue, error)

func (*IssueRepository) GetAllForIssue

func (r *IssueRepository) GetAllForIssue(ctx context.Context, issueID model.ID, offset, limit int) ([]*model.Issue, error)

func (*IssueRepository) GetAllForProject

func (r *IssueRepository) GetAllForProject(ctx context.Context, projectID model.ID, offset, limit int) ([]*model.Issue, error)

func (*IssueRepository) GetRelations

func (r *IssueRepository) GetRelations(ctx context.Context, issue model.ID) ([]*model.IssueRelation, error)

func (*IssueRepository) GetWatchers

func (r *IssueRepository) GetWatchers(ctx context.Context, issue model.ID) ([]*model.User, error)

func (*IssueRepository) RemoveRelation

func (r *IssueRepository) RemoveRelation(ctx context.Context, source, target model.ID, kind model.IssueRelationKind) error

func (*IssueRepository) RemoveWatcher

func (r *IssueRepository) RemoveWatcher(ctx context.Context, issue model.ID, user model.ID) error

func (*IssueRepository) Update

func (r *IssueRepository) Update(ctx context.Context, id model.ID, patch map[string]any) (*model.Issue, error)

type LabelRepository

type LabelRepository struct {
	// contains filtered or unexported fields
}

LabelRepository is a repository for managing labels.

func NewLabelRepository

func NewLabelRepository(opts ...RepositoryOption) (*LabelRepository, error)

NewLabelRepository creates a new label baseRepository.

func (*LabelRepository) AttachTo

func (r *LabelRepository) AttachTo(ctx context.Context, labelID, attachTo model.ID) error

func (*LabelRepository) Create

func (r *LabelRepository) Create(ctx context.Context, label *model.Label) error

func (*LabelRepository) Delete

func (r *LabelRepository) Delete(ctx context.Context, id model.ID) error

func (*LabelRepository) DetachFrom

func (r *LabelRepository) DetachFrom(ctx context.Context, labelID, detachFrom model.ID) error

func (*LabelRepository) Get

func (r *LabelRepository) Get(ctx context.Context, id model.ID) (*model.Label, error)

func (*LabelRepository) GetAll

func (r *LabelRepository) GetAll(ctx context.Context, offset, limit int) ([]*model.Label, error)

func (*LabelRepository) Update

func (r *LabelRepository) Update(ctx context.Context, id model.ID, patch map[string]any) (*model.Label, error)

type LicenseRepository

type LicenseRepository struct {
	// contains filtered or unexported fields
}

func NewLicenseRepository

func NewLicenseRepository(opts ...RepositoryOption) (*LicenseRepository, error)

NewLicenseRepository creates a new LicenseRepository

func (*LicenseRepository) ActiveOrganizationCount

func (r *LicenseRepository) ActiveOrganizationCount(ctx context.Context) (int, error)

func (*LicenseRepository) ActiveUserCount

func (r *LicenseRepository) ActiveUserCount(ctx context.Context) (int, error)

func (*LicenseRepository) DocumentCount

func (r *LicenseRepository) DocumentCount(ctx context.Context) (int, error)

func (*LicenseRepository) NamespaceCount

func (r *LicenseRepository) NamespaceCount(ctx context.Context) (int, error)

func (*LicenseRepository) ProjectCount

func (r *LicenseRepository) ProjectCount(ctx context.Context) (int, error)

func (*LicenseRepository) RoleCount

func (r *LicenseRepository) RoleCount(ctx context.Context) (int, error)

type NamespaceRepository

type NamespaceRepository struct {
	// contains filtered or unexported fields
}

NamespaceRepository is a repository for managing namespaces.

func NewNamespaceRepository

func NewNamespaceRepository(opts ...RepositoryOption) (*NamespaceRepository, error)

NewNamespaceRepository creates a new namespace baseRepository.

func (*NamespaceRepository) Create

func (r *NamespaceRepository) Create(ctx context.Context, orgID model.ID, namespace *model.Namespace) error

func (*NamespaceRepository) Delete

func (r *NamespaceRepository) Delete(ctx context.Context, id model.ID) error

func (*NamespaceRepository) Get

func (*NamespaceRepository) GetAll

func (r *NamespaceRepository) GetAll(ctx context.Context, orgID model.ID, offset, limit int) ([]*model.Namespace, error)

func (*NamespaceRepository) Update

func (r *NamespaceRepository) Update(ctx context.Context, id model.ID, patch map[string]any) (*model.Namespace, error)

type OrganizationRepository

type OrganizationRepository struct {
	// contains filtered or unexported fields
}

OrganizationRepository is a repository for managing organizations.

func NewOrganizationRepository

func NewOrganizationRepository(opts ...RepositoryOption) (*OrganizationRepository, error)

NewOrganizationRepository creates a new organization baseRepository.

func (*OrganizationRepository) AddMember

func (r *OrganizationRepository) AddMember(ctx context.Context, orgID, memberID model.ID) error

func (*OrganizationRepository) Create

func (r *OrganizationRepository) Create(ctx context.Context, owner model.ID, organization *model.Organization) error

func (*OrganizationRepository) Delete

func (r *OrganizationRepository) Delete(ctx context.Context, id model.ID) error

func (*OrganizationRepository) Get

func (*OrganizationRepository) GetAll

func (r *OrganizationRepository) GetAll(ctx context.Context, offset, limit int) ([]*model.Organization, error)

func (*OrganizationRepository) RemoveMember

func (r *OrganizationRepository) RemoveMember(ctx context.Context, orgID, memberID model.ID) error

func (*OrganizationRepository) Update

func (r *OrganizationRepository) Update(ctx context.Context, id model.ID, patch map[string]any) (*model.Organization, error)

type PermissionRepository

type PermissionRepository struct {
	// contains filtered or unexported fields
}

PermissionRepository is a repository for managing permissions.

func NewPermissionRepository

func NewPermissionRepository(opts ...RepositoryOption) (*PermissionRepository, error)

NewPermissionRepository creates a new permission baseRepository.

func (*PermissionRepository) Create

func (r *PermissionRepository) Create(ctx context.Context, perm *model.Permission) error

Create creates a new permission if it does not already exist between the subject and target. If the permission already exists, no action is taken.

func (*PermissionRepository) Delete

func (r *PermissionRepository) Delete(ctx context.Context, id model.ID) error

Delete deletes an existing permission. If the permission does not exist, no errors are returned.

func (*PermissionRepository) Get

Get returns an existing permission, its subject and target. If the permission does not exist, an error is returned.

func (*PermissionRepository) GetBySubject

func (r *PermissionRepository) GetBySubject(ctx context.Context, id model.ID) ([]*model.Permission, error)

GetBySubject returns all permissions for a given subject. If no permissions exist, an empty slice is returned.

func (*PermissionRepository) GetBySubjectAndTarget

func (r *PermissionRepository) GetBySubjectAndTarget(ctx context.Context, source, target model.ID) ([]*model.Permission, error)

GetBySubjectAndTarget returns all permissions for a given target that the source has. If no permissions exist, an empty slice is returned.

func (*PermissionRepository) GetByTarget

func (r *PermissionRepository) GetByTarget(ctx context.Context, id model.ID) ([]*model.Permission, error)

GetByTarget returns all permissions for a given target. If no permissions exist, an empty slice is returned.

func (*PermissionRepository) HasAnyRelation

func (r *PermissionRepository) HasAnyRelation(ctx context.Context, source, target model.ID) (bool, error)

HasAnyRelation returns true if there is a relation between the source and target. If there is no relation, false is returned.

func (*PermissionRepository) HasPermission

func (r *PermissionRepository) HasPermission(ctx context.Context, subject, target model.ID, kinds ...model.PermissionKind) (bool, error)

HasPermission returns true if the subject has the given permission on the target. If the permission does not exist, false is returned. TODO: Refactor this code. This is a mess.

func (*PermissionRepository) HasSystemRole

func (r *PermissionRepository) HasSystemRole(ctx context.Context, source model.ID, roles ...model.SystemRole) (bool, error)

HasSystemRole returns true if there is a relation between the source and target that is a system role. If there is no relation, false is returned.

func (*PermissionRepository) Update

Update updates an existing permission's kind. If the permission does not exist, an error is returned. If the permission's kind is already the same as the one provided, the kind is overwritten and the updated_at timestamp is updated.

type ProjectRepository

type ProjectRepository struct {
	// contains filtered or unexported fields
}

ProjectRepository is a repository for managing projects.

func NewProjectRepository

func NewProjectRepository(opts ...RepositoryOption) (*ProjectRepository, error)

NewProjectRepository creates a new project baseRepository.

func (*ProjectRepository) Create

func (r *ProjectRepository) Create(ctx context.Context, namespaceID model.ID, project *model.Project) error

func (*ProjectRepository) Delete

func (r *ProjectRepository) Delete(ctx context.Context, id model.ID) error

func (*ProjectRepository) Get

func (*ProjectRepository) GetAll

func (r *ProjectRepository) GetAll(ctx context.Context, namespaceID model.ID, offset, limit int) ([]*model.Project, error)

func (*ProjectRepository) GetByKey

func (r *ProjectRepository) GetByKey(ctx context.Context, key string) (*model.Project, error)

func (*ProjectRepository) Update

func (r *ProjectRepository) Update(ctx context.Context, id model.ID, patch map[string]any) (*model.Project, error)

type PropertyGetter

type PropertyGetter interface {
	GetProperties() map[string]any
}

PropertyGetter is an interface for getting properties from a node or relationship.

type RepositoryOption

type RepositoryOption func(*baseRepository) error

RepositoryOption configures a baseRepository for a Neo4j baseRepository.

func WithDatabase

func WithDatabase(db *Database) RepositoryOption

WithDatabase sets the baseRepository for a baseRepository.

func WithRepositoryLogger

func WithRepositoryLogger(logger log.Logger) RepositoryOption

WithRepositoryLogger sets the logger for a baseRepository.

func WithRepositoryTracer

func WithRepositoryTracer(tracer tracing.Tracer) RepositoryOption

WithRepositoryTracer sets the tracer for a baseRepository.

type RoleRepository

type RoleRepository struct {
	// contains filtered or unexported fields
}

RoleRepository is a repository for managing roles.

func NewRoleRepository

func NewRoleRepository(opts ...RepositoryOption) (*RoleRepository, error)

NewRoleRepository creates a new role baseRepository.

func (*RoleRepository) AddMember

func (r *RoleRepository) AddMember(ctx context.Context, roleID, memberID, belongsToID model.ID) error

func (*RoleRepository) Create

func (r *RoleRepository) Create(ctx context.Context, createdBy, belongsTo model.ID, role *model.Role) error

func (*RoleRepository) Delete

func (r *RoleRepository) Delete(ctx context.Context, id, belongsTo model.ID) error

func (*RoleRepository) Get

func (r *RoleRepository) Get(ctx context.Context, id, belongsTo model.ID) (*model.Role, error)

func (*RoleRepository) GetAllBelongsTo

func (r *RoleRepository) GetAllBelongsTo(ctx context.Context, belongsTo model.ID, offset, limit int) ([]*model.Role, error)

func (*RoleRepository) RemoveMember

func (r *RoleRepository) RemoveMember(ctx context.Context, roleID, memberID, belongsToID model.ID) error

func (*RoleRepository) Update

func (r *RoleRepository) Update(ctx context.Context, id, belongsTo model.ID, patch map[string]any) (*model.Role, error)

type TodoRepository

type TodoRepository struct {
	// contains filtered or unexported fields
}

TodoRepository is a repository for managing todos.

func NewTodoRepository

func NewTodoRepository(opts ...RepositoryOption) (*TodoRepository, error)

NewTodoRepository creates a new todo baseRepository.

func (*TodoRepository) Create

func (r *TodoRepository) Create(ctx context.Context, todo *model.Todo) error

func (*TodoRepository) Delete

func (r *TodoRepository) Delete(ctx context.Context, id model.ID) error

func (*TodoRepository) Get

func (r *TodoRepository) Get(ctx context.Context, id model.ID) (*model.Todo, error)

func (*TodoRepository) GetByOwner

func (r *TodoRepository) GetByOwner(ctx context.Context, ownerID model.ID, offset, limit int, completed *bool) ([]*model.Todo, error)

func (*TodoRepository) Update

func (r *TodoRepository) Update(ctx context.Context, id model.ID, patch map[string]any) (*model.Todo, error)

type UserRepository

type UserRepository struct {
	// contains filtered or unexported fields
}

UserRepository is a repository for managing users.

func NewUserRepository

func NewUserRepository(opts ...RepositoryOption) (*UserRepository, error)

NewUserRepository creates a new user baseRepository.

func (*UserRepository) Create

func (r *UserRepository) Create(ctx context.Context, user *model.User) error

Create creates a new user if it does not already exist. Also, create all missing languages and user-language relationships.

func (*UserRepository) Delete

func (r *UserRepository) Delete(ctx context.Context, id model.ID) error

Delete deletes a user by its ID.

func (*UserRepository) Get

func (r *UserRepository) Get(ctx context.Context, id model.ID) (*model.User, error)

Get returns a user by its ID.

func (*UserRepository) GetAll

func (r *UserRepository) GetAll(ctx context.Context, offset, limit int) ([]*model.User, error)

GetAll returns all users respecting the given offset and limit.

func (*UserRepository) GetByEmail

func (r *UserRepository) GetByEmail(ctx context.Context, email string) (*model.User, error)

GetByEmail returns a user by its email.

func (*UserRepository) Update

func (r *UserRepository) Update(ctx context.Context, id model.ID, patch map[string]any) (*model.User, error)

Update updates a user by its ID with any given patch.

Jump to

Keyboard shortcuts

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