Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Neo4j Support the concept of views

I'm starting with Neo4J trying to migrate my current system from a Relational DB to Neo4j and have a peculiar problem to overcome.

I have a table called Orders and has 2 particular columns that are being a pain. ShipBy is a value for (Train/Air/Truck) Carrier is the Id of the company carrying the order but this changes, if it ships by Air, it has something like UPS/ALASKA/CONTINENTAL; if it ships by Train, it has something like BNSF/KANSASCITYRAIL/ETC...

these values come from different catalog tables, so this was resolved in my system with something like this Select Orders.Number, Carrier.Name from Orders, (Select 'T' Type,Id,Name from Truckers union all Select 'R' Type, Id, Name from RailCompanies union all Select 'A' Type, Id, Name from AirLines) Carriers Where Orders.ShipBy = Carriers.Type and Orders.CarrierId=Carrier.Id

I'd appreciate any pointer on this.

like image 590
Fernando Avatar asked Dec 10 '25 05:12

Fernando


1 Answers

Neo4J doesn't have views in the way that relational DBs have. There are several things you could do as alternates:

  1. Continually re-issue the query that computes the "view" you need, as needed
  2. Create a special "view node", and then link that node via relationships to all of the other nodes that would naturally occur in your "view". Querying your view then becomes as simple as pulling up that one "view node" and traversing your edges to the view results.

Option #1 is easiest, option #2 is probably faster, but comes with it the maintenance burden that as your underlying nodes in the DB change, you need to maintain your view and make sure it points to the right places.

like image 59
FrobberOfBits Avatar answered Dec 13 '25 06:12

FrobberOfBits