Building into Cypher Rules guides, this article talks about the newest temporal day models put in the Neo4j step three.4. On doing this article, you should be capable perform, contrast, and you will structure these thinking.
You should be familiar with graph database basics and the property graph design. This informative guide is actually an extension of your rules chatted about on earlier in the day Cypher areas. Just be regularly Matches, Create/Update/Remove, and you can Filtering concepts just before walking through this guide.
Undertaking and updating beliefs
Why don’t we start with undertaking some nodes that have an effective Datetime possessions. We are able to accomplish that from the performing the following Cypher ask:
UNWIND [ , , ] AS articleProperties CREATE (article:Article ) SET article.created = articleProperties.created, article.datePublished = articleProperties.datePublished, article.readingTime = duration(articleProperties.readingTime)
- new composed property is good DateTime sorts of equivalent to the newest datetime at the time this new ask try executed.
- this new date property is a night out together sort of equal to this new big date at that time the brand new inquire try executed.
- this new readingTime are a span types of three full minutes 30 seconds.
We have decided to upload this article in the future in the place of now, therefore we should make that transform. If we want to do yet another Go out sorts of playing with a beneficial offered format, we are able to get it done utilizing the following query:
Suits (article:Blog post ) Set post.datePublished = date("2019-09-30")
But what when we must do a date variety of established on the a keen unsupported structure? To do so we are going to use a function throughout the APOC collection so you can parse the fresh sequence.
The next ask parses a keen unsupported data format with the a good millisecond situated timestamp, brings good Datetime from one timestamp, and produces a romantic date of that Datetime :
Having apoc.go out.parse("Sunshine, ", "ms", "EEE, dd MMMM yyyy") Just like the ms Fits (article:Post ) Put blog post.datePublished = date(datetime())
We can make use of this exact same way of inform new composed possessions. The one thing we should instead changes is the fact we don’t have to transfer brand new Datetime types of so you’re able to a romantic date :
That have apoc.time.parse(" ", "ms", "dd MMMM yyyy HH:mm:ss") As the ms Suits (article:Blog post ) Put post.authored = datetime()
Possibly we together with decide that the discovering day is actually going getting another more than what we should to begin with envision. We can improve the new readingTime assets toward adopting the inquire:
Suits (article:Post ) Put article.readingTime = article.readingTime + duration()
Format values
Today we wish to make an inquiry to return our article. We could do that of the doing next query:
Meets (article:Article) Come back article.term Given that label, blog post.authored Due to the fact composed, post.datePublished Because datePublished, blog post.readingTime Because the readingTime
If we have to structure these types of values we can play with temporal characteristics about APOC collection. The next inquire formats each one of the temporary types into far more amicable platforms:
Meets (article:Article) Get back post.label Once the name, apoc.temporal.format(article.created, "dd MMMM yyyy HH:mm") Because the composed, apoc.temporary.format(blog post.datePublished,"dd MMMM yyyy") Since datePublished, apoc.temporary.format(blog post.readingTime, "mm:ss") While the readingTime
Evaluating and you will selection philosophy
Fits (article:Article) Where article.datePublished = date() Come back blog post.identity Since the title, article.created Since the composed, blog post.datePublished As the datePublished, post.readingTime Since the readingTime
What about if we need to get a hold of every articles blogged in the ? We might develop next query to do so:
Fits (article:Article) Where blog post.datePublished = date() Come back blog post.title Because label, blog post.written Because written, article.datePublished Once the datePublished, blog post.readingTime While the readingTime
This doesn’t search correct – what about the fresh new Cypher Principles II blog post that was blogged with the next ? The trouble we have the following is you to definitely date() output 2019-06-01 , thus we’re just selecting posts blogged for the initially .
Matches (article:Article) Where day() > blog post.datePublished >= date() Come back article.term As the identity, post.created Because composed, article.datePublished Once the datePublished, article.readingTime Since the readingTime