Swift: Update data

Examples

Updating your data

try await supabase
  .from("countries")
  .update(["name": "Australia"])
  .eq("id", value: 1)
  .execute()

Update a record and return it

struct Country: Decodable \{
  let id: Int
  let name: String          
\}

let country: Country = try await supabase
  .from("countries")
  .update(["name": "Australia"])
  .eq("id", value: 1)
  .select()
   // If you know this query should return a single object, append a `single()` modifier to it.
  .single()
  .execute()
  .value

Updating JSON data

struct User: Decodable \{
  let id: Int
  let name: String
  let address: Address

  struct Address: Codable \{
    let street: String
    let postcode: String
  \}
\}

struct UpdateUser: Encodable \{
  let address: User.Address
\}

let users: [User] = try await supabase
  .from("users")
  .update(
    UpdateUser(
      address: .init(
        street: "Melrose Place",
        postcode: "90210"
      )
    )
  )
  .eq("address->postcode", value: "90210")
  .select()
  .execute()
  .value