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 Country: Decodable \{
let id: Int
let name: String
\}
let countries: [Country] = try await supabase.database
.from("countries")
.select()
.execute()
.value
Selecting specific columns
struct Country: Decodable \{
let name: String
\}
let countries: [Country] = try await supabase.database
.from("countries")
.select("name")
.execute()
.value
Query foreign tables
struct Country: Decodable \{
let name: String
let cities: [City]
\}
struct City: Decodable \{
let name: String
\}
let countries: [Country] = try await supabase.database
.from("countries")
.select(
"""
name,
cities (
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.database
.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.database
.from("messages")
.select(
"""
content,
from:sender_id(name),
to:sended_id(name)
"""
)
.execute()
.value
Filtering through foreign tables
struct City: Decodable \{
let name: String
let countries: [Country]?
\}
struct Country: Decodable \{
let name: String
\}
let cities: [City] = try await supabase.database
.from("cities")
.select("name, countries(*)")
.eq("countries.name", value: "Estonia")
.execute()
.value
Querying foreign table with count
struct Country: Decodable \{
let id: UUID
let name: String
let cities: [City]
\}
struct City: Decodable \{
let count: Int
\}
let countries: [Country] = try await supabase.database
.from("countries")
.select("*, cities(count)")
.execute()
.value