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
Copy file name to clipboardExpand all lines: README.md
+29-28Lines changed: 29 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ let package = Package(
12
12
...
13
13
dependencies: [
14
14
...
15
-
.package(name: "Supabase", url: "https://github.com/supabase/supabase-swift.git", .branch("main")), // Add the package
15
+
.package(name: "Supabase", url: "https://github.com/supabase/supabase-swift.git", .branch("master")), // Add the package
16
16
],
17
17
targets: [
18
18
.target(
@@ -37,43 +37,44 @@ This client object will be used for all the following examples.
37
37
38
38
Query todo table for all completed todos.
39
39
```swift
40
-
do {
41
-
let query =try client.database.from("todos")
42
-
.select()
43
-
.eq(column: "isDone", value: "true")
44
-
45
-
try query.execute { [weakself] (results) in
46
-
guardletself=selfelse { return }
47
-
48
-
// Handle results
49
-
}
50
-
} catch {
51
-
print("Error querying for todos: \(error)")
40
+
structTodo: Codable {
41
+
var id: String=UUID().uuidString
42
+
var label: String
43
+
var isDone: Bool=false
52
44
}
53
45
```
54
46
55
-
Insert a todo into the database.
56
47
```swift
57
-
structTodo: Codable {
58
-
var id: UUID =UUID()
59
-
var label: String
60
-
var isDone: Bool=false
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
+
}
61
62
}
63
+
```
64
+
65
+
Insert a todo into the database.
62
66
67
+
```swift
63
68
let todo =Todo(label: "Example todo!")
64
69
65
-
do {
66
-
let jsonData: Data =tryJSONEncoder().encode(todo)
67
-
let jsonDict: [String: Any] =try JSONSerialization.jsonObject(with: jsonData, options: .allowFragments))
68
-
69
-
try client.database.from("todos")
70
-
.insert(values: jsonDict)
71
-
.execute { results in
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
72
76
// Handle response
73
77
}
74
-
} catch {
75
-
print("Error inserting the todo: \(error)")
76
-
}
77
78
```
78
79
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.
0 commit comments