For AI agents: the documentation index is at llms.txt. Guide pages have a markdown version at the same path with .md appended, before any query string or fragment.
range() queries to paginate through your data.select() can be combined with Modifiersselect() can be combined with Filtersapikey is technically a reserved keyword, since the API gateway will pluck it out for authentication. It should be avoided as a column name.value property of the response. Declare a Decodable type and annotate the variable, so the client knows what to decode.PostgrestError. Its code holds the PostgreSQL or PostgREST error code, such as PGRST116.@Table macro and from(Todo.self). It needs @_spi(Experimental) import Supabase and can change in a minor release. The examples on this page use the string-based API.struct Instrument: Decodable {
let id: Int
let name: String
}
let instruments: [Instrument] = try await supabase
.from("instruments")
.select()
.execute()
.value
struct Instrument: Decodable {
let name: String
}
let instruments: [Instrument] = try await supabase
.from("instruments")
.select("name")
.execute()
.value
struct OrchestralSection: Decodable {
let name: String
let instruments: [Instrument]
}
struct Instrument: Decodable {
let name: String
}
let orchestralSections: [OrchestralSection] = try await supabase
.from("orchestral_sections")
.select(
"""
name,
instruments (
name
)
"""
)
.execute()
.value
struct User: Decodable {
let name: String
let teams: [Team]
}
struct Team: Decodable {
let name: String
}
let users: [User] = try await supabase
.from("users")
.select(
"""
name,
teams (
name
)
"""
)
.execute()
.value
struct Message: Decodable {
let content: String
let from: User
let to: User
}
struct User: Decodable {
let name: String
}
let messages: [Message] = try await supabase
.from("messages")
.select(
"""
content,
from:sender_id(name),
to:receiver_id(name)
"""
)
.execute()
.value
struct Instrument: Decodable {
let name: String
let orchestralSections: OrchestralSection?
enum CodingKeys: String, CodingKey {
case name
case orchestralSections = "orchestral_sections"
}
}
struct OrchestralSection: Decodable {
let name: String
}
let instruments: [Instrument] = try await supabase
.from("instruments")
.select("name, orchestral_sections(*)")
.eq("orchestral_sections.name", value: "percussion")
.execute()
.value
struct OrchestralSection: Decodable {
let id: UUID
let name: String
let instruments: [Instrument]
}
struct Instrument: Decodable {
let count: Int
}
let orchestralSections: [OrchestralSection] = try await supabase
.from("orchestral_sections")
.select("*, instruments(count)")
.execute()
.value
let count = try await supabase
.from("instruments")
.select("*", head: true, count: .exact)
.execute()
.count
struct User: Decodable {
let id: Int
let name: String
let city: String
}
let users: [User] = try await supabase
.from("users")
.select(
"""
id, name,
address->city
"""
)
.execute()
.value
struct Instrument: Decodable {
let name: String
}
struct OrchestralSection: Decodable {
let name: String
let instruments: [Instrument]
}
let orchestralSections: [OrchestralSection] = try await supabase
.from("orchestral_sections")
.select("name, instruments!inner(name)")
.eq("name", value: "strings")
.execute()
.value
try await supabase
.schema("myschema")
.from("mytable")
.select()
.execute()