Forked from chrisdkemper/ecommerce-example-beginnning-neo4j.cql
Created
January 14, 2016 10:09
-
-
Save mbusch/442d6cf98e7d677f76b3 to your computer and use it in GitHub Desktop.
This is an example Ecommerce data structure from the book Beginning Neo4j (tested with Neo4j v2.2.8)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Add some contstraints for good measture, constraints must be ran individually | |
CREATE CONSTRAINT ON (c:Customer) ASSERT c.email IS UNIQUE; | |
CREATE CONSTRAINT ON (p:Product) ASSERT p.uuid IS UNIQUE; | |
//:Start Product and customer query: | |
//Products, bundles and categories | |
CREATE (product1:Product {name: "Product 1", uuid: "d8d177cc-1542-11e5-b60b-1697f925ec7b", price: 10}) | |
CREATE (product2:Product {name: "Product 2", uuid: "d8d17b28-1542-11e5-b60b-1697f925ec7b", price: 20}) | |
CREATE (product3:Product {name: "Product 3", uuid: "d8d17c72-1542-11e5-b60b-1697f925ec7b", price: 30}) | |
CREATE (product4:Product {name: "Product 4", uuid: "d8d1b958-1542-11e5-b60b-1697f925ec7b", price: 40}) | |
CREATE (product5:Product {name: "Product 5", uuid: "d8d1bade-1542-11e5-b60b-1697f925ec7b", price: 50}) | |
CREATE (category1:Category {name: "Category 1"}) | |
CREATE (category2:Category {name: "Category 2"}) | |
CREATE (category3:Category {name: "Category 3"}) | |
CREATE (bundle1:Bundle {name: "Bundle 1", price: 35}) | |
//Customer creation | |
CREATE (customer1:Customer {name: "Chris", email: "[email protected]"}) | |
CREATE (customer2:Customer {name: "Kane", email: "[email protected]"}) | |
//Products in categories | |
CREATE UNIQUE (product1)-[:BELONGS_TO]->(category1) | |
CREATE UNIQUE (product2)-[:BELONGS_TO]->(category1) | |
CREATE UNIQUE (product3)-[:BELONGS_TO]->(category2) | |
CREATE UNIQUE (product4)-[:BELONGS_TO]->(category3) | |
CREATE UNIQUE (product5)-[:BELONGS_TO]->(category2) | |
//Products in bundle | |
CREATE UNIQUE (product1)-[:PART_OF]->(bundle1) | |
CREATE UNIQUE (product3)-[:PART_OF]->(bundle1) | |
//Nested category | |
CREATE UNIQUE (category3)-[:CHILD_OF]->(category1) | |
//:End Product and customer query: | |
//:Start Order query: | |
//Match the customer ready for the order | |
MATCH (customer:Customer {email: "[email protected]"}),(product1:Product {uuid: "d8d177cc-1542-11e5-b60b-1697f925ec7b"}),(product2:Product {uuid: "d8d17b28-1542-11e5-b60b-1697f925ec7b"}) | |
//Create the order node | |
CREATE (order:Order {date: "2015-05-15"}) | |
//Add the products to the order | |
CREATE UNIQUE (product1)-[:IN_ORDER]->(order) | |
CREATE UNIQUE (product2)-[:IN_ORDER]->(order) | |
//Relate the customer to the order | |
CREATE UNIQUE (customer)-[:CREATED]->(order) | |
//:End Order query: | |
//:Start Sale query: | |
//Add the sale node | |
CREATE (sale1:Sale {name: "Sale 1", active: TRUE}) | |
//Products on sale | |
WITH sale1 | |
MATCH (product4:Product {uuid: "d8d1b958-1542-11e5-b60b-1697f925ec7b"}),(product5:Product {uuid: "d8d1bade-1542-11e5-b60b-1697f925ec7b"}) | |
CREATE UNIQUE (product4)-[:ON_SALE {price: 36}]->(sale1) | |
CREATE UNIQUE (product5)-[:ON_SALE {price: 45}]->(sale1) | |
//:End Sale query: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment