Hey! I'm trying to update my `customer` table via ...
# help
l
Hey! I'm trying to update my
customer
table via the supabase-js client.
Copy code
javascript
const { data: dataCustomerUpdate, error: errorCustomerUpdate } =
await supabase.from("customer").update(
  {
    first_name: checkoutForm.billingFirstName,
    last_name: checkoutForm.billingLastName,
    email_address: checkoutForm.billingEmail,
    mobile_phone_number: checkoutForm.billingMobilePhoneNumber,
  },
)
.eq("id", customerIdSelectedFromIncomingOrderTable) // Here is where I need help.
I need to find what
customer
row to update. This is the problem. I have another table called
incoming_order
which contains a
stripe_payment_id
and the foreign key
customer_id
which I'm looking to select. I have the
stripe_payment_id
string which should be used to find (filter for) the correct row in
incoming_order
, and from that row I need to get the
customer_id
used instead of the
customerIdSelectedFromIncomingOrderTable
which I wrote above. I'm looking to do it all in this one query if that is possible.
n
Hello @Ludvig! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
s
You won't be able to do this in one query using the JS library like this, you would have to create a postgres function and call it from the
.rpc
method to do both in one query.
n
Ludvig (2022-04-27)
s
What is your concern at this stage in the project to have it all from one query if you don't mind me asking?
l
Alright. Somewhat expected this answer. Well, since this is not the only time I need to do something similar, I'm just trying to avoid a lot of code for readability's sake. I'm also just assuming it's more performant to do one call (even if it's more advanced) than 2. Perhaps it might be the best to create a database function (rpc) as you said and run it from there
Thank you for answering!