Database Reference
In-Depth Information
Examples
The types of tools you use for your imports or synchronizations should be based on your goals. The following
scenarios commonly occur in development:
A new application without legacy data
An existing application that is switching to a graph database
An existing application that will use a graph and another data store
to get the working examples for this chapter, go to www.graphstory.com/practicalneo4j and
download Chapter 5.
Note
Test Data with Cypher
If you are building out a new application that has no any legacy data, your best bet is to use Cypher in one form or another
to import data. For example, creating a spreadsheet with sample data and saving it as a CSV file can be done fairly easily
and quickly. Next, you could use the newly available LOAD CSV to take a few generated files and run a quick import.
However, there is an alternative that might be acceptable during the development and testing stages, depending
on your application's or organization's demands. By using a few Cypher statements, you can build out a small,
representative graph for your application and do so within just a few minutes.
In this example, we will create a very small graph that represents users in a social network. We will use the Twitter
method of user relationships, which is a bidirectional relationship called FOLLOWS . We will start by first creating a list of
users by using a Cypher statement. Again, we are just aiming for some test data to use in our fledgling application, so
the variation on the size of the user set will be limited but still representative of what the application requires and will
take only a few minutes to run. Listing 5-1 shows the Cypher command that will create the users.
Listing 5-1. Cypher Command to Create the Users
WITH
["Brian","Jeremy","Brad","Daniel","Kenny","Michael","Greg","Leonard"] AS fname,
["Seesharp","Phpish","Pychamp","Rubyster","Relman","Writesalot","Goodguy","Graphman"] AS lname
FOREACH (r IN range(0,7) |
CREATE (:User {id:r, username : lower(fname[r % size(fname)]+""+r), firstname : fname[r %
size(fname)], lastname : lname[r % size(lname)] }
));
adding a large number of nodes or relationships to your local graph or remote graph will take some time. In
addition, you should have—at a minimum—4 gB to spare for the neo4j server for the best performance.
Note
Listing 5-1 creates eight users in the graph with a distinct ID and username but keeps the first name and last
name as set in the Array. By running MATCH (n:`User`) RETURN n LIMIT 25 , you can verify the users were added.
Next, we will associate the users to each other by adding the FOLLOWS relationship, as shown in Listing 5-2.
 
 
Search WWH ::




Custom Search