generated from alecodes/base-template
also refactor public and internal api to support transaction between multiple methods #2
46 lines
1.8 KiB
Go
46 lines
1.8 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 {
|
|
// 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
|
|
}
|