Strengthening on the Cypher Principles books, this article covers the brand new temporal time versions produced inside Neo4j 3.4. Abreast of completing this article, you need to be able to manage, examine, and you can style these philosophy.
Just be regularly graph databases concepts and the possessions chart design. This guide try a continuation of the maxims discussed about early in the day Cypher areas. Just be regularly Suits, Create/Update/Erase, and you will Filtering rules in advance of taking walks from this guide.
Performing and you may updating opinions
Why don’t we start with doing certain nodes that have a great Datetime property. We could do this of the doing the second Cypher ask:
UNWIND [ < title:>, < title:>, < title:> ] AS articleProperties CREATE (article:Article ) SET article.created = articleProperties.created, article.datePublished = articleProperties.datePublished, article.readingTime = duration(articleProperties.readingTime)
- the latest authored property is good DateTime form of comparable to new datetime at that time the brand new inquire is actually executed.
- this new go out home is a night out together kind of comparable to the fresh new date at the time the latest ask try executed.
- the latest readingTime is a period form of three full minutes half a minute.
There is chose to upload the content a few weeks in place of now, therefore we should make one change. When we need to manage a new Go out sorts of using a great offered format, we can exercise making use of the adopting the query:
Match (article:Blog post ) Place article.datePublished = date("2019-09-30")
Exactly what whenever we have to carry out a night out together sort of established on the an enthusiastic unsupported style? To do so we’re going to explore a purpose in the APOC collection so you can parse the sequence.
The next inquire parses an unsupported file format to your good millisecond situated timestamp, brings a Datetime away from you to timestamp, and creates a night out together from one Datetime :
Having apoc.day.parse("Sunlight, ", "ms", "EEE, dd MMMM yyyy") As the ms Meets (article:Post ) Put post.datePublished = date(datetime())
We can make use of this same method of upgrade the fresh new written possessions. The thing we have to alter is the fact we don’t need to convert the new Datetime particular in order to a romantic date :
Having apoc.time.parse(" ", "ms", "dd MMMM yyyy HH:mm:ss") Because ms Meets (article:Post ) Put blog post.created = datetime()
Possibly we including decide that the reading go out is simply supposed becoming another over what we originally believe. We can change brand new readingTime assets into following inquire:
Match (article:Post ) Lay post.readingTime = blog besök webbplatsen här post.readingTime + duration()
Formatting viewpoints
Today we want to create a query to go back all of our post. We could do this from the performing another inquire:
Fits (article:Article) Get back article.term Given that label, article.created Once the created, post.datePublished As the datePublished, blog post.readingTime Because the readingTime
Whenever we should structure this type of values we could use temporal features on the APOC collection. The next query formats each of the temporal products to the far more friendly platforms:
Suits (article:Article) Come back blog post.label While the term, apoc.temporary.format(article.authored, "dd MMMM yyyy HH:mm") Just like the composed, apoc.temporal.format(article.datePublished,"dd MMMM yyyy") As datePublished, apoc.temporal.format(blog post.readingTime, "mm:ss") Due to the fact readingTime
Contrasting and you may selection opinions
Matches (article:Article) In which blog post.datePublished = date() Get back blog post.name As the identity, blog post.written Once the written, blog post.datePublished Once the datePublished, blog post.readingTime Given that readingTime
How about if we want to come across all articles authored within the ? We possibly may make another ask to take action:
Meets (article:Article) Where article.datePublished = date() Return article.identity As the name, article.created Because the created, post.datePublished Just like the datePublished, blog post.readingTime Due to the fact readingTime
This does not see proper – what about the brand new Cypher Principles II blog post which was composed for the 2nd ? The challenge we have let me reveal one to time() returns 2019-06-01 , so we are only in search of posts authored on the initially .
Matches (article:Article) In which time() > article.datePublished >= date() Get back article.label Since label, blog post.created Given that authored, post.datePublished Given that datePublished, article.readingTime Because readingTime