Merge branch 'master' of github.com:supabase/supabase

This commit is contained in:
Terry Sutton committed 2024-04-10 15:58:26 -02:30
commit c9ef31f1e1
25 files changed
+1377 -3

No files matched your search

@@ -169,5 +169,12 @@ final data = await supabase.from('todos').select('*');
response = supabase.table('todos').select("*").execute()
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let response = try await supabase.from("todos").select()
```
</TabPanel>
</Tabs>
@@ -64,6 +64,15 @@ Call the [`signInAnonymously()`](/docs/reference/dart/auth-signinanonymously) me
await supabase.auth.signInAnonymously();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
Call the [`signInAnonymously()`](/docs/reference/swift/auth-signinanonymously) method:
```swift
let session = try await supabase.auth.signInAnonymously()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -106,6 +115,17 @@ You can use the [`updateUser()`](/docs/reference/dart/auth-updateuser) method to
await supabase.auth.updateUser(UserAttributes(email: 'example@email.com'));
```
</TabPanel>
<TabPanel id="swift" label="Swift">
You can use the [`updateUser()`](/docs/reference/swift/auth-updateuser) method to link an email or phone identity to the anonymous user.
```swift
try await supabase.auth.updateUser(
user: UserAttributes(email: "example@email.com")
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -146,6 +166,15 @@ You can use the [`linkIdentity()`](/docs/reference/dart/auth-linkidentity) metho
await supabase.auth.linkIdentity(OAuthProvider.google);
```
</TabPanel>
<TabPanel id="swift" label="Swift">
You can use the [`linkIdentity()`](/docs/reference/swift/auth-linkidentity) method to link an OAuth identity to the anonymous user.
```swift
try await supabase.auth.linkIdentity(provider: .google)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -57,6 +57,19 @@ Future<void> signUpNewUser() async {
}
```
</TabPanel>
<TabPanel id="swift" label="Swift">
To sign up the user, call [signUp()](/docs/reference/swift/auth-signup) with their email address and password:
```swift
let response = try await supabase.auth.signUp(
email: "example@email.com",
password: "example-password",
redirectTo: URL(string: "https://example.com/welcome")
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -110,6 +123,18 @@ Future<void> signInWithEmail() async {
}
```
</TabPanel>
<TabPanel id="swift" label="Swift">
When your user signs in, call [signIn(email:password:)](/docs/reference/swift/auth-signinwithpassword) with their email address and password:
```swift
try await supabase.auth.signIn(
email: "example@email.com",
password: "example-password"
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -157,6 +182,15 @@ Future<void> signOut() async {
}
```
</TabPanel>
<TabPanel id="swift" label="Swift">
When your user signs out, call [signOut()](/docs/reference/swift/auth-signout) to remove the session from the local storage:
```swift
try await supabase.auth.signOut()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -54,6 +54,15 @@ Supabase Auth allows a user to initiate identity linking with a different email
const { data, error } = await supabase.auth.linkIdentity({ provider: 'google' })
```
</TabPanel>
<TabPanel id="swift" label="Swift">
Supabase Auth allows a user to initiate identity linking with a different email address when they are logged in. To link an OAuth identity to the user, call [`linkIdentity()`](/docs/reference/swift/auth-linkidentity):
```swift
try await supabase.auth.linkIdentity(provider: .google)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -94,6 +103,22 @@ const googleIdentity = identities.find((identity) => identity.provider === 'goog
const { data, error } = await supabase.auth.unlinkIdentity(googleIdentity)
```
</TabPanel>
<TabPanel id="swift" label="Swift">
You can use [`getUserIdentities()`](/docs/reference/swift/auth-getuseridentities) to fetch all the identities linked to a user. Then, call [`unlinkIdentity()`](/docs/reference/swift/auth-unlinkidentity) to unlink the identity. The user needs to be logged in and have at least 2 linked identities in order to unlink an existing identity.
```swift
// retrieve all identities linked to a user
let identities = try await supabase.auth.userIdentities()
// find the google identity linked to the user
let googleIdentity = identities.first { $0.provider == .google }
// unlink the google identity from the user
try await supabase.auth.unlinkIdentity(googleIdentity)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -213,6 +213,17 @@ await supabase.auth.signInWithSSO(
Calling [`signInWithSSO`](/docs/reference/dart/auth-signinwithsso) starts the sign-in process using the identity provider registered for the `company.com` domain name. It is not required that identity providers be assigned one or multiple domain names, in which case you can use the provider's unique ID instead.
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
try await supabase.auth.signInWithSSO(
domain: "company.com"
)
```
Calling [`signInWithSSO`](/docs/reference/swift/auth-signinwithsso) starts the sign-in process using the identity provider registered for the `company.com` domain name. It is not required that identity providers be assigned one or multiple domain names, in which case you can use the provider's unique ID instead.
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -107,6 +107,26 @@ const { data: profile } = await supabase
.select('id, username, avatar_url, website')
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
// This will return nothing while the user is logged out
let profiles: [Profile] = try await supabase.from("profiles")
.select("id, username, avatar_url, website")
.execute()
.value
// After the user is logged in, this will only return
// the logged-in user's data - in this case a single row
try await supabase.auth.signInWithOTP(email: email)
let profile: Profile = try await supabase.from("profiles")
.select("id, username, avatar_url, website")
.single()
.execute()
.value
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -163,6 +183,20 @@ const { data, error } = await supabase.auth.signUp({
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
try await supabase.auth.signUp(
email: "example@email.com",
password: "example-password",
data: [
"first_name": .string("John"),
"age": .integer(27),
]
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -198,6 +232,14 @@ const {
let metadata = user.user_metadata
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let user = try await supabase.auth.user()
let metadata = user.userMetadata
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -54,6 +54,18 @@ Future<void> signInWithEmailOtp() async {
}
```
</TabPanel>
<TabPanel id="swift" label="Swift">
When your user signs in, call [signInWithOTP()](/docs/reference/swift/auth-signinwithotp) with their email address:
```swift
try await supabase.auth.signInWithOTP(
email: "example@email.com",
// set this to false if you do not want the user to be automatically signed up
shouldCreateUser: false
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -106,6 +118,19 @@ const {
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
Provide an input field for the user to key in the one-time code. To verify the code and complete the user's sign in, call [verifyOTP()](/docs/reference/swift/auth-verifyotp) with their email address, the code, and `type: .email`:
```swift
try await supabase.auth.verifyOTP(
email: email,
token: "123456",
type: .email
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -19,6 +19,8 @@ Set up Magic Link logins for your Supabase application.
When using Magic Links in [the PKCE Flow](/blog/supabase-auth-sso-pkce#introducing-pkce), keep in mind that links can only be opened from the same browser that they are sent from (as defined in the PKCE spec). Consequently, a magic link sent from Chrome on Desktop will be invalid if used on a Mobile Device.
The same applies for Magic Links in mobile devices. Magic Links can only be opened on the device they are sent from.
</Admonition>
<Tabs
@@ -76,6 +78,19 @@ Future<void> signInWithEmail() async {
}
```
</TabPanel>
<TabPanel id="swift" label="Swift">
When your user signs in, call [signInWithOTP()](/docs/reference/swift/auth-signinwithotp) with their email address:
```swift
try await supabase.auth.signInWithOTP(
email: "example@email.com",
redirectTo: URL(string: "https://example.com/welcome"),
// set this to false if you do not want the user to be automatically signed up
shouldCreateUser: false
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -119,6 +134,14 @@ Future<void> signOut() async {
}
```
</TabPanel>
<TabPanel id="swift" label="Swift">
When your user signs out, call [signOut()](/docs/reference/swift/auth-signout) to remove them from the local storage:
```swift
try await supabase.auth.signOut()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -91,6 +91,18 @@ await supabase.auth.resetPasswordForEmail('hello@example.com', {
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
Supabase provides a convenient method [`supabase.auth.resetPasswordForEmail`](/docs/reference/swift/auth-resetpasswordforemail) to reset a user password. This method takes a parameter of `redirectTo`, which is an absolute URL to the update password page. This URL must be saved in your allowed [Redirect URLs](https://supabase.com/dashboard/project/_/auth/url-configuration) list found at [Authentication > Redirect Configuration](https://supabase.com/dashboard/project/_/auth/url-configuration).
```swift
try await supabase.auth.resetPasswordForEmail(
"hello@example.com",
redirectTo: URL(string: "http://example.com/account/update-password")
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -125,6 +137,15 @@ To update the password, call the [`supabase.auth.updateUser`](/docs/reference/ja
await supabase.auth.updateUser({ password: new_password })
```
</TabPanel>
<TabPanel id="swift" label="Swift">
To update the password, call the [`supabase.auth.updateUser`](/docs/reference/swift/auth-updateuser) method with the new password.
```swift
try await supabase.auth.updateUser(user: UserAttributes(password: newPassword))
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -80,6 +80,16 @@ const { data, error } = await supabase.auth.signUp({
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
try await supabase.auth.signUp(
phone: "+13334445555",
password: "some-password"
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -126,6 +136,16 @@ const { user, error } = await supabase.auth.signInWithPassword({
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
try await supabase.auth.signIn(
phone: "+13334445555",
password: "some-password"
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -171,6 +191,15 @@ const { data, error } = await supabase.auth.signInWithOtp({
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
try await supabase.auth.signInWithOTP(
phone: "+13334445555"
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -216,6 +245,17 @@ const { data, error } = await supabase.auth.updateUser({
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
try await supabase.auth.updateUser(
user: UserAttributes(
phone: "123456789"
)
)
```
</TabPanel>
</Tabs>
@@ -247,6 +287,19 @@ const {
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
You should present a form to the user so they can input the 6 digit pin, then send it along with the phone number to `verifyOTP`:
```swift
try await supabase.auth.verifyOTP(
phone: "+13334445555",
token: "123456",
type: .sms
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -72,6 +72,30 @@ const { data, error } = await supabase
.insert([{ id: 2, textarray: ['one', 'two', 'three', 'four'] }])
```
</TabPanel>
<TabPanel id="swift" label="Swift">
Insert a record from the Swift client:
```swift
struct ArrayTest: Encodable {
let id: Int
let textarray: [String]
}
try await supabase
.from("arraytest")
.insert(
[
ArrayTest(
id: 2,
textarray: ["one", "two", "three", "four"]
)
]
)
.execute()
```
</TabPanel>
</Tabs>
@@ -156,6 +180,30 @@ returns:
]
```
</TabPanel>
<TabPanel id="swift" label="Swift">
This returns the entire array field:
```swift
struct Response: Decodable {
let textarray: [String]
}
let response: [Response] = try await supabase.from("arraytest").select("textarray").execute().value
dump(response)
```
returns:
```
[
Response(
textarray: ["Harry", "Larry", "Moe"],
)
]
```
</TabPanel>
</Tabs>
@@ -139,6 +139,26 @@ await supabase.from('restaurants').insert([
]);
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
struct Restaurant: Codable {
let name: String
let location: String // You could also use a custom type with a custom `Encodable` conformance for convenience.
}
try await supabase.from("restaurants")
.insert(
[
Restaurant(name: "Supa Burger", location: "POINT(-73.946823 40.807416)"),
Restaurant(name: "Supa Pizza", location: "POINT(-73.94581 40.807475)"),
Restaurant(name: "Supa Taco", location: "POINT(-73.945826 40.80629)"),
]
)
.execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -215,6 +235,34 @@ final data = await supabase.rpc('nearby_restaurants',params: {
});
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
struct Response: Codable {
let id: Int
let name: String
let lat: Double
let long: Double
let distance: Double
enum CodingKeys: String, CodingKey {
case id, name, lat, long
case distance = "dist_meters"
}
}
let response: Response = try await supabase.rpc(
"nearby_restaurants",
params: [
"lat": 40.807313,
"long": -73.946713
]
)
.execute()
.value
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -314,6 +362,30 @@ final data = await supabase.rpc('restaurants_in_view', params: {
});
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
struct Response: Codable {
let id: Int
let name: String
let lat: Double
let long: Double
}
let response: Response = try await supabase.rpc(
"restaurants_in_view",
params: [
"min_lat": 40.807,
"min_long": -73.946,
"max_long": -73.945,
"max_lat": 40.808,
]
)
.execute()
.value
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -138,6 +138,16 @@ final result = await client
.eq('title', 'Harry');
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let response = try await supabase.from("books")
.select()
.eq("title", value: "Harry")
.execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -187,6 +197,15 @@ final result = await client
.textSearch('title', "'Harry'");
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let response = try await supabase.from("books")
.select()
.textSearch("title", value: "'Harry'")
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -243,6 +262,16 @@ final result = await client
.textSearch('description', "'big'");
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let response = await client.from("books")
.select()
.textSearch("description", value: "'big'")
.execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -326,6 +355,23 @@ final result = await client
.textSearch('title_description', "little")
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```sql
create function title_description(books) returns text as $$
select $1.title || ' ' || $1.description;
$$ language sql immutable;
```
```swift
let response = try await client
.from("books")
.select()
.textSearch("title_description", value: "little")
.execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -401,6 +447,17 @@ final result = await client
.textSearch('description', "'little' & 'big'");
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let response = try await client
.from("books")
.select()
.textSearch("description", value: "'little' & 'big'");
.execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -469,6 +526,17 @@ final result = await client
.textSearch('description', "'little' | 'big'");
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let response = try await client
.from("books")
.select()
.textSearch("description", value: "'little' | 'big'")
.execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -548,6 +616,17 @@ const { data, error } = await supabase.rpc('search_books_by_title_prefix', { pre
final data = await supabase.rpc('search_books_by_title_prefix', params: { 'prefix': 'Lit' });
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let response = try await supabase.rpc(
"search_books_by_title_prefix",
params: ["prefix": "Lit"]
)
.execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -660,6 +739,17 @@ final result = await client
.textSearch('fts', "'little' & 'big'");
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let response = try await client
.from("books")
.select()
.textSearch("fts", value: "'little' & 'big'")
.execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -733,6 +823,17 @@ final result = await client
.textSearch('description', "'big' <-> 'dreams'");
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let response = try await client
.from("books")
.select()
.textSearch("description", value: "'big' <-> 'dreams'")
.execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -787,6 +888,17 @@ final result = await client
.textSearch('description', "'year' <2> 'school'");
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let response = try await supabase
.from("books")
.select()
.textSearch("description", value: "'year' <2> 'school'")
.execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -844,6 +956,17 @@ final result = await client
.textSearch('description', "'big' & !'little'");
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let response = try await client
.from("books")
.select()
.textSearch("description", value: "'big' & !'little'")
.execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -94,6 +94,15 @@ final data = await supabase
Reference: [rpc()](../../reference/dart/rpc)
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
try await supabase.rpc("hello_world").execute()
```
Reference: [rpc()](../../reference/swift/rpc)
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -216,6 +225,13 @@ final data = await supabase
.eq('id', 1);
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let response = try await supabase.rpc("get_planets").eq("id", value: 1).execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -281,6 +297,33 @@ final data = await supabase
.rpc('add_planet', params: { 'name': 'Jakku' });
```
</TabPanel>
<TabPanel id="swift" label="Swift">
Using `Encodable` type:
```swift
struct Planet: Encodable {
let name: String
}
try await supabase.rpc(
"add_planet",
params: Planet(name: "Jakku")
)
.execute()
```
Using `AnyJSON` convenience` type:
```swift
try await supabase.rpc(
"add_planet",
params: ["name": AnyJSON.string("Jakku")]
)
.execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -135,6 +135,28 @@ const countriesWithCities: CountriesWithCities = data
final data = await supabase.from('countries').select('id, name, cities(id, name)');
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
struct Country: Codable {
let id: Int
let name: String
let cities: [City]
struct City: Codable {
let id: Int
let name: String
}
}
let countries: [Country] = try await supabase
.from("countries")
.select("id, name, cities(id, name)")
.execute()
.value
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -222,6 +244,38 @@ const { data, error } = await supabase.from('teams').select(`
final data = await supabase.from('teams').select('id, team_name, users(id, name)');
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
struct Team: Codable {
let id: Int
let name: String
let users: [User]
struct User: Codable {
let id: Int
let name: String
}
enum CodingKeys: String, CodingKey {
case id, users
case name = "team_name"
}
}
let teams [Team] = try await supabase
.from("teams")
.select(
"""
id,
team_name,
users ( id, name )
"""
)
.execute()
.value
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -315,5 +369,51 @@ const { data, error } = await supabase.from('shifts').select(
)
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
struct Shift: Codable {
let id: Int
let userId: Int
let attendanceStatus: String?
let scans: [Scan]
struct Scan: Codable {
let id: Int
let userId: Int
let badgeScanTime: TimeInterval
enum CodingKeys: String, CodingKey {
case id
case userId = "user_id"
case badgeScanTime = "badge_scan_time"
}
}
enum CodingKeys: String, CodingKey {
case id
case userId = "user_id"
case attendanceStatus = "attendance_status"
}
}
let shifts: [Shift] = try await supabase
.from("shifts")
.select(
"""
*,
scans:scan_id_start (
id,
user_id,
badge_scan_time
)
"""
)
.execute()
.value
```
</TabPanel>
</Tabs>
@@ -177,6 +177,70 @@ const { data, error } = await supabase.from('books').insert([
])
```
</TabPanel>
<TabPanel id="swift" label="Swift">
Supabase Swift provides a convenience `AnyJSON` type.
```swift
struct Book {
val title: String,
val author: String,
val metadata: [String: AnyJSON]
}
try await supabase.from("books")
.insert(
[
Book(
title: "The Poky Little Puppy",
author: "Janette Sebring Lowrey",
metadata: [
"description": "Puppy is slower than other, bigger animals.",
"price": 5.95,
"ages": [3, 6]
]
),
Book(
title: "Tale of Peter Rabbit",
author: "Beatrix Potter",
metadata: [
"description": "Rabbit eats some vegetables.",
"price": 4.49,
"ages": [2, 5]
]
),
Book(
title: "Tootle",
author: "Gertrude Crampton",
metadata: [
"description": "Little toy train has big dreams.",
"price": 3.99,
"ages": [2, 5]
]
),
Book(
title: "Green Eggs and Ham",
author: "Dr. Seuss",
metadata: [
"description": "Sam has changing food preferences and eats unusually colored food.",
"price": 7.49,
"ages": [4, 8]
]
),
Book(
title: "Harry Potter and the Goblet of Fire",
author: "J.K. Rowling",
metadata: [
"description": "Fourth year of school starts, big drama ensues.",
"price": 24.95,
"ages": [10, 99]
]
)
]
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -247,6 +311,24 @@ const { data, error } = await supabase.from('books').select(`
`)
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
try await supabase
.from("books")
.select(
"""
title,
description: metadata->description,
price: metadata->price,
low_age: metadata->ages->0,
high_age: metadata->ages->1
"""
)
.execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -230,6 +230,28 @@ await supabase
}]);
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
try await supabase.from("movies")
.insert(
[
[
"name": "The Empire Strikes Back",
"description":
"After the Rebels are brutally overpowered by the Empire on the ice planet Hoth, Luke Skywalker begins Jedi training with Yoda.",
],
[
"name": "Return of the Jedi",
"description":
"After a daring mission to rescue Han Solo from Jabba the Hutt, the Rebels dispatch to Endor to destroy the second Death Star.",
],
]
)
.execute()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
+27
View File
@@ -110,6 +110,33 @@ supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
// Initialize the Swift client
import Supabase
let supabase = SupabaseClient(supabaseURL: SUPABASE_URL, supabaseKey: SUPABASE_ANON_KEY)
// Create channel
let channel = await supabase.realtime.channel("todos")
// Create the observations before subscribing
let insertions = await channel.postgresChanges(
InsertAction.self,
schema: "public",
table: "todos"
)
await channel.subscribe()
for await insertion in insertions {
let todo = try insertion.decoded(as: Todo.self)
print("Todo inserted", todo)
}
```
</TabPanel>
</Tabs>
@@ -49,6 +49,18 @@ Go to your Supabase project's [API Settings](https://supabase.com/dashboard/proj
final supabase = Supabase.instance.client;
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
import Supabase
let SUPABASE_URL = "https://<project>.supabase.co"
let SUPABASE_KEY = "<your-anon-key>"
let client = SupabaseClient(supabaseURL: URL(string: SUPABASE_URL)!, supabaseKey: SUPABASE_KEY)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -112,6 +124,22 @@ You can provide a callback for the `broadcast` channel to receive message. In th
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let channelA = await clientA.channel("room-1")
// Listen for broadcast messages
let broadcastStream = await channelA.broadcast(event: "test")
await channelA.subscribe()
for await event in broadcastStream {
print(event)
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -185,6 +213,22 @@ You can provide a callback for the `broadcast` channel to receive message. In th
});
```
</TabPanel>
<TabPanel id="swift" label="Swift">
We can send Broadcast messages using `channelB.broadcast()`. Let's set up another client to send messages.
```swift
let channelB = await clientA.channel("room-1")
await channelB.subscribe()
try await channelB.broadcast(
event: "test",
message: YourMessage(message: "hello, world!")
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -273,6 +317,28 @@ You can pass configuration options while initializing the Supabase Client.
});
```
</TabPanel>
<TabPanel id="swift" label="Swift">
By default, broadcast messages are only sent to other clients. You can broadcast messages back to the sender by setting Broadcast's `receiveOwnBroadcasts` parameter to `true`.
```swift
let myChannel = await supabase.channel("room-2") {
$0.broadcast.receiveOwnBroadcasts = true
}
let broadcastStream = await myChannel.broadcast(event: "test-my-messages")
await myChannel.subscribe()
try await myChannel.broadcast(
event: "test-my-messages",
payload: YourMessage(
message: "talking to myself"
)
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -361,6 +427,21 @@ You can pass configuration options while initializing the Supabase Client.
});
```
</TabPanel>
<TabPanel id="swift" label="Swift">
You can confirm that Realtime received your message by setting Broadcast's `acknowledgeBroadcasts` config to `true`.
```swift
let myChannel = await clientD.channel("room-3") {
$0.broadcast.acknowledgeBroadcasts = true
}
await myChannel.subscribe()
await myChannel.broadcast(event: "acknowledge", message: [:])
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -435,6 +516,18 @@ You can also send a Broadcast message by making an HTTP request to Realtime serv
print(res);
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let myChannel = await supabase.channel("room-2") {
$0.broadcast.acknowledgeBroadcasts = true
}
// No need to subscribe to channel
await myChannel.broadcast(event: "test", message: ["message": "HI"])
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
```kotlin
@@ -236,6 +236,26 @@ supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let myChannel = await supabase.channel("schema-db-changes")
let changes = await myChannel.postgresChange(AnyAction.self, schema: "public")
await myChannel.subscribe()
for await change in changes {
switch change {
case .insert(let action): print(action)
case .update(let action): print(action)
case .delete(let action): print(action)
case .select(let action): print(action)
}
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -302,6 +322,23 @@ final changes = supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
Use `InsertAction.self` as type to listen only to database `INSERT`s:
```swift
let myChannel = await supabase.channel("schema-db-changes")
let changes = await myChannel.postgresChange(InsertAction.self, schema: "public")
await myChannel.subscribe()
for await change in changes {
print(change.record)
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -366,6 +403,23 @@ supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
Use `UpdateAction.self` as type to listen only to database `UPDATE`s:
```swift
let myChannel = await supabase.channel("schema-db-changes")
let changes = await myChannel.postgresChange(UpdateAction.self, schema: "public")
await myChannel.subscribe()
for await change in changes {
print(change.oldRecord, change.record)
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -430,6 +484,23 @@ supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
Use `DeleteAction.self` as type to listen only to database `DELETE`s:
```swift
let myChannel = await supabase.channel("schema-db-changes")
let changes = await myChannel.postgresChange(DeleteAction.self, schema: "public")
await myChannel.subscribe()
for await change in changes {
print(change.oldRecord)
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -496,6 +567,26 @@ supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let myChannel = await supabase.channel("db-changes")
let changes = await myChannel.postgresChange(AnyAction.self, schema: "public", table: "todos")
await myChannel.subscribe()
for await change in changes {
switch change {
case .insert(let action): print(action)
case .update(let action): print(action)
case .delete(let action): print(action)
case .select(let action): print(action)
}
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -576,6 +667,18 @@ supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let myChannel = await supabase.channel("db-changes")
let messageChanges = await myChannel.postgresChange(AnyAction.self, schema: "public", table: "messages")
let userChanges = await myChannel.postgresChange(InsertAction.self, schema: "public", table: "users")
await myChannel.subscribe()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -641,6 +744,26 @@ const changes = client
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let myChannel = await supabase.channel("db-changes")
let changes = await myChannel.postgresChange(
InsertAction.self,
schema: "public",
table: "todos",
filter: "id=eq.1"
)
await myChannel.subscribe()
for await change in changes {
print(change.record)
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -716,6 +839,26 @@ supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let myChannel = await supabase.channel("db-changes")
let changes = await myChannel.postgresChange(
UpdateAction.self,
schema: "public",
table: "messages",
filter: "body=eq.hey"
)
await myChannel.subscribe()
for await change in changes {
print(change.record)
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -789,6 +932,26 @@ supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let myChannel = await supabase.channel("db-changes")
let changes = await myChannel.postgresChange(
UpdateAction.self,
schema: "public",
table: "messages",
filter: "body=neq.hey"
)
await myChannel.subscribe()
for await change in changes {
print(change.record)
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -863,6 +1026,26 @@ supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let myChannel = await supabase.channel("db-changes")
let changes = await myChannel.postgresChange(
InsertAction.self,
schema: "public",
table: "profiles",
filter: "age=lt.65"
)
await myChannel.subscribe()
for await change in changes {
print(change.record)
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -936,6 +1119,26 @@ supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let myChannel = await supabase.channel("db-changes")
let changes = await myChannel.postgresChange(
InsertAction.self,
schema: "public",
table: "profiles",
filter: "age=lte.65"
)
await myChannel.subscribe()
for await change in changes {
print(change.record)
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -1009,6 +1212,26 @@ supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let myChannel = await supabase.channel("db-changes")
let changes = await myChannel.postgresChange(
InsertAction.self,
schema: "public",
table: "products",
filter: "quantity=gt.10"
)
await myChannel.subscribe()
for await change in changes {
print(change.record)
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -1082,6 +1305,26 @@ supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let myChannel = await supabase.channel("db-changes")
let changes = await myChannel.postgresChange(
InsertAction.self,
schema: "public",
table: "products",
filter: "quantity=gte.10"
)
await myChannel.subscribe()
for await change in changes {
print(change.record)
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -1155,6 +1398,26 @@ supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let myChannel = await supabase.channel("db-changes")
let changes = await myChannel.postgresChange(
InsertAction.self,
schema: "public",
table: "products",
filter: "name=in.(red, blue, yellow)"
)
await myChannel.subscribe()
for await change in changes {
print(change.record)
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -1277,6 +1540,28 @@ supabase
.subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
await supabase.realtime.setAuth("your-custom-jwt")
let myChannel = await supabase.channel("db-changes")
let changes = await myChannel.postgresChange(
UpdateAction.self,
schema: "public",
table: "products",
filter: "name=in.(red, blue, yellow)"
)
await myChannel.subscribe()
for await change in changes {
print(change.record)
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -1333,6 +1618,13 @@ supabase.realtime.setAuth('fresh-token')
supabase.realtime.setAuth('fresh-token');
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
await supabase.realtime.setAuth("fresh-token")
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -48,6 +48,17 @@ void main() {
final supabase = Supabase.instance.client;
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let supabaseURL = "https://<project>.supabase.co"
let supabaseKey = "<your-anon-key>"
let supabase = SupabaseClient(supabaseURL: URL(string: supabaseURL)!, supabaseKey: supabaseKey)
let realtime = supabase.realtime
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -110,6 +121,23 @@ roomOne.onPresenceSync((_) {
}).subscribe();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
Listen to the presence change stream, emitting a new `PresenceAction` whenever someone joins or leaves:
```swift
let roomOne = await supabase.channel("room_01")
let presenceStream = await roomOne.presenceChange()
await roomOne.subscribe()
for await presence in presenceStream {
print(presence.join) // You can also use presence.decodeJoins(as: MyType.self)
print(presence.leaves) // You can also use presence.decodeLeaves(as: MyType.self)
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -180,6 +208,31 @@ roomOne.subscribe((status, error) async {
});
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let roomOne = await supabase.channel("room_01")
// Using a custom type
let userStatus = UserStatus(
user: "user-1",
onlineAt: Date().timeIntervalSince1970
)
await roomOne.subscribe()
try await roomOne.track(userStatus)
// Or using a raw JSONObject.
await roomOne.track(
[
"user": .string("user-1"),
"onlineAt": .double(Date().timeIntervalSince1970)
]
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -237,6 +290,13 @@ untrackPresence() async {
untrackPresence();
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
await roomOne.untrack()
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -290,6 +350,15 @@ final channelC = supabase.channel(
);
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let channelC = await supabase.channel("test") {
$0.presence.key = "userId-123"
}
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -37,6 +37,17 @@ supabase.storage.from('bucket').getPublicUrl('image.jpg', {
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let url = try await supabase.storage.from("bucket")
.getPublicURL(
path: "image.jpg"
options: TransformOptions(with: 500, height: 600)
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -75,6 +86,21 @@ supabase.storage.from('bucket').createSignedUrl('image.jpg', 60000, {
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let url = try await supabase.storage.from("bucket")
.createSignedURL(
path: "image.jpg",
expiresIn: 60,
transform: TransformOptions(
width: 200,
height: 200
)
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -111,6 +137,20 @@ supabase.storage.from('bucket').download('image.jpg', {
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let data = try await supabase.storage.from("bucket")
.download(
path: "image.jpg",
options: TransformOptions(
width: 800,
height: 300
)
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -164,6 +204,21 @@ await storage.from('bucket').download('image.jpeg', {
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let data = try await supabase.storage.from("bucket")
.download(
path: "image.jpg",
options: TransformOptions(
width: 200,
height: 200,
format: "origin"
)
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -248,6 +303,19 @@ supabase.storage.from('bucket').download('image.jpg', {
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let data = try await supabase.storage.from("bucket")
.download(
path: "image.jpg",
options: TransformOptions(
quality: 50
)
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -303,6 +371,21 @@ supabase.storage.from('bucket').download('image.jpg', {
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
let data = try await supabase.storage.from("bucket")
.download(
path: "image.jpg",
options: TransformOptions(
width: 800,
height: 300,
resize: "contain" // "cover" | "fill"
)
)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -44,6 +44,18 @@ async function uploadFile(file) {
}
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
import Supabase
// Create Supabase client
let supabase = SupabaseClient(supabaseURL: URL(string: "your_project_url")!, supabaseKey: "your_supabase_api_key")
try await supabase.storage.from("bucket_name").upload(path: "file_path", file: file)
```
</TabPanel>
<TabPanel id="kotlin" label="Kotlin">
@@ -88,6 +100,25 @@ await supabase.storage.from('bucket_name').upload('file_path', file, {
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
import Supabase
// Create Supabase client
let supabase = SupabaseClient(supabaseURL: URL(string: "your_project_url")!, supabaseKey: "your_supabase_api_key")
try await supabase.storage.from("bucket_name")
.upload(
path: "file_path",
file: file,
options: FileOptions(
upsert: true
)
)
```
</TabPanel>
</Tabs>
@@ -116,6 +147,25 @@ await supabase.storage.from('bucket_name').upload('file_path', file, {
})
```
</TabPanel>
<TabPanel id="swift" label="Swift">
```swift
import Supabase
// Create Supabase client
let supabase = SupabaseClient(supabaseURL: URL(string: "your_project_url")!, supabaseKey: "your_supabase_api_key")
try await supabase.storage.from("bucket_name")
.upload(
path: "file_path",
file: file,
options: FileOptions(
contentType: "image/jpeg"
)
)
```
</TabPanel>
</Tabs>
+1 -1
View File
@@ -96,7 +96,7 @@ const footerData = [
},
{
text: 'Contributing',
url: '/docs/handbook/contributing',
url: 'https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md',
},
{
text: 'Open Source',
+2 -2
View File
@@ -53,10 +53,10 @@
"# logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)\n",
"# logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))\n",
"\n",
"from llama_index.storage import StorageContext\n",
"from llama_index.core.storage import StorageContext\n",
"from llama_index.readers.web import SimpleWebPageReader\n",
"from llama_index.indices.vector_store import VectorStoreIndex\n",
"from llama_index.vector_stores import SupabaseVectorStore\n",
"from llama_index.vector_stores.supabase import SupabaseVectorStore\n",
"import textwrap\n",
"import html2text"
]