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

50 lines
1.9 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 RelationshipClass interface {
// How to transform the struct into a collection. It needs to return the class,
// and a []byte representation of the metadata.
//
// - class: Is used for classification and query pourposes. It's recomended to provide a constante string to increase consistency.
// - metadata: Arbitrary data. This will be stored as a jsonb in the database
//
ToRelationship() (string, []byte, error)
// How to transform a relationship into the struct. This method should modify the
// struct directly as it receives a pointer.
//
// - class: Is used for classification and query pourposes.
// - metadata: Arbitrary data. This is stored as a jsonb in the database
FromRelationship(string, []byte) error
}
// 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 (relationship *Relationship) GetClass() string {
return relationship._class
}