import { initializeApp } from "npm:firebase@9.20.0/app";
import {
collection,
endAt,
getDocs,
getFirestore,
limit as limitItems,
orderBy,
query,
QueryConstraint,
startAt,
} from "npm:firebase/firestore/lite";
/**
* @param order_by Name of the field to order by.
*
* @param start_at Can only be used if `order_by` is present,
* because it'll filter based on the value of that field.
*
* @param end_at Can only be used if `order_by` is present,
* because it'll filter based on the value of that field.
*/
type Firebase = {
apiKey: string;
authDomain: string;
projectId: string;
storageBucket: string;
messagingSenderId: string;
appId: string;
measurementId: string;
};
export async function main(
auth: Firebase,
collection_id: string,
order_by?: string,
order_direction: "asc" | "desc" = "asc",
start_at?: number | string,
end_at?: number | string,
limit?: number,
) {
const app = initializeApp(auth);
const store = getFirestore(app);
const colRef = collection(store, collection_id);
const constraints = [
order_by ? orderBy(order_by, order_direction) : undefined,
start_at ? startAt(start_at) : undefined,
end_at ? endAt(end_at) : undefined,
limit ? limitItems(limit) : undefined,
].filter(Boolean) as QueryConstraint[];
const snapshot = await getDocs(query(colRef, ...constraints));
const list = snapshot.docs.map((doc) => doc.data());
return list;
}
Submitted by admin 501 days ago
import { Resource } from "https://deno.land/x/windmill@v1.89.0/mod.ts";
import { initializeApp } from "npm:firebase@9.20.0/app";
import {
collection,
endAt,
getDocs,
getFirestore,
limit as limitItems,
orderBy,
query,
QueryConstraint,
startAt,
} from "npm:firebase/firestore/lite";
/**
* @param order_by Name of the field to order by.
*
* @param start_at Can only be used if `order_by` is present,
* because it'll filter based on the value of that field.
*
* @param end_at Can only be used if `order_by` is present,
* because it'll filter based on the value of that field.
*/
export async function main(
auth: Resource<"firebase">,
collection_id: string,
order_by?: string,
order_direction: "asc" | "desc" = "asc",
start_at?: number | string,
end_at?: number | string,
limit?: number,
) {
const app = initializeApp(auth);
const store = getFirestore(app);
const colRef = collection(store, collection_id);
const constraints = [
order_by ? orderBy(order_by, order_direction) : undefined,
start_at ? startAt(start_at) : undefined,
end_at ? endAt(end_at) : undefined,
limit ? limitItems(limit) : undefined,
].filter(Boolean) as QueryConstraint[];
const snapshot = await getDocs(query(colRef, ...constraints));
const list = snapshot.docs.map((doc) => doc.data());
return list;
}
Submitted by adam186 607 days ago
import { Resource } from "https://deno.land/x/windmill@v1.89.0/mod.ts";
import { initializeApp } from "npm:firebase@9.20.0/app";
import {
collection,
endAt,
getDocs,
getFirestore,
orderBy,
query,
QueryConstraint,
startAt,
} from "npm:firebase/firestore/lite";
/**
* @param order_by Name of the field to order by.
*
* @param start_at Can only be used if `order_by` is present,
* because it'll filter based on the value of that field.
*
* @param end_at Can only be used if `order_by` is present,
* because it'll filter based on the value of that field.
*/
export async function main(
auth: Resource<"firebase">,
collection_id: string,
order_by?: string,
order_direction: "asc" | "desc" = "asc",
start_at?: number | string,
end_at?: number | string,
) {
const app = initializeApp(auth);
const store = getFirestore(app);
const colRef = collection(store, collection_id);
const constraints = [
order_by ? orderBy(order_by, order_direction) : undefined,
start_at ? startAt(start_at) : undefined,
end_at ? endAt(end_at) : undefined,
].filter(Boolean) as QueryConstraint[];
const snapshot = await getDocs(query(colRef, ...constraints));
const list = snapshot.docs.map((doc) => doc.data());
return list;
}
Submitted by adam186 607 days ago