Skip to content

Instantly share code, notes, and snippets.

@ClydeDz
Created April 12, 2020 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClydeDz/76030075aebbd4673a45bdac13de7979 to your computer and use it in GitHub Desktop.
Save ClydeDz/76030075aebbd4673a45bdac13de7979 to your computer and use it in GitHub Desktop.
JS to FaunaDB - Stack Overflow
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