Kitura-CouchDB is a pure Swift client which allows Kitura applications to interact with a CouchDB database.
Add the Kitura-CouchDB
package to the dependencies within your application’s Package.swift
file. Substitute "x.x.x"
with the latest Kitura-CouchDB
release.
.package(url: "https://github.com/IBM-Swift/Kitura-CouchDB.git", from: "x.x.x")
Add CouchDB
to your target's dependencies:
.target(name: "example", dependencies: ["CouchDB"]),
import CouchDB
The CouchDBSample executable demonstrates how to create, read, update and delete documents within a CouchDB database in Swift.
-
Download CouchDB and install.
-
Set up an admin username and password in CouchDB.
-
Create a database with the name
kitura_test_db
. -
Clone this repository:
git clone https://github.com/IBM-Swift/Kitura-CouchDB.git
-
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):let connProperties = ConnectionProperties( host: host, // httpd address port: port, // httpd port secured: secured, // https or http username: nil, // admin username password: nil // admin password )
-
Open a Terminal window, change into the
Kitura-CouchDB
folder and runswift build
:swift build
-
Run the CouchDBSample executable:
.build/debug/CouchDBSample
You will 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.
For a more comprehensive example, you can follow the Kitura tutorial Getting Started with Server-side Swift on raywenderlich.com that shows you how to create a backend API and then link this to a CouchDB instance running on your local machine.
For more information visit our API reference.
We love to talk server-side Swift, and Kitura. Join our Slack to meet the team!
This library is licensed under Apache 2.0. Full license text is available in LICENSE.