Swift: Insert data

Examples

Create a record

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

let country = Country(id: 1, name: "Denmark")

try await supabase
  .from("countries")
  .insert(country)
  .execute()

Create a record and return it

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

let country: Country = try await supabase
  .from("countries")
  .insert(Country(id: 1, name: "Denmark"))
  .select()
  // specify you want a single value returned, otherwise it returns a list.
  .single() 
  .execute()
  .value

Bulk create

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

let countries = [
  Country(id: 1, name: "Nepal"),
  Country(id: 1, name: "Vietnam"),
]

try await supabase
  .from("countries")
  .insert(countries)
  .execute()