https://supabase.com/ logo
Join DiscordCommunities
Powered by
# javascript
  • u

    user

    08/11/2021, 7:47 AM
    https://gist.github.com/berbaroovez/9871883b7df63d771feb52cc0ac1d1eb Im trying to get the user back after signing in with twitch. so i can update their information in a table incase they changed their twitch name. but when user is returned it is undefined and then the page reloads after returning from twitch. I took the code exactly from the document.
  • u

    user

    08/11/2021, 7:47 AM
    am i doing this wrong if so how can i properly get the user back when logging in with twitch
  • s

    stibbs

    08/11/2021, 7:48 AM
    That just logs the user in, you sound like you want an editable form for them to be able to change details?
  • u

    user

    08/11/2021, 7:50 AM
    wait actually nvm im a idiot i can just pull it from onauthstatechange
  • u

    user

    08/11/2021, 7:51 AM
    🦆 rubber duck moment
  • u

    user

    08/11/2021, 7:55 AM
    even though i can pull it from onauthstatechange im still curious on why when pulling user and session from the sign in method that they return null
  • l

    Lesourdingo

    08/11/2021, 4:58 PM
    Hello, i have some json data (let say { "name": "Bob", "age": "30" }, { "name": "Ema", "age": "30" }, etc) and i would like to insert it into my database. I dont know how to map through the data to insert it automatically. Thanks
    b
    • 2
    • 10
  • j

    jianjie

    08/11/2021, 5:48 PM
    i'm not sure if there's any easier way to import json data right now. but you can definitely write a node.js script to read from that json file and insert your data as postgres rows into your destination table.
  • j

    jianjie

    08/11/2021, 5:48 PM
    i did something similar when migrating my data from firebase to supabase. you can check out this repo for reference: https://github.com/liaujianjie/firebase-to-supabase-auth-migrator/blob/a9385529e8a386b75b9bafdf2588fc70d2746642/scripts/import-supabase-auth.ts#L50-L137
  • j

    jianjie

    08/11/2021, 5:49 PM
    you can ignore the bit about chunking if you have less than ~10000 rows for insertion
  • s

    Steve

    08/11/2021, 5:57 PM
    You can insert an array normally: https://supabase.io/docs/reference/javascript/insert#bulk-create
  • s

    Steve

    08/11/2021, 5:59 PM
    If you batch insert(pass an array, instead of looping) It should be fast even if you're inserting thousands of rows. This was discussed before on https://github.com/supabase/supabase-js/issues/195
  • b

    burggraf

    08/11/2021, 6:33 PM
    Inserting JSON Data
  • l

    Lesourdingo

    08/11/2021, 7:09 PM
    Thanks, it looks a bit too complicated for me right now but i understand the idea, i will try to find another solution.
  • l

    Lesourdingo

    08/11/2021, 7:20 PM
    The problem is i want to be able to select wich property from the json file i want to insert.
    s
    • 2
    • 3
  • s

    Steve

    08/11/2021, 7:34 PM
    insert json selectively
  • t

    tasty

    08/12/2021, 12:05 AM
    hello is there a way upsert/update all rows?
  • s

    stibbs

    08/14/2021, 6:17 AM
    I need to prevent duplicate records being created where both user_id and a date field are the same. E.g. if I try to create 2 records both with 14/Aug/2021 it should fail. Is there a clever way to do this? I could... 1) Make the PK a combo of user_id + date 2) Client-side call to check for existing rows before saving? Throw error if combo found 3) Something clever on server side??
  • l

    lawrencecchen

    08/14/2021, 7:47 AM
    Yeah, a unique index on (user_id, date) should do the trick (https://www.postgresql.org/docs/9.4/indexes-unique.html). Defining constraints within the database is preferable to doing it on client-side imo
  • s

    stibbs

    08/14/2021, 8:15 AM
    Perfect, yeah I wass trying to avoid doing anything on client side if possible!
  • d

    Deleted User

    08/14/2021, 3:56 PM
    Hello 👋 Does someone have an example of how to integrate Supabase with Redux Toolkit Query?
  • z

    Zenon

    08/14/2021, 7:29 PM
    Hey I'm creating an app in NextJS I want to listen to realtime DB using Supabase, I subscribed to all changes in the posts table as mentioned in the docs, but how do I get the data that has been modified?
  • t

    Tyler

    08/14/2021, 11:29 PM
    Is there a way to update a row's value to its current value + 1, without making two calls?
  • l

    lawrencecchen

    08/15/2021, 2:39 AM
    You should receive the updated row in
    payload.new
    which is passed in the callback function (https://supabase.io/docs/reference/javascript/subscribe#listening-to-a-specific-table). Make sure that replication is enabled for realtime (https://supabase.io/docs/guides/api#managing-realtime)
  • l

    lawrencecchen

    08/15/2021, 2:51 AM
    Not sure if its possible with postgrest grammar, but you can always write a stored procedure and use normal sql. Here's an example:
    Copy code
    sql
    create function increment(post_id integer)
    returns integer as $$
      update posts 
        set upvotes = upvotes + 1
      where id = post_id;
    $$ language sql immutable;
    https://postgrest.org/en/v8.0/api.html#stored-procedures
  • z

    Zenon

    08/15/2021, 7:15 AM
    Thanks! Replication is enabled for realtime, but I do not get any response in the console when I make a new entry to the table. I still don't know where to get the payload and use it in the frontend. Is there a react/nextjs example for this? I tried finding it but couldn't find any
  • l

    lawrencecchen

    08/15/2021, 7:35 AM
    example: https://github.com/antosan/supabase-nextjs-slack-clone/blob/main/lib/Store.js Seeing your code would make it easier for people to help
  • z

    Zenon

    08/15/2021, 7:55 AM
    Thanks! Here's the code. I'm fairly new to react/next so excuse the silly mistakes..I'm fetching posts the normal way using the supabase query methods, I just wanted to make the same function work realtime.
  • u

    user

    08/15/2021, 8:03 AM
    Hi, I'm facing an issue with supabase query.
  • u

    user

    08/15/2021, 8:03 AM
    I have a table with a user id as it's primary key and a cash (float8) column. I want to query the cash value for a specific user.
1...8910...81Latest