Created
April 12, 2020 07:44
-
-
Save ClydeDz/76030075aebbd4673a45bdac13de7979 to your computer and use it in GitHub Desktop.
JS to FaunaDB - Stack Overflow
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
import { client, q } from '../config/db'; | |
var getAllChoices = client.query( | |
q.Paginate( | |
q.Match( | |
q.Ref('indexes/choices_index'))) | |
) | |
.then(response => { | |
const notesRefs = response.data | |
const getAllProductDataQuery = notesRefs.map((ref) => { | |
return q.Get(ref) | |
}) | |
return client.query(getAllProductDataQuery).then((data) => data) | |
}) | |
.catch(error => console.warn('error', error.message)) | |
var seedData = (create) => { | |
if(!create){ | |
return null; | |
} | |
return client.query( | |
q.Create( | |
q.Collection('choices'), | |
{ | |
data: { | |
mocha: 0, | |
longBlack: 0 | |
}, | |
}, | |
) | |
) | |
.then(ret => ret) | |
.catch(err => console.warn(err)) | |
} | |
var updateChoices = (id, newData) => { | |
return client.query( | |
q.Update( | |
q.Ref(q.Collection('choices'), id), | |
{ data: newData }, | |
) | |
) | |
.then((ret) => console.log(ret)) | |
.catch(err => console.warn(err)) | |
} | |
export { getAllChoices, seedData, updateChoices } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment