Edits history of script submission #288 for ' Upsert data (supabase)'

  • deno
    import {
      refreshAndRetryIfExpired,
      removeObjectEmptyFields,
    } from "https://deno.land/x/[email protected]/mod.ts";
    
    /**
     * @param on_conflict Comma-separated UNIQUE column(s) to specify how duplicate
     * rows are determined. Two rows are duplicates if all the onConflict columns are equal.
     *
     * @param ignore_duplicates If true, duplicate rows are ignored. If false, duplicate
     * rows are merged with existing rows.
     *
     * @param token Supabase `access_token` and `refresh_token`. `expires_at` (optional) is a UNIX
     * timestamp in seconds.
     *
     * @param count Count algorithm to use to count rows in the table or view.
     * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the hood.
     * `"planned"`: Approximated but fast count algorithm. Uses the Postgres statistics under the hood.
     * `"estimated"`: Uses exact count for low numbers and planned count for high numbers.
     */
    type Supabase = {
      url: string;
      key: string;
    };
    export async function main(
      auth: Supabase,
      table: string,
      values: any,
      on_conflict?: string,
      ignore_duplicates: boolean = true,
      return_updated: boolean = false,
      token?: {
        access: string;
        refresh: string;
        expires_at?: number;
      },
      count?: "exact" | "planned" | "estimated",
    ) {
      return await refreshAndRetryIfExpired(auth, token, async (client) => {
        let query: any = client
          .from(table)
          .upsert(
            values,
            removeObjectEmptyFields({ on_conflict, ignore_duplicates, count }),
          );
        if (return_updated) {
          query = query.select();
        }
    
        return query;
      });
    }
    

    Submitted by hugo697 399 days ago

  • deno
    import {
      refreshAndRetryIfExpired,
      removeObjectEmptyFields,
    } from "https://deno.land/x/[email protected]/mod.ts";
    
    /**
     * @param on_conflict Comma-separated UNIQUE column(s) to specify how duplicate
     * rows are determined. Two rows are duplicates if all the onConflict columns are equal.
     *
     * @param ignore_duplicates If true, duplicate rows are ignored. If false, duplicate
     * rows are merged with existing rows.
     *
     * @param token Supabase `access_token` and `refresh_token`. `expires_at` (optional) is a UNIX
     * timestamp in seconds.
     *
     * @param count Count algorithm to use to count rows in the table or view.
     * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the hood.
     * `"planned"`: Approximated but fast count algorithm. Uses the Postgres statistics under the hood.
     * `"estimated"`: Uses exact count for low numbers and planned count for high numbers.
     */
    type Supabase = {
      url: string;
      key: string;
    };
    export async function main(
      auth: Supabase,
      table: string,
      values: any,
      on_conflict?: string,
      ignore_duplicates: boolean = true,
      return_updated: boolean = false,
      token?: {
        access: string;
        refresh: string;
        expires_at?: number;
      },
      count?: "exact" | "planned" | "estimated",
    ) {
      return await refreshAndRetryIfExpired(auth, token, async (client) => {
        let query: any = client
          .from(table)
          .upsert(
            values,
            removeObjectEmptyFields({ on_conflict, ignore_duplicates, count }),
          );
        if (return_updated) {
          query = query.select();
        }
    
        return query;
      });
    }
    

    Submitted by admin 1031 days ago

  • deno
    import { refreshAndRetryIfExpired, removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts";
    
    /**
     * @param on_conflict Comma-separated UNIQUE column(s) to specify how duplicate 
     * rows are determined. Two rows are duplicates if all the onConflict columns are equal.
     * 
     * @param ignore_duplicates If true, duplicate rows are ignored. If false, duplicate 
     * rows are merged with existing rows.
     * 
     * @param token Supabase `access_token` and `refresh_token`. `expires_at` (optional) is a UNIX
     * timestamp in seconds.
     * 
     * @param count Count algorithm to use to count rows in the table or view.
     * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the hood.
     * `"planned"`: Approximated but fast count algorithm. Uses the Postgres statistics under the hood.
     * `"estimated"`: Uses exact count for low numbers and planned count for high numbers.
     */
    type Supabase = {
      url: string;
      key: string;
    };
    export async function main(
      auth: Supabase,
      table: string,
      values: any,
      on_conflict?: string,
      ignore_duplicates: boolean = true,
      return_updated: boolean = false,
      token?: {
        access: string;
        refresh: string;
        expires_at?: number;
      },
      count?: "exact" | "planned" | "estimated",
    ) {
      return await refreshAndRetryIfExpired(auth, token, async (client) => {
        let query: any = client.from(table).upsert(
          values,
          removeObjectEmptyFields({ on_conflict, ignore_duplicates, count })
        );
        if (return_updated) {
          query = query.select()
        }
    
        return query;
      })
    }
    

    Submitted by admin 1034 days ago

  • deno
    import { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    import { refreshAndRetryIfExpired, removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts";
    
    /**
     * @param on_conflict Comma-separated UNIQUE column(s) to specify how duplicate 
     * rows are determined. Two rows are duplicates if all the onConflict columns are equal.
     * 
     * @param ignore_duplicates If true, duplicate rows are ignored. If false, duplicate 
     * rows are merged with existing rows.
     * 
     * @param token Supabase `access_token` and `refresh_token`. `expires_at` (optional) is a UNIX
     * timestamp in seconds.
     * 
     * @param count Count algorithm to use to count rows in the table or view.
     * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the hood.
     * `"planned"`: Approximated but fast count algorithm. Uses the Postgres statistics under the hood.
     * `"estimated"`: Uses exact count for low numbers and planned count for high numbers.
     */
    export async function main(
      auth: Resource<"supabase">,
      table: string,
      values: any,
      on_conflict?: string,
      ignore_duplicates: boolean = true,
      return_updated: boolean = false,
      token?: {
        access: string;
        refresh: string;
        expires_at?: number;
      },
      count?: "exact" | "planned" | "estimated",
    ) {
      return await refreshAndRetryIfExpired(auth, token, async (client) => {
        let query: any = client.from(table).upsert(
          values,
          removeObjectEmptyFields({ on_conflict, ignore_duplicates, count })
        );
        if (return_updated) {
          query = query.select()
        }
    
        return query;
      })
    }
    

    Submitted by adam186 1161 days ago

  • deno
    import { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    import { refreshAndRetryIfExpired, removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts";
    
    /**
     * @param on_conflict Comma-separated UNIQUE column(s) to specify how duplicate 
     * rows are determined. Two rows are duplicates if all the onConflict columns are equal.
     * 
     * @param ignore_duplicates If true, duplicate rows are ignored. If false, duplicate 
     * rows are merged with existing rows.
     * 
     * @param token Supabase `access_token` and `refresh_token`. `expires_at` (optional) is a UNIX
     * timestamp in seconds.
     * 
     * @param count Count algorithm to use to count rows in the table or view.
     * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the hood.
     * `"planned"`: Approximated but fast count algorithm. Uses the Postgres statistics under the hood.
     * `"estimated"`: Uses exact count for low numbers and planned count for high numbers.
     */
    export async function main(
      auth: Resource<"supabase">,
      table: string,
      values: any,
      on_conflict?: string,
      ignore_duplicates: boolean = true,
      return_updated: boolean = false,
      token?: {
        access: string;
        refresh: string;
        expires_at?: number;
      },
      count?: "exact" | "planned" | "estimated",
    ) {
      return await refreshAndRetryIfExpired(auth, token, async (client) => {
        let query: any = client.from(table).upsert(
          values,
          removeObjectEmptyFields({ on_conflict, ignore_duplicates, count })
        );
        if (return_updated) {
          query = query.select()
        }
    
        return query;
      })
    }
    

    Submitted by adam186 1161 days ago

  • deno
    import { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts";
    import { createClient } from "https://esm.sh/@supabase/supabase-js@2";
    
    /**
     * @param on_conflict Comma-separated UNIQUE column(s) to specify how duplicate 
     * rows are determined. Two rows are duplicates if all the onConflict columns are equal.
     * 
     * @param ignore_duplicates If true, duplicate rows are ignored. If false, duplicate 
     * rows are merged with existing rows.
     * 
     * @param access_token It is only needed if you have an affecting RLS policy enabled
     * on the table that you want to access.
     * Learn more about RLS here: https://supabase.com/docs/guides/auth/row-level-security
     * 
     * @param count Count algorithm to use to count rows in the table or view.
     * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the hood.
     * `"planned"`: Approximated but fast count algorithm. Uses the Postgres statistics under the hood.
     * `"estimated"`: Uses exact count for low numbers and planned count for high numbers.
     */
    export async function main(
      auth: Resource<"supabase">,
      table: string,
      values: any,
      on_conflict?: string,
      ignore_duplicates: boolean = true,
      return_updated: boolean = false,
      access_token?: string,
      count?: "exact" | "planned" | "estimated",
    ) {
      const headers = access_token ? {
        global: { headers: { Authorization: `bearer ${access_token}` } },
      } : undefined
      const client = createClient(auth.url, auth.key, headers);
    
      let query: any = client.from(table).upsert(
        values,
        removeObjectEmptyFields({ on_conflict, ignore_duplicates, count })
      );
      if (return_updated) {
        query = query.select()
      }
    
      return await query;
    }
    

    Submitted by adam186 1163 days ago

  • deno
    import { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts";
    import { createClient } from "https://esm.sh/@supabase/supabase-js@2";
    
    /**
     * @param on_conflict Comma-separated UNIQUE column(s) to specify how duplicate 
     * rows are determined. Two rows are duplicates if all the onConflict columns are equal.
     * 
     * @param ignore_duplicates If true, duplicate rows are ignored. If false, duplicate 
     * rows are merged with existing rows.
     * 
     * @param access_token It is only needed if you have an affecting RLS policy enabled
     * on the table that you want to access.
     * Learn more about RLS here: https://supabase.com/docs/guides/auth/row-level-security
     * 
     * @param count Count algorithm to use to count rows in the table or view.
     * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the hood.
     * `"planned"`: Approximated but fast count algorithm. Uses the Postgres statistics under the hood.
     * `"estimated"`: Uses exact count for low numbers and planned count for high numbers.
     */
    export async function main(
      auth: Resource<"supabase">,
      table: string,
      values: any,
      on_conflict?: string,
      ignore_duplicates: boolean = true,
      return_updated: boolean = false,
      access_token?: string,
      count?: "exact" | "planned" | "estimated",
    ) {
      const headers = access_token ? {
        global: { headers: { Authorization: `bearer ${access_token}` } },
      } : undefined
      const client = createClient(auth.url, auth.key, headers);
    
      let query: any = client.from(table).upsert(
        values,
        removeObjectEmptyFields({ on_conflict, ignore_duplicates, count })
      );
      if (return_updated) {
        query = query.select()
      }
    
      return await query;
    }
    

    Submitted by adam186 1170 days ago

  • deno
    import { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts";
    import { createClient } from "https://esm.sh/@supabase/supabase-js@2";
    
    /**
     * @param onConflict Comma-separated UNIQUE column(s) to specify how duplicate 
     * rows are determined. Two rows are duplicates if all the onConflict columns are equal.
     * 
     * @param ignoreDuplicates If true, duplicate rows are ignored. If false, duplicate 
     * rows are merged with existing rows.
     * 
     * @param count Count algorithm to use to count rows in the table or view.
     * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the hood.
     * `"planned"`: Approximated but fast count algorithm. Uses the Postgres statistics under the hood.
     * `"estimated"`: Uses exact count for low numbers and planned count for high numbers.
     */
    export async function main(
      auth: Resource<"supabase">,
      table: string,
      values: any,
      onConflict?: string,
      ignoreDuplicates: boolean = true,
      returnUpdated: boolean = false,
      count?: "exact" | "planned" | "estimated",
    ) {
      const client = createClient(auth.url, auth.key);
    
      let query: any = client.from(table).upsert(
        values,
        removeObjectEmptyFields({ onConflict, ignoreDuplicates, count })
      );
      if (returnUpdated) {
        query = query.select()
      }
    
      return await query;
    }
    

    Submitted by admin 1187 days ago

  • deno
    import { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts";
    import { createClient } from "https://esm.sh/@supabase/supabase-js@2";
    
    /**
     * @param onConflict Comma-separated UNIQUE column(s) to specify how duplicate 
     * rows are determined. Two rows are duplicates if all the onConflict columns are equal.
     * 
     * @param ignoreDuplicates If true, duplicate rows are ignored. If false, duplicate 
     * rows are merged with existing rows.
     * 
     * @param count Count algorithm to use to count rows in the table or view.
     * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the hood.
     * `"planned"`: Approximated but fast count algorithm. Uses the Postgres statistics under the hood.
     * `"estimated"`: Uses exact count for low numbers and planned count for high numbers.
     */
    export async function main(
      auth: Resource<"supabase">,
      table: string,
      values: any,
      onConflict?: string,
      ignoreDuplicates: boolean = true,
      returnUpdated: boolean = false,
      count?: "exact" | "planned" | "estimated",
    ) {
      const client = createClient(auth.supabaseUrl, auth.supabaseKey);
    
      let query: any = client.from(table).upsert(
        values,
        removeObjectEmptyFields({ onConflict, ignoreDuplicates, count })
      );
      if (returnUpdated) {
        query = query.select()
      }
    
      return await query;
    }
    

    Submitted by adam186 1198 days ago

  • deno
    import { Resource } from "https://deno.land/x/[email protected]/mod.ts";
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts";
    import { createClient } from "https://esm.sh/@supabase/supabase-js@2";
    
    /**
     * @param onConflict Comma-separated UNIQUE column(s) to specify how duplicate 
     * rows are determined. Two rows are duplicates if all the onConflict columns are equal.
     * 
     * @param ignoreDuplicates If true, duplicate rows are ignored. If false, duplicate 
     * rows are merged with existing rows.
     * 
     * @param count Count algorithm to use to count rows in the table or view.
     * `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the hood.
     * `"planned"`: Approximated but fast count algorithm. Uses the Postgres statistics under the hood.
     * `"estimated"`: Uses exact count for low numbers and planned count for high numbers.
     */
    export async function main(
      auth: Resource<"supabase">,
      table: string,
      values: any,
      onConflict?: string,
      ignoreDuplicates: boolean = true,
      returnUpdated: boolean = false,
      count?: "exact" | "planned" | "estimated",
    ) {
      const client = createClient(auth.supabaseUrl, auth.supabaseKey);
    
      let query: any = client.from(table).upsert(
        values,
        removeObjectEmptyFields({ onConflict, ignoreDuplicates, count })
      );
      if (returnUpdated) {
        query = query.select()
      }
    
      return await query;
    }
    

    Submitted by adam186 1234 days ago