You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This client object will be used for all the following examples.
35
-
36
-
### Database
37
-
38
-
Query todo table for all completed todos.
39
-
```swift
40
-
structTodo: Codable {
41
-
var id: String=UUID().uuidString
42
-
var label: String
43
-
var isDone: Bool=false
44
-
}
45
-
```
46
-
47
-
```swift
48
-
let query =try client.database.from("todos")
49
-
.select()
50
-
.eq(column: "isDone", value: "true")
51
-
52
-
query.execute { [weakself] results in
53
-
guardletself=selfelse { return }
54
-
55
-
switch results {
56
-
caselet .success(response):
57
-
let todos =try? response.decoded(to: [Todo].self)
58
-
print(todos)
59
-
caselet .failure(error):
60
-
print(error.localizedDescription)
61
-
}
62
-
}
63
-
```
64
-
65
-
Insert a todo into the database.
66
31
67
32
```swift
68
-
let todo =Todo(label: "Example todo!")
69
-
70
-
let jsonData: Data =tryJSONEncoder().encode(todo)
71
-
let jsonDict: [String: Any] =try JSONSerialization.jsonObject(with: jsonData, options: .allowFragments))
72
-
73
-
client.database.from("todos")
74
-
.insert(values: jsonDict)
75
-
.execute { results in
76
-
// Handle response
77
-
}
78
-
```
79
-
80
-
For more query examples visit [the Javascript docs](https://supabase.io/docs/reference/javascript/select) to learn more. The API design is a near 1:1 match.
81
-
82
-
Execute an RPC
83
-
```swift
84
-
do {
85
-
try client.database.rpc(fn: "testFunction", parameters: nil).execute { result in
86
-
// Handle result
87
-
}
88
-
} catch {
89
-
print("Error executing the RPC: \(error)")
90
-
}
91
-
```
92
-
93
-
### Realtime
94
-
95
-
> Realtime docs coming soon
96
-
97
-
### Auth
98
-
99
-
Sign up with email and password
100
-
```swift
101
-
client.auth.signUp(email: "[email protected]", password: "password") { result in
0 commit comments