{"id":31962148,"url":"https://github.com/pointfreeco/sqlite-data","last_synced_at":"2026-01-28T22:01:05.558Z","repository":{"id":277607022,"uuid":"902097949","full_name":"pointfreeco/sqlite-data","owner":"pointfreeco","description":"A fast, lightweight replacement for SwiftData, powered by SQL and supporting CloudKit synchronization.","archived":false,"fork":false,"pushed_at":"2026-01-24T03:36:28.000Z","size":2932,"stargazers_count":1549,"open_issues_count":18,"forks_count":76,"subscribers_count":22,"default_branch":"main","last_synced_at":"2026-01-24T13:58:20.641Z","etag":null,"topics":["cloudkit","database","observation","persistence","sql","sqlite","swiftdata","swiftui","synchronization"],"latest_commit_sha":null,"homepage":"https://www.pointfree.co","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/pointfreeco.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-12-11T22:44:01.000Z","updated_at":"2026-01-23T22:42:21.000Z","dependencies_parsed_at":"2026-01-21T20:05:52.282Z","dependency_job_id":null,"html_url":"https://github.com/pointfreeco/sqlite-data","commit_stats":null,"previous_names":["pointfreeco/sharing-grdb","pointfreeco/sqlite-data"],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/pointfreeco/sqlite-data","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointfreeco%2Fsqlite-data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointfreeco%2Fsqlite-data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointfreeco%2Fsqlite-data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointfreeco%2Fsqlite-data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pointfreeco","download_url":"https://codeload.github.com/pointfreeco/sqlite-data/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointfreeco%2Fsqlite-data/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28853194,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T15:15:36.453Z","status":"ssl_error","status_checked_at":"2026-01-28T15:15:13.020Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cloudkit","database","observation","persistence","sql","sqlite","swiftdata","swiftui","synchronization"],"created_at":"2025-10-14T16:35:21.512Z","updated_at":"2026-01-28T22:01:05.551Z","avatar_url":"https://github.com/pointfreeco.png","language":"Swift","readme":"# SQLiteData\n\nA [fast](#Performance), lightweight replacement for SwiftData, powered by SQL and supporting\nCloudKit synchronization.\n\n[![CI](https://github.com/pointfreeco/sqlite-data/actions/workflows/ci.yml/badge.svg)](https://github.com/pointfreeco/sqlite-data/actions/workflows/ci.yml)\n[![Slack](https://img.shields.io/badge/slack-chat-informational.svg?label=Slack\u0026logo=slack)](https://www.pointfree.co/slack-invite)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fpointfreeco%2Fsqlite-data%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/pointfreeco/sqlite-data)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fpointfreeco%2Fsqlite-data%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/pointfreeco/sqlite-data)\n\n  * [Learn more](#Learn-more)\n  * [Overview](#Overview)\n  * [Quick start](#Quick-start)\n  * [Performance](#Performance)\n  * [SQLite knowledge required](#SQLite-knowledge-required)\n  * [Overview](#Overview)\n  * [Demos](#Demos)\n  * [Documentation](#Documentation)\n  * [Installation](#Installation)\n  * [Community](#Community)\n  * [License](#License)\n\n## Learn more\n\nThis library was motivated and designed over the course of many episodes on\n[Point-Free](https://www.pointfree.co), a video series exploring advanced programming topics in the\nSwift language, hosted by [Brandon Williams](https://twitter.com/mbrandonw) and\n[Stephen Celis](https://twitter.com/stephencelis). To support the continued development of this\nlibrary, [subscribe today](https://www.pointfree.co/pricing).\n\n\u003ca href=\"https://www.pointfree.co/collections/modern-persistence\"\u003e\n  \u003cimg alt=\"video poster image\" src=\"https://d3rccdn33rt8ze.cloudfront.net/episodes/0325.jpeg\" width=\"600\"\u003e\n\u003c/a\u003e\n\n## Overview\n\nSQLiteData is a [fast](#performance), lightweight replacement for SwiftData, including CloudKit\nsynchronization (and even CloudKit sharing), built on top of the popular [GRDB] library.\nTo populate data from the database you can use `@Table` and `@FetchAll`, which are\nsimilar to SwiftData's `@Model` and `@Query`:\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003cth\u003eSQLiteData\u003c/th\u003e\n\u003cth\u003eSwiftData\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr valign=top\u003e\n\u003ctd width=415\u003e\n\n```swift\n@FetchAll\nvar items: [Item]\n\n@Table\nstruct Item {\n  let id: UUID\n  var title = \"\"\n  var isInStock = true\n  var notes = \"\"\n}\n```\n\n\u003c/td\u003e\n\u003ctd width=415\u003e\n\n```swift\n@Query\nvar items: [Item]\n\n@Model\nclass Item {\n  var title: String\n  var isInStock: Bool\n  var notes: String\n  init(\n    title: String = \"\",\n    isInStock: Bool = true,\n    notes: String = \"\"\n  ) {\n    self.title = title\n    self.isInStock = isInStock\n    self.notes = notes\n  }\n}\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\nBoth of the above examples fetch items from an external data store using Swift data types, and both\nare automatically observed by SwiftUI so that views are recomputed when the external data changes,\nbut SQLiteData is powered directly by SQLite and is usable from UIKit, `@Observable` models, and\nmore.\n\nFor more information on SQLiteData's querying capabilities, see\n[Fetching model data][fetching-article].\n\n## Quick start\n\nBefore SQLiteData's property wrappers can fetch data from SQLite, you need to provide–at\nruntime–the default database it should use. This is typically done as early as possible in your\napp's lifetime, like the app entry point in SwiftUI, and is analogous to configuring model storage\nin SwiftData:\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003cth\u003eSQLiteData\u003c/th\u003e\n\u003cth\u003eSwiftData\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr valign=top\u003e\n\u003ctd width=415\u003e\n\n```swift\n@main\nstruct MyApp: App {\n  init() {\n    prepareDependencies {\n      let db = try! DatabaseQueue(\n        // Create/migrate a database\n        // connection\n      )\n      $0.defaultDatabase = db\n    }\n  }\n  // ...\n}\n```\n\n\u003c/td\u003e\n\u003ctd width=415\u003e\n\n```swift\n@main\nstruct MyApp: App {\n  let container = {\n    // Create/configure a container\n    try! ModelContainer(/* ... */)\n  }()\n\n  var body: some Scene {\n    WindowGroup {\n      ContentView()\n        .modelContainer(container)\n    }\n  }\n}\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n\u003e [!NOTE]\n\u003e For more information on preparing a SQLite database, see\n\u003e [Preparing a SQLite database][preparing-db-article].\n\nThis `defaultDatabase` connection is used implicitly by SQLiteData's strategies, like\n[`@FetchAll`][fetchall-docs] and [`@FetchOne`][fetchone-docs], which are similar to SwiftData's\n`@Query` macro, but more powerful:\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003cth\u003eSQLiteData\u003c/th\u003e\n\u003cth\u003eSwiftData\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr valign=top\u003e\n\u003ctd width=415\u003e\n\n```swift\n@FetchAll\nvar items: [Item]\n\n@FetchAll(Item.order(by: \\.title))\nvar items\n\n@FetchAll(Item.where(\\.isInStock))\nvar items\n\n\n\n@FetchAll(Item.order(by: \\.isInStock))\nvar items\n\n@FetchOne(Item.count())\nvar itemsCount = 0\n\n```\n\n\u003c/td\u003e\n\u003ctd width=415\u003e\n\n```swift\n@Query\nvar items: [Item]\n\n@Query(sort: [SortDescriptor(\\.title)])\nvar items: [Item]\n\n@Query(filter: #Predicate\u003cItem\u003e {\n  $0.isInStock\n})\nvar items: [Item]\n\n// No @Query equivalent of ordering\n// by boolean column.\n\n// No @Query equivalent of counting\n// entries in database without loading\n// all entries.\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\nAnd you can access this database throughout your application in a way similar to how one accesses\na model context, via a property wrapper:\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003cth\u003eSQLiteData\u003c/th\u003e\n\u003cth\u003eSwiftData\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr valign=top\u003e\n\u003ctd width=415\u003e\n\n```swift\n@Dependency(\\.defaultDatabase)\nvar database\n\nlet newItem = Item(/* ... */)\ntry database.write { db in\n  try Item.insert { newItem }\n    .execute(db))\n}\n```\n\n\u003c/td\u003e\n\u003ctd width=415\u003e\n\n```swift\n@Environment(\\.modelContext)\nvar modelContext\n\nlet newItem = Item(/* ... */)\nmodelContext.insert(newItem)\ntry modelContext.save()\n\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n\u003e [!NOTE]\n\u003e For more information on how SQLiteData compares to SwiftData, see\n\u003e [Comparison with SwiftData][comparison-swiftdata-article].\n\nFurther, if you want to synchronize the local database to CloudKit so that it is available on\nall your user's devices, simply configure a `SyncEngine` in the entry point of the app:\n\n```swift\n@main\nstruct MyApp: App {\n  init() {\n    prepareDependencies {\n      $0.defaultDatabase = try! appDatabase()\n      $0.defaultSyncEngine = SyncEngine(\n        for: $0.defaultDatabase,\n        tables: Item.self\n      )\n    }\n  }\n  // ...\n}\n```\n\n\u003e [!NOTE]\n\u003e For more information on synchronizing the database to CloudKit and sharing records with iCloud\n\u003e users, see [CloudKit Synchronization].\n\nThis is all you need to know to get started with SQLiteData, but there's much more to learn. Read\nthe [articles][articles] below to learn how to best utilize this library:\n\n  * [Fetching model data][fetching-article]\n  * [Observing changes to model data][observing-article]\n  * [Preparing a SQLite database][preparing-db-article]\n  * [Dynamic queries][dynamic-queries-article]\n  * [CloudKit Synchronization]\n  * [Comparison with SwiftData][comparison-swiftdata-article]\n\n[observing-article]: https://swiftpackageindex.com/pointfreeco/sqlite-data/main/documentation/sqlitedata/observing\n[dynamic-queries-article]: https://swiftpackageindex.com/pointfreeco/sqlite-data/main/documentation/sqlitedata/dynamicqueries\n[articles]: https://swiftpackageindex.com/pointfreeco/sqlite-data/main/documentation/sqlitedata#Essentials\n[comparison-swiftdata-article]: https://swiftpackageindex.com/pointfreeco/sqlite-data/main/documentation/sqlitedata/comparisonwithswiftdata\n[fetching-article]: https://swiftpackageindex.com/pointfreeco/sqlite-data/main/documentation/sqlitedata/fetching\n[preparing-db-article]: https://swiftpackageindex.com/pointfreeco/sqlite-data/main/documentation/sqlitedata/preparingdatabase\n[CloudKit Synchronization]: https://swiftpackageindex.com/pointfreeco/sqlite-data/main/documentation/sqlitedata/cloudkit\n[fetchall-docs]: https://swiftpackageindex.com/pointfreeco/sqlite-data/main/documentation/sqlitedata/fetchall\n[fetchone-docs]: https://swiftpackageindex.com/pointfreeco/sqlite-data/main/documentation/sqlitedata/fetchone\n\n## Performance\n\nSQLiteData leverages high-performance decoding from [StructuredQueries][] to turn fetched data into\nyour Swift domain types, and has a performance profile similar to invoking SQLite's C APIs directly.\n\nSee the following benchmarks against\n[Lighter's performance test suite](https://github.com/Lighter-swift/PerformanceTestSuite) for a\ntaste of how it compares:\n\n```\nOrders.fetchAll                           setup    rampup   duration\n   SQLite (generated by Enlighter 1.4.10) 0        0.144    7.183\n   Lighter (1.4.10)                       0        0.164    8.059\n┌──────────────────────────────────────────────────────────────────┐\n│  SQLiteData (1.0.0)                     0        0.172    8.511  │\n└──────────────────────────────────────────────────────────────────┘\n   GRDB (7.4.1, manual decoding)          0        0.376    18.819\n   SQLite.swift (0.15.3, manual decoding) 0        0.564    27.994\n   SQLite.swift (0.15.3, Codable)         0        0.863    43.261\n   GRDB (7.4.1, Codable)                  0.002    1.07     53.326\n```\n\n## SQLite knowledge required\n\nSQLite is one of the\n[most established and widely distributed](https://www.sqlite.org/mostdeployed.html) pieces of\nsoftware in the history of software. Knowledge of SQLite is a great skill for any app developer to\nhave, and this library does not want to conceal it from you. So, we feel that to best wield this\nlibrary you should be familiar with the basics of SQLite, including schema design and normalization,\nSQL queries, including joins and aggregates, and performance, including indices.\n\nWith some basic knowledge you can apply this library to your database schema in order to query\nfor data and keep your views up-to-date when data in the database changes, and you can use\n[StructuredQueries][] to build queries, either using its type-safe, discoverable\n[query building APIs][], or using its `#sql` macro for writing [safe SQL strings][].\n\nFurther, this library is built on the popular and battle-tested [GRDB] library for\ninteracting with SQLite, such as executing queries and observing the database for changes.\n\n[StructuredQueries]: https://github.com/pointfreeco/swift-structured-queries\n[GRDB]: https://github.com/groue/GRDB.swift\n[query building APIs]: https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore\n[safe SQL strings]: https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/safesqlstrings\n\n## Demos\n\nThis repo comes with _lots_ of examples to demonstrate how to solve common and complex problems with\nSQLiteData. Check out [this](./Examples) directory to see them all, including:\n\n* [**Case Studies**](./Examples/CaseStudies)\n  \u003cbr\u003e Demonstrates how to solve some common application problems in an isolated environment, in\n  both SwiftUI and UIKit. Things like animations, dynamic queries, database transactions, and more.\n\n* [**CloudKitDemo**](./Examples/CloudKitDemo)\n  \u003cbr\u003e A simplified demo that shows how to synchronize a SQLite database to CloudKit and how to\n  share records with other iCloud users. See our dedicated articles on [CloudKit Synchronization]\n  and [CloudKit Sharing] for more information.\n\n  [CloudKit Synchronization]: https://swiftpackageindex.com/pointfreeco/sqlite-data/main/documentation/sqlitedata/cloudkit\n  [CloudKit Sharing]: https://swiftpackageindex.com/pointfreeco/sqlite-data/main/documentation/sqlitedata/cloudkitsharing\n\n* [**Reminders**](./Examples/Reminders)\n  \u003cbr\u003e A rebuild of Apple's [Reminders][reminders-app-store] app that uses a SQLite database to\n  model the reminders, lists and tags. It features many advanced queries, such as searching, stats\n  aggregation, and multi-table joins. It also features CloudKit synchronization and sharing.\n\n* [**SyncUps**](./Examples/SyncUps)\n  \u003cbr\u003e This application is a faithful reconstruction of one of Apple's more interesting sample\n  projects, called [Scrumdinger][scrumdinger], and uses SQLite to persist the data for meetings.\n  We have also added CloudKit synchronization so that all changes are automatically made available\n  on all of the user's devices.\n\n[Scrumdinger]: https://developer.apple.com/tutorials/app-dev-training/getting-started-with-scrumdinger\n[reminders-app-store]: https://apps.apple.com/us/app/reminders/id1108187841\n\n## Documentation\n\nThe documentation for releases and `main` are available here:\n\n  * [`main`](https://swiftpackageindex.com/pointfreeco/sqlite-data/main/documentation/sqlitedata/)\n  * [1.x.x](https://swiftpackageindex.com/pointfreeco/sqlite-data/~/documentation/sqlitedata/)\n\n## Installation\n\nYou can add SQLiteData to an Xcode project by adding it to your project as a package…\n\n\u003e https://github.com/pointfreeco/sqlite-data\n\n…and adding the `SQLiteData` product to your target.\n\nIf you want to use SQLiteData in a [SwiftPM](https://swift.org/package-manager/) project, it's as\nsimple as adding it to your `Package.swift`:\n\n``` swift\ndependencies: [\n  .package(url: \"https://github.com/pointfreeco/sqlite-data\", from: \"1.0.0\")\n]\n```\n\nAnd then adding the following product to any target that needs access to the library:\n\n```swift\n.product(name: \"SQLiteData\", package: \"sqlite-data\"),\n```\n\n## Community\n\nIf you want to discuss this library or have a question about how to use it to solve a particular\nproblem, there are a number of places you can discuss with fellow\n[Point-Free](http://www.pointfree.co) enthusiasts:\n\n  * For long-form discussions, we recommend the\n    [discussions](http://github.com/pointfreeco/sqlite-data/discussions) tab of this repo.\n\n  * For casual chat, we recommend the\n    [Point-Free Community Slack](http://www.pointfree.co/slack-invite).\n\n## License\n\nThis library is released under the MIT license. See [LICENSE](LICENSE) for details.\n","funding_links":[],"categories":["Swift"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpointfreeco%2Fsqlite-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpointfreeco%2Fsqlite-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpointfreeco%2Fsqlite-data/lists"}