<?php /** * divNoSQL * * This is a basic example of divNoSQL that demonstrates their main functionalities. * * @author Rafa Rodriguez <*****@*****.**> * */ include "../divNoSQL.php"; // Adding a schema on the fly if not exists $db = new divNoSQL("database/contacts"); // Deleting all nodes in schema database/contacts $db->delNodes(); // Add node into schema database/contacts $id = $db->addNode(array("name" => "Peter", "age" => 25)); // Change data of node $db->setNode($id, array("email" => "*****@*****.**", "phone" => "+1222553335")); // Retrieve a node from schema database/contacts $contact = $db->getNode($id); echo "Name: " . $contact['name'] . " <br/>\n"; echo "Phone: " . $contact['phone'] . " <br/>\n"; echo "Email: " . $contact['email'] . " <br/>\n"; // Remove node $db->delNode($id);
/** * divNoSQL * * References example * * @author Rafa Rodriguez <*****@*****.**> * */ include "../../divNoSQL.php"; // Adding a schema on the fly if not exists $db = new divNoSQL("database/companies"); // Deleting all nodes in schema database/companies $db->delNodes(); // Add node into schema database/companies $id = $db->addNode(array("name" => "Company A", "phone" => "1-(111) 223-333")); // Change data of node $db->setNode($id, array("email" => "*****@*****.**", "phone" => "+1233455566")); // Retrieve a node from schema database/companies $company = $db->getNode($id); echo $company['name'] . " - "; // Adding a schema on the fly if not exists $db->addSchema("database/employees"); // Clear the new schema $db->delNodes(array(), "database/employees"); // Add reference on the fly $db->addReference(array("schema" => "database/employees", "foreign_schema" => "database/companies", "property" => "company")); // Add node related $ide = $db->addNode(array("name" => "Rafa Rodriguez", "company" => $id), null, "database/employees"); // Add another node related $ide = $db->addNode(array("name" => "Peter Joseph", "company" => $id), null, "database/employees");
* @author Rafa Rodriguez <*****@*****.**> * */ include "../divNoSQL.php"; // Your entity class Person { public $first_name; public $last_name; public function getFullName() { return $this->first_name . " " . $this->last_name; } } // Clear schema $db = new divNoSQL('database'); $db->delNodes(); $person = new Person(); $person->first_name = "John"; $person->last_name = "Nash"; // Save entity $db->addNode($person); $person = new Person(); $person->first_name = "Albert"; $person->last_name = "Einstein"; // Save entity $db->addNode($person); $entities = $db->getNodes(array('order' => 'first_name')); foreach ($entities as $e) { echo $e->getFullName() . "<br/>\n"; }