Created
March 6, 2022 07:10
-
-
Save trezy/19d49f0631bde46d190655daece03242 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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