By default, Supabase projects will return a maximum of 1,000 rows. This setting can be changed in Project API Settings. It's recommended that you keep it low to limit the payload size of accidental or malicious requests. You can use range() queries to paginate through your data.
If using the Supabase hosted platform apikey is technically a reserved keyword, since the API gateway will pluck it out for authentication. It should be avoided as a column name.
The recommended solution for getting data is to use the value property which will return a decoded model. Create a Codable to easily decode your database responses.
Examples
Getting your data
struct Instrument: Decodable \{
let id: Int
let name: String
\}
let instruments: [Instrument] = try await supabase
.from("instruments")
.select()
.execute()
.value
Selecting specific columns
struct Instrument: Decodable \{
let name: String
\}
let instruments: [Instrument] = try await supabase
.from("instruments")
.select("name")
.execute()
.value
Query foreign tables
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
Query foreign tables through a join table
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
Query the same foreign table multiple times
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:sended_id(name)
"""
)
.execute()
.value
Filtering through foreign tables
struct Instrument: Decodable \{
let name: String
let orchestralSections: [OrchestralSection]?
\}
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
Querying foreign table with count
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