Created
July 9, 2017 11:14
-
-
Save andrewhl/42483fdb4b877e9334caff30b67f48b3 to your computer and use it in GitHub Desktop.
This file contains 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
// Iterate through request files array and write each file to Neo4j | |
images.forEach(image => { | |
session.writeTransaction(tx => { | |
tx.run(`MATCH (n:Article {uuid: $uuid})-[:HAS]->(f:File) | |
MERGE (n)-[:HAS]->(i:File { | |
name: $name, | |
caption: $caption | |
}) WITH i,n SET i.uuid = $fileUuid, | |
i.url = $url, | |
i.updated_at = $updatedAt, | |
i.created_at = $createdAt RETURN n`, | |
{ | |
uuid: req.params.uuid, | |
fileUuid: uuidV4(), | |
url: image.url, | |
name: image.name, | |
caption: image.caption, | |
createdAt: moment().format('YYYY-MM-DD'), | |
updatedAt: moment().format('YYYY-MM-DD'), | |
}) | |
}).then(result => { | |
console.log('File saved.') | |
}).catch(error => { | |
console.log(error); | |
driver.close(); | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment