This repository has been archived on 2025-05-15. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
synchronizator-go/pkg/relationship.go

53 lines
1.5 KiB
Go

package synchronizator
// A user representation of a relationship, this interface should be implemented by the user
// to provide the ability to parse the database relationship into a user defined
// struct that fulfills it's requirements.
//
// Example usage:
//
// type collection_relation struct{}
//
// func (collection *collection_relation) ToRelationship() (string, []byte, error) {
// return "COLLECTION_HAS", nil, nil
// }
//
// func (collection *collection_relation) FromRelationship(_class string, metadata []byte) error {
// if _class != "COLLECTION_HAS" {
// return fmt.Errorf("invalid class %s", _class)
// }
// return nil
// }
type StandardRelationship interface {
GetClass() string
GetNodes() (int64, int64)
GetMetadata() []byte
SetConnection(*DB)
}
// A relationship in the database.
// It adds some helper methods to easily manage the node.
type Relationship struct {
_conn *DB // Underlaying connection to the database.
_class string // The class of the node, should not be modified to avoid inconsistencies.
From int64 // From what node this relation comes from
To int64 // To what node this relation goes to
metadata []byte // Arbitrary data. This is stored as a jsonb in the database
}
func (relation *Relationship) GetClass() string {
return relation._class
}
func (relation *Relationship) GetMetadata() []byte {
return relation.metadata
}
func (relation *Relationship) GetNodes() (int64, int64) {
return relation.From, relation.To
}
func (relation *Relationship) SetConnection(db *DB) {
relation._conn = db
}