Skip to content

Instantly share code, notes, and snippets.

@trezy
Created March 6, 2022 07:10
Show Gist options
  • Save trezy/19d49f0631bde46d190655daece03242 to your computer and use it in GitHub Desktop.
Save trezy/19d49f0631bde46d190655daece03242 to your computer and use it in GitHub Desktop.
// Local imports
import {
client,
q,
} from './fauna.js'
export function getFortuneByIndex(index) {
const functionRef = q.Function('getFortuneByIndex')
return client.query(q.Call(functionRef, index))
}
export function getFortuneCount() {
const functionRef = q.Function('getFortuneCount')
return client.query(q.Call(functionRef))
}
export async function getRandomFortune() {
const fortuneCount = await getFortuneCount()
const index = Math.floor(Math.random() * fortuneCount)
const fortune = await getFortuneByIndex(index)
return fortune
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment