Docs

Swift: Database

Run SQL with bound parameters and select, insert, update, delete and call database functions with the Swift SDK.

Updated Oct 24, 2026

Run SQL with bound parameters and select, insert, update, delete and call database functions. Every call runs as the client's signed-in user, so your project's policies and row-level security apply. Types and members are listed in source order; each one links to its HTTP endpoint where it maps to one.

#Types and members

SqlResult

The result of a SQL statement: the rows, and the raw response.

public struct SqlResult: @unchecked Sendable

SqlResult.rows

A property.

public let rows: [[String: Any]]

SqlResult.raw

A property.

public let raw: [String: Any]

SovariaDatabase

The project's Postgres database. Every value is a bound parameter ($1, $2, …), so user input never becomes SQL; table and column names are checked and quoted. Row security and access policies apply to app users exactly as on the web.

public final class SovariaDatabase: @unchecked Sendable

SovariaDatabase.sql

Run one statement: sql("SELECT * FROM todos WHERE owner = $1", userId).

public func sql(_ statement: String, _ params: [Any] = []) async throws -> SqlResult

SovariaDatabase.rpc

Call one of your Postgres functions: with the arguments by name. A function that returns one value returns that value; one that returns rows returns an array of dictionaries.

public func rpc(_ name: String, args: [String: Any] = [:], get: Bool = false,
                query: [String: Any?]? = nil) async throws -> Any?

App users need an access policy that allows fn:<name>. get calls with GET and the arguments in the query string (functions that only read); query adds PostgREST parameters (select, order, limit, filters such as ["status": "eq.open"]) for functions that return rows.

let n = try await sovaria.db.rpc("post_count", args: ["u": userId]) as? Int

SovariaDatabase.select

SELECT with equality filters.

public func select(_ table: String, columns: [String] = [""], where filters: [String: Any?] = [:],
                   orderBy: String? = nil, descending: Bool = false, limit: Int? = nil, offset: Int? = nil) async throws -> [[String: Any]]

SovariaDatabase.insert

INSERT … RETURNING *.

public func insert(_ table: String, _ values: [String: Any]) async throws -> [[String: Any]]

SovariaDatabase.update

UPDATE … SET … WHERE … RETURNING * (a filter is required).

public func update(_ table: String, _ values: [String: Any], where filters: [String: Any?]) async throws -> [[String: Any]]

SovariaDatabase.delete

DELETE … WHERE … RETURNING * (a filter is required).

public func delete(_ table: String, where filters: [String: Any?]) async throws -> [[String: Any]]