Database Reference
In-Depth Information
" MERGE (c)-[:HAS]->(t) " +
" )" +
" RETURN c.contentId as contentId, c.title as title, c.tagstr as tagstr, " +
" c.timestamp as timestamp, c.url as url, {u} as username, true as owner "
results=neo.execute_query(cypher, { :u => username,
:title => contentItem["title"].strip,
:url => contentItem["url"].strip,
:tagstr => tagstr,
:contentId => contentItem["contentId"],
:tags => tags } )
r=results["data"].map {|row| Hash[*results["columns"].zip(row).flatten] }
r.each do |e|
#convert the timestamp to readable date and time
e.merge!("timestampAsStr" => Time.at(e["timestamp"]).strftime("%m/%d/%Y") +
" at " +
Time.at(e["timestamp"]).strftime("%l:%M %p"))
end
r
end
In the case of the edit feature, you do not need to update relationships. Instead, simply retrieve the existing node
by its generated String Id (not its graph id), update its properties where necessary, and save it back to the graph.
Deleting a Status Update
As with the “edit” option, when status updates are displayed, the current user's status updates will contain a link to
“Delete” the status. Once clicked, it will ask if you want it deleted (no regrets!) and, if accepted, generate an AJAX GET
request to call the delete route and corresponding method in the Content class, shown in Listing 10-34.
Listing 10-34. Deleting a Status Update
# delete post
get '/posts/delete/:contentId' do
delete_content(neo,request.cookies[graphstoryUserAuthKey],params[:contentId])
end
# delete a status update
def delete_content(neo,username,contentId)
cypher = " MATCH (u:User { username: {u} }), (c:Content { contentId: {contentId} }) " +
" WITH u,c " +
" MATCH (u)-[:CURRENTPOST]->(c)-[:NEXTPOST]->(nextPost) " +
" WHERE nextPost is not null " +
" CREATE UNIQUE (u)-[:CURRENTPOST]->(nextPost) " +
" WITH count(nextPost) as cnt " +
" MATCH (before)-[:NEXTPOST]->(c:Content { contentId: {contentId}})-[:NEXTPOST]->(after) " +
" WHERE before is not null AND after is not null " +
" CREATE UNIQUE (before)-[:NEXTPOST]->(after) " +
" WITH count(before) as cnt " +
" MATCH (c:Content { contentId: {contentId} })-[r]-() " +
" DELETE c, r"
results=neo.execute_query(cypher, {:u => username, :contentId => contentId})
end
 
Search WWH ::




Custom Search