Skip to content

User guide

Rahil khan edited this page Mar 26, 2023 · 2 revisions

📗Clorograph user guide

This guide will teach you to use this database in the easiest way possible. After reading this guide, you would never be required to see its Javadoc.

🔰Initiaialization

Initialization of this is as simple as creating a File object.

CloroGraph dB = new CloroGraph(directory);

directory is the location where you want to create the database. On android, use context.getDataDir() or context.getFileDir()

Now through this dB object, we can:-

  • Create or open graphs or trees
  • Save or delete graphs or trees

Basically, this class is responsible for the transaction to the database while the other classes of the database are just data structures which hold data.

📈Graphs & trees

To store the data, first, we need to know how to construct the data. I first recommend reading this article about these data structures.

Which one to use & when?

The SimpleGraph databases uses 2D array matrix, while the RelationalGraph uses LinkedList with HashMap (for faster performance). So you can read this article to decide which suits best in what condition.

Trees are special types of graph which holds data in a hierarchy. It is best to represent a family. Trees don't have edges, the nodes which are of the same parent are considered to be related (mostly as siblings).

There is only one type of tree in this database. That is the N-Array tree. This tree can have n-number of children in its node.

⚒️Working with database

Because this is a graph database, it can only store data in the form of a Graph or Tree. Hope you have already learnt to create the tree and graph, if not yet go and learn them first.

Here are some of the ways you can create/open data structures.

To save a graph in the database

db.saveGraph(graph);

To save a tree in the database

db.saveTree("demoTree",tree);

To open a tree from the database

Tree<Person> tree = (Tree<Person>) db.openTree("demoTree");

To open a graph from the database

Graph<Person> graph = db.openGraph("demoGraph");

NOTE

  • It could be either a SimpleGraph or RelationalGraph.

📝Writing/Updating data in the database

To write data to a database, first, structure it in a Tree or a Graph.

Graph

RelationalGraph<Person> graph = new RelationalGraph<>();
...
...
...
db.saveGraph(graph);  // or graph.commit(db)

or with Tree

Tree<Person> tree = new Tree<>(root);
...
...
...
db.saveTree("familyTree",tree);

The better approach

var initialGraph = new RelationalGraph<Person>();
...  // setting up graph for the first time
RelationalGraph<Person> graph = db.createOrOpenGraph("familyTree",initialGraph);
... // update the graph
... // remove or insert some data
db.saveGraph(graph); // then again save it

In this example, the database will create the graph (initialGraph) if it is not already there.

The same is for Tree also.

✅That's all

That's all that you need to know about this database. If you have any doubts, please see the issues.

Thank you, have a nice day :-)