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
Added doc sections to the README.md, including docs for the database, contributing instructions and more thorough installation instructions.
Changed `SupabaseClient` to `Supabase`
.package(name: "Supabase", url: "https://github.com/supabase/supabase-swift.git", .branch("main")),// Add the package
16
16
],
17
17
targets: [
18
18
.target(
@@ -24,3 +24,94 @@ let package = Package(
24
24
```
25
25
26
26
If you're using Xcode, [use this guide](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app) to add `supabase-swift` to your project. Use `https://github.com/supabase/supabase-swift.git` for the url when Xcode asks.
27
+
28
+
## Usage
29
+
30
+
For all requests made for supabase, you will need to initialize a `Supabase` object.
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
+
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)")
52
+
}
53
+
```
54
+
55
+
Insert a todo into the database.
56
+
```swift
57
+
structTodo: Codable {
58
+
var id: UUID =UUID()
59
+
var label: String
60
+
var isDone: Bool=false
61
+
}
62
+
63
+
let todo =Todo(label: "Example todo!")
64
+
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
72
+
// Handle response
73
+
}
74
+
} catch {
75
+
print("Error inserting the todo: \(error)")
76
+
}
77
+
```
78
+
79
+
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.
80
+
81
+
Execute an RPC
82
+
```swift
83
+
do {
84
+
try client.database.rpc(fn: "testFunction", parameters: nil).execute { result in
85
+
// Handle result
86
+
}
87
+
} catch {
88
+
print("Error executing the RPC: \(error)")
89
+
}
90
+
```
91
+
92
+
### Realtime
93
+
94
+
> Realtime docs coming soon
95
+
96
+
### Auth
97
+
98
+
> Auth docs coming soon
99
+
100
+
### Storage
101
+
102
+
> Storage docs coming soon
103
+
104
+
105
+
## Contributing
106
+
107
+
- Fork the repo on GitHub
108
+
- Clone the project to your own machine
109
+
- Commit changes to your own branch
110
+
- Push your work back up to your fork
111
+
- Submit a Pull request so that we can review your changes and merge
112
+
113
+
## Sponsors
114
+
115
+
We are building the features of Firebase using enterprise-grade, open source products. We support existing communities wherever possible, and if the products don’t exist we build them and open source them ourselves. Thanks to these sponsors who are making the OSS ecosystem better for everyone.
0 commit comments