{"id":29536764,"url":"https://github.com/drewalth/pocketbase-swift-sdk","last_synced_at":"2025-07-17T03:09:31.660Z","repository":{"id":304726043,"uuid":"1019151202","full_name":"drewalth/pocketbase-swift-sdk","owner":"drewalth","description":"PocketBase Swift SDK","archived":false,"fork":false,"pushed_at":"2025-07-14T22:49:51.000Z","size":1926,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-15T00:52:11.126Z","etag":null,"topics":["pocketbase","pocketbase-realtime","realtime","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drewalth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-13T21:12:13.000Z","updated_at":"2025-07-14T23:32:58.000Z","dependencies_parsed_at":"2025-07-15T00:52:29.479Z","dependency_job_id":"896e5477-e5c7-44a7-a40f-00887cd59686","html_url":"https://github.com/drewalth/pocketbase-swift-sdk","commit_stats":null,"previous_names":["drewalth/pocketbase-swift-sdk"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/drewalth/pocketbase-swift-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewalth%2Fpocketbase-swift-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewalth%2Fpocketbase-swift-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewalth%2Fpocketbase-swift-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewalth%2Fpocketbase-swift-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drewalth","download_url":"https://codeload.github.com/drewalth/pocketbase-swift-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewalth%2Fpocketbase-swift-sdk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265562379,"owners_count":23788517,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pocketbase","pocketbase-realtime","realtime","swift"],"created_at":"2025-07-17T03:09:30.914Z","updated_at":"2025-07-17T03:09:31.648Z","avatar_url":"https://github.com/drewalth.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pocketbase Swift SDK\n\nA Swift SDK for [Pocketbase](https://pocketbase.io/) v0.28.2.\n\n[![Build](https://github.com/drewalth/pocketbase-swift-sdk/actions/workflows/main.yaml/badge.svg)](https://github.com/drewalth/pocketbase-swift-sdk/actions/workflows/main.yaml) [![Swift](https://img.shields.io/badge/Swift-6.0-orange?style=flat-square)](https://img.shields.io/badge/Swift-6.0-Orange?style=flat-square)\n[![Platforms](https://img.shields.io/badge/Platforms-macOS_iOS-yellowgreen?style=flat-square)](https://img.shields.io/badge/Platforms-macOS_iOS-YellowGreen?style=flat-square)\n\n\n## Features\n\n- ✅ Generic user authentication (supports any model)\n- ✅ User authentication (sign up, sign in, sign out)\n- ✅ Token refresh\n- ✅ Password reset\n- ✅ CRUD operations\n- ✅ Realtime subscriptions\n- ✅ Type-safe data models\n- ✅ Automatic token management (stores tokens securely)\n\n\n\u003e Note: This is a work in progress. The SDK is not yet have 100% feature parity with the [js-sdk](https://github.com/pocketbase/js-sdk) but it's close.\n\u003e Any contributions are welcome!\n\n## Motivation\n\nPocketbase is a great framework for quick prototyping and small scale applications. In an ideal world, Pocketbase would generate Swagger/OpenAPI documentation, but currently it doesn't. And there is [no plan](https://github.com/pocketbase/pocketbase/issues/945) to add it in the future. \n\nThis SDK aims to make it easier to use Pocketbase with Swift projects.\n\n## Installation\n\nAdd the package to your `Package.swift`:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/drewalth/pocketbase-swift-sdk.git\", from: \"1.0.0\")\n]\n```\n\n## Usage\n\n### Basic Setup\n\n```swift\nlet pb = PocketBase(baseURL: \"http://127.0.0.1:8090\")\n```\n\n### Data Models\n\nThe SDK uses generics to support any user model that conforms to `PBIdentifiableCollection`. You need to define your own User models:\n\n```swift\n// Define your User model\nstruct User: PBIdentifiableCollection {\n    let id: String\n    let email: String\n    let username: String?\n    let name: String?\n    let avatar: String?\n    let verified: Bool\n    let created: String\n    let updated: String\n    let collectionId: String\n    let collectionName: String\n    // Add any additional fields your PocketBase user collection has\n}\n```\n\n### Authentication\n\nThe SDK provides comprehensive authentication functionality with generic support:\n\n#### User Authentication\n\n```swift\n// Sign up a new user\nlet createUserDto = CreateUser(\n    email: \"new@drewalth.com\",\n    name: \"Test User\",\n    password: \"password123\",\n    passwordConfirm: \"password123\")\nlet authResult = try await pb.signUp(dto: createUserDto, userType: User.self)\n\n// Sign in with email/username and password\nlet authResult = try await pb.authWithPassword(\n    email: \"user@example.com\",\n    password: \"password123\",\n    userType: User.self\n)\n\n// Refresh authentication token\nlet refreshResult = try await pb.authRefresh(userType: User.self)\n\n// Check authentication status\nif pb.isAuthenticated {\n    print(\"User is authenticated\")\n    print(\"User ID: \\(pb.currentUserId ?? \"Unknown\")\")\n}\n\n// Sign out\npb.signOut()\n```\n\n#### Password Reset and Email Verification\n\n```swift\n// Request password reset\ntry await pb.requestPasswordReset(email: \"user@example.com\")\n\n// Confirm password reset (with token from email)\ntry await pb.confirmPasswordReset(\n    token: \"reset_token_from_email\",\n    password: \"newpassword\",\n    passwordConfirm: \"newpassword\"\n)\n\n// Request email verification\ntry await pb.requestVerification(email: \"user@example.com\")\n\n// Confirm email verification (with token from email)\ntry await pb.confirmVerification(token: \"verification_token_from_email\")\n```\n\n### CRUD Operations\n\n```swift\nlet bookmarksCollection = pb.collection(\"bookmarks\")\n\n// Get a single record\nlet bookmark = try await bookmarksCollection.getOne(id: \"e849z3g13jls740\")\n\n// Get a list of records\nlet bookmarks = try await bookmarksCollection.getList()\n\n// Create a new record\nlet newBookmark = try await bookmarksCollection.create(record: Bookmark(\n    title: \"My First Bookmark\",\n    url: \"https://www.google.com\"\n))\n\n// Update a record\nlet updatedBookmark = try await bookmarksCollection.update(\n    id: newBookmark.id,\n    record: Bookmark(\n        title: \"My Updated Bookmark\",\n        url: \"https://www.google.com\"\n    )\n)\n\n// Delete a record\ntry await bookmarksCollection.delete(id: newBookmark.id)\n```\n\n### Expand Functionality\n\nThe SDK provides powerful expand functionality to include related data in your queries:\n\n#### Basic Expansion\n\n```swift\n// Expand a single field\nlet expandQuery = ExpandQuery(\"author\")\nlet posts = try await pb.getList(\n    collection: \"posts\",\n    model: Post.self,\n    expand: expandQuery\n)\n\n// Expand multiple fields\nlet expandQuery = ExpandQuery(\"author\", \"category\", \"tags\")\nlet posts = try await pb.getList(\n    collection: \"posts\",\n    model: Post.self,\n    expand: expandQuery\n)\n```\n\n#### Nested Expansion\n\n```swift\n// Expand nested relationships\nlet expandQuery = ExpandQuery(\"author.profile\", \"category.parent\")\nlet posts = try await pb.getList(\n    collection: \"posts\",\n    model: Post.self,\n    expand: expandQuery\n)\n```\n\n#### Builder Pattern\n\n```swift\n// Use the builder pattern for complex expansions\nlet expandQuery = ExpandBuilder()\n    .field(\"author\")\n    .field(\"category\")\n    .nested(\"author.profile\")\n    .nested(\"category.parent\")\n    .build()\n\nlet posts = try await pb.getList(\n    collection: \"posts\",\n    model: Post.self,\n    expand: expandQuery\n)\n```\n\n#### Fluent API with Expand\n\n```swift\nlet posts: Collection\u003cPost\u003e = pb.collection(\"posts\")\n\n// Expand with fluent API\nlet expandQuery = ExpandQuery(\"author\", \"category\")\nlet result = try await posts.getList(expand: expandQuery)\n\n// Expand on single record\nlet post = try await posts.getOne(\n    id: \"post-id\",\n    expand: ExpandQuery(\"author.profile\")\n)\n```\n\n#### Conditional Expansion\n\n```swift\nlet builder = ExpandBuilder()\n\nif shouldIncludeAuthor {\n    builder.field(\"author\")\n}\n\nif shouldIncludeCategory {\n    builder.field(\"category\")\n}\n\nlet expandQuery = builder.build()\nlet posts = try await pb.getList(\n    collection: \"posts\",\n    model: Post.self,\n    expand: expandQuery\n)\n```\n\n### Realtime\n\n```swift\nlet realtime = pb.realtime(\n    collection: \"bookmarks\",\n    record: \"*\",\n    onConnect: {\n        print(\"Connected to realtime\")\n    },\n    onDisconnect: {\n        print(\"Disconnected from realtime\")\n    },\n    onEvent: { event in\n        print(\"Received event: \\(event.action) for record: \\(event.record)\")\n    }\n)\n\ntry await realtime.subscribe()\n\n// Unsubscribe from realtime\nrealtime.unsubscribe()\n```\n\n## Data Models\n\nDefine your data models by conforming to `PBCollection`:\n\n```swift\nstruct Bookmark: PBCollection {\n    let id: String\n    let title: String\n    let url: String\n    let created: String\n    let updated: String\n    let collectionId: String\n    let collectionName: String\n}\n```\n\nFor models that need an `id` property (like User and Admin), use `PBIdentifiableCollection`:\n\n```swift\nstruct User: PBIdentifiableCollection {\n    let id: String\n    let email: String\n    // ... other properties\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrewalth%2Fpocketbase-swift-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrewalth%2Fpocketbase-swift-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrewalth%2Fpocketbase-swift-sdk/lists"}