Swiftpack.co - Package - IBM-Swift/Kitura-CouchDB

Kitura

APIDoc Build Status - Master macOS Linux Apache 2 Slack Status

Kitura-CouchDB

Kitura-CouchDB is a pure Swift client which allows Kitura applications to interact with a CouchDB database.

Usage

Add dependencies

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 package

import CouchDB

Use Kitura-CouchDB locally

The CouchDBSample executable demonstrates how to create, read, update and delete documents within a CouchDB database in Swift.

  1. Download CouchDB and install.

  2. Set up an admin username and password in CouchDB.

  3. Create a database with the name kitura_test_db.

  4. Clone this repository:

    git clone https://github.com/IBM-Swift/Kitura-CouchDB.git
    
  5. 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
    )
    
  6. Open a Terminal window, change into the Kitura-CouchDB folder and run swift build:

    swift build
    
  7. 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.

Example

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.

API Documentation

For more information visit our API reference.

Community

We love to talk server-side Swift, and Kitura. Join our Slack to meet the team!

License

This library is licensed under Apache 2.0. Full license text is available in LICENSE.