Building for the Cypher Rules courses, this article talks about the brand new temporal date products delivered for the Neo4j step 3.cuatro. On finishing this informative guide, you should be capable create, evaluate, and you may style this type of viewpoints.
You need to be regularly graph database rules while the possessions chart model. This informative guide try a continuation of one’s principles discussed regarding the prior Cypher parts. Just be used to Match, Create/Update/Delete, and you may Selection rules just before strolling by this publication.
Performing and you may updating values
Why don’t we begin by doing certain nodes having an effective Datetime possessions. We could do this of the carrying out the next Cypher inquire:
UNWIND [ < title:>, < title:>, < title:> ] AS articleProperties CREATE (article:Article ) SET article.created = articleProperties.created, article.datePublished = articleProperties.datePublished, article.readingTime = duration(articleProperties.readingTime)
- the brand new authored home is a beneficial DateTime particular comparable to the fresh new datetime during the time this new inquire is actually performed.
- brand new time property is a night out together style of comparable to new date during the time the newest query is actually performed.
- the fresh new readingTime was a span variety of three full minutes 30 seconds.
We chose to publish the content a few weeks in lieu of now, so we should make you to transform. Whenever we must carry out a unique Date kind of playing with an excellent served format, we can do so by using the adopting the query:
Fits (article:Article ) Put blog post.datePublished = date("2019-09-30")
But what whenever we need certainly to do a night out together method of based into the a keen unsupported structure? To do so we’ll explore a function regarding the APOC collection so you can parse this new sequence.
Another query parses a keen unsupported file format with the a great millisecond depending timestamp, produces a Datetime away from you to timestamp, following brings a date from that Datetime :
That have apoc.go out.parse("Sunrays, ", "ms", "EEE, dd MMMM yyyy") Because the ms Matches (article:Post ) Place blog post.datePublished = date(datetime())
We are able to use this exact same method of posting the new written property. The thing we must changes would be the fact do not need to move the Datetime type of to a night out together :
That have apoc.date.parse(" ", "ms", "dd MMMM yyyy HH:mm:ss") As the ms Match (article:Post ) Place post.written = datetime()
Possibly i plus select the studying day is simply heading getting a second more everything we originally imagine. We can modify the brand new readingTime property towards the adopting the ask:
Meets (article:Blog post ) Put article.readingTime = article.readingTime + duration()
Formatting philosophy
Today we would like to establish a query to return all of our post. We could do this from the doing another query:
Matches (article:Article) Go back post.identity Because the identity, article.authored While the written, post.datePublished While the datePublished, post.readingTime Because readingTime
Whenever we want kissbrides.com här borta to style this type of opinions we are able to use temporary qualities on the APOC collection. Another query formats each of the temporary products on even more amicable platforms:
Suits (article:Article) Get back article.term Once the term, apoc.temporary.format(article.created, "dd MMMM yyyy HH:mm") As created, apoc.temporary.format(post.datePublished,"dd MMMM yyyy") As datePublished, apoc.temporal.format(article.readingTime, "mm:ss") As readingTime
Contrasting and you can selection viewpoints
Suits (article:Article) In which blog post.datePublished = date() Come back blog post.label Due to the fact label, article.created Just like the authored, post.datePublished As the datePublished, blog post.readingTime Since the readingTime
How about when we have to discover the content composed for the ? We possibly may develop another query to do so:
Meets (article:Article) Where post.datePublished = date() Go back article.title Just like the title, blog post.written Given that written, post.datePublished Just like the datePublished, article.readingTime Due to the fact readingTime
This won’t appear proper – how about the brand new Cypher Principles II post which had been penned towards second ? The situation i have is you to definitely big date() yields 2019-06-01 , therefore our company is merely interested in content had written for the initially .
Suits (article:Article) In which time() > article.datePublished >= date() Return article.label As the title, article.created Given that created, post.datePublished As datePublished, post.readingTime Due to the fact readingTime
Enter the text or HTML code here