Skip to content

Commit 30dd67d

Browse files
committed
Update documentation, fix naming
Added doc sections to the README.md, including docs for the database, contributing instructions and more thorough installation instructions. Changed `SupabaseClient` to `Supabase`
1 parent 64309c0 commit 30dd67d

File tree

2 files changed

+93
-3
lines changed

2 files changed

+93
-3
lines changed

README.md

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let package = Package(
1212
...
1313
dependencies: [
1414
...
15-
.package(name: "Supabase", url: "https://github.com/supabase/supabase-swift.git", .branch("main")),
15+
.package(name: "Supabase", url: "https://github.com/supabase/supabase-swift.git", .branch("main")), // Add the package
1616
],
1717
targets: [
1818
.target(
@@ -24,3 +24,94 @@ let package = Package(
2424
```
2525

2626
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.
31+
```swift
32+
let client = Supabase(supabaseUrl: "{ Supabase URL }", supabaseKey: "{ Supabase anonymous Key }")
33+
```
34+
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 { [weak self] (results) in
46+
guard let self = self else { 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+
struct Todo: 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 = try JSONEncoder().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.
116+
117+
[![New Sponsor](https://user-images.githubusercontent.com/10214025/90518111-e74bbb00-e198-11ea-8f88-c9e3c1aa4b5b.png)](https://github.com/sponsors/supabase)

Tests/SupabaseTests/SupabaseTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import XCTest
44
@testable import Supabase
55

66
final class SupabaseTests: XCTestCase {
7-
var supabase = Supabase(
8-
supabaseUrl: SupabaseTests.supabaseUrl(), supabaseKey: SupabaseTests.supabaseKey())
7+
var supabase = Supabase(supabaseUrl: SupabaseTests.supabaseUrl(), supabaseKey: SupabaseTests.supabaseKey())
98

109
static func supabaseUrl() -> String {
1110
if let token = ProcessInfo.processInfo.environment["supabaseUrl"] {

0 commit comments

Comments
 (0)