Hey guys, struggling with something hope to find s...
# javascript
r
Hey guys, struggling with something hope to find some help here. I want to update my table with a key-value pair object which I have got as input from the user. I'm matching it with the original values that are there in the Table. I keep getting 404 Error. Is this happening cause supabase doesn't support it yet? (RLS is disabled for now)
Copy code
const { data, error } = await supabase
      .from("company")
      .update([inputFields.values])
      .match([originalFields.values]);
  };
This is what inputFields.values / originalFields.values look like
Copy code
{
  "name": "Piramal Glassed",
  "email": "piramal@glass.com",
  "contact": "98203"
}
g
Hey guys, struggling with something hope to find some help here. I want to update my table with a key-value pair object which I have got as input from the user. I'm matching it with the original values that are there in the Table. I keep getting 404 Error. Is this happening cause supabase doesn't support it yet? (RLS is disabled for now)
Copy code
const { data, error } = await supabase
      .from("company")
      .update([inputFields.values])
      .match([originalFields.values]);
  };
This is what inputFields.values / originalFields.values look like
Copy code
{
  "name": "Piramal Glassed",
  "email": "piramal@glass.com",
  "contact": "98203"
}
Is the data json or a js object? It needs to be an object.
r
js object... have detailed the issue properly on stackoverflow => https://stackoverflow.com/q/71159169/13764834
g
You should not be using arrays, just the objects. const { data, error } = await supabase .from('cities') .update({ name: 'Mordor' }) .match({name: 'Beijing', country_id: 156})
r
Still returns an error 😦
g
Can you show your new call.
r
Copy code
const { data, error } = await supabase
      .from("company")
      .update(inputFields.values)
      .match(dataModal.values);
g
Drop .values
Never mind.
r
.values contains the object that I need to send..
Copy code
{
  "name": "Piramal Glasss",
  "email": "piramal@glass.com",
  "contact": "98203",
  "address": "I - 402, Ekta Bhoomi Gardens, Rajendra Nagar, Borivali East.",
  "pin": 400066,
  "city": "Mumbai",
  "state": "Maharashtra",
  "country": "India",
  "type": "Seller",
  "dl_no": "8SD978F67F5G",
  "pan_no": "2123SAD6780SF",
  "responsible_person": "Maheshwari Gupt",
  "responsible_phone": 982031,
  "gstin": "CHUTIYABANAYA2153678"
}
That's one entire row in the table
that I am trying to update
It is possible to
update()
the entire row with one call right?
g
Do a test using just {name:"Primal Glasssad"} as the match
r
didn't work
g
Can you do select on that match? And hopefully you did not copy my object as I did not spell it correctly per your data above...
r
Ah the match doesn't seem to return any data back
g
const { data, error } = await supabase .from('company') .select('*') .match({name: "Piramal Glasssad"} if that does not work, then make sure the record exists, and RLS is really off
r
the record exists, i tried using .eq as well
Copy code
const { data, error } = await supabase
      .from("company")
      .select("*")
      .eq("name", "Piramal Glass");
it was misspelt in the example I sent you earlier apologies
g
OK does just .select("*") work with no filter?
r
Ok It's returning value, turns out I was mispelling it.. but the update still doesn't work
g
The update with just a single column match?
r
getting a 500 error
g
Normally when you do match you want to do the minimum columns that make the rows unique anyway, not the entire old record.
OK so now it is finding the record, and it is your update data formatted wrong most likely
r
interesting, what do you mean when you say formatted wrong?
g
Not an array, a js object not json, all columns spelled correctly, all data of correct type.
r
Okay
g
Try just hardcoding an object in the update for a test
r
The thing is, I am modifying the object returned by the read table call, so i'm pretty sure there are no data-type mismatches. I have verified this by checking the it in the console logs too. Should I try trimming the object and only sending back values that need to be updated instead of the entire row?
g
First just paste the object in to the update (don't use your variable) and see if that works, then just try a column or two if not. Need to narrow down where the issue is.
r
Okay, give me a min
Still giving 500 error
g
Even with a few columns in the update part? Also can you show the code you just tested.
r
Copy code
const { data, error } = await supabase
      .from("company")
      .update({
        name: "Piramal Glasssed",
        email: "piramal@glass.come",
        contact: "9820e3",
        address:
          "I - e402, Ekta Bhoomi Gardens, Rajendra Nagar, Borivali East.",
        pin: 4000626,
        city: "Mumbaei",
        state: "Maharashdtra",
        country: "Inddia",
        type: "Seldler",
        dl_no: "8SDd978F67F5G",
        pan_no: "2123SdAD6780SF",
        responsible_person: "Maheshwadri Gupt",
        responsible_phone: 9382031,
        gstin: "CHUTIYABANAYA21e53678",
      })
      .match({ name: "Piramal Glass" });
have changed the first value from
Piramal Glass
to
Piramal Glassed
in the update fn
This doesn't seem to work either
Copy code
const { data, error } = await supabase
      .from("company")
      .update({
        name: "Piramal Glasssed",
      })
      .match({ name: "Piramal Glass" });
Same ol 500 error
g
Pretty basic call at this point...
r
yeah 😦
g
Do you have any triggers on your table in SQL?
r
Nope, none yet
I made a new table with two columns. And even here
insert()
Works but
update()
doesn't seem to work
Copy code
const { data, error } = await supabase
      .from("test")
      .insert({
        text: "Some Text",
        text2: "Some Text 2",
      })
This worked....
Copy code
const { data, error } = await supabase
      .from("test")
      .update({
        text: "Some New Text",
        text2: "Some New Text 2",
      })
      .match({
        text: "Some Text",
        text2: "Some Text 2",
      });
But this returns a 404 Error
Okay,
update()
too is working on this new table
g
Yeah I just ran your above test on a test table for kicks and no issues.
500 error can come from many, many things. https://postgrest.org/en/stable/api.html#http-status-codes
r
Thanks, hopefully I'll figure out a solution soon
Will update this thread with a solution once I land on it
Could you try running this to verify if it works? It doesn't seem to be working for me.. For supabase
Copy code
create table company (
  name text,
  email text,
  contact text,
  address text,
  pin text,
  city text,
  states text,
  country text,
  typeOfCompany text,
  dl_no text,
  pan_no text,
  responsible_person text,
  responsible_phone text,
  gstin text 
);
And then this to insert rows
Copy code
const { data, error } = await supabase.from("company").insert({
      name: "Piruss",
      email: "Piruss",
      contact: "Piruss",
      address: "Piruss",
      pin: "Piruss",
      city: "Piruss",
      states: "Piruss",
      country: "Piruss",
      typeOfCompany: "Piruss",
      dl_no: "Piruss",
      pan_no: "Piruss",
      responsible_person: "Piruss",
      responsible_phone: "Piruss",
      gstin: "Piruss",
    });
Why is this returning me a 404 error?
g
404 or 400? I get 400 with response of {"message":"column \"typeOfCompany\" of relation \"company\" does not exist","code":"42703","details":null,"hint":null} postgres converts caps to lowercase column name (check your table in the UI you'll see) unless you put it in quotes, but you really should not use caps if you can avoid it and use _ between column name words instead.
You can get more specific error message in the network response.
r
Interesting
How can I see the specific errors
g
Developer network tab:
I’ve got to run. Good luck.
r
Sure man, thanks!