@@ -31,7 +31,16 @@ public final class SupabaseClient: @unchecked Sendable {
3131 public let auth : AuthClient
3232
3333 /// Database client for Supabase.
34- public private( set) lazy var database = PostgrestClient (
34+ @available (
35+ * ,
36+ deprecated,
37+ message: " Direct access to database is deprecated, please use one of the available methods such as, SupabaseClient.from(_:), SupabaseClient.rpc(_:params:), or SupabaseClient.schema(_:). "
38+ )
39+ public var database : PostgrestClient {
40+ rest
41+ }
42+
43+ private lazy var rest = PostgrestClient (
3544 url: databaseURL,
3645 schema: options. db. schema,
3746 headers: defaultHeaders,
@@ -145,6 +154,80 @@ public final class SupabaseClient: @unchecked Sendable {
145154 listenForAuthEvents ( )
146155 }
147156
157+ /// Performs a query on a table or a view.
158+ /// - Parameter table: The table or view name to query.
159+ /// - Returns: A PostgrestQueryBuilder instance.
160+ public func from( _ table: String ) -> PostgrestQueryBuilder {
161+ rest. from ( table)
162+ }
163+
164+ /// Performs a function call.
165+ /// - Parameters:
166+ /// - fn: The function name to call.
167+ /// - params: The parameters to pass to the function call.
168+ /// - count: Count algorithm to use to count rows returned by the function.
169+ /// Only applicable for set-returning functions.
170+ /// - Returns: A PostgrestFilterBuilder instance.
171+ /// - Throws: An error if the function call fails.
172+ public func rpc(
173+ _ fn: String ,
174+ params: some Encodable & Sendable ,
175+ count: CountOption ? = nil
176+ ) throws -> PostgrestFilterBuilder {
177+ try rest. rpc ( fn, params: params, count: count)
178+ }
179+
180+ /// Performs a function call.
181+ /// - Parameters:
182+ /// - fn: The function name to call.
183+ /// - count: Count algorithm to use to count rows returned by the function.
184+ /// Only applicable for set-returning functions.
185+ /// - Returns: A PostgrestFilterBuilder instance.
186+ /// - Throws: An error if the function call fails.
187+ public func rpc(
188+ _ fn: String ,
189+ count: CountOption ? = nil
190+ ) throws -> PostgrestFilterBuilder {
191+ try rest. rpc ( fn, count: count)
192+ }
193+
194+ /// Select a schema to query or perform an function (rpc) call.
195+ ///
196+ /// The schema needs to be on the list of exposed schemas inside Supabase.
197+ /// - Parameter schema: The schema to query.
198+ public func schema( _ schema: String ) -> PostgrestClient {
199+ rest. schema ( schema)
200+ }
201+
202+ /// Returns all Realtime channels.
203+ public var channels : [ RealtimeChannelV2 ] {
204+ get async {
205+ await Array ( realtimeV2. subscriptions. values)
206+ }
207+ }
208+
209+ /// Creates a Realtime channel with Broadcast, Presence, and Postgres Changes.
210+ /// - Parameters:
211+ /// - name: The name of the Realtime channel.
212+ /// - options: The options to pass to the Realtime channel.
213+ public func channel(
214+ _ name: String ,
215+ options: @Sendable ( inout RealtimeChannelConfig ) -> Void = { _ in }
216+ ) async -> RealtimeChannelV2 {
217+ await realtimeV2. channel ( name, options: options)
218+ }
219+
220+ /// Unsubscribes and removes Realtime channel from Realtime client.
221+ /// - Parameter channel: The Realtime channel to remove.
222+ public func removeChannel( _ channel: RealtimeChannelV2 ) async {
223+ await realtimeV2. removeChannel ( channel)
224+ }
225+
226+ /// Unsubscribes and removes all Realtime channels from Realtime client.
227+ public func removeAllChannels( ) async {
228+ await realtimeV2. removeAllChannels ( )
229+ }
230+
148231 deinit {
149232 listenForAuthEventsTask. value? . cancel ( )
150233 }
0 commit comments