Swift
PotaLabBase is the application client for Swift 5.9+ (iOS 15+, macOS 12+, also Linux). It uses async/await, URLSession and Codable, with no third-party dependencies. It mirrors the JavaScript client.
.package(url: "https://github.com/PotaLab-Dev/base-sdk.git", from: "0.1.0")import PotaLabBase
let base = BaseClient(url: "https://app.example.com", key: "pb_pub_...")try await base.auth.signInWithPassword(email: "ada@example.com", password: "secret")
struct Todo: Codable { var id: Int; var title: String }let todos = try await base.from("todos").select("id,title") .eq("done", false).order("id", ascending: false).limit(20) .execute(as: [Todo].self)
try await base.from("todos").insert(["title": "buy tea"]).execute()- Errors are thrown as
BaseErrorwithcode,status,details,hint,requestId. - Tokens refresh automatically shortly before expiry and once after a 401. Concurrent requests share one refresh.
- Keychain: implement the
SessionStorageprotocol (loadSession,saveSession,removeSession) and pass it assessionStorage:. The default keeps the session in memory only. - Queries:
eq neq gt gte lt lte like ilike in is or not,order,limit,range,single,maybeSingle,asOf, plusinsert,upsert,update,deleteandrpc. - Storage:
base.storage.from("avatars").upload("me.png", data: data), plusdownload,createSignedURL,getPublicURL,list,remove. - Functions:
try await base.functions.invoke("send-welcome", body: ["user_id": "u1"]). - A secret key (
pb_sec_..., server only) is exchanged for a short-livedservice_roletoken, and is never used again once a user session exists. - Not yet in the Swift client: transactions, Realtime, vectors, MFA, passkeys, OAuth and bucket management.