Edits history of script submission #356 for ' List Documents (firebase)'

  • deno
    import { initializeApp } from "npm:[email protected]/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 hugo697 399 days ago

  • deno
    import { initializeApp } from "npm:[email protected]/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 1034 days ago

  • deno
    import { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    import { initializeApp } from "npm:[email protected]/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 1141 days ago

  • deno
    import { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    import { initializeApp } from "npm:[email protected]/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 1141 days ago