Skip to content

Commit

Permalink
chore(docs): update documentation for PostgREST (#339)
Browse files Browse the repository at this point in the history
* code format

* chore: update postgrest documentation

* test: add test for query with nil value

* revert: removal of returning param was breaking change
  • Loading branch information
grdsdev authored Apr 15, 2024
1 parent 7329528 commit 8843529
Show file tree
Hide file tree
Showing 24 changed files with 440 additions and 232 deletions.
3 changes: 1 addition & 2 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--swiftversion 5.7
--swiftversion 5.9
--binarygrouping none
--decimalgrouping none
--hexgrouping none
Expand All @@ -9,4 +9,3 @@
--wrapcollections before-first
--wrapparameters before-first
--extensionacl on-declarations
--maxwidth 100
4 changes: 2 additions & 2 deletions Examples/Examples/AnyJSONView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ extension AnyJSON {
var isPrimitive: Bool {
switch self {
case .null, .bool, .integer, .double, .string:
return true
true
case .object, .array:
return false
false
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions Sources/Auth/AuthError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public enum AuthError: LocalizedError, Sendable, Equatable {

public var errorDescription: String? {
switch self {
case let .api(error): return error.errorDescription ?? error.msg ?? error.error
case .missingExpClaim: return "Missing expiration claim on access token."
case .malformedJWT: return "A malformed JWT received."
case .sessionNotFound: return "Unable to get a valid session."
case .pkce(.codeVerifierNotFound): return "A code verifier wasn't found in PKCE flow."
case .pkce(.invalidPKCEFlowURL): return "Not a valid PKCE flow url."
case .invalidImplicitGrantFlowURL: return "Not a valid implicit grant flow url."
case .missingURL: return "Missing URL."
case .invalidRedirectScheme: return "Invalid redirect scheme."
case let .api(error): error.errorDescription ?? error.msg ?? error.error
case .missingExpClaim: "Missing expiration claim on access token."
case .malformedJWT: "A malformed JWT received."
case .sessionNotFound: "Unable to get a valid session."
case .pkce(.codeVerifierNotFound): "A code verifier wasn't found in PKCE flow."
case .pkce(.invalidPKCEFlowURL): "Not a valid PKCE flow url."
case .invalidImplicitGrantFlowURL: "Not a valid implicit grant flow url."
case .missingURL: "Missing URL."
case .invalidRedirectScheme: "Invalid redirect scheme."
}
}
}
4 changes: 2 additions & 2 deletions Sources/Auth/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ public enum AuthResponse: Codable, Hashable, Sendable {

public var user: User {
switch self {
case let .session(session): return session.user
case let .user(user): return user
case let .session(session): session.user
case let .user(user): user
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Functions/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public enum FunctionsError: Error, LocalizedError {
public var errorDescription: String? {
switch self {
case .relayError:
return "Relay Error invoking the Edge Function"
"Relay Error invoking the Edge Function"
case let .httpError(code, _):
return "Edge Function returned a non-2xx status code: \(code)"
"Edge Function returned a non-2xx status code: \(code)"
}
}
}
Expand Down
10 changes: 0 additions & 10 deletions Sources/PostgREST/Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,3 @@ extension PostgrestClient {
)
}
}

extension PostgrestFilterBuilder {
@available(*, deprecated, renamed: "textSearch(_:value:)")
public func textSearch(
_ column: String,
range: any URLQueryRepresentable
) -> PostgrestFilterBuilder {
textSearch(column, value: range)
}
}
35 changes: 14 additions & 21 deletions Sources/PostgREST/PostgrestClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public final class PostgrestClient: Sendable {

let logger: (any SupabaseLogger)?

/// Initializes a new configuration for the PostgREST client.
/// Creates a PostgREST client.
/// - Parameters:
/// - url: The URL of the PostgREST server.
/// - schema: The schema to use.
/// - headers: The headers to include in requests.
/// - url: URL of the PostgREST endpoint.
/// - schema: Postgres schema to switch to.
/// - headers: Custom headers.
/// - logger: The logger to use.
/// - fetch: The fetch handler to use for requests.
/// - fetch: Custom fetch.
/// - encoder: The JSONEncoder to use for encoding.
/// - decoder: The JSONDecoder to use for decoding.
public init(
Expand Down Expand Up @@ -68,11 +68,11 @@ public final class PostgrestClient: Sendable {

/// Creates a PostgREST client with the specified parameters.
/// - Parameters:
/// - url: The URL of the PostgREST server.
/// - schema: The schema to use.
/// - headers: The headers to include in requests.
/// - url: URL of the PostgREST endpoint.
/// - schema: Postgres schema to switch to.
/// - headers: Custom headers.
/// - logger: The logger to use.
/// - session: The URLSession to use for requests.
/// - fetch: Custom fetch.
/// - encoder: The JSONEncoder to use for encoding.
/// - decoder: The JSONDecoder to use for decoding.
public convenience init(
Expand Down Expand Up @@ -110,24 +110,20 @@ public final class PostgrestClient: Sendable {
return self
}

/// Performs a query on a table or a view.
/// Perform a query on a table or a view.
/// - Parameter table: The table or view name to query.
/// - Returns: A PostgrestQueryBuilder instance.
public func from(_ table: String) -> PostgrestQueryBuilder {
PostgrestQueryBuilder(
configuration: configuration,
request: .init(path: table, method: .get, headers: configuration.headers)
)
}

/// Performs a function call.
/// Perform a function call.
/// - Parameters:
/// - fn: The function name to call.
/// - params: The parameters to pass to the function call.
/// - count: Count algorithm to use to count rows returned by the function.
/// Only applicable for set-returning functions.
/// - Returns: A PostgrestFilterBuilder instance.
/// - Throws: An error if the function call fails.
/// - count: Count algorithm to use to count rows returned by the function. Only applicable for [set-returning functions](https://www.postgresql.org/docs/current/functions-srf.html).
public func rpc(
_ fn: String,
params: some Encodable & Sendable,
Expand All @@ -139,13 +135,10 @@ public final class PostgrestClient: Sendable {
).rpc(params: params, count: count)
}

/// Performs a function call.
/// Perform a function call.
/// - Parameters:
/// - fn: The function name to call.
/// - count: Count algorithm to use to count rows returned by the function.
/// Only applicable for set-returning functions.
/// - Returns: A PostgrestFilterBuilder instance.
/// - Throws: An error if the function call fails.
/// - count: Count algorithm to use to count rows returned by the function. Only applicable for [set-returning functions](https://www.postgresql.org/docs/current/functions-srf.html).
public func rpc(
_ fn: String,
count: CountOption? = nil
Expand Down
Loading

0 comments on commit 8843529

Please sign in to comment.