Swift: Update data

Examples

Updating your data

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

Update a record and return it

struct Instrument: Decodable { let id: Int let name: String } let instrument: Instrument = try await supabase .from("instruments") .update(["name": "piano"]) .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