Skip to content

Instantly share code, notes, and snippets.

View ptpaterson's full-sized avatar
🤓

Paul Paterson ptpaterson

🤓
View GitHub Profile
@ptpaterson
ptpaterson / functionToLet.js
Last active May 1, 2020 21:15
Convert a function to a FaunaDB Let expression
const { query: q } = require('faunadb')
// fn-annotate
// https://www.npmjs.com/package/fn-annotate
const annotate = require('fn-annotate')
// converts a function into a faunaDB Let expression, but allows it to be used,
// as a regular function. This allows functions to be composed in JS land and
// turn out correctly in Fauna land.
const functionToLet = (fn) => (...args) => {
@ptpaterson
ptpaterson / nested-fql-manual.js
Last active December 26, 2021 15:09
Template for building deeply nested FQL queries for FaunaDB
const baseQuery = q.Paginate(q.Match(q.Index(indexName), terms));
// or
// const baseQuery = q.Paginate(q.Collection(collectionName))
const expandedQuery = q.Map(baseQuery, (ref) =>
q.Let(
{
instance: q.Get(q.Var('ref'))
},
{