-
Notifications
You must be signed in to change notification settings - Fork 0
Nodes
A node is one of two entities available in Arachnid. A node class represents a node (vertex) in Neo4j. To define a node, simply create a class with the correct annotations, as shown in Entities.
Every entity in Arachnid needs a primary ID. A class property can be flagged as the ID with the Auto
annotation. For example:
/**
* @LRezek\Arachnid\Annotation\Node
*/
class User
{
/**
* @LRezek\Arachnid\Annotation\Auto
*/
protected $id;
}
As mentioned before, you can simply import the annotation namespace to make these annotations shorter. For example:
use LRezek\Arachnid\Annotation as Arachnid;
/**
* @Arachnid\Node
*/
class User
{
/**
* @Arachnid\Auto
*/
protected $id;
}
This ID is what is used by arachnid to keep track of the entity, and as such, requires a getter and setter:
use LRezek\Arachnid\Annotation as Arachnid;
/**
* @Arachnid\Node
*/
class User
{
/**
* @Arachnid\Auto
*/
protected $id;
function getId()
{
return $this->id;
}
function setId($id)
{
$this->id = $id;
}
}
This is all that is required for a basic node implementation.
Obviously, a node as shown above isn't very useful. Let's add some properties:
use LRezek\Arachnid\Annotation as Arachnid;
/** @Arachnid\Node */
class User
{
/** @Arachnid\Auto */
protected $id;
/**
* @Arachnid\Property
* @Arachnid\Index
*/
protected $username;
/**
* @Arachnid\Property
*/
protected $password;
function getId()
{
return $this->id;
}
function setId($id)
{
$this->id = $id;
}
function getUsername()
{
return $this->username;
}
function setUsername($username)
{
$this->username = $username;
}
function getPassword()
{
return $this->password;
}
function setPassword($password)
{
$this->password = $password;
}
}
As you probably guessed, this class will correspond to a Neo4J node with username
and password
properties. This means that setting these properties and saving the node will update it in the database (shown later), and when the node is queried for, those properties will be populated with the database values.
Furthermore, the @Arachnid\Index
annotation specifies a property to index in Neo4J. If a property is indexed, you can do queries for nodes based on that property, as shown in the repository page of this wiki.