Swift: Insert data

Examples

Create a record

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

let instrument = Instrument(id: 1, name: "ukelele")

try await supabase
  .from("instruments")
  .insert(instrument)
  .execute()

Create a record and return it

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

let instrument: Instrument = try await supabase
  .from("instruments")
  .insert(Instrument(id: 1, name: "banjo"))
  .select()
  // specify you want a single value returned, otherwise it returns a list.
  .single()
  .execute()
  .value

Bulk create

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

let instruments = [
  Instrument(id: 1, name: "xylophone"),
  Instrument(id: 1, name: "tuba"),
]

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