feat: allow to fetch collections

This commit is contained in:
Alexander Navarro 2024-11-21 20:27:57 -03:00
parent 01086d12c9
commit 8c660053e5
7 changed files with 147 additions and 83 deletions

View file

@ -1,29 +1,6 @@
package synchronizator
// A user representation of a node, this interface should be implemented by the user
// to provide the ability to parse the database node into a user defined
// struct that fulfills it's requirements.
//
// This interface is compatible with the [NodeClass] interface but it doesn't
// handle the class parameter as it's a static value provided by the
// StandardNode
type StandardNode interface {
// How to transform the struct into a node. It needs to return the class,
// name and a []byte representation of the metadata.
//
// - name: A user friendly name
// - metadata: Arbitrary data. This will be stored as a jsonb in the database
//
ToNode() (string, []byte, error)
// How to transform a node into the struct. This method should modify the
// struct directly as it receives a pointer.
//
// - class: The class of the node, should not be modified to avoid inconsistencies.
// - name: A user friendly name
// - metadata: Arbitrary data. This is stored as a jsonb in the database
FromNode(string, string, []byte) error
}
type StandardNode interface{}
// A node in the database.
// It adds some helper methods to easily manage the node.
@ -112,19 +89,6 @@ func (node *Node) Delete() error {
return node._conn.DeleteNode(node.Id)
}
// Allows to retreive the saved information back into the user struct. This
// method will call the [NodeClass.FromNode] of the provided struct.
//
// Example:
//
// data := &Library{}
// if err := node.Unmarshall(data); err != nil {
// println(err)
// }
func (node *Node) Unmarshall(dst StandardNode) error {
return dst.FromNode(node._class, node.name, node.metadata)
}
// Returns the class of the node
func (relationship *Relationship) GetClass() string {
return relationship._class