{"id":13428729,"url":"https://github.com/PerfectlySoft/Perfect-SQLite","last_synced_at":"2025-03-16T01:33:25.957Z","repository":{"id":8256806,"uuid":"55420623","full_name":"PerfectlySoft/Perfect-SQLite","owner":"PerfectlySoft","description":"A stand-alone Swift wrapper around the SQLite 3 client library.","archived":false,"fork":false,"pushed_at":"2022-05-18T18:27:31.000Z","size":211,"stargazers_count":51,"open_issues_count":6,"forks_count":19,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-15T02:20:08.843Z","etag":null,"topics":["database","perfect","server-side-swift","sqlite","sqlite3","swift"],"latest_commit_sha":null,"homepage":"https://www.perfect.org","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PerfectlySoft.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}},"created_at":"2016-04-04T15:02:34.000Z","updated_at":"2025-02-08T06:43:45.000Z","dependencies_parsed_at":"2022-11-28T10:38:43.597Z","dependency_job_id":null,"html_url":"https://github.com/PerfectlySoft/Perfect-SQLite","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-SQLite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-SQLite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-SQLite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-SQLite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PerfectlySoft","download_url":"https://codeload.github.com/PerfectlySoft/Perfect-SQLite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814905,"owners_count":20352037,"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":["database","perfect","server-side-swift","sqlite","sqlite3","swift"],"created_at":"2024-07-31T01:01:03.662Z","updated_at":"2025-03-16T01:33:25.634Z","avatar_url":"https://github.com/PerfectlySoft.png","language":"Swift","readme":"# Perfect - SQLite Connector\n\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"http://perfect.org/get-involved.html\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://perfect.org/assets/github/perfect_github_2_0_0.jpg\" alt=\"Get Involed with Perfect!\" width=\"854\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/PerfectlySoft/Perfect\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_1_Star.jpg\" alt=\"Star Perfect On Github\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"http://stackoverflow.com/questions/tagged/perfect\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/perfect_gh_button_2_SO.jpg\" alt=\"Stack Overflow\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"https://twitter.com/perfectlysoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_3_twit.jpg\" alt=\"Follow Perfect on Twitter\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"http://perfect.ly\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_4_slack.jpg\" alt=\"Join the Perfect Slack\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://developer.apple.com/swift/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat\" alt=\"Swift 4.0\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://developer.apple.com/swift/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Platforms-OS%20X%20%7C%20Linux%20-lightgray.svg?style=flat\" alt=\"Platforms OS X | Linux\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://perfect.org/licensing.html\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/License-Apache-lightgrey.svg?style=flat\" alt=\"License Apache\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://twitter.com/PerfectlySoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Twitter-@PerfectlySoft-blue.svg?style=flat\" alt=\"PerfectlySoft Twitter\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://perfect.ly\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://perfect.ly/badge.svg\" alt=\"Slack Status\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nThis project provides a Swift wrapper around the SQLite 3 library.\n\nThis package builds with Swift Package Manager and is part of the [Perfect](https://github.com/PerfectlySoft/Perfect) project. It was written to be stand-alone and so does not require PerfectLib or any other components.\n\nEnsure you have installed and activated the latest Swift 4.0 tool chain.\n\nTo learn more, you can read the full documentation guide [here](https://github.com/PerfectlySoft/PerfectDocs/blob/master/guide/SQLite.md) or jump to the example [here](#Usage-Example)\n\n\n## Linux Build Notes\n\nEnsure that you have installed sqlite3.\n\n```\nsudo apt-get install sqlite3\n```\n\n## Building\n\nAdd this project as a dependency in your Package.swift file.\n\n```\n.Package(url: \"https://github.com/PerfectlySoft/Perfect-SQLite.git\", majorVersion: 3)\n```\n\n### Edge Case\nIf you encounter error like such ``` sqlite3.h file not found ``` during ```$ swift build ```, one solution is to install the sqlite3-dev i.e. ```$ sudo apt-get install libsqlite3-dev```\n\n\n## Usage Example\n\nLet’s assume you’d like to host a blog in Swift. First we need tables. Assuming you’ve created an SQLite file `./db/database`, we simply need to connect and add the tables. \n\n```swift\nlet dbPath = \"./db/database\"\n\ndo {\n\tlet sqlite = try SQLite(dbPath)\n\tdefer {  \n\t\tsqlite.close()\n\t}\n\n\ttry sqlite.execute(statement: \"CREATE TABLE IF NOT EXISTS posts (id INTEGER PRIMARY KEY NOT NULL, post_title TEXT NOT NULL, post_content TEXT NOT NULL, featured_image_uri TEXT NOT NULL)\")\n} catch {\n\tprint(\"Failure creating database tables\") //Handle Errors\n}\n```\n\nNext, we would need to add some content. \n\n```swift\nlet dbPath = \"./db/database\"\nlet postTitle = \"Test Title\"\nlet postContent = \"Lorem ipsum dolor sit amet…\"\n\ndo {\n   let sqlite = try SQLite(dbPath)\n   defer {\n     sqlite.close()\n   }\n\n   try sqlite.execute(statement: \"INSERT INTO posts (post_title, post_content) VALUES (:1,:2)\") {\n     (stmt:SQLiteStmt) -\u003e () in\n\n     try stmt.bind(position: 1, postTitle)\n     try stmt.bind(position: 2, postContent)\n   }\n } catch {\n\t\t//Handle Errors\n }\n```\n\nFinally, we retrieve posts and post titles from an SQLite database full of blog content. Each id, post, and title is appended to a dictionary for use elsewhere. \n\n``` swift\nlet dbPath = \"./db/database\"\nvar contentDict = [String: Any]()\n\ndo {\n\tlet sqlite = try SQLite(dbPath)\n\t\tdefer {\n\t\t\tsqlite.close() // This makes sure we close our connection.\n\t\t}\n\t\n\tlet demoStatement = \"SELECT post_title, post_content FROM posts ORDER BY id DESC LIMIT :1\"\n\t\n\ttry sqlite.forEachRow(statement: demoStatement, doBindings: {\n\t\t\n\t\t(statement: SQLiteStmt) -\u003e () in\n\t\t\n\t\tlet bindValue = 5\n\t\ttry statement.bind(position: 1, bindValue)\n\t\t\n\t}) {(statement: SQLiteStmt, i:Int) -\u003e () in\n\n        self.contentDict.append([\n                \"id\": statement.columnText(position: 0),\n                \"second_field\": statement.columnText(position: 1),\n                \"third_field\": statement.columnText(position: 2)\n            ])\n  }\n\t\n} catch {\n\t//Handle Errors\n}\n```\n\n## Further Information\nFor more information on the Perfect project, please visit [perfect.org](http://www.perfect.org/docs/SQLite.html).\n","funding_links":[],"categories":["Database","Packages","Database Connectors","Swift"],"sub_categories":["Other free courses","Database","SQLite"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPerfectlySoft%2FPerfect-SQLite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPerfectlySoft%2FPerfect-SQLite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPerfectlySoft%2FPerfect-SQLite/lists"}