Git Product home page Git Product logo

swift-cloudant's Introduction

swift-cloudant

Version Platform Build Status

Applications use swift-cloudant to store, index and query remote JSON data on Cloudant or CouchDB.

Swift-Cloudant is an Apache CouchDB™ client written in Swift 3. It is built by Cloudant and is available under the Apache 2.0 license.

Early-Release

This is an early-release version of the library, with support for the following operations:

  • Getting documents by doc ID.
  • Updating and deleting documents.
  • Creating and deleting databases.
  • Changes Feed operations
  • Creating, updating and deleting of attachments.
  • Querying views.
  • Creating, deleting and querying indexes.

We will be rounding out the feature set in upcoming releases.

Currently it does not support being called from Objective-C.

Support

SwiftCloudant is supported, however since it is an early release it is on a "best effort" basis.

Platforms

Currently Swift Cloudant suppports:

  • macOS

Swift Cloudant is unsupported on:

  • iOS (should work, but hasn't been tested)
  • tvOS
  • watchOS
  • Linux (see issue #121 for progress updates)

Using in your project

SwiftCloudant is available using the Swift Package Manager and CocoaPods.

To use with CocoaPods add the following line to your Podfile:

pod 'SwiftCloudant', :git => 'https://github.com/cloudant/swift-cloudant.git'

To use with the swift package manager add the following line to your dependencies in your Package.swift:

.Package(url: "https://github.com/cloudant/swift-cloudant.git")

Overview of the library

import SwiftCloudant

// Create a CouchDBClient
let cloudantURL = NSURL(string:"https://username.cloudant.com")!
let client = CouchDBClient(url:cloudantURL, username:"username", password:"password")
let dbName = "database"

// Create a document
let create = PutDocumentOperation(id: "doc1", body: ["hello":"world"], databaseName: dbName) {(response, httpInfo, error) in
    if let error = error {
        print("Encountered an error while creating a document. Error:\(error)")
    } else {
        print("Created document \(response?["id"]) with revision id \(response?["rev"])")
    }
}
client.add(operation:create)

// create an attachment
let attachment = "This is my awesome essay attachment for my document"
let putAttachment = PutAttachmentOperation(name: "myAwesomeAttachment",
    contentType:"text/plain",
    data: attachment.data(using: NSUTF8StringEncoding, allowLossyConversion: false),
    documentID: "doc1"
    revision: "1-revisionidhere",
    databaseName: dbName) { (response, info, error) in
        if let error = error {
            print("Encountered an error while creating an attachment. Error:\(error)")
        } else {
            print("Created attachment \(response?["id"]) with revision id \(response?["rev"])")
        }       
    }   
client.add(operation: putAttachment)

// Read a document
let read = GetDocumentOperation(id: "doc1", databaseName: dbName) { (response, httpInfo, error) in
    if let error = error {
        print("Encountered an error while reading a document. Error:\(error)")
    } else {
        print("Read document: \(response)")
    }   
}
client.add(operation:read)

// Delete a document
let delete = DeleteDocumentOperation(id: "doc1",
    revision: "1-revisionidhere",
    databaseName: dbName) { (response, httpInfo, error) in
    if let error = error {
        print("Encountered an error while deleting a document. Error: \(error)")
    } else {
        print("Document deleted")
    }   
}
client.add(operation:delete)

Requirements

Currently they are no third party dependencies.

Contributors

See CONTRIBUTORS.

Contributing to the project

See CONTRIBUTING.

License

See LICENSE

swift-cloudant's People

Contributors

rhyshort avatar mikerhodes avatar ricellis avatar smithsz avatar xpqz avatar tfrank64 avatar

Watchers

James Cloos avatar Ian Partridge avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.