Introduction

Creating an application often leads to the following data workflow:

Serialized data → memory data → view data → memory data →serialized data

The application deserializes data then optionally process it into memory then display it in a view.

A user can modify a data through a view, which is optionally processed in memory and then stored into a file or a database.

Because the serialized object, the memory objects, and view objects are different entities, the code will have some code like this:

myMemoryObject.memoryPropertyName = mySerializedObject.serializedPropertyName;

myViewObject.viewPropertyName = myMemoryObject.memoryPropertyName;

Which means that the synchronization between the different entities are based on a static key value system.

Unfortunately, during the development the system will change a lot for different reasons among:

  • The serialization system is changing
  • The view components are changed or upgraded
  • The structure of the objects has changed, to handle new features, or improvements

When a change occurs, the developer must update the bindings in the code using some find and replace operations and recompile the application.

There are many developer’s tools that efficiently handle these tasks, but the base Graph seems to offer great possibilities to deal with binding.

The current experimentation is trying to leverage on Graph database to have a dynamic binding system.

The system will also put the primitive values at the center of relationships showing how to automatically build subset of interesting queries.

The document will explore the creation of a simple Angular web app, displaying data from a Neo4j Graph database.

The final code can be found at : https://github.com/mathiastiberghien/graph_based_coding.git

To make it work, without any changes, you’ll need to install Neo4j Desktop create a database with ‘admin’ as password. The database mus have the setting ‘cypher.lenient_create_relationship’ at true in the neo4j.conf file of the database.

This document is targeting Graph database users or application developers. The sample provided in the documents are very simple and are more focused on the concept that the technology. We will describe the relevant piece of code so that developers can follow the development logic, step by step but this document is not really a tutorial.

Note: I’m very new to Graph database, and I tried through these experiments to understand the reasons of starting to use Graph database in production applications.

Database dynamic model

Before to begin, we need to define the way we will store data into the database. We decided to consider an abstract model representing data from a developer perspective.

Here’s the schema of our graph database:

Image for post

Dynamic model schema

It contains 5 labels:

  • Model (properties: name)
  • Key (properties: name, isArray)
  • Instance (properties: id)
  • KeyValuePair
  • Type (properties: name)

And 8 relationships:

  • EXTENDS
  • HAS_TYPE
  • HAS_KEY
  • HAS_MODELTYPE
  • IS_EQUIVALENT
  • HAS_VALUE
  • IS_INSTANCE_OF
  • HAS_KEYVALUE_PAIR

This describe the following:

  • A Model defines keys
  • Instances are related to a Model
  • Instances define a collection of KeyValuePair
  • KeyValuePair is mapping a specific Key to a specific Instance
  • A Key has a Type, and can be related to a Model (if the type is an object)
  • A Model can extend other models
  • A Model can be equivalent to another Model
  • A Key of a model can be equivalent to the key of another Model
  • Retrieving Instances of a model should give all the instances of the model but also the instances of the extending models and the instances of the equivalent models
  • The Instances of a model should expose the keys of the model but also the key of extended models. It should use keys equivalency relationship to provide the appropriate key identifier

#cypher #development #neo4j #dynamic-programming #graph-database #database

Exploring Graph Database Based Apps Using a Dynamic Model
1.45 GEEK