{"id":13505013,"url":"https://github.com/Kitura/Kitura-CouchDB","last_synced_at":"2025-03-29T22:31:22.659Z","repository":{"id":47641765,"uuid":"51158521","full_name":"Kitura/Kitura-CouchDB","owner":"Kitura","description":"CouchDB adapter for Kitura","archived":false,"fork":false,"pushed_at":"2021-08-19T09:47:22.000Z","size":822,"stargazers_count":50,"open_issues_count":12,"forks_count":28,"subscribers_count":33,"default_branch":"master","last_synced_at":"2024-05-21T06:06:48.330Z","etag":null,"topics":["cloudant","couchdb","couchdb-client","database","kitura","nosql"],"latest_commit_sha":null,"homepage":"","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/Kitura.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-05T16:28:14.000Z","updated_at":"2022-05-28T13:17:15.000Z","dependencies_parsed_at":"2022-09-23T14:42:47.558Z","dependency_job_id":null,"html_url":"https://github.com/Kitura/Kitura-CouchDB","commit_stats":null,"previous_names":["ibm-swift/kitura-couchdb"],"tags_count":73,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitura%2FKitura-CouchDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitura%2FKitura-CouchDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitura%2FKitura-CouchDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitura%2FKitura-CouchDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kitura","download_url":"https://codeload.github.com/Kitura/Kitura-CouchDB/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246254077,"owners_count":20747946,"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":["cloudant","couchdb","couchdb-client","database","kitura","nosql"],"created_at":"2024-08-01T00:00:56.853Z","updated_at":"2025-03-29T22:31:20.395Z","avatar_url":"https://github.com/Kitura.png","language":"Swift","funding_links":[],"categories":["Packages"],"sub_categories":["Database"],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"http://kitura.dev/\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/Kitura/Kitura/master/Sources/Kitura/resources/kitura-bird.svg?sanitize=true\" height=\"100\" alt=\"Kitura\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://ibm-swift.github.io/Kitura-CouchDB/index.html\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/apidoc-KituraCouchDB-1FBCE4.svg?style=flat\" alt=\"APIDoc\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://travis-ci.org/Kitura/Kitura-CouchDB\"\u003e\n    \u003cimg src=\"https://travis-ci.org/Kitura/Kitura-CouchDB.svg?branch=master\" alt=\"Build Status - Master\"\u003e\n    \u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/badge/os-macOS-green.svg?style=flat\" alt=\"macOS\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/os-linux-green.svg?style=flat\" alt=\"Linux\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-Apache2-blue.svg?style=flat\" alt=\"Apache 2\"\u003e\n    \u003ca href=\"http://swift-at-ibm-slack.mybluemix.net/\"\u003e\n    \u003cimg src=\"http://swift-at-ibm-slack.mybluemix.net/badge.svg\" alt=\"Slack Status\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n# Kitura-CouchDB\n\nKitura-CouchDB is a pure Swift client which allows Kitura applications to interact with a CouchDB or Cloudant database.\n\n## Usage\n\n#### Add dependencies\n\nAdd the `Kitura-CouchDB` package to the dependencies within your application’s `Package.swift` file. Substitute `\"x.x.x\"` with the latest `Kitura-CouchDB` [release](https://github.com/Kitura/Kitura-CouchDB/releases).\n\n```swift\n.package(url: \"https://github.com/Kitura/Kitura-CouchDB.git\", from: \"x.x.x\")\n```\n\nAdd `CouchDB` to your target's dependencies:\n\n```swift\n.target(name: \"example\", dependencies: [\"CouchDB\"]),\n```\n\n#### Import package\n\n```swift\nimport CouchDB\n```\n\n## Run Kitura-CouchDB Sample\n\nTo run the CouchDB Sample, you must set up and connect to a local CouchDB database by following the steps below:\n\n1. [Download and install CouchDB.](http://couchdb.apache.org/#download)\n\n2. Set up an admin username and password in CouchDB.\n\n3. Create a database with the name `kitura_test_db`.\n\n4. Clone this repository:\n\n    ```bash\n    git clone https://github.com/Kitura/Kitura-CouchDB.git\n    ```\n\n5. Update the following code in `Sources\\CouchDBSample\\main.swift` with your admin username and password (the host will default to 127.0.0.1 and the port will default to 5984):\n\n    ```swift\n    let connProperties = ConnectionProperties(\n        host: host,         // http address\n        port: port,         // http port\n        secured: secured,   // https or http\n        username: nil,      // admin username\n        password: nil       // admin password\n    )\n    ```\n\n6. Open a Terminal window, change into the `Kitura-CouchDB` folder and run `swift build`:\n\n    ```bash\n    swift build\n    ```\n\n7. Run the CouchDBSample executable:\n\n    ```bash\n    .build/debug/CouchDBSample\n    ```\n\n    You should see informational messages such as \"Successfully created the following JSON document in CouchDB:\" for each of the operations (create, read, update and delete) performed on the `kitura_test_db` database.\n\n## API Documentation\n\n#### Document\n\nCouchDB is a NoSQL database for storing documents. A `Document` is any structure that can be represented as JSON and contains `_id` and `_rev` fields.  \n - The `_id` field is the unique identifier for the document. If it is not set, a random UUID will be assigned for the document.  \n - The `_rev` field is the revision of the document. It is returned when you make requests and is used to prevent conflicts from multiple users updating the same document.  \n\nTo define a CouchDB document, create a Swift object and make it conform to the `Document` protocol:\n ```swift\n struct MyDocument: Document {\n    let _id: String?\n    var _rev: String?\n    var value: String\n}\n ```\n\n#### CouchDBClient\n\nThe `CouchDBClient` represents a connection to a CouchDB server. It is initialized with your `ConnectionProperties` and handles the creation, retrieval and deletion of CouchDB databases.\n\n```swift\n// Define ConnectionProperties\nlet conProperties = ConnectionProperties(\n    host: \"127.0.0.1\",              // http address\n    port: 5984,                     // http port\n    secured: false,                 // https or http\n    username: \"\u003cCouchDB-username\u003e\", // admin username\n    password: \"\u003cCouchDB-password\u003e\"  // admin password\n)\n// Initialize CouchDBClient\nlet couchDBClient = CouchDBClient(connectionProperties: conProperties)\n```\n- Create a new database\n\n```swift\ncouchDBClient.createDB(\"NewDB\") { (database, error) in\n    if let database = database {\n        // Use database\n    }\n}\n```\n- Get an existing database\n\n```swift\ncouchDBClient.retrieveDB(\"ExistingDB\") { (database, error) in\n    if let database = database {\n        // Use database\n    }\n}\n```\n- Delete a database\n\n```swift\ncouchDBClient.deleteDB(\"ExistingDB\") { (error) in\n    if let error = error {\n        // Handle the error\n    }\n}\n```\n\n#### Database\n\nThe `Database` class is used to make HTTP requests to the corresponding CouchDB database. This class can make CRUD (Create, Retrieve, Update, Delete) requests for:\n\n- A single CouchDB `Document`\n- An array of CouchDB documents\n- A CouchDB `DesignDocument`\n- A `Document` attachment\n\nThe following code demonstrates the CRUD operations for a single `Document`:  \n\n```swift\nvar myDocument = MyDocument(_id: \"Kitura\", _rev: nil, value: \"Hello World\")\n```\n- Create a Document:  \n\n```swift\ndatabase.create(myDocument) { (response, error) in\n    if let response = response {\n        print(\"Document: \\(response.id), created with rev: \\(response.rev)\")\n    }\n}\n```\n- Retrieve a Document:  \n\n```swift\ndatabase.retrieve(\"Kitura\") { (document: MyDocument?, error: CouchDBError?) in\n    if let document = document {\n        print(\"Retrieved document with value: \\(document.value)\")\n    }\n}\n```\n- Update a Document:  \n\n```swift\nmyDocument.value = \"New Value\"\ndatabase.update(\"Kitura\", rev: \"\u003clatest_rev\u003e\", document: myDocument) { (response, error) in\n    if let response = response {\n        print(\"Document: \\(response.id), updated\")\n    }\n}\n```\n- Delete a Document:  \n\n```swift\ndatabase.delete(\"Kitura\", rev: \"\u003clatest_rev\u003e\") { (error) in\n    if error == nil {\n        print(\"Document successfully deleted\")\n    }\n}\n```\n\nFor more information visit our [API reference](https://ibm-swift.github.io/Kitura-CouchDB/index.html).\n\n## Community\nWe love to talk server-side Swift, and Kitura. Join our [Slack](http://swift-at-ibm-slack.mybluemix.net/) to meet the team!\n\n## License\nThis library is licensed under Apache 2.0. Full license text is available in [LICENSE](https://github.com/Kitura/Kitura-CouchDB/blob/master/LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKitura%2FKitura-CouchDB","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKitura%2FKitura-CouchDB","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKitura%2FKitura-CouchDB/lists"}