Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ semaphore.wait()

## Contributing

- Fork the repo on GitHub
- Clone the project to your own machine
- Commit changes to your own branch
- Push your work back up to your fork
- Submit a Pull request so that we can review your changes and merge
- Fork the repo on GitHub
- Clone the project to your own machine
- Commit changes to your own branch
- Push your work back up to your fork
- Submit a Pull request so that we can review your changes and merge

## License

Expand Down
16 changes: 8 additions & 8 deletions Sources/PostgREST/PostgrestQueryBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class PostgrestQueryBuilder: PostgrestBuilder {
)
}

public func insert(values: Any, upsert: Bool = false, onConflict: String? = nil) -> PostgrestBuilder {
public func insert(values: Any, upsert: Bool = false, onConflict: String? = nil, returning: PostgrestReturningOptions = .representation) -> PostgrestBuilder {
method = "POST"
headers["Prefer"] = upsert ? "return=representation,resolution=merge-duplicates" : "return=representation"
headers["Prefer"] = upsert ? "return=\(returning.rawValue),resolution=merge-duplicates" : "return=\(returning.rawValue)"
if let onConflict = onConflict {
appendSearchParams(name: "on_conflict", value: onConflict)
}
Expand All @@ -29,9 +29,9 @@ public class PostgrestQueryBuilder: PostgrestBuilder {
return self
}

public func upsert(values: Any, onConflict: String? = nil) -> PostgrestBuilder {
public func upsert(values: Any, onConflict: String? = nil, returning: PostgrestReturningOptions = .representation) -> PostgrestBuilder {
method = "POST"
headers["Prefer"] = "return=representation,resolution=merge-duplicates"
headers["Prefer"] = "return=\(returning.rawValue),resolution=merge-duplicates"
if let onConflict = onConflict {
appendSearchParams(name: "on_conflict", value: onConflict)
}
Expand All @@ -40,19 +40,19 @@ public class PostgrestQueryBuilder: PostgrestBuilder {
return self
}

public func update(values: Any) -> PostgrestFilterBuilder {
public func update(values: Any, returning: PostgrestReturningOptions = .representation) -> PostgrestFilterBuilder {
method = "PATCH"
headers["Prefer"] = "return=representation"
headers["Prefer"] = "return=\(returning.rawValue)"
body = values
return PostgrestFilterBuilder(
url: url, queryParams: queryParams, headers: headers, schema: schema, method: method,
body: body
)
}

public func delete() -> PostgrestFilterBuilder {
public func delete(returning: PostgrestReturningOptions = .representation) -> PostgrestFilterBuilder {
method = "DELETE"
headers["Prefer"] = "return=representation"
headers["Prefer"] = "return=\(returning.rawValue)"
return PostgrestFilterBuilder(
url: url, queryParams: queryParams, headers: headers, schema: schema, method: method,
body: body
Expand Down
10 changes: 10 additions & 0 deletions Sources/PostgREST/PostgrestReturningOptions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// Enum of options representing the ways PostgREST can return values from the server.
/// Options are:
/// - minimal => Returns nothing from the server
/// - representation => Returns a copy of the updated data.
///
/// https://postgrest.org/en/v9.0/api.html?highlight=PREFER#insertions-updates
public enum PostgrestReturningOptions: String {
case minimal = "minimal"
case representation = "representation"
}