{"id":13720978,"url":"https://github.com/pkrll/deta-swift","last_synced_at":"2026-01-20T23:43:16.247Z","repository":{"id":39990414,"uuid":"387118690","full_name":"pkrll/deta-swift","owner":"pkrll","description":"🦜 The unofficial Deta SDK for Swift","archived":false,"fork":false,"pushed_at":"2024-05-12T20:22:13.000Z","size":119,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-04T01:14:05.823Z","etag":null,"topics":["deta","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pkrll.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["pkrll"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2021-07-18T07:38:15.000Z","updated_at":"2024-05-12T20:21:58.000Z","dependencies_parsed_at":"2022-09-05T09:30:57.998Z","dependency_job_id":null,"html_url":"https://github.com/pkrll/deta-swift","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkrll%2Fdeta-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkrll%2Fdeta-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkrll%2Fdeta-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pkrll%2Fdeta-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pkrll","download_url":"https://codeload.github.com/pkrll/deta-swift/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224604636,"owners_count":17339173,"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":["deta","swift"],"created_at":"2024-08-03T01:01:10.727Z","updated_at":"2026-01-20T23:43:16.239Z","avatar_url":"https://github.com/pkrll.png","language":"Swift","funding_links":["https://github.com/sponsors/pkrll"],"categories":["SDK's"],"sub_categories":["Swift SDK"],"readme":"\u003cimg alt=\"logo\" src=\"https://user-images.githubusercontent.com/140205/126669572-809c2700-7fcd-4177-9a9d-88721fddc21e.png\"\u003e\n\n[![Swift 5.5](https://img.shields.io/badge/Swift-5.5-orange)](https://www.swift.org/blog/swift-5.5-released/) [![SPM Compatible](https://img.shields.io/badge/SPM-Compatible-success)](https://swift.org/package-manager/) [![Swift](https://github.com/pkrll/deta-swift/actions/workflows/swift.yml/badge.svg)](https://github.com/pkrll/deta-swift/actions/workflows/swift.yml)\n\nDeta-Swift is the unofficial Deta SDK for Swift.\n\n:warning: This package is still under active development and things might and will change. Do not use this package as-is in a production app. :warning:\n\n## Installation\n\nTo use ``Deta-Swift`` in your project, add the following line to your ``Package.swift`` file:\n\n```swift\n.package(url: \"https://github.com/pkrll/deta-swift.git\", from: \"1.0.0\")\n```\n\nAdd the dependency to the targets that will use ``Deta-Swift``:\n\n```swift\nlet package = Package(\n    // ...\n    dependencies: [\n        .package(url: \"https://github.com/pkrll/deta-swift.git\", from: \"1.0.0\")\n        // Other dependencies...\n    ],\n    targets: [\n        .target(\n            name: \"\u003cSomeApp\u003e\",\n            dependencies: [\n                .product(name: \"Deta\", package: \"deta-swift\")\n                // Other dependencies...\n            ]\n        ),\n        // Other targets...\n    ]\n)\n```\n\n## Usage\n\nTo start using Deta, you need to first retrieve your project key. Initialize the Deta object with your project key, and the name of your Deta base:\n\n```swift\nimport Deta\n\nlet deta = Deta(projectKey: \"YourProjectKey\", base: \"SampleDB\")\n```\n\nThe Deta SDK for Swift supports all of Deta's HTTP API endpoints currently available.\n\n#### :warning: Warning :warning:\n\n**Remember that your project key is a secret. Anyone with the key can access and modify your database. This SDK is not meant to be used client side, as it requires the API key to be sent over HTTPs and therefore visible for everyone. Do not commit this key to a public repository.**\n\n### Put Item\n\nThe ``put`` method allows for adding multiple items to the Deta base in a single request. Your models must conform to the ``DetaModel`` protocol.\n\n```swift\nstruct SomeModel: DetaModel {\n    let key: String?\n    let title: String\n}\n\nlet items = [\n    SomeModel(key: \"1\", title: \"First item\"),\n    SomeModel(key: \"2\", title: \"Second item\")\n]\n\nlet response = try await deta.put(items: items)\n// response.processed contains all items that were successfully added.\n// response.failed contains any item that failed due to internal processing.\n```\n\nFor more information, please see the documentation for [Put Item](https://docs.deta.sh/docs/base/http/#put-item) on Deta Docs.\n\n### Get Item\n\nThe ``get`` method retrieves a single item from the Deta base. This method requires a specific model type specified when retrieving. The return value must conform to your model, otherwise an error is returned.\n\nIf the item does not exist, an error will be returned.\n\n```swift\nstruct SomeModel: DetaModel {\n    let key: String?\n    let title: String\n}\n\nlet model = try await deta.get(model: SomeModel.self, key: \"1\")\n```\n\nFor more information, please see the documentation for [Get Item](https://docs.deta.sh/docs/base/http/#get-item) on Deta Docs.\n\n### Delete Item\n\nThe ``delete`` method deletes an item from the Deta base. Regardless of whether the item exists or not, a successful response will be returned.\n\n```swift\ntry await deta.delete(key: \"1\")\n```\n\nFor more information, please see the documentation for [Delete Item](https://docs.deta.sh/docs/base/http/#delete-item) on Deta Docs.\n\n### Insert Item\n\nThe ``insert`` method inserts a single item into the Deta Base. If an item with the same key already exists, an error will be returned.\n\n```swift\nstruct SomeModel: Fetchable {\n    let key: String?\n    let title: String\n}\n\nlet itemToInsert = SomeModel(key: \"1\", title: \"First item\")\nlet insertedItem = try await deta.insert(itemToInsert)\n```\n\nFor more information, please see the documentation for [Insert Item](https://docs.deta.sh/docs/base/http/#insert-item) on Deta Docs.\n\n### Fetch Item\n\nThe ``fetch`` method retrieves items that matches some predicate. The predicate is a collection of `Query` objects. For more information on queries, please consult the [Deta docs](https://docs.deta.sh/docs/base/sdk/#queries).\n\n``Deta-Swift`` has support for the following operators:\n\n**Equals**:\n\n```swift\nQuery(_: String, equals: AnyEncodable)\n```\n\n**Less Than**\n\n```swift\nQuery(_: String, isLessThan: AnyEncodable)\nQuery(_: String, isLessThanOrEqualsTo: AnyEncodable)\n```\n\n**Greater than**\n\n```swift\nQuery(_: String, isGreaterThan: AnyEncodable)\nQuery(_: String, isGreaterThanOrEqualsTo: AnyEncodable)\n```\n\n**Prefix**\n\n```swift\nQuery(_: String, hasPrefix: AnyEncodable)\n```\n\n**Range**\n\n```swift\nQuery(_: String, isBetween: ClosedRange\u003cInt\u003e)\nQuery(_: String, isBetween: ClosedRange\u003cDouble\u003e)\n```\n\n**Contains**\n\n```swift\nQuery(_: String, contains: AnyEncodable)\nQuery(_: String, doesNotContain: AnyEncodable)\n```\n\n`Query` objects can be grouped using `GroupedQueries`:\n\n```swift\nGroupedQueries {\n    Query(\"someField\", contains: \"Some value\")\n    Query(\"someOtherField\", isGreaterThan: 13)\n}\n```\n\nGrouping queries are equivalent to ``OR``, while multiple groups of queries will be `AND`ed.\n\n```swift\nstruct SomeModel: Fetchable {\n    let key: String?\n    let title: String\n    let year: Int\n}\n\n// Fetch items that satisfies the following:\n// - Title contains \"some value\" AND year equals to 1988, OR:\n// - Year ranges between 2000 and 2010\nlet response1 = try await deta.fetch(model: SomeModel.self) {\n    GroupedQueries {\n        Query(\"title\", contains: \"Some value\")\n        Query(\"year\", equals: \"1988\")\n    }\n    \n    GroupedQueries {\n        Query(\"year\", isBetween: 2000...2010)\n    }\n}\n\n// Fetch items that satisfies the following:\n// - Title contains \"some value\" AND\n// - Year is less than 1960\nlet response2 = try await deta.fetch(model: SomeModel.self) {\n    Query(\"title\", contains: \"Some value\")\n    Query(\"year\", isLessThan: 1960)\n}\n```\n\nFor more information, please see the documentation for [Query Item](https://docs.deta.sh/docs/base/http/#query-item) on Deta Docs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkrll%2Fdeta-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpkrll%2Fdeta-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpkrll%2Fdeta-swift/lists"}