4
4
This is the main class in this package. Use it to execute queries on a PostgREST instance on Supabase.
5
5
*/
6
6
public class PostgrestClient {
7
- var url : String
8
- var headers : [ String : String ]
9
- var schema : String ?
7
+ /// Configuration for the client
8
+ public var config : PostgrestClientConfig
9
+
10
+ /// Struct for PostgrestClient config options
11
+ public struct PostgrestClientConfig {
12
+ public var url : String
13
+ public var headers : [ String : String ]
14
+ public var schema : String ?
15
+ }
10
16
11
17
/// Initializes the `PostgrestClient` with the correct parameters.
12
18
/// - Parameters:
13
19
/// - url: Url of your supabase db instance
14
20
/// - headers: Headers to include when querying the database. Eg, an authentication header
15
21
/// - schema: Schema ID to use
16
22
public init ( url: String , headers: [ String : String ] = [ : ] , schema: String ? ) {
17
- self . url = url
18
- self . headers = headers
19
- self . schema = schema
23
+ self . config = PostgrestClientConfig ( url: url,
24
+ headers: headers,
25
+ schema: schema)
26
+ }
27
+
28
+ /// Initializes the `PostgrestClient` with a config object
29
+ /// - Parameter config: A `PostgrestClientConfig` struct with the correct parameters
30
+ public init ( config: PostgrestClientConfig ) {
31
+ self . config = config
20
32
}
21
33
22
34
/// Select a table to query from
23
35
/// - Parameter table: The ID of the table to query
24
36
/// - Returns: `PostgrestQueryBuilder`
25
37
public func from( _ table: String ) -> PostgrestQueryBuilder {
26
- return PostgrestQueryBuilder ( url: " \( url) / \( table) " , queryParams: [ ] , headers: headers, schema: schema, method: nil , body: nil )
38
+ return PostgrestQueryBuilder ( url: " \( config . url) / \( table) " , queryParams: [ ] , headers: config . headers, schema: config . schema, method: nil , body: nil )
27
39
}
28
40
29
41
/// Call a stored procedure, aka a "Remote Procedure Call"
@@ -32,6 +44,6 @@ public class PostgrestClient {
32
44
/// - parameters: Parameters to pass to the procedure.
33
45
/// - Returns: `PostgrestTransformBuilder`
34
46
public func rpc( fn: String , parameters: [ String : Any ] ? ) -> PostgrestTransformBuilder {
35
- return PostgrestRpcBuilder ( url: " \( url) /rpc/ \( fn) " , queryParams: [ ] , headers: headers, schema: schema, method: nil , body: nil ) . rpc ( parameters: parameters)
47
+ return PostgrestRpcBuilder ( url: " \( config . url) /rpc/ \( fn) " , queryParams: [ ] , headers: config . headers, schema: config . schema, method: nil , body: nil ) . rpc ( parameters: parameters)
36
48
}
37
49
}
0 commit comments