Skip to content

Commit ad61ce7

Browse files
authored
Fix example in README and add platforms to Package.swift (#11)
* Update Package.swift * Update Package.swift * Update Package.swift * Update README.md
1 parent fe1ca00 commit ad61ce7

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

Package.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import PackageDescription
55

66
let package = Package(
77
name: "Supabase",
8+
platforms: [
9+
.macOS(.v10_15),
10+
.iOS(.v11),
11+
.tvOS(.v11),
12+
.watchOS(.v3)
13+
],
814
products: [
915
.library(
1016
name: "Supabase",

README.md

Lines changed: 29 additions & 28 deletions
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")), // Add the package
15+
.package(name: "Supabase", url: "https://github.com/supabase/supabase-swift.git", .branch("master")), // Add the package
1616
],
1717
targets: [
1818
.target(
@@ -37,43 +37,44 @@ This client object will be used for all the following examples.
3737

3838
Query todo table for all completed todos.
3939
```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)")
40+
struct Todo: Codable {
41+
var id: String = UUID().uuidString
42+
var label: String
43+
var isDone: Bool = false
5244
}
5345
```
5446

55-
Insert a todo into the database.
5647
```swift
57-
struct Todo: 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 { [weak self] results in
53+
guard let self = self else { return }
54+
55+
switch results {
56+
case let .success(response):
57+
let todos = try? response.decoded(to: [Todo].self)
58+
print(todos)
59+
case let .failure(error):
60+
print(error.localizedDescription)
61+
}
6162
}
63+
```
64+
65+
Insert a todo into the database.
6266

67+
```swift
6368
let todo = Todo(label: "Example todo!")
6469

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
70+
let jsonData: Data = try JSONEncoder().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
7276
// Handle response
7377
}
74-
} catch {
75-
print("Error inserting the todo: \(error)")
76-
}
7778
```
7879

7980
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

Comments
 (0)