{"id":28909138,"url":"https://github.com/pointfreeco/swift-structured-queries","last_synced_at":"2026-02-20T02:01:36.382Z","repository":{"id":289135496,"uuid":"905508028","full_name":"pointfreeco/swift-structured-queries","owner":"pointfreeco","description":"Truly type-safe SQL.","archived":false,"fork":false,"pushed_at":"2026-02-19T02:27:43.000Z","size":917,"stargazers_count":320,"open_issues_count":5,"forks_count":54,"subscribers_count":19,"default_branch":"main","last_synced_at":"2026-02-19T07:41:02.958Z","etag":null,"topics":["database","macros","query-builder","sql","swift","type-safe"],"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-19T01:14:25.000Z","updated_at":"2026-02-13T17:21:17.000Z","dependencies_parsed_at":"2025-04-21T18:41:26.508Z","dependency_job_id":"6e246578-7955-4dd6-b32e-f24da012c984","html_url":"https://github.com/pointfreeco/swift-structured-queries","commit_stats":null,"previous_names":["pointfreeco/swift-structured-queries"],"tags_count":43,"template":false,"template_full_name":null,"purl":"pkg:github/pointfreeco/swift-structured-queries","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointfreeco%2Fswift-structured-queries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointfreeco%2Fswift-structured-queries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointfreeco%2Fswift-structured-queries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointfreeco%2Fswift-structured-queries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pointfreeco","download_url":"https://codeload.github.com/pointfreeco/swift-structured-queries/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pointfreeco%2Fswift-structured-queries/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29638772,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T22:32:43.237Z","status":"online","status_checked_at":"2026-02-20T02:00:07.535Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["database","macros","query-builder","sql","swift","type-safe"],"created_at":"2025-06-21T17:07:33.223Z","updated_at":"2026-02-20T02:01:36.375Z","avatar_url":"https://github.com/pointfreeco.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# StructuredQueries\n\n[![CI](https://github.com/pointfreeco/swift-structured-queries/actions/workflows/ci.yml/badge.svg)](https://github.com/pointfreeco/swift-structured-queries/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%2Fswift-structured-queries%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/pointfreeco/swift-structured-queries)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fpointfreeco%2Fswift-structured-queries%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/pointfreeco/swift-structured-queries)\n\nA library for building SQL in a safe, expressive, and composable manner.\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/sqlite/sql-building\"\u003e\n  \u003cimg alt=\"video poster image\" src=\"https://d3rccdn33rt8ze.cloudfront.net/episodes/0315.jpeg\" width=\"600\"\u003e\n\u003c/a\u003e\n\n## Overview\n\nStructuredQueries provides a suite of tools that empower you to write safe, expressive, composable\nSQL with Swift. By simply attaching macros to types that represent your database schema:\n\n```swift\n@Table\nstruct Reminder {\n  let id: Int\n  var title = \"\"\n  var isCompleted = false\n  var priority: Int?\n  var dueDate: Date?\n}\n```\n\nYou get instant access to a rich set of query building APIs, from simple:\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003cth\u003eSwift\u003c/th\u003e\n\u003cth\u003eSQL\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr valign=top\u003e\n\u003ctd width=415\u003e\n\n```swift\nReminder.all\n// =\u003e [Reminder]\n```\n\n\u003c/td\u003e\n\u003ctd width=415\u003e\n\n```sql\nSELECT\n  \"reminders\".\"id\",\n  \"reminders\".\"title\",\n  \"reminders\".\"isCompleted\",\n  \"reminders\".\"priority\",\n  \"reminders\".\"dueDate\"\nFROM \"reminders\"\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\nTo complex:\n\n\u003ctable\u003e\n\u003ctr\u003e\n\u003cth\u003eSwift\u003c/th\u003e\n\u003cth\u003eSQL\u003c/th\u003e\n\u003c/tr\u003e\n\u003ctr valign=top\u003e\n\u003ctd width=415\u003e\n\n```swift\nReminder\n  .select {\n     ($0.priority,\n      $0.title.groupConcat())\n  }\n  .where { !$0.isCompleted }\n  .group(by: \\.priority)\n  .order { $0.priority.desc() }\n// =\u003e [(Int?, String)]\n```\n\n\u003c/td\u003e\n\u003ctd width=415\u003e\n\n```sql\nSELECT\n  \"reminders\".\"priority\",\n  group_concat(\"reminders\".\"title\")\nFROM \"reminders\"\nWHERE (NOT \"reminders\".\"isCompleted\")\nGROUP BY \"reminders\".\"priority\"\nORDER BY \"reminders\".\"priority\" DESC\n```\n\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\nThese APIs help you avoid runtime issues caused by typos and type errors, but they still embrace SQL\nfor what it is. StructuredQueries is not an ORM or a new query language you have to learn: its APIs\nare designed to read closely to the SQL it generates, though they are often more succinct, and\nalways safer.\n\nYou are also never constrained by the query builder. You are free to introduce _safe_ SQL strings at\nthe granularity of your choice using the `#sql` macro. From small expressions:\n\n```swift\nReminder.where {\n  !$0.isCompleted \u0026\u0026 #sql(\"\\($0.dueDate) \u003c date()\")\n}\n```\n\nTo entire statements:\n\n```swift\n#sql(\n  \"\"\"\n  SELECT \\(Reminder.columns) FROM \\(Reminder.self)\n  WHERE \\(Reminder.priority) \u003e= \\(selectedPriority)\n  \"\"\",\n  as: Reminder.self\n)\n```\n\nThe library supports building everything from `SELECT`, `INSERT`, `UPDATE`, and `DELETE` statements,\nto type-safe outer joins and recursive common table expressions. To learn more about building SQL\nwith StructuredQueries, check out the\n[documentation](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/).\n\n\u003e [!IMPORTANT]\n\u003e This library does not come with any database drivers for making actual database requests, _e.g._,\n\u003e to SQLite, Postgres, MySQL. This library focuses only on building SQL statements and providing the\n\u003e tools to integrate with another library that makes the actual database requests. See\n\u003e [Database drivers](#database-drivers) for more information.\n\n## Documentation\n\nThe documentation for the latest unstable and stable releases are available here:\n\n  * [`main`](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/main/documentation/structuredqueriescore/)\n  * [0.x.x](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/)\n\nThere are a number of articles in the documentation that you may find helpful as you become more\ncomfortable with the library:\n\n  * [Getting started](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/gettingstarted)\n  * [Defining your schema](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/definingyourschema)\n  * [Primary-keyed tables](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/primarykeyedtables)\n  * [Safe SQL strings](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/safesqlstrings)\n  * [Query cookbook](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/querycookbook)\n\nAs well as more comprehensive example usage:\n\n  * [Selects](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/selectstatements)\n  * [Inserts](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/insertstatements)\n  * [Updates](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/updatestatements)\n  * [Deletes](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/deletestatements)\n  * [\"Where\" clauses](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/whereclauses)\n  * [Common table expressions](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/commontableexpressions)\n  * [Aggregate functions](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/aggregatefunctions)\n  * [Operators](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/operators)\n  * [Scalar functions](https://swiftpackageindex.com/pointfreeco/swift-structured-queries/~/documentation/structuredqueriescore/scalarfunctions)\n\n## Demos\n\nThere are a number of sample applications that demonstrate how to use StructuredQueries in the\n[SQLiteData](https://github.com/pointfreeco/sqlite-data) repo. Check out\n[this](https://github.com/pointfreeco/sqlite-data/tree/main/Examples) directory to see them all,\nincluding:\n\n  * [Case Studies](https://github.com/pointfreeco/sqlite-data/tree/main/Examples/CaseStudies):\n    A number of case studies demonstrating the built-in features of the library.\n\n  * [Reminders](https://github.com/pointfreeco/sqlite-data/tree/main/Examples/Reminders): A rebuild\n    of Apple's [Reminders][reminders-app-store] app that uses a SQLite database to model the\n    reminders, lists and tags. It features many advanced queries, such as searching, and stats\n    aggregation.\n\n  * [SyncUps](https://github.com/pointfreeco/sqlite-data/tree/main/Examples/SyncUps): We also\n    rebuilt Apple's [Scrumdinger][scrumdinger] demo application using modern, best practices for\n    SwiftUI development, including using this library to query and persist state using SQLite.\n\n[reminders-app-store]: https://apps.apple.com/us/app/reminders/id1108187841\n[scrumdinger]: https://developer.apple.com/tutorials/app-dev-training/getting-started-with-scrumdinger\n\n## Database drivers\n\nStructuredQueries is built with the goal of supporting any SQL database (SQLite, MySQL, Postgres,\n_etc._), but is currently tuned to work with SQLite. It currently has one official driver:\n\n  * [SQLiteData](https://github.com/pointfreeco/sqlite-data): A lightweight replacement for\n    SwiftData and the `@Query` macro. SQLiteData includes `StructuredQueriesGRDB`, a library that\n    integrates this one with the popular [GRDB](https://github.com/groue/GRDB.swift) SQLite library.\n\nIf you are interested in building a StructuredQueries integration for another database library,\nplease see [Integrating with database libraries][sq-docs-integration], and\n[start a discussion](http://github.com/pointfreeco/swift-structured-queries/discussions/new/choose)\nto let us know of any challenges you encounter.\n\n[sq-docs-integration]: https://swiftpackageindex.com/pointfreeco/swift-structured-queries/main/documentation/structuredqueriescore/integration\n\n## Installation\n\nYou can add StructuredQueries to an Xcode project by adding it to your project as a package.\n\n\u003e https://github.com/pointfreeco/swift-structured-queries\n\nIf you want to use StructuredQueries in a [SwiftPM](https://swift.org/package-manager/) project,\nit's as simple as adding it to your `Package.swift`:\n\n``` swift\ndependencies: [\n  .package(url: \"https://github.com/pointfreeco/swift-structured-queries\", from: \"0.22.0\"),\n]\n```\n\nAnd then adding the product to any target that needs access to the library:\n\n```swift\n.product(name: \"StructuredQueries\", package: \"swift-structured-queries\"),\n```\n\nIf you are on Swift 6.1 or greater, you can enable package traits that extend the library with\nsupport for other libraries:\n\n  * `StructuredQueriesCasePaths`: Adds support for single-table inheritance _via_ \"enum\" tables by\n    leveraging the [CasePaths](https://github.com/pointfreeco/swift-case-paths) library.\n\n  * `StructuredQueriesTagged`: Adds support for type-safe identifiers _via_\n    the [Tagged](https://github.com/pointfreeco/swift-tagged) library.\n\n```diff\n dependencies: [\n   .package(\n     url: \"https://github.com/pointfreeco/swift-structured-queries\",\n     from: \"0.28.0\",\n+    traits: [\n+      \"StructuredQueriesCasePaths\",\n+      \"StructuredQueriesTagged\",\n+    ],\n   ),\n+  .package(\n+    url: \"https://github.com/pointfreeco/swift-case-paths\",\n+    from: \"1.0.0\"\n+  ),\n+  .package(\n+    url: \"https://github.com/pointfreeco/swift-tagged\",\n+    from: \"0.1.0\"\n+  ),\n ]\n```\n\n\u003e [!IMPORTANT]\n\u003e As shown above, you _must_ explicitly depend on `swift-case-paths` and/or `swift-tagged` depending\n\u003e on the trait(s) you enable to work around a Swift bug.\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/swift-structured-queries/discussions) tab of this\n    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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpointfreeco%2Fswift-structured-queries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpointfreeco%2Fswift-structured-queries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpointfreeco%2Fswift-structured-queries/lists"}