Skip to main content

Code Snippets

Here you can find the code snippets for the common scenarios and use cases while working with Rowy.

Accessing data from another collection

The following is a code snippet that shows how to access data from another collection and display it as a list of options using the connector field.

const firestoreCollectionConnector: Connector = async ({ db, query, row, user }) => {
// 1️⃣ Edit Collection: connect to Firestore collection
const collectionId = "lwjShow"
// 2️⃣ set max results you want to show in the dropdown
const maxResults = 5
// 3️⃣ Edit field: connect to Firestore field to filter by in the input text
const queryField = "noun"
// Map result: use as it is or shape the returned data as need
const resultsFormatter = (doc) => ({ id: doc.id, snapshot: doc.data() })

// Logic for data retrieval, no edits needed here
const collectionRef = db.collection(collectionId).limit(maxResults)
if (query === "") {
return (await collectionRef.get()).docs.map(resultsFormatter)
}
const end = query.replace(/.$/, (c) => String.fromCharCode(c.charCodeAt(0) + 1));
return (await collectionRef.where(queryField, ">=", query).where(queryField, "<", end).get())
.docs.map(resultsFormatter)
};

Accessing data from an external API using a Connector

The following is a code snippet that shows how to access data from an external API and display it as a list of options using the connector field.

const apiConnector: Connector = async ({query, row, user}) => {
const response = await fetch(`https://api.boardgameatlas.com/api/search?name=${query}&client_id=JLBr5npPhV`)
const {games} = await response.json()
return games
};